rpm: Remove MEncoder from rpm packaging
[mplayer/glamo.git] / mp3lib / test2.c
blobccedbecdbd470d58783caf59ad063ab2c0140592
1 /*
2 * This file is part of MPlayer.
4 * MPlayer is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * MPlayer is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License along
15 * with MPlayer; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 #include <stdio.h>
20 #include <stdlib.h>
21 #include <string.h>
23 #include <fcntl.h>
24 #include <sys/ioctl.h>
25 #include <unistd.h>
26 #include <sys/soundcard.h>
28 #include "config.h"
29 #include "mp3lib/mp3.h"
30 #include "cpudetect.h"
32 static FILE* mp3file=NULL;
34 int mplayer_audio_read(char *buf,int size){
35 return fread(buf,1,size,mp3file);
38 #define BUFFLEN 4608
39 static unsigned char buffer[BUFFLEN];
42 int main(int argc,char* argv[]){
43 int len;
44 int total=0;
45 int r;
46 int audio_fd;
48 mp3file=fopen((argc>1)?argv[1]:"test.mp3","rb");
49 if(!mp3file){ printf("file not found\n"); exit(1); }
51 GetCpuCaps(&gCpuCaps);
53 // MPEG Audio:
54 #ifdef CONFIG_FAKE_MONO
55 MP3_Init(0);
56 #else
57 MP3_Init();
58 #endif
59 MP3_samplerate=MP3_channels=0;
60 len=MP3_DecodeFrame(buffer,-1);
62 audio_fd=open("/dev/dsp", O_WRONLY);
63 if(audio_fd<0){ printf("Can't open audio device\n");exit(1); }
64 r=AFMT_S16_LE;ioctl (audio_fd, SNDCTL_DSP_SETFMT, &r);
65 r=MP3_channels-1;ioctl (audio_fd, SNDCTL_DSP_STEREO, &r);
66 r=MP3_samplerate;ioctl (audio_fd, SNDCTL_DSP_SPEED, &r);
67 printf("audio_setup: using %d Hz samplerate (requested: %d)\n",r,MP3_samplerate);
69 while(1){
70 int len2;
71 if(len==0) len=MP3_DecodeFrame(buffer,-1);
72 if(len<=0) break; // EOF
74 // play it
75 len2=write(audio_fd,buffer,len);
76 if(len2<0) break; // ERROR?
77 len-=len2; total+=len2;
78 if(len>0){
79 // this shouldn't happen...
80 memcpy(buffer,buffer+len2,len);
81 putchar('!');fflush(stdout);
85 fclose(mp3file);
86 return 0;