Piezo Buzzer question

26 Jun 2015

I am trying an AC piezo buzzer with mbed. I know how to generate a single tone sound using PWM and how to generate simple sounds by varying the PWM frequency (that is setting two arrays, one for frequencies and the other for durations and then changing the PWM frequency after the time defined in duration has elapsed).

My question is: how can I build the two arrays (frequencies and durations) from a generic sound I have in the form of a .mp3 or .wav or .mid file?

Is it possible to define the two arrays in a way to create some sort of voice?

Thanks.

26 Jun 2015

MIDI may be easiest. A MIDI sequence is already defined as a series of musical tones (freq and duration). Converting an mp3 or wav file is more difficult. You may have to do some sort of FFT to extract the spectrum at regular intervals and generate the tones accordingly. That will only work when the sound consists of a series of single frequencies. The alternative is to take the sound amplitude samples in the wav file and use an analog output pin instead of PWM. Third option is to generate analog outputs using a high freq PWM output and lowpass filter that signal.

26 Jun 2015

If I have a .mid file is there some software then can extract the (freq , duration) sequence and save it as a txt file?

28 Jun 2015

I dont have experience with midi, but google provides this link for converting midi to csv files: http://www.fourmilab.ch/webtools/midicsv/