Author Topic: Determine Bitrate of Wav file  (Read 430 times)

moz

  • Posts: 10
Determine Bitrate of Wav file
« on: 18 Apr '19 - 18:37 »
Hi:

I have a question regarding sample info. I am trying to determine the samplerate, channel and bitrate of a wav file.

I have found BASS_SampleGetInfo which gives me samplerate (freqs) channels (chans) but somehow I struggle with the bitrate.

For most of my test files it works when checking info.origres which is either 8, 16 or 24 bit. For some of my test files the info.origres = 65568.
Checking the file with another software it tells me it is 32 bit float. How can I properly check the bitrate for these types of files?

Also, the reason I like to find out the bitrate is because I like to calculate how many bytes I need to read for 300ms of data using BASS_ChannelGetData.

Here is how i calculate it:
 
Code: [Select]
int bufferSize = (info.freq / 1000) * info.chans * (info.origres / 8) * 300;

This seems to work well for 8,16,24,32 bit wav files but not sure how to do this for 32 bit float data? Suggestions?

Thanks a lot in advance.


Ian @ un4seen

  • Administrator
  • Posts: 22121
Re: Determine Bitrate of Wav file
« Reply #1 on: 19 Apr '19 - 12:51 »
In the case of floating-point files, the BASS_ORIGRES_FLOAT flag will be set in the "origres" value and the low 16 bits contains the number of bits. 65568 = BASS_ORIGRES_FLOAT + 32 (32 bit floating-point). You can modify your code like this:

Code: [Select]
int bufferSize = (info.freq / 1000) * info.chans * (LOWORD(info.origres) / 8) * 300;

But note that calculation isn't reliable for getting the number of bytes for a BASS_ChannelGetData call because the "origres" value doesn't necessarily match what the stream/sample is using (the BASS_SAMPLE_FLOAT/8BITS flags tell that). A better way to calculate that is to use BASS_ChannelSeconds2Bytes:

Code: [Select]
int bufferSize = BASS_ChannelSeconds2Bytes(handle, 0.3);

moz

  • Posts: 10
Re: Determine Bitrate of Wav file
« Reply #2 on: 19 Apr '19 - 13:05 »
ah I see. Thanks Ian for pointing this out.

What a great lib by the way.

THANK YOU !