WavePlayer

06 Dec 2009

So I imported WavePlayer into my compiler... click compile and I am getting a bunch off errors.  I am new to mbed and maybe I am missing something.  Anybody tried this program before?  I searched but this forum is a real mess.

06 Dec 2009

Hey Sam,

The reason that this is not compiling is because some of the code was written for the old mbed boards. For example pin declarations;

AnalogOut DACout(18);

should be
AnalogOut DACout(p18);
I can try and rewrite this code for you.

06 Dec 2009 . Edited: 06 Dec 2009

Hey Sam,

I have rewritten the code with new updated libraries and the wav should now play, I have not tested it as I dont have a SD card reader (waiting for sparkfun's FREE day)

Try it out, and let me know how it works for you

WavePlayer

The problem was since it was importing form a zip, it also had all the old mbed library version 7 I think, as well as the old FAT and SD card reader libraries, just changing the pins and updating the new libraries did it.

06 Dec 2009

Thanks very much.

02 Jan 2010

Hello Sam,

Have you tested this application ? I imported the WavePlayer too, I corrected the compiler errors and the application run smoothly on the mbed. I just do not have sound between p18 and gnd. Is there a specific wiring ?

Cheers,

Stephane

02 Jan 2010 . Edited: 02 Jan 2010

I have found the problem.

There are two write functions in AnalogOut. the "write" and the "write_u16" in line 186 or so.

Both Vlad and myself corrected the code using "write" which needs a float and the buffer used is made of shorts. So we have to use "write_u16" which stand for unsigned 16 bits int.

Now it plays the sound ! The output is very low so it needs amplification.

Here is the working application :WAVEplayer

04 Jan 2010

Hey guys, thanks for updating the code and sharing it.  In case you don't know, that code was originally written for my billy bass demo.  I updated billy to the latest mbed library but didn't do the same for the cookbook code.

One thing I didn't do, but which probably needs to be done, is to add a DC blocking circuit to pin 18 before connecting it to an amplifier.  The ADC can only produce a positive output voltage, so in order to keep the negative half of the waveform the whole thing needs a 1.65V offset.  I don't know if that may damage an amplifier (mine seems to work OK), but it does result in a lot of annoying pops and clicks.

--steve

04 Jan 2010

So I guess an Op-Amp like the LM358 and some resistors could do the job to do the 1.65v offset.

What kind of amplifier are you using ?

By the way I discovered mbed thru an article about your Billy Bass demo on Gizmodo in september. So if I am here, it is with your help ;-)

04 Jan 2010 . Edited: 04 Jan 2010

Probably, a simpler solution may be an audio isolation transformer or a blocking cap.

I used a cheap 9V powered amplifier from Radio Shack, and also some powered computer speakers.

--steve

05 Jan 2010

What lib did you use to transform text to speach for the Billy Bass demo ?

05 Jan 2010

The whole twitter/text to speech part was added by Simon and Rolf, so you'll have to ask them.  The text-to-speech wasn't done on the mbed, it was done by sending the text over the internet to a server "somewhere", and retrieving the speech from the server and playing it.  In the context of mbed, this is a more compelling demonstration of its rapid prototyping capabilities.  Any one of us could get a text to speech library and port it to mbed, that's a fairly straightforward task.  More surprising to potential developers is how easy it is to prototype an embedded gadget that is connected to the internet and can operate at a high level (understanding twitter, http get/post requests, etc.)

Check Simon's mbed account, he may have published that portion of his code.  I know there are twitter and http client/server examples both in the cookbook and published by individuals.

--steve

09 Mar 2010

Thanks for the WavePlayer code. It appears some wav files will work and some don't? I'm not sure why.

The included clint16.wav and baddonut.wav files work with the most recent WavePlayer program (from http://mbed.org/projects/cookbook/wiki/WavePlayer), but so far I haven't managed to find any others that do. I've tried a variety of sample rates and resolutions, but can still only get the included audio files to work. For example I couldn't get it to work with any of the example files I tried from wikipedia (http://en.wikipedia.org/wiki/WAV). I'm just wondering if I'm missing something obvious?

Basically, with any other wav files, the fopen command is not successful and returns NULL, given the unable to open error...

  wavfile=fopen(wavname,"rb");
  if (!wavfile) {
    printf("Unable to open wav file '%s'\n",wavname);
    exit(1);
  }

My SD card is working fine and all I am doing is changing the file name to that of another wav file on the same SD card, so I'm uncertain why the fopen command works for some .wav files and not for others, any ideas? I think this might be a wav file structure issue rather than an mbed issue to be fair.

robt

09 Mar 2010

You should download a program called audacity and convert your audio file to 16KHz and make sure that it is on 16bit, you also have to make sure you have it set to mono.

Here is a good tutorial on converting audio for play from SD card. http://www.ladyada.net/make/waveshield/convert.html

09 Mar 2010

Hi, thanks for a quick reply - unfortunately it hasn't solved the problem. I do all my wav manipulation in Wavelab 6 so have tried a number of different sample rates, resolutions etc. I've been working at 16kHz, 16-bit mono, but can still only get the provided example files to open. I tried Audacity too in order to double check Wavelab wasn't saving wav files with a different PCM or something, but that hasn't worked either I'm afraid. Bit of a mystery...

09 Mar 2010

I think theres an issue with underscores in the file name. For some reason 'sine_wav.wav' won't open but when I rename it 'sinewav.wav' it will. Problem kind of solved...  :)

10 Mar 2010

The SD card uses a FAT filesystem with 8.3 filenames.  I would think that sine_wav.wav would be fine but apparently not.

The WavePlayer code has been modified by others since I originally wrote it, but the original version should have been able to handle any number of audio channels (they are all averaged together before being sent to the single D/A) and any sample rate up until mbed can't keep up anymore.  I think some of the audio clips I used were 22 kHz.  It currently only plays 16 bit files but with just a couple lines of code could play 8 and 32 as well.  The switch statement is there but only the 16 bit case is coded :-)

--steve

22 Jul 2010

I'm trying to play back a file from a microSD. I've got the SD card working with foo txt. I also have a sawtooth working through the speaker. However, when I try and run wav player I get:

Hello, world!

Playing wave file '/sd/baddonut.wav'

Read chunk ID 0x46464952, size 0x27f70

RIFF chunk

chunk size 163696 (0x27f70)

RIFF type 0x45564157

Read chunk ID 0x20746d66, size 0x10

FORMAT chunk

chunk size 16 (0x10)

compression code 1

1 channels

11025 samples/sec

22050 bytes/sec

block align 2

16 bits per sample

Read chunk ID 0x61746164, size 0x27f4c

DATA chunk

chunk size 163660 (0x27f4c)

81830 slices

Ideal sample interval=90

programmed interrupt tick interval=90

 

----

Then it just sits there, any ideas anyone?

25 Jul 2010

I also had problems with the original WavePlayer.  I have modified it and placed it in a library.  Have a look at EA_WavPlayer this works fine for me.

26 Jul 2010

Hi Tom,

That's great, worked a treat thanks for your help.