[Flac-dev] Finding start of audio data using metadata level 2 interface.

Josh Coalson xflac at yahoo.com
Tue Sep 28 10:33:26 PDT 2004


--- Dan Sully <daniel at electricrain.com> wrote:

> * Josh Coalson <xflac at yahoo.com> shaped the electrons to say...
> 
> >yep, that will work too.  but just writing skipping code is
> >pretty simple:
> >
> >is_last=0
> >read 'fLaC' string
> >while (!is_last) {
> >   read 1 byte metadata block type
> >   read 3 byte metadata block length
> >   is_last = type & 0x80
> >   fseek(file,length,SEEK_CUR)
> >}
> >last_offset=ftell(file)
> >
> >see also:
> >  http://flac.sourceforge.net/format.html#metadata_block_header
> >'length' is big-endian
> 
> Should type be of FLAC__byte, and length of FLAC__uint32? I'm not
> having much
> luck here.. (not a C programmer by nature).

better:

#include <stdio.h>
#include <string.h>
long get_offset(FILE *f)
{
    unsigned int is_last=0;
    unsigned char buf[4];
    long len;
    if(fread(buf,4,1,f)!=1)
        return -1;
    if(memcmp(buf,"fLaC",4))
        return -1;
    while (!is_last) {
        if(fread(buf,4,1,f)!=1)
            return -1;
        is_last=(unsigned int)(buf[0]&0x80);
        len=(long)((buf[1]<<16)|(buf[2]<<8)|(buf[3]));
        fseek(f,len,SEEK_CUR);
    }
    return ftell(f);
}



		
__________________________________
Do you Yahoo!?
Yahoo! Mail - 50x more storage than other providers!
http://promotions.yahoo.com/new_mail


More information about the Flac-dev mailing list