tags:

views:

756

answers:

1

Hi I have PCM samples in a short array. What is the best way to play this out? The format is 8000Hz, Mono, 16 bit, big endian. (The PCM samples are generated in the code and not read through some file)

Thanks

+1  A: 

With the javax.sound.sampled package it's pretty much straightforward, but you have to use some boilerplate.

Here's a good tutorial on that: www.wikijava.org/wiki/Play_a_wave_sound_in_Java

Basically you have to create an InputStream from your array and use that to create an AudioInputStream. There you have to specify the format of your audio data.

Then you open an output stream (SourceDataLine) and copy the bytes from the audio stream into that stream.

DR
Thanks for the tip. I tried this method but couldn't play the pcm data properly, I could only get noise. Probably some config issue with AudioFormat. But I found a work around: I dumped the pcm data to a FileOutputStream (/tmp/x.wav)and exec'd aplay command (alsa utility in linux) to play /tmp/x.wav.
Geos