I've been developing an audio synthesizer and it's pretty much all up and running, but I've run into a bit of an issue while trying to load various audio.

Everything works as intended to the best of my debugging abilities. I think that the problem is not in the implementation, but that wav files can have samples represented in different ways. For example, a 32-bit wav file may use 32-bit integers or 32-bit floats (especially from the range of -1.0 to 1.0). There are similar cases for other bit depths (16 & 24).

My question is, how can these differences be detected? I don't know of any tag that describes the format of how audio samples should be saved. If it is safe to assume certain forms over others, such as floats from -1 to +1 being more common than floats in their full range, then may I get help telling me where to find these preferred formats?

  • This is getting more in to nuts and bolts of an audio format rather than its usage in Sound Design or audio ventures. I think file format recognition is probably more of an SO question. It is probably off topic here. There is some general (but inconclusive) discussion about it here.
    – AJ Henderson
    Oct 24, 2014 at 20:33
  • @AJHenderson Feel free to migrate it, then. I made an effort to ensure that it was on-topic, especially by looking around at similar questions regarding wav files (see related questions section). This is only on Sound Design because I tried to find the best fit. When I looked at the help center, it was incredibly vague, making a sweeping sentence about what was allowed, so it wasn't easy to tell.
    – kettlecrab
    Oct 26, 2014 at 22:27
  • @AJHenderson I don't have any sway, but maybe somebody should recommend changing the scope of the allowed questions to omit formatting.
    – kettlecrab
    Oct 26, 2014 at 22:28
  • 1
    agreed, we've been trying to figure out the site scope and are having a lot of difficulty due to conflicting goals. I commented because I'm not even 100 percent sure it is off topic. It seems it likely is but things are very ambiguous around here currently.
    – AJ Henderson
    Oct 27, 2014 at 0:41

2 Answers 2


First step when reading audio data from a wav file is to parse the header, especially the 'fmt ' chunk, as described for example in the wikipedia page or on this page.

The 'fmt ' chunk will give you informations on :

  • the audio format (PCM or not ...)
  • the number of channels
  • the sample rate
  • bits per sample
  • other stuff

The audio samples themselves are in the 'data' chunk. If there are more than one channel, samples are stored in interleaved form. The actual value of a sample is represented by one or several bytes, in the (common) case where more than one byte is used for one sample as integer, it is encoded as 2's complement in little-endian order. It means that depending on your platform's endianess and the available types in your programming language, you might have to perform some operations to convert two bytes into a 16 bit signed integer for example. For 24 bits samples, you have to somehow convert them to a 32 bits signed integer.

A suggested in csaudiodesign answer, I would also suggest using libsndfile unless you're willing to implement your own wav file parser. Or using the builtin .net functions ? It seems that you are limited to 16 bits samples.

There's no such thing as predicting samples format in a wav file. An audio file that only contains audio data is commonly known as raw and you need extra information on the content to be able to use it.

  • (Actually, this is about my own wav writer.) Examples to illustrate my question better... I know that 8-bit audio is supposed to be unsigned and everything else is signed. I know that if I encode the data with floats that I need to set them in a range from 0 to 1. The question is really where are these requirements (regarding format of the data itself) spelled out? They seem to be part of the wav specification and I couldn't find them. (I agree it should be migrated to SO now; I wasn't sure when I made it). They aren't covered by the fmt chunk.
    – kettlecrab
    Dec 24, 2014 at 15:05

Since there exist many other audio-formats apart from WAV, you would have to write code that predicts / knows how to read all of them. But you can do it much more simple by using a library. I strongly recommend libsndfile by Erik de Castro Lopo. It has an amazing amount of formats it can read and write, and it offers functions that give you the same sample format no matter what file format you want to read. I used this library in several projects and I'm really happy with it.

  • I'm not looking for libraries, I just want to know what the implicit de facto is for the format of wav samples. I'm actually writing my own wav library and it's fairly complete. It can read/write most other formats, but I haven't implemented 24-bit yet because there are no .net data types for it.
    – kettlecrab
    Oct 26, 2014 at 22:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.