Go Down

Topic: How to play Raw audio? (Read 16233 times) previous topic - next topic


I have sent raw audio from my Arduino to a Web Host and saved it as a file.  How can I play it on my PC?  iPhone?  Browser?  There is no Wav header.  No compression.  Just raw 8-bit per sample PCM data.  I'd like to make it easy for the end user.  But first I need an idea that I can test myself no matter how difficult it is?


Nov 11, 2013, 06:05 am Last Edit: Nov 11, 2013, 06:09 am by jremington Reason: 1
What is the sample rate?  If 8 kHz, this would be the DS0 international telephony standard (64 kbits/sec). There might be an application that could play that as audio.

Edit: evidently most DS0 signals are 12 or 13 bits compressed to 8. From wikipedia:
In telephony, a standard audio signal for a single phone call is encoded as 8,000 analog samples per second, of 8 bits each, giving a 64 kbit/s digital signal known as DS0. The default signal compression encoding on a DS0 is either ?-law (mu-law) PCM (North America and Japan) or A-law PCM (Europe and most of the rest of the world). These are logarithmic compression systems where a 12 or 13-bit linear PCM sample number is mapped into an 8-bit value. This system is described by international standard G.711.


I can change the sample rate to any reasonable value.  I have an algorithm to convert to ulaw before I even send it.  But how do I play it back to test it myself?  How do I make it easier for the end user?  Would it help to make a Wav header?  I have done this years ago.  Not sure if that goes with ulaw compression. 


Probably the easiest way to proceed is to convert the raw file into a .wav file. The header format is not that complicated and the file type does appear to support uncompressed 8 bit PCM data.

There is available a standard C code library, called libsndfile, that does most of the work for a variety of sound file formats. One description of libsndfile is at http://www.mega-nerd.com/libsndfile/api.html

Some simple example programs are included in the source tarball. For code development on Windoze, I like Code::Blocks (free).


Since the PCM samples are originating from the Arduino, why don't you add the header before sending it?
You know the sample rate, the number of channels and bits per sample so it's straight forward.
The wav format is pretty simple and the Arduino is more than capable of adding the header with very little overhead.

A note of warning though, since you want to be able to play the resulting sound in all sorts of browsers (pc, smarthones, tablets), first make sure that the browsers on those devices do actually support the wav format.
(see  attached table for Win 7 support of wav in some common browsers).

The link below will give you a better idea of the wav file structure:



Nov 11, 2013, 07:03 pm Last Edit: Nov 11, 2013, 09:11 pm by jremington Reason: 1
It is interesting that according to the table in the previous post, Internet Explorer 9 doesn't play .wav format files (which Microsoft defined).


I saw that bit it didn't surprise me in the least.
They are masters at things like that.

Come across some html files once that just didn't display properly on I.E. 9, nothing strange there until I read the html code and guess what was in the META GENERATOR tag?

Yep, "Microsoft Word"   :)


I have sent raw audio from my Arduino to a Web Host and saved it as a file

Another possible way:

Does the web host you refer to have any cgi capabilities?
If so, you could write a script in Perl/PHP/ASP to automatically add the header or even convert it to other formats that could not be easily done on the Arduino, like MP3 or Ogg.


I think we're on the right track with the WAV header.  But then I can't use uLaw compression?  I'm sure I can figure out how to play a WAV file by referencing the file URL with a specific browser.  How can I make it easy for everyone else regardless of their browser?  Is there some sort of website where I can pass the WAV file URL and it will play thru the browser?


Is there a Flash or Java player I can embed on my web site? 
One that plays uncompressed PCM?  uLaw?


Nov 12, 2013, 12:26 am Last Edit: Nov 12, 2013, 12:50 am by UnoDueTre Reason: 1

I think we're on the right track with the WAV header.  But then I can't use uLaw compression?

wav files do support compression but I cannot tell you if uLaw is specifically supported and under which platforms.
If there is any compression, it is usually indicated in the header (offset 20).
You will have to do some research on that.

I'm sure I can figure out how to play a WAV file by referencing the file URL with a specific browser.  How can I make it easy for everyone else regardless of their browser?  Is there some sort of website where I can pass the WAV file URL and it will play thru the browser?

I don't quite understand your question.
I was under the impression that you upload your sound file to a server (web host as you put it) thus it will already have a URL associated with it.
For example:
h t t p://www.YourServer.com/SomePath/YourWav.wav
Now if it has a header (whether inserted by the Arduino or a server-side script) then you simply point the user to that URL
and provided that their browser plays wavs, they will hear it.

You don't need flash or js as that just adds another layer of complexity.


Js is not  server-side it's client side so that would mean the users device would first have to download the audio, cache it locally, process it then only play it.
With flash, the swf will have to be either "pre-compiled" or compiled on the fly then you hope/assume that the user has flash on his/her device.
If you have to process the raw audio on the server, then rather use something like Perl or PHP to take the raw samples and make a more generic mp3 out of it.
Consult with your hosting provider as many already have Perl or PHP enabled and the libs for them to create mp3 (or something else) are easily available.
The conversion would be automatic as you would post to the script, it would process the data and place it in a predefined directory on the server and thus you will have the URL.


For now, keep things simple, make the Arduino add the header before uploading the wav file.
Then test on as many browsers as you can, which support wav and which don't.

Depending on the results, you can then take another route if required.


I second the suggestion to have the Arduino add the wav header. There are plenty of tools on line to convert .wav files into something else, so if necessary you could post two versions of each file (.mp3 ?) side by side on your web site. When users click on a link, the browsers are supposed to know how to handle the file extension, even if Internet Explorer doesn't know what to do with Micro$oft's .wav.


What I had in mind was an automated process as shown in the attached diagram.


Thanks for all of your timely advice!  If I make the WAV header on the Uno, I can use HTML5 which works with an Iphone Browser like this:

Since I already have uLaw data, I can add a much simpler header, only a few bytes.  Then play with this Flash Player on most browsers, but not iPhone.  The advantage is half the data size and more customization.

I wish I could have the best of both worlds in one file, but instead I will have to implement both?
So it will run on all platforms.

Go Up