Question

OK. I'm trying to learn about audio and compression. I have a fundamental question that I haven't found the answer to yet scouring the internet.

I know that there are self describing formats with header information. If I convert different files into "raw" format with sox, am I wrong in thinking that gives them the same number of "channels" and "sample rate"?

I guess I was thinking that raw would be the great "neutralizer." Is this not the case? Like you could treat all files as if they were the same if they were in raw format?

Wikipedia says...

RAW Audio format or just RAW Audio is a computer format for storing uncompressed audio in raw form. Comparable to WAV or AIFF in size, RAW Audio file does not include any header information (sampling rate, bit depth, endian, or number of channels). Data can be written in PCM, IEEE 754 or ASCII.[citation needed]

There is also some good information on file format in general at http://en.wikipedia.org/wiki/Audio_file_format

Clarification I need to concatenate mp3 files that may start out with different numbers of channels and sampling rates. I don't honestly know how many channels I want to end up with. I am trying to combine the different files with sox. However, sox needs the files be in the same file format. So, I was hoping to get them in the "same file format" meaning the same number of channels and sampling rate.

However, now it seems that raw might just these two items but remove the self describing header information? In other words, an mp3 file converted to raw, retains the same properties (sampling rate and number of channels)?

Was it helpful?

Solution

What you want to do is:

  1. Extract the data from each mp3-file and convert it to a WAV file (You'll have to find a mp3 decoder for that).
  2. Convert the WAV-files so they all have the same WAV format (what ever format you like, format meaning: sample rate, bit resolution, etc.).
  3. Concatenate the files to one WAV-file.
  4. Convert the resulting file back to mp3 (mp3 encoder needed).

RAW-files are the same as WAV-files, only that they have no header that tells you the format. So you can completely forget about RAW-files unless you happen to know the audio format of the file anyway, and therefore don't need that header information.

OTHER TIPS

There isn't any "standard" for raw audio files. They can be encoded any number of ways, with different bit rates and channel counts. If you're trying to find a way to convert audio between formats, this is not the answer for you.

MP3 files can be directly concatenated even with varying rates, &c. You may have other reasons for wanting raw data or wav (raw + header), but you can do this without a decode/encode step.


I stand corrected. A lot of the MP3 files I manage via back-end programming (scripts) indeed vary their frame headers, bit rates, et cetera. We then stream it through through another commercial product BUT APPARENTLY said product respects each and every header!

When I tried the same input stream through Google Chrome as well as QuickTime it appears as only the very first header is respected and assumed throughout the whole file! Who'da thunk?

So I learned a big lesson here, thank goodness the streamer must pre-flight the MP3 stream! In this case I think decoding to "raw" with the maximum # of channels that you expect in the output is the way to go, then you can downmix to the # of channels needed upon encoding.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top