I’m using C++ and fmod and I’d like to split a song in several fragments in order to save it in a list. Each element of the list has to represent the same duration (for exemple 1 second).

I’ve tried this solution :

FSOUND_Init(44100, 32, 0);
sound = FSOUND_Sample_Load(FSOUND_FREE, “sound.mp3”, FSOUND_NORMAL,0,13201024/8);
FSOUND_PlaySound(FSOUND_FREE, sound);

The operation : “13201024/8″ means that I want to play “1” sec. from my mp3 song which is 320kb/s encoded (so I do 320*1024/8 to get it in byte).
It’s working fine, but I need to know the bitrate of the song (that is not always 320kb/s… !). How can I find the bitrate of a song with fmod ?

Maybe, I’m on the wrong way. I’d like to create a timer which will play the list, element by element with FSOUND_PlaySound(FSOUND_FREE, sound); where “sound” is stored in a var in each element. I’m doing that, because I want to realize a visual grid, splitted in several cases which represent an unity of time. The user may use several tracks (or grids) and play it simultaneously. It should look like “Music” on PSOne. Is the multi-splitted sounds list a good solution ? Or what can I do ?

  • You must to post comments

Thank you for your code :

[quote:3ozdlfeu]Heres an interesting way i thought of using FMOD and it works for every format, not just MP3.
The code is in C but it is almost pseudocode it is that simple to understand.

unsigned int lenms, lenbytes, kbps;
lenms = FSOUND_Stream_GetLengthMs(stream);
lenbytes = FSOUND_Stream_GetLength(stream);
kbps = lenbytes / (lenms / 1000) /1000 * 8;

This will work out the average bitrate even for VBR mp3 files. It just works out the number of bytes per second. I truncate lenms with that initeger divide but it seems to work better (ie it gives 128 instead of 127 when i tried it with floats).[/quote:3ozdlfeu]

But don’t you think that the correct operation is : kbps = lenbytes / (lenms / 1000) /1024 * 8; ? Because 1kbyte = 1024 bytes. I’ve tried with a 128 kbs mp3, and 128 is returned by the both operations. But there may be errors with the value ‘1000’ I think.

  • You must to post comments

Parsimony, people! Don’t think too much.

[code:1ejjuli4]kbps = lenBytes / lenMsec * 8[/code:1ejjuli4]

I remember thinking that previous code sample was a bit silly. Granted, it did what the author wanted.

  • SD
  • You must to post comments
Showing 2 results
Your Answer

Please first to submit.