Help - Search - Members - Calendar
Full Version: MPC in XMMS and BMP
Hydrogenaudio Forums > Lossy Audio Compression > MPC
paranoos
I was able to fix a bug I was experiencing with the MPC plugin in XMMS and Beep Media Player.

Basically, when the playlist grabs the song length, it assumes it is the same sample rate as the song being played. This generally isn't a problem, as most songs are 44.1 kHz. However, BEFORE a song is being played, the SAMPLERATE variable is set to 8000Hz, which results in quite incorrect song lengths being displayed in the playlist on startup.

Has anyone else noticed this bug before?

Well, I rewrote the StreamInfo struct to also include the SampleRate variable, and rewrote the ReadFileHeader function to read the SampleRate from the file in question. This function gets called when XMMS wants to know how long a song is when it's not playing it. Works like a charm smile.gif

Is anybody interested in this patch? (xmix, i would guess you are heh)
Chun-Yu
Ah, so that's why the time displayed is always much larger than the actual time. I just never had time to look into it smile.gif I would be interested in this patch.
xmixahlx
of course i'm interested!

i'm even more interested in this being sent upstream to the xmms/corecodec cvs

you should create a diff/patch and attach it to this thread

(btw, i did notice this bug, which doesn't happen all the time for some reason...)


later
paranoos
biggrin.gif ok, here's the patch

CODE
--- in_mpc.c 2003-01-16 17:17:01.000000000 -0500
+++ in_mpc.c.paranoos 2004-04-01 21:30:02.000000000 -0500
@@ -50,6 +50,7 @@
    unsigned int  ByteLength;
    unsigned int  Profile;
    unsigned int  EncVersion;
+ unsigned int  SampleRate;
} StreamInfo;

int                TrueGapless      = 0;
@@ -337,6 +338,9 @@
{
    unsigned int  HeaderData [7];
    FILE*         fp;
+    static const unsigned short
+                      sftable [4] = { 44100, 48000, 37800, 32000 };
+

    memset ( Info, 0, sizeof (*Info) );

@@ -352,10 +356,11 @@
        Info -> StreamVersion = HeaderData[0] >> 24;

    if ( Info -> StreamVersion >= 7 ) {
-        Info -> Frames        =  HeaderData [1];
-        Info -> MS            = (HeaderData [2] << 1) >> 31;
-        Info -> Profile       = (HeaderData [2] >> 20) & 15;
-        Info -> EncVersion    =  HeaderData [6] >> 24;
+        Info -> Frames        =             HeaderData [1];
+        Info -> MS            =            (HeaderData [2] << 1) >> 31;
+        Info -> Profile       =            (HeaderData [2] >> 20) & 15;
+        Info -> SampleRate    =  sftable [ (HeaderData [2] >> 16) & 19 ];
+        Info -> EncVersion    =             HeaderData [6] >> 24;
    }
    else {
        Info -> Bitrate       = (HeaderData [0] >> 23);
@@ -1592,7 +1597,6 @@
getfileinfo ( char* filename, char** _title, int* length_in_ms )
{
    StreamInfo    Info;
-    unsigned int  tmpFrames;

    if ( filename == NULL  ||  filename[0] == '\0' ) {  // currently playing file
        if ( length_in_ms != NULL )
@@ -1603,8 +1607,7 @@
        if ( length_in_ms != NULL ) {
            if ( ReadFileHeader ( filename, &Info) )
                return;
-            tmpFrames     = Info.Frames;
-            *length_in_ms = (int) ( tmpFrames * 1152.e3 / SAMPLERATE + 0.5f );
+            *length_in_ms = (int) ( Info.Frames * 1152.e3 / Info.SampleRate + 0.5f );
        }
    }
}
robUx4
It will be added to CVS this week-end.
I'll hopefully have all possible binaries available too.
Lefungus
patch from paranoos don't work for me, i had to change a line by this :

CODE
+        Info -> SampleRate    =  sftable [ (HeaderData [2] >> 16) & 3 ];


then it works fine, accurately detect time for all supported frequencies, with files encoded with 1.15r
xmixahlx
robUx4 -

while you are adding stuff to CVS, you'll want to change the Makefile in sv7 to support gcc3.x:

146c146
< -mpreferred-stack-boundary=2 -malign-jumps=5 -malign-loops=0 -malign-functions=5
---
> -mpreferred-stack-boundary=2 -falign-jumps=5 -falign-loops=0 -falign-functions=5
159c159
< -mpreferred-stack-boundary=2 -malign-jumps=5 -malign-loops=0 -malign-functions=5
---
> -mpreferred-stack-boundary=2 -falign-jumps=5 -falign-loops=0 -falign-functions=5

(and i have many more changes, but i'm assuming that creating libmusepack will change all that smile.gif )


later
paranoos
QUOTE(Lefungus @ Apr 2 2004, 10:15 AM)
patch from paranoos don't work for me, i had to change a line by this :

CODE
+        Info -> SampleRate    =  sftable [ (HeaderData [2] >> 16) & 3 ];


then it works fine, accurately detect time for all supported frequencies, with files encoded with 1.15r

Turns out that &3 works for me also. To be honest, the choice of &19 was pretty random... it just worked, so i used it. Reading the code now, however, it makes sense to me. I tested it with my entire MPC v1.1 collection. now that I actually think about it though, it seems that &19 would read the sample rate, as well as the last bit from the profile in the headers.

so it seems that 1.1 doesn't has the last bit from the profile set to 0, otherwise it would mess me up too.

Hopefully robUx4 will make these changes in my patch before adding it to CVS. (edit: i just emailed him biggrin.gif )

Thanks, Lefungus!
robUx4
Sorry guys, so far I haven't found the time because I'm preparing my vacation trip (leaving tomorrow). Maybe I can do that tonight, but I'm not sure.
Lefungus
Plugins updated here !

Now let's wait peacefully for that musepack library laugh.gif
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2008 Invision Power Services, Inc.