How to generate a piano sound using SPI

Hi,

Does anyone know how to generate a piano waveform using SPI? =( I wanted to be able to output piano sound using a 12bit DAC. Any suggestions and comments are greatly appreciated! >__<

Thanks.. :blush:

I would suggest finding the model of your DAC, then locate the data sheet and search for examples on the forums and google, there is a good chance someone has done a write up on it.
Once you have a working example you can then focus on producing specific sounds.

The idea is simple. You have a code that makes the DAC output a sinusoidal waveform that decreases in output level ovre time:
/
_/ /_

You can store the values you want in a table, and change the frequency you write them out to change the note.
This yields a 0-5V output, so run that thru a capacitor before going into an amplifier to achieve a +/-2.5V signal.

A piano has a very complicated waveform with complex dynamics. I doubt that an Arduino can replicate it on the fly. Your best bit is a GM synthesizer chip where you can send midi messages.

Like this:

An arduino might come close to making some kind of neatish sound.
I took a 12-bit DAC and ramped it full up & full down, 0-4095-0, achieved 4KHz I think without doing much special.
So the upper frequency would be limited, and it'd hard to have it play a lot of notes and keep the frequency up I would think.
I have some dual DACs with SPI interface, will have to try it some time.
Or get some octal DACs with SPI interface

or 16 channel

and try that.
But I only have 10 fingers, so 8 seems like plenty, and you run out of cycles to udpate them all anyway.
Maybe just a single per uC and just have multiple uC modules, and do an analog mix before going into an amp. Then play with hold & sustain pedal, have speed sensitive trigger capture, etc.
Then the DACs are only $1 each.

Still need to come up with the waveform you want them to play too.

CrossRoads:
An arduino might come close to making some kind of neatish sound.
I took a 12-bit DAC and ramped it full up & full down, 0-4095-0, achieved 4KHz I think without doing much special.
So the upper frequency would be limited, and it'd hard to have it play a lot of notes and keep the frequency up I would think.
I have some dual DACs with SPI interface, will have to try it some time.
Or get some octal DACs with SPI interface
http://www.digikey.com/scripts/dksearch/dksus.dll?FV=fff40027%2Cfff80184%2C2640004&k=dac&vendor=0&mnonly=0&newproducts=0&ptm=0&fid=0&quantity=0&PV1173=9&stock=1
or 16 channel
http://www.digikey.com/scripts/dksearch/dksus.dll?FV=fff40027%2Cfff80184%2C2640004&k=dac&vendor=0&mnonly=0&newproducts=0&ptm=0&fid=0&quantity=0&PV1173=11&stock=1
and try that.
But I only have 10 fingers, so 8 seems like plenty, and you run out of cycles to udpate them all anyway.
Maybe just a single per uC and just have multiple uC modules, and do an analog mix before going into an amp. Then play with hold & sustain pedal, have speed sensitive trigger capture, etc.
Then the DACs are only $1 each.
http://www.digikey.com/product-detail/en/MCP4725A0T-E%2FCH/MCP4725A0T-E%2FCHCT-ND/1817328

Still need to come up with the waveform you want them to play too.

Hi Robert,

Thank you for your reply. I was thinking about a wavetable synthesis using the 12-bit DAC. And I was able to get a piano wave. However, I am facing with a math problem. I do not quite know how to genrate different pitch. I know that if I increment my pointer at a fixed rate but by a different value I can get various pitch. But it will be a fractional increment and I am really new to it. I know if I increment by two I will get an octave higher, but I want to increment by a fraction. Have you done that before? All help is appreciated!

Thanks,
Chloe

I have not. The base frequency of notes are well published, like A = 440,
http://coba.belmont.edu/fac/tappant/piano.htm
so taking your wavetable and applying some excel to it should get you going down the right path.

For a tempered scale? (usage) the notes vary by the 12th root of 2 or 1.0594630943592952645618252949463 un necessary? a float difficult to generate or use... Perhaps it might be best to use a top octave look-up table and divide it down for the lower octaves.
Mostek made a chip years back that was just that and the square waves were divided down and then used as either the direct shaped output or as sync for other waveform generators, all from a 3.58 MHz crystal. They are still available on Ebay... At $40 - $60.00 Ea. a whole lot of electronic organs used them for many years.

Doc

How many samples are in your piano wave? Where will you store them?

This might help with the 'fractional values' -

Duane B

rcarduino.blogspot.com

You might table a sine wave and then vary the pitch by how fast you shove the data through the DAC.

Also look up ADSR envelope to see about volume control.

Best move, get a sound chip with MIDI and room for 'effects' like reverb, etc. MIDI w/o effects takes a lot of work to sound good.