Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » sound format

This thread is locked; no one can reply to it. rss feed Print
sound format
kazzmir
Member #1,786
December 2001
avatar

I have someones music file that is encoded with adpcm. I used his decoding function to decode the data from the file( read into an array of char) into an array of shorts, but Im at a loss as to what do with that data. How can I write the decoded data to a .wav file? I cant quite tell if the music is interleaved or not, but it doesnt seem like it is right now. I think my question may be a bit vague, so if you want any extra information I can post it.

Oscar Giner
Member #2,207
April 2002
avatar

Quote:

I cant quite tell if the music is interleaved or not, but it doesnt seem like it is right now

The wave format has samples interleaved between channels. Not sure if that's your question.

kazzmir
Member #1,786
December 2001
avatar

well here is what I know so far.. The file contains a struct which has the following fields:

int frequency
int channels
short * data

but what do the channels mean if the data is one long array? Are the channels laid out in sequential order so if there are 3 channels then the first and second bytes of the song per channel would be:

0(1st) 1(1st) 2(1st) 0(2nd) 1(2nd) 2(2nd)

aquasync
Member #3,964
October 2003

If you have sox (and you probably do), you use it to convert adpcm files to normal wav files with one line.

edit:
To test it out, try plaing it using allegro's sample routines. just set sample->bits, sample->len, sample->data & sample->freq, then try playing it.
If it sounds ok, then just save the raw data to sample.raw (allegro has no save_sample).
Then just sox -r $freq -w (or -b if it is 8bit) sample.raw sample.wav

Oscar Giner
Member #2,207
April 2002
avatar

No, the samples are interleaved. That is, if you have a stereo wave, the data would be:

0(1st) 0(2nd) 1(1st) 1(2nd)

Were the first number is a sample, not a byte.

kazzmir
Member #1,786
December 2001
avatar

aquasync: sox seems like a cool program, but it doesnt seem to be working. I havent tried to play the raw data in allegro, but I am trying this:

$ sox -a -c 1 -r 22050 -w song.raw song.wav

song.wav is always 90 bytes no matter what the sampling rate is and sox says

sox: Overriding output size to bytes for compressed data.

the raw file is 1715934 bytes long.

[edit]
here is the output of sox when -V is given:

1$ sox -a -c 1 -r 22050 -w 1boss.raw -r 22050 -w 1boss.w
2sox: Detected file format type: raw
3 
4sox: Input file 1boss.raw: using sample rate 22050
5 size shorts, encoding adpcm, 1 channel
6sox: Input file 1boss.raw: comment "1boss.raw"
7 
8sox: Overriding output size to bytes for compressed data.
9sox: Writing Wave file: Microsoft ADPCM format, 1 channel, 22050 samp/sec
10sox: 11567 byte/sec, 128 block align, 4 bits/samp
11sox: Output file 1boss.wav: using sample rate 22050
12 size bytes, encoding adpcm, 1 channel
13sox: Output file: comment "1boss.raw"
14 
15sox: Finished writing Wave file, 0 data bytes 0 samples

[edit]
UPDATE: I solved my problem. I simply used the decoding method to decode the adpcm stream into raw pcm as signed shorts, then sox could interpret that pretty easily and finally I pumped each .wav into lame.

aquasync
Member #3,964
October 2003

Are you trying that on the original sound file from the person, or a dump of the sample data after decoding?
Its just that, while sox can decode standard adpcm's, if his algorithm/file format is different, you should decode using that, then dump that as a raw file, and convert it.

edit: it seems like you are trying to convert the dump ('sample.raw') with adpcm format ('sox -a'), which isn't going to work. Either try '-a' with the original file, or try the dumped data without it.

Go to: