summaryrefslogtreecommitdiffstats
path: root/mpg123_artsplugin/mpg123/vbrhead.c
blob: f77ab2794b4f704e4181cf894ff34446797ed96c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
/*
 * This checks for the VBR Header defined by Xing(tm)
 */

#include "mpg123.h"

static unsigned long get32bits(unsigned char *buf) {
    unsigned long ret = 0;

    ret = (((unsigned long) buf[0]) << 24) |
	(((unsigned long) buf[1]) << 16) |
	(((unsigned long) buf[2]) << 8) |
	((unsigned long) buf[3]) ;

    return ret;
}

int getVBRHeader(struct vbrHeader *head,unsigned char *buf, struct frame *fr) 
{
    int ssize;

    if(fr->lay != 3)
	return 0;

    if(fr->lsf)
	ssize = (fr->stereo == 1) ? 9 : 17;
    else
	ssize = (fr->stereo == 1) ? 17 : 32;


    buf += ssize;

    if(( buf[0] != 'X' ) || ( buf[1] != 'i' ) ||
       ( buf[2] != 'n' ) || ( buf[3] != 'g' ) ) 
	return 0;
    buf+=4;
    
    head->flags = get32bits(buf);
    buf+=4;
    
    if(head->flags & VBR_FRAMES_FLAG) {
	head->frames = get32bits(buf);
	buf += 4;
    }

    if(head->flags & VBR_BYTES_FLAG) {
	head->bytes  = get32bits(buf); 
	buf += 4;
    }

    if(head->flags & VBR_TOC_FLAG) {
	memcpy(head->toc,buf,100);
	buf += 100;
    }

    if(head->flags & VBR_SCALE_FLAG) {
	head->scale = get32bits(buf);
	buf += 4;
    }

    fprintf(stderr,"Found XING %04lx\n",head->flags);

    return 1;

}