Mercurial > mplayer.hg
annotate mp3lib/test2.c @ 26907:f0d0b666ee35
Fix compilation with internal dvdnav
author | rtogni |
---|---|
date | Sat, 31 May 2008 13:42:09 +0000 |
parents | 01829c7ce94d |
children | e7c989f7a7c9 |
rev | line source |
---|---|
789
989b921361d0
test2 added for playback test, testreanmed to test1 to make Atmosfear happy...
arpi_esp
parents:
diff
changeset
|
1 #include <stdio.h> |
989b921361d0
test2 added for playback test, testreanmed to test1 to make Atmosfear happy...
arpi_esp
parents:
diff
changeset
|
2 #include <stdlib.h> |
26498 | 3 #include <string.h> |
789
989b921361d0
test2 added for playback test, testreanmed to test1 to make Atmosfear happy...
arpi_esp
parents:
diff
changeset
|
4 |
989b921361d0
test2 added for playback test, testreanmed to test1 to make Atmosfear happy...
arpi_esp
parents:
diff
changeset
|
5 #include <fcntl.h> |
989b921361d0
test2 added for playback test, testreanmed to test1 to make Atmosfear happy...
arpi_esp
parents:
diff
changeset
|
6 #include <sys/ioctl.h> |
989b921361d0
test2 added for playback test, testreanmed to test1 to make Atmosfear happy...
arpi_esp
parents:
diff
changeset
|
7 #include <unistd.h> |
989b921361d0
test2 added for playback test, testreanmed to test1 to make Atmosfear happy...
arpi_esp
parents:
diff
changeset
|
8 #include <sys/soundcard.h> |
989b921361d0
test2 added for playback test, testreanmed to test1 to make Atmosfear happy...
arpi_esp
parents:
diff
changeset
|
9 |
26203 | 10 #include "config.h" |
789
989b921361d0
test2 added for playback test, testreanmed to test1 to make Atmosfear happy...
arpi_esp
parents:
diff
changeset
|
11 #include "mp3lib/mp3.h" |
10343 | 12 #include "cpudetect.h" |
789
989b921361d0
test2 added for playback test, testreanmed to test1 to make Atmosfear happy...
arpi_esp
parents:
diff
changeset
|
13 |
989b921361d0
test2 added for playback test, testreanmed to test1 to make Atmosfear happy...
arpi_esp
parents:
diff
changeset
|
14 static FILE* mp3file=NULL; |
989b921361d0
test2 added for playback test, testreanmed to test1 to make Atmosfear happy...
arpi_esp
parents:
diff
changeset
|
15 |
989b921361d0
test2 added for playback test, testreanmed to test1 to make Atmosfear happy...
arpi_esp
parents:
diff
changeset
|
16 int mplayer_audio_read(char *buf,int size){ |
989b921361d0
test2 added for playback test, testreanmed to test1 to make Atmosfear happy...
arpi_esp
parents:
diff
changeset
|
17 return fread(buf,1,size,mp3file); |
989b921361d0
test2 added for playback test, testreanmed to test1 to make Atmosfear happy...
arpi_esp
parents:
diff
changeset
|
18 } |
989b921361d0
test2 added for playback test, testreanmed to test1 to make Atmosfear happy...
arpi_esp
parents:
diff
changeset
|
19 |
989b921361d0
test2 added for playback test, testreanmed to test1 to make Atmosfear happy...
arpi_esp
parents:
diff
changeset
|
20 #define BUFFLEN 4608 |
989b921361d0
test2 added for playback test, testreanmed to test1 to make Atmosfear happy...
arpi_esp
parents:
diff
changeset
|
21 static unsigned char buffer[BUFFLEN]; |
989b921361d0
test2 added for playback test, testreanmed to test1 to make Atmosfear happy...
arpi_esp
parents:
diff
changeset
|
22 |
10343 | 23 |
789
989b921361d0
test2 added for playback test, testreanmed to test1 to make Atmosfear happy...
arpi_esp
parents:
diff
changeset
|
24 int main(int argc,char* argv[]){ |
989b921361d0
test2 added for playback test, testreanmed to test1 to make Atmosfear happy...
arpi_esp
parents:
diff
changeset
|
25 int len; |
989b921361d0
test2 added for playback test, testreanmed to test1 to make Atmosfear happy...
arpi_esp
parents:
diff
changeset
|
26 int total=0; |
989b921361d0
test2 added for playback test, testreanmed to test1 to make Atmosfear happy...
arpi_esp
parents:
diff
changeset
|
27 int r; |
989b921361d0
test2 added for playback test, testreanmed to test1 to make Atmosfear happy...
arpi_esp
parents:
diff
changeset
|
28 int audio_fd; |
989b921361d0
test2 added for playback test, testreanmed to test1 to make Atmosfear happy...
arpi_esp
parents:
diff
changeset
|
29 |
989b921361d0
test2 added for playback test, testreanmed to test1 to make Atmosfear happy...
arpi_esp
parents:
diff
changeset
|
30 mp3file=fopen((argc>1)?argv[1]:"test.mp3","rb"); |
989b921361d0
test2 added for playback test, testreanmed to test1 to make Atmosfear happy...
arpi_esp
parents:
diff
changeset
|
31 if(!mp3file){ printf("file not found\n"); exit(1); } |
10343 | 32 |
33 GetCpuCaps(&gCpuCaps); | |
789
989b921361d0
test2 added for playback test, testreanmed to test1 to make Atmosfear happy...
arpi_esp
parents:
diff
changeset
|
34 |
989b921361d0
test2 added for playback test, testreanmed to test1 to make Atmosfear happy...
arpi_esp
parents:
diff
changeset
|
35 // MPEG Audio: |
989b921361d0
test2 added for playback test, testreanmed to test1 to make Atmosfear happy...
arpi_esp
parents:
diff
changeset
|
36 #ifdef USE_FAKE_MONO |
989b921361d0
test2 added for playback test, testreanmed to test1 to make Atmosfear happy...
arpi_esp
parents:
diff
changeset
|
37 MP3_Init(0); |
989b921361d0
test2 added for playback test, testreanmed to test1 to make Atmosfear happy...
arpi_esp
parents:
diff
changeset
|
38 #else |
989b921361d0
test2 added for playback test, testreanmed to test1 to make Atmosfear happy...
arpi_esp
parents:
diff
changeset
|
39 MP3_Init(); |
989b921361d0
test2 added for playback test, testreanmed to test1 to make Atmosfear happy...
arpi_esp
parents:
diff
changeset
|
40 #endif |
989b921361d0
test2 added for playback test, testreanmed to test1 to make Atmosfear happy...
arpi_esp
parents:
diff
changeset
|
41 MP3_samplerate=MP3_channels=0; |
989b921361d0
test2 added for playback test, testreanmed to test1 to make Atmosfear happy...
arpi_esp
parents:
diff
changeset
|
42 len=MP3_DecodeFrame(buffer,-1); |
989b921361d0
test2 added for playback test, testreanmed to test1 to make Atmosfear happy...
arpi_esp
parents:
diff
changeset
|
43 |
989b921361d0
test2 added for playback test, testreanmed to test1 to make Atmosfear happy...
arpi_esp
parents:
diff
changeset
|
44 audio_fd=open("/dev/dsp", O_WRONLY); |
989b921361d0
test2 added for playback test, testreanmed to test1 to make Atmosfear happy...
arpi_esp
parents:
diff
changeset
|
45 if(audio_fd<0){ printf("Can't open audio device\n");exit(1); } |
989b921361d0
test2 added for playback test, testreanmed to test1 to make Atmosfear happy...
arpi_esp
parents:
diff
changeset
|
46 r=AFMT_S16_LE;ioctl (audio_fd, SNDCTL_DSP_SETFMT, &r); |
989b921361d0
test2 added for playback test, testreanmed to test1 to make Atmosfear happy...
arpi_esp
parents:
diff
changeset
|
47 r=MP3_channels-1;ioctl (audio_fd, SNDCTL_DSP_STEREO, &r); |
989b921361d0
test2 added for playback test, testreanmed to test1 to make Atmosfear happy...
arpi_esp
parents:
diff
changeset
|
48 r=MP3_samplerate;ioctl (audio_fd, SNDCTL_DSP_SPEED, &r); |
989b921361d0
test2 added for playback test, testreanmed to test1 to make Atmosfear happy...
arpi_esp
parents:
diff
changeset
|
49 printf("audio_setup: using %d Hz samplerate (requested: %d)\n",r,MP3_samplerate); |
989b921361d0
test2 added for playback test, testreanmed to test1 to make Atmosfear happy...
arpi_esp
parents:
diff
changeset
|
50 |
989b921361d0
test2 added for playback test, testreanmed to test1 to make Atmosfear happy...
arpi_esp
parents:
diff
changeset
|
51 while(1){ |
989b921361d0
test2 added for playback test, testreanmed to test1 to make Atmosfear happy...
arpi_esp
parents:
diff
changeset
|
52 int len2; |
989b921361d0
test2 added for playback test, testreanmed to test1 to make Atmosfear happy...
arpi_esp
parents:
diff
changeset
|
53 if(len==0) len=MP3_DecodeFrame(buffer,-1); |
989b921361d0
test2 added for playback test, testreanmed to test1 to make Atmosfear happy...
arpi_esp
parents:
diff
changeset
|
54 if(len<=0) break; // EOF |
989b921361d0
test2 added for playback test, testreanmed to test1 to make Atmosfear happy...
arpi_esp
parents:
diff
changeset
|
55 |
989b921361d0
test2 added for playback test, testreanmed to test1 to make Atmosfear happy...
arpi_esp
parents:
diff
changeset
|
56 // play it |
989b921361d0
test2 added for playback test, testreanmed to test1 to make Atmosfear happy...
arpi_esp
parents:
diff
changeset
|
57 len2=write(audio_fd,buffer,len); |
989b921361d0
test2 added for playback test, testreanmed to test1 to make Atmosfear happy...
arpi_esp
parents:
diff
changeset
|
58 if(len2<0) break; // ERROR? |
989b921361d0
test2 added for playback test, testreanmed to test1 to make Atmosfear happy...
arpi_esp
parents:
diff
changeset
|
59 len-=len2; total+=len2; |
989b921361d0
test2 added for playback test, testreanmed to test1 to make Atmosfear happy...
arpi_esp
parents:
diff
changeset
|
60 if(len>0){ |
989b921361d0
test2 added for playback test, testreanmed to test1 to make Atmosfear happy...
arpi_esp
parents:
diff
changeset
|
61 // this shouldn't happen... |
989b921361d0
test2 added for playback test, testreanmed to test1 to make Atmosfear happy...
arpi_esp
parents:
diff
changeset
|
62 memcpy(buffer,buffer+len2,len); |
989b921361d0
test2 added for playback test, testreanmed to test1 to make Atmosfear happy...
arpi_esp
parents:
diff
changeset
|
63 putchar('!');fflush(stdout); |
989b921361d0
test2 added for playback test, testreanmed to test1 to make Atmosfear happy...
arpi_esp
parents:
diff
changeset
|
64 } |
989b921361d0
test2 added for playback test, testreanmed to test1 to make Atmosfear happy...
arpi_esp
parents:
diff
changeset
|
65 } |
989b921361d0
test2 added for playback test, testreanmed to test1 to make Atmosfear happy...
arpi_esp
parents:
diff
changeset
|
66 |
989b921361d0
test2 added for playback test, testreanmed to test1 to make Atmosfear happy...
arpi_esp
parents:
diff
changeset
|
67 fclose(mp3file); |
26500 | 68 return 0; |
789
989b921361d0
test2 added for playback test, testreanmed to test1 to make Atmosfear happy...
arpi_esp
parents:
diff
changeset
|
69 } |