Author Topic: Play/Save raw bytes  (Read 1536 times)

3coy

  • Posts: 5
Play/Save raw bytes
« on: 4 Dec '10 - 18:15 »
Hey all.
  I've recorded raw audio from a microphone (byte array). How can I convert this to a playable WAV? Or, for non-persistent reasons, how can I play the byte array without saving it to a WAV? Is there an option to stream raw audio? I'm using the .NET library. I tried this:
Code: [Select]
int stream = Bass.BASS_SampleLoad(audioByteArray, 0, bb.Length, 1, BASSFlag.BASS_SAMPLE_SOFTWARE); but I get BASS_ERROR_FILEFORM

I'm new to Bass, so apologies if I'm missing something obvious.

Thanks

Ian @ un4seen

  • Administrator
  • Posts: 20425
Re: Play/Save raw bytes
« Reply #1 on: 6 Dec '10 - 15:00 »
  I've recorded raw audio from a microphone (byte array). How can I convert this to a playable WAV?

The simplest way to do that is with the BASSenc add-on and a "dummy" stream. Something like this...

Code: [Select]
HSTREAM dummy=BASS_StreamCreate(freq, chans, BASS_STREAM_DECODE, STREAMPROC_DUMMY, 0); // create a dummy stream with matching sample format
BASS_Encode_Start(dummy, "out.wav", BASS_ENCODE_PCM|BASS_ENCODE_AUTOFREE, 0, 0); // set an encoder (WAV writer) on the dummy stream
BASS_Encode_Write(dummy, buffer, length); // send the buffered data to the encoder
BASS_StreamFree(dummy); // free the dummy stream (and encoder due to AUTOFREE)

Or, for non-persistent reasons, how can I play the byte array without saving it to a WAV? Is there an option to stream raw audio? I'm using the .NET library. I tried this:
Code: [Select]
int stream = Bass.BASS_SampleLoad(audioByteArray, 0, bb.Length, 1, BASSFlag.BASS_SAMPLE_SOFTWARE); but I get BASS_ERROR_FILEFORM

BASS_SampleLoad would need the data to have a WAVE header, to tell the sample format. To stream the data without requiring a header, you can use BASS_StreamCreate instead. That could use a STREAMPROC callback function to feed the data to the stream, or it could be a "push" stream. The latter will be simpler but a bit less efficient (it's a duplicate copy of the data in memory).

3coy

  • Posts: 5
Re: Play/Save raw bytes
« Reply #2 on: 6 Dec '10 - 20:41 »
Thanks a lot for the help Ian, that's just what I need! :)