Jukebox

A basic tune player written in C.

: C

Concepts Used

  • Structural Programming
  • Musical notations
  • Windows/DOS C Api

Features

  • Can play about 4 tunes.
  • Easy to navigate CLI
  • Basic Text animation.

Code


Introduction

Once in the Turbo C++ , running on dos, which they still use to teach C in colleges, I came across this functions in dos.h :

  • sound(<freq>) : to make sound of a specified frequency
  • delay(<time>) : delay in milliseconds
  • nosound() : stop sound

These could be used to make my own tunes!

I had learned to play the guitar in school years. Even though I suck at it big time, I do remember how to read and understand sheet music.

And thus, I sat down transcoding simple tunes like :

  • Frolic
  • Old MacDonald
  • Sparkling Stella
  • Buffalo Gals

Then one day I learned that in windows.h, in C++ there is function called beep(<freq>,<time>) which replaces 4 lines of old codes each, and it works in modern PCs. So I changed it all again and this time I added a resource file with icon for the program, which builds to a .exe .

Working

I had determined the frequency of the notes on the guitar and gave them as inputs to the sound function in C and later the beep functions in C++.

Then I figured out a beat duration. In sheet music notes:

  • 1 full note lasts 4 beats
  • A Half note lasts 2 beats
  • A Quarter note lasts 1 beat

Accordingly I used the note freqency and beat duration and with a combination of for loops I made the program make the sounds as needed to play different tunes.

The following tunes are hardcoded into the program:

  • Sparkling Stella
  • Old McDonald
  • Frolic(My Favourite)
  • Buffalo Gals

You get to select the tune in the beginning. When the tune is playing, a starry background plays using the blink function..

Conclusion

I had fun doing this project as I could finally use my musical knowlegde, in my own way..