Home > Hobby > A Musical Beginning!

A Musical Beginning!

This is my first blog!

I’ll be writing about the hobby project I did this Saturday and Sunday. Friday evening i had a thought of getting a bit musical. I don’t have any instrument with me. So decided on reviving one of my old project titled ‘project mozart’, which was originally written in C language for 8051 kind of microcontrollers. The 8051 I used for that couldn’t support anything more than 2MIPS. At that power only continuous notes, like that from a violin continuously bowed, could be produced. This ability alone didn’t satisfy me. So i decided to implement it in my newly bought Atmega32 controller, supporting upto 16MIPS.

I had architecture of the circuit, part in my mind, and part in the C file. The circuit is rather simple with a microcontroller, a DAC0808 digital to analog convertor, and a 741 op amp configured as a current to voltage convertor. Breadboarded it quickly. Then ported the C file to the new hardware.

My expectations out of the device were as follows. I wanted a device like a piano/synthesiser, that has 32keys (White + black). There are 12 keys per octave on a standard piano/keyboard. This touches 3 octaves, with 2 in full and one partial. For my design it stretched form 175.28Hz to 1108.7kHz. (F2 to C5). Another aim was to have a full polyphony. You can press any number of keys, you should get mixture of all that notes. In addition to this, another objective — to have the Attack-Decay-Sustain-Release sort of sound (sound similar to that of a bell, which is not continuous like a violin). The sample rate chosen was 2793.6kHz for legacy reason and because, anything more is not computationally possible on that 8 bit chip.

The working of the software is as follows (Sorry i can’t make it any simpler). The software would scan the keyboard and identify the keys pressed at approx. 10 times per second. For the keys pressed the timer ISR, would If a new key is pressed, corresponding sinusoidal signal will be played. The sinusoidal signal is made know to the program in the form of a table of size 256bytes, which together represented the values of a single cycle of a sinusoid. If I send each of the table values to the DAC in each sample interval again and again, cycling through the wavetable, I will get a sine wave of 2793.6/256 = 10.955Hz. If I send every 16th entry of the table to the DAC, i will get, 10.955*16=175.28Hz sine wave, which is almost F2. Similarly you can calculate which sample to be played with the help of a bit music theory, which you can learn from wikipedia.

By the method presented so far, we could only get continuous note like that of a violin/saxophone. I need notes like that of a piano/bell/guitar. For this I will generate an envelope based on the duration for which each key is pressed, and will multiply that envelope with the continuous signal produced. This way, I could do the Attack-Sustain-Release phases. The decay phase is yet to be implemented.

At this poor bit depth(8bit) and poor sample rate too, the sound looks pretty good. I know of some possible additions, like addition of wave tables for more real life instruments, a full attack-decay-sustain-release cycle for each instrument, better sampling rate, better bit depth for the sound etc…. Your suggestions and links to your project pages are welcome.

Advertisements
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: