summary refs log tree commit diff stats
path: root/plugins/mpcinfo/oggInfo.c
blob: 64c9c5129a98227ce3fd5084780ecf5a191b9afc (plain) (blame)
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
/*
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 */

static int getOggInt(char *buff, int beg, int bytes){
//if (DEBUG==1) putlog("getOggInt");
	int ret=0;
	int i;
	for (i=0;i<bytes;i++){
		if (buff[i+beg]>=0) ret+=buff[i+beg]*iPow(256,i);else ret+=(256+buff[i+beg])*iPow(256,i);
		//printf("[%i]=%i\n",i,buff[i+beg]);
	}
	return ret;
}

static char *upperStr(char *text){
//if (DEBUG==1) putlog("converting text to uc");
    //printf("upperStr(%s)\n",text);
	int i;
	char *ret=(char*) malloc(sizeof(char)*(strlen(text)+1));
	ret[strlen(text)]=0;
	for (i=0;i<strlen(text);i++) ret[i]=toupper(text[i]);
	//printf("Result: %s\n",ret);
	return ret;
}

struct tagInfo getOggHeader(char *file){
//if (DEBUG==1) putlog("reading ogg header");
	char header[4096];
	int i, c;
	int h1pos, h3pos, maxBr, nomBr, minBr, pos, count, tagLen;
	char *sub;
	char *name;
	char *val;
	char *HEADLOC1, *HEADLOC3, *HEADLOC5;
	FILE *f;
	struct tagInfo info;

	info.artist=NULL;
	f = fopen(file,"rb");
	if (f==NULL){
       hexchat_print(ph,"file not found while trying to read ogg header");
       //if (DEBUG==1) putlog("file not found while trying to read ogg header");
       return info;
    }

	for (i=0;i<4095;i++) {c=fgetc(f);header[i]=(char)c;}
	fclose(f);
	HEADLOC1="_vorbis";
	HEADLOC1[0]=1;
	HEADLOC3="_vorbis";
	HEADLOC3[0]=3;
	HEADLOC5="_vorbis";
	HEADLOC5[0]=5;
	h1pos=inStr(header,4096,HEADLOC1);
	h3pos=inStr(header,4096,HEADLOC3);
	//int h5pos=inStr(header,4096,HEADLOC5); //not needed
	
	//printf("loc1: %i\n",h1pos);printf("loc3: %i\n",h3pos);printf("loc5: %i\n",h5pos);
	maxBr=getOggInt(header,h1pos+7+9,4);
	nomBr=getOggInt(header,h1pos+7+13,4);
	minBr=getOggInt(header,h1pos+7+17,4);
	info.freq=getOggInt(header,h1pos+7+5,4);
	info.mode=header[h1pos+7+4];
	info.bitrate=nomBr;
	if (((maxBr==nomBr)&&(nomBr=minBr))||((minBr==0)&&(maxBr==0))||((minBr=-1)&&(maxBr=-1)) )info.cbr=1;else info.cbr=0;
	printf("bitrates: %i|%i|%i\n",maxBr,nomBr,minBr);
	printf("freq: %i\n",info.freq);
	pos=h3pos+7;
	pos+=getOggInt(header,pos,4)+4;
	count=getOggInt(header,pos,4);
	//printf("tags: %i\n",count);
	pos+=4;

	info.artist=NULL;info.title=NULL;info.album=NULL;info.comment=NULL;info.genre=NULL;
	for (i=0;i<count;i++){
		tagLen=getOggInt(header,pos,4);
		//printf("taglength: %i\n",tagLen);
		sub=substring(header,pos+4,tagLen);
		name=upperStr(substring(sub,0,inStr(sub,tagLen,"=")));
		val=substring(sub,inStr(sub,tagLen,"=")+1,tagLen-inStr(sub,tagLen,"=")-1);
		//printf("Tag: %s\n",sub);
		//printf("Name: %s\n",name);
		//printf("value: %s\n",val);
		if (strcmp(name,"ARTIST")==0) info.artist=val;
		if (strcmp(name,"TITLE")==0) info.title=val;
		if (strcmp(name,"ALBUM")==0) info.album=val;
		if (strcmp(name,"GENRE")==0) info.genre=val;
		if (strcmp(name,"COMMENT")==0) info.comment=val;
		pos+=4+tagLen;
	}
	if (info.artist==NULL) info.artist="";
	if (info.album==NULL) info.album ="";
	if (info.title==NULL) info.title="";
	if (info.genre==NULL) info.genre="";
	if (info.comment==NULL) info.comment="";
	
	printf("Artist: %s\nTitle: %s\nAlbum: %s\n",info.artist,info.title, info.album);
	printf("Genre: %s\nComment: %s\nMode: %i\nCBR: %i\n",info.genre,info.comment,info.mode,info.cbr);
	//if (DEBUG==1) putlog("ogg header readed");
	return info;
}

/*
void printOggInfo(char *file){
	printf("Scanning Ogg-File for Informations: %s\n",file);
	printf("size:\t%10d byte\n",getSize(file));
	struct tagInfo info = getOggHeader(file);
}
*/
$11, %mm1 /* g0 00 */ psllw $8, %mm0 /* 0r 00 */ psrlw $3, %mm1 /* 0g 00 */ psrlw $3, %mm2 /* 0b 00 */ pmulhw %mm5, %mm0 /* 00 0r */ pmulhw %mm6, %mm1 /* 00 0g */ pmulhw %mm7, %mm2 /* 00 0b */ psllw $10, %mm0 /* r0 00 */ psllw $5, %mm1 /* 0g g0 */ por %mm2, %mm0 /* r0 0b */ por %mm1, %mm0 /* rg gb */ movq %mm0, (%esi, %ecx, 2) addl $4, %ecx js 2b jmp 4f 3: movw (%esi, %ecx, 2), %ax movd %eax, %mm0 movq %mm0, %mm1 /* rg gb */ movq %mm0, %mm2 /* rg gb */ psrlw $5, %mm1 /* 0r rg */ psrlw $10, %mm0 /* 00 0r */ psllw $11, %mm2 /* b0 00 */ psllw $11, %mm1 /* g0 00 */ psllw $8, %mm0 /* 0r 00 */ psrlw $3, %mm1 /* 0g 00 */ psrlw $3, %mm2 /* 0b 00 */ pmulhw %mm5, %mm0 /* 00 0r */ pmulhw %mm6, %mm1 /* 00 0g */ pmulhw %mm7, %mm2 /* 00 0b */ psllw $10, %mm0 /* r0 00 */ psllw $5, %mm1 /* 0g g0 */ por %mm2, %mm0 /* r0 0b */ por %mm1, %mm0 /* rg gb */ movd %mm0, %eax movw %ax, (%esi, %ecx, 2) incl %ecx 4: cmpl $2, %ecx jng 3b addl bpl, %esi decl %edx jnz 1b 5: LEAVE shade_ximage_15_mmx_saturate: pcmpeqw %mm3, %mm3 psllw $5, %mm3 /* ff e0 ff e0 ff e0 ff e0 */ 1: movl %ebx, %ecx addl $3, %ecx jns 3f 2: movq (%esi, %ecx, 2), %mm0 movq %mm0, %mm1 /* rg gb */ movq %mm0, %mm2 /* rg gb */ psrlw $5, %mm1 /* 0r rg */ psrlw $10, %mm0 /* 00 0r */ psllw $11, %mm2 /* b0 00 */ psllw $11, %mm1 /* g0 00 */ psllw $8, %mm0 /* 0r 00 */ psrlw $3, %mm1 /* 0g 00 */ psrlw $3, %mm2 /* 0b 00 */ pmulhw %mm5, %mm0 /* xx xr */ pmulhw %mm6, %mm1 /* xx xg */ pmulhw %mm7, %mm2 /* xx xb */ /* Saturate upper */ paddusw %mm3, %mm0 /* ff er */ paddusw %mm3, %mm1 /* ff eg */ paddusw %mm3, %mm2 /* ff eb */ psubw %mm3, %mm0 /* 00 0r */ psubw %mm3, %mm1 /* 00 0g */ psubw %mm3, %mm2 /* 00 0b */ psllw $10, %mm0 /* r0 00 */ psllw $5, %mm1 /* 0g g0 */ por %mm2, %mm0 /* r0 0b */ por %mm1, %mm0 /* rg gb */ movq %mm0, (%esi, %ecx, 2) addl $4, %ecx js 2b jmp 4f 3: movw (%esi, %ecx, 2), %ax movd %eax, %mm0 movq %mm0, %mm1 /* rg gb */ movq %mm0, %mm2 /* rg gb */ psrlw $5, %mm1 /* 0r rg */ psrlw $10, %mm0 /* 00 0r */ psllw $11, %mm2 /* b0 00 */ psllw $11, %mm1 /* g0 00 */ psllw $8, %mm0 /* 0r 00 */ psrlw $3, %mm1 /* 0g 00 */ psrlw $3, %mm2 /* 0b 00 */ pmulhw %mm5, %mm0 /* xx xr */ pmulhw %mm6, %mm1 /* xx xg */ pmulhw %mm7, %mm2 /* xx xb */ /* Saturate upper */ paddusw %mm3, %mm0 /* ff er */ paddusw %mm3, %mm1 /* ff eg */ paddusw %mm3, %mm2 /* ff eb */ psubw %mm3, %mm0 /* 00 0r */ psubw %mm3, %mm1 /* 00 0g */ psubw %mm3, %mm2 /* 00 0b */ psllw $10, %mm0 /* r0 00 */ psllw $5, %mm1 /* 0g g0 */ por %mm2, %mm0 /* r0 0b */ por %mm1, %mm0 /* rg gb */ movd %mm0, %eax movw %ax, (%esi, %ecx, 2) incl %ecx 4: cmpl $2, %ecx jng 3b addl bpl, %esi decl %edx jnz 1b 5: LEAVE SHADE_XIMAGE_16: ENTER leal -6(%esi, %ebx, 2), %esi negl %ebx jz 5f /* Setup multipliers */ movd rm, %mm5 movd gm, %mm6 movd bm, %mm7 punpcklwd %mm5, %mm5 /* 00 00 00 00 rm rm rm rm */ punpcklwd %mm6, %mm6 /* 00 00 00 00 gm gm gm gm */ punpcklwd %mm7, %mm7 /* 00 00 00 00 bm bm bm bm */ punpckldq %mm5, %mm5 /* rm rm rm rm rm rm rm rm */ punpckldq %mm6, %mm6 /* gm gm gm gm gm gm gm gm */ punpckldq %mm7, %mm7 /* bm bm bm bm bm bm bm bm */ cmpl $256, rm jg shade_ximage_16_mmx_saturate cmpl $256, gm jg shade_ximage_16_mmx_saturate cmpl $256, bm jg shade_ximage_16_mmx_saturate 1: movl %ebx, %ecx addl $3, %ecx jns 3f 2: movq (%esi, %ecx, 2), %mm0 movq %mm0, %mm1 /* rg gb */ movq %mm0, %mm2 /* rg gb */ psrlw $5, %mm1 /* 0r rg */ psrlw $11, %mm0 /* 00 0r */ psllw $11, %mm2 /* b0 00 */ psllw $10, %mm1 /* g0 00 */ psllw $8, %mm0 /* 0r 00 */ psrlw $2, %mm1 /* 0g 00 */ psrlw $3, %mm2 /* 0b 00 */ pmulhw %mm5, %mm0 /* 00 0r */ pmulhw %mm6, %mm1 /* 00 0g */ pmulhw %mm7, %mm2 /* 00 0b */ psllw $11, %mm0 /* r0 00 */ psllw $5, %mm1 /* 0g g0 */ por %mm2, %mm0 /* r0 0b */ por %mm1, %mm0 /* rg gb */ movq %mm0, (%esi, %ecx, 2) addl $4, %ecx js 2b jmp 4f 3: movw (%esi, %ecx, 2), %ax movd %eax, %mm0 movq %mm0, %mm1 /* rg gb */ movq %mm0, %mm2 /* rg gb */ psrlw $5, %mm1 /* 0r rg */ psrlw $11, %mm0 /* 00 0r */ psllw $11, %mm2 /* b0 00 */ psllw $10, %mm1 /* g0 00 */ psllw $8, %mm0 /* 0r 00 */ psrlw $2, %mm1 /* 0g 00 */ psrlw $3, %mm2 /* 0b 00 */ pmulhw %mm5, %mm0 /* 00 0r */ pmulhw %mm6, %mm1 /* 00 0g */ pmulhw %mm7, %mm2 /* 00 0b */ psllw $11, %mm0 /* r0 00 */ psllw $5, %mm1 /* 0g g0 */ por %mm2, %mm0 /* r0 0b */ por %mm1, %mm0 /* rg gb */ movd %mm0, %eax movw %ax, (%esi, %ecx, 2) incl %ecx 4: cmpl $2, %ecx jng 3b addl bpl, %esi decl %edx jnz 1b 5: LEAVE shade_ximage_16_mmx_saturate: pcmpeqw %mm3, %mm3 movq %mm3, %mm4 psllw $5, %mm3 /* ff e0 ff e0 ff e0 ff e0 */ psllw $6, %mm4 /* ff c0 ff c0 ff c0 ff c0 */ 1: movl %ebx, %ecx addl $3, %ecx jns 3f 2: movq (%esi, %ecx, 2), %mm0 movq %mm0, %mm1 /* rg gb */ movq %mm0, %mm2 /* rg gb */ psrlw $5, %mm1 /* 0r rg */ psrlw $11, %mm0 /* 00 0r */ psllw $11, %mm2 /* b0 00 */ psllw $10, %mm1 /* g0 00 */ psllw $8, %mm0 /* 0r 00 */ psrlw $2, %mm1 /* 0g 00 */ psrlw $3, %mm2 /* 0b 00 */ pmulhw %mm5, %mm0 /* xx xr */ pmulhw %mm6, %mm1 /* xx xg */ pmulhw %mm7, %mm2 /* xx xb */ /* Saturate upper */ paddusw %mm3, %mm0 /* ff er */ paddusw %mm4, %mm1 /* ff cg */ paddusw %mm3, %mm2 /* ff eb */ psubw %mm4, %mm1 /* 00 0g */ psubw %mm3, %mm2 /* 00 0b */ psllw $11, %mm0 /* r0 00 */ psllw $5, %mm1 /* 0g g0 */ por %mm2, %mm0 /* r0 0b */ por %mm1, %mm0 /* rg gb */ movq %mm0, (%esi, %ecx, 2) addl $4, %ecx js 2b jmp 4f 3: movw (%esi, %ecx, 2), %ax movd %eax, %mm0 movq %mm0, %mm1 /* rg gb */ movq %mm0, %mm2 /* rg gb */ psrlw $5, %mm1 /* 0r rg */ psrlw $11, %mm0 /* 00 0r */ psllw $11, %mm2 /* b0 00 */ psllw $10, %mm1 /* g0 00 */ psllw $8, %mm0 /* 0r 00 */ psrlw $2, %mm1 /* 0g 00 */ psrlw $3, %mm2 /* 0b 00 */ pmulhw %mm5, %mm0 /* xx xr */ pmulhw %mm6, %mm1 /* xx xg */ pmulhw %mm7, %mm2 /* xx xb */ /* Saturate upper */ paddusw %mm3, %mm0 /* ff er */ paddusw %mm4, %mm1 /* ff cg */ paddusw %mm3, %mm2 /* ff eb */ psubw %mm4, %mm1 /* 00 0g */ psubw %mm3, %mm2 /* 00 0b */ psllw $11, %mm0 /* r0 00 */ psllw $5, %mm1 /* 0g g0 */ por %mm2, %mm0 /* r0 0b */ por %mm1, %mm0 /* rg gb */ movd %mm0, %eax movw %ax, (%esi, %ecx, 2) incl %ecx 4: cmpl $2, %ecx jng 3b addl bpl, %esi decl %edx jnz 1b 5: LEAVE SHADE_XIMAGE_32: ENTER leal (%esi, %ebx, 4), %esi negl %ebx jz 3f movd rm, %mm4 movd gm, %mm5 movd bm, %mm6 psllq $32, %mm4 psllq $16, %mm5 por %mm6, %mm4 por %mm5, %mm4 pcmpeqw %mm6, %mm6 psllw $15, %mm6 /* 80 00 80 00 80 00 80 00 */ movq %mm6, %mm5 pmulhw %mm4, %mm5 /* Get correction factor */ 1: movl %ebx, %ecx 2: movd (%esi, %ecx, 4), %mm1 /* 00 rr gg bb */ pxor %mm0, %mm0 punpcklbw %mm1, %mm0 /* 00 00 rr 00 gg 00 bb 00 */ pxor %mm6, %mm0 /* Flip sign */ pmulhw %mm4, %mm0 /* 00 00 xx rr xx gg xx bb */ psubw %mm5, %mm0 /* Correct range */ packuswb %mm0, %mm0 /* 00 rr gg bb 00 rr gg bb */ movd %mm0, (%esi, %ecx, 4) incl %ecx jnz 2b addl bpl, %esi decl %edx jnz 1b 3: LEAVE HAVE_MMX: push %ebx /* Check if bit 21 in flags word is writeable */ pushfl popl %eax movl %eax,%ebx xorl $0x00200000, %eax pushl %eax popfl pushfl popl %eax cmpl %eax, %ebx je 8f /* OK, we have CPUID */ movl $1, %eax cpuid test $0x00800000, %edx jz 8f movl $1, %eax /* success, have mmx */ popl %ebx ret 8: xorl %eax,%eax /* failed, no mmx */ popl %ebx ret #if defined(__GNUC__) && !defined(_WIN32) .section .note.GNU-stack, "", @progbits .previous #endif