tags:

views:

245

answers:

1

Hi,

I'm looking for a way to programmatically save an array of shorts as PCM data. I know that this should be possible, but I haven't found a very easy way to do this on Android.

Essentially, I'm taking voltage data, and I want to save it in PCM format. My function looks something like this:

  public void audifySignal(short[] signal) {
    // Create a WAV file from the incoming signal
  }

Any suggestions would be awesome, or even references. Seems like the audio APIs built in to android are more geared for directly recording from the mic, and not so much for lower level signal processing type work (at least for saving raw data to a file). I'd also like to avoid having to manually write the PCM file headers and what not...

Thanks!

A: 

Sam, I dunno about Android-specific libraries, but I'll go ahead and say this:

Raw PCM data is pretty straight forward. It's generally just sequential data. Maybe you need to understand the WAV format in order to understand what PCM is and how it works.

WAV is fairly widely used as a container for uncompressed audio. Gaining an understanding of how the WAV file contains the data will cast a fair bit of light on how raw digital audio works in general.

This page helped me a fair bit:

http://www.sonicspot.com/guide/wavefiles.html

Interestingly you can more or less fire ANY data at a sound-card and it'll play it. It'll probably sound crazy to us humans as the sound card doesn't care about whether it sounds garbled or not.

Whether it sounds pleasing to the ear or not will depend upon whether you've provided the correct sample size, number of channels, frequency and some PCM data that conforms to the former.

See you can't "detect" the sample size, the number of channels or the correct frequency from the raw PCM data itself. You have to store this crucial data ALONG with the PCM data so that other pieces of software can let the sound-card know how to handle your PCM data.

That's where the WAV container format comes in.

There are other formats but WAV is pretty commonplace and it's therefore a good place to start.

Cheers Tristen

Tristen