0
0

Hi

How can i display the variable bitrate, for a mp3/ogg file playing. In winamp you can see how many kbps the current frame is encoded at, and this number shifts rapidly. How can i implement this, using fmod.. preferebly in Delphi?

• You must to post comments
0
0

You can do this by keeping track of the position in time and file. I’m not on a PC right now, so I can’t check the exact function names, but you’ll figure it out; here’s some pseudo code:

[code:1mz6pg6o]int prevPos, prevPosMs;
int dPos, dPosMs;
int currentPos, currentPosMs;
int bitrate;

while (1) {
currentPos = FSOUND_Stream_GetTime(stream); // or something
currentPosMs = FSOUND_Stream_GetPosition(stream); // or something
dPos = currentPos – prevPos; prevPos = currentPos;
dPosMs = currentPosMs – prevPosMs; prevPosMs = currentPosMs;
bitrate = 8000 * (dPos / dPosMs); // should private bitrate in bits/second ( bitrate = 8 * byterate, byterate = dPos/(dPosMs/1000) = 1000 * dPos/dPosMs, bitrate = 8000 * dPos/dPosMs )
}
[/code:1mz6pg6o]

I think that should be about right.

• You must to post comments
0
0

Thx alot for that

I got it to work, but it seems to me its very inaccurate. The math looks ok to me, but it keep returning kbit in rages of 32-96 kbit, even when im sure the current mp3 file s playing in 160-320 kbit ranges.

## This is what i do:

``````  currentPos:= FSOUND_Stream_GetTime(stream);
currentPosMs:= FSOUND_Stream_GetPosition(stream);
dPos:= currentPos - prevPos;
prevPos:= currentPos;
dPosMs:= currentPosMs - prevPosMs;
prevPosMs:= currentPosMs;

if dpos&gt;0 then
if dposms&gt;0 then
byterate:=dPos/(dPosMs/1000);
``````

## bitrate:= (8 * round(byterate))*6;

Notice the ugly *6.. ๐
Btw.. i declared all the above variables global… and initialized PrevPos,prevPosMs to 0

I have verified this by enoding a mp3 myself, using the specified ranges, using lame v3.92

“lame.exe -v –vbr-new -b 160 -B 320”

This shows correctly in winamp(I know.. winamp is no reference ๐ ).

When i play files not encoded using VBR, it stills jumps up and down in kbit value..

When you get back to ya pc, can you verify this?

I was more looking for something more accurate like:
FSOUND_Stream_GetCurrentKbps(stream);

Hope it makes sense ๐

[img:2w2dbgj9]http://www.gif.com/ImageGallery/Animated/Music/3D/music.gif[/img:2w2dbgj9]

• You must to post comments
0
0

Hmm, I recall noticing weird behaviour of the GetTimeMs function, but I just added a factor and dismissed the problem. I’ll look into this again, however right now my computers are still in my dorm and I’m at home, so until I get the chance to move them here you’ll have to wait a bit
You could also try to increase the delay between updates, to improve the accuracy.

• You must to post comments
0
0

Any news on this?

I have tried several different solutions to this. This is my latest approch, and should work regardless of platform, and the type of file playing (Delphi):
[code:2qukpoqe]
nowpos:=FSOUND_Stream_GetPosition(song.Stream);
nowtime:=FSOUND_Stream_GetTime(song.Stream);

// Calculate how many bits, used in the last (nowtime-lasttime) ms
bitrate:=(8*(nowpos-lastpos))/(nowtime-lasttime);
[/code:2qukpoqe]

This is the most accurate result i’ve got so far, but it still jumps up above 400kbit and goes below 32kbit, even on CBR mp3 files. (??)

Evinyatar Wrote:
[quote:2qukpoqe]Hmm, I recall noticing weird behaviour of the GetTimeMs function, but I just added a factor and dismissed the problem.[/quote:2qukpoqe]

Hmm.. yes, i’ve added my own scaling factor, scaling to 1 whole second (1000 ms)

[code:2qukpoqe]
scale:=1000/abs(nowtime-lasttime);
bitrate:=bitrate*scale;
[/code:2qukpoqe]

Still i get inaccurate results. If i try using it on CBR MP3 files, it still varies in kbit.

And yes, i’ve tried to update the bitrate every 25th ms, or once a second, and i’ve get slightly better results.. still alot inaccurate. Also tried, according to help:
[quote:2qukpoqe]Position information is also based on the current file position, not the actual playing
position, so if the stream is only updated every 100ms, then the position will only be
updated every 100ms.[/quote:2qukpoqe], to update to aaround every 100ms, and even wait for ‘GetPosition’ to change, until i update my bitrate calculations, still highly inaccurate.

My latest solution was to use the value returned from FSOUND_Stream_GetPosition, and then open the current mp3(it only works for mp3 files), and seek to the position from FSOUND_Stream_GetPosition, and then decode the header/frame info, to get an accurate value.. but this also proved highly inaccurate, and only works with mp3 files.

Hope someone got news on this, or any other way to get the current kbps for the currently playing media file(Streams).

• You must to post comments
0
0

๐ฅ

I’m amazed that this ‘simple’ thing(To show how many kbps the current fram is using, like winamp) is so hard to implement. I have tried tons of dofferent approches, but still i’m left with an painfully inaccurate kbps value for my player.

Even tried to scan the m3 for its headers, but is utter useless, and requires too many ressources for a simple player.

Is there really no news on this, or is fmod inaccurate in reporting back its consumption of bytes per second, while playing a media file?

• You must to post comments
0
0

Download [url=http://www.foobar2000.org/SDK.zip:15raj6df]this[/url:15raj6df]. This is the SDK of the [url=http://www.foobar2000.org:15raj6df]Foobar2000[/url:15raj6df] player. Go to the “foobar2000\foo_input_std” directory and open the mp3.cpp file. You can find an interresting function : get_dynamic_info(). Here, for each frame, you must recalculate the bitrate. Good luck.

• You must to post comments
Showing 6 results