~ubuntu-dev/mplayer/ubuntu-feisty

« back to all changes in this revision

Viewing changes to mp3lib/test2.c

  • Committer: Reinhard Tartler
  • Date: 2006-07-08 08:45:33 UTC
  • Revision ID: siretart@tauware.de-20060708084533-dbc155bde7122e78
imported mplayer_0.99+1.0pre7try2+cvs20060117

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
 
 
2
//gcc test2.c -O2 -I.. -L. ../libvo/aclib.c -lMP3 -lm -o test2
 
3
 
 
4
#include <stdio.h>
 
5
#include <stdlib.h>
 
6
 
 
7
#include <fcntl.h>
 
8
#include <sys/ioctl.h>
 
9
#include <unistd.h>
 
10
#include <sys/soundcard.h>
 
11
 
 
12
#include "mp3lib/mp3.h"
 
13
#include "config.h"
 
14
#include "cpudetect.h"
 
15
 
 
16
static FILE* mp3file=NULL;
 
17
 
 
18
int mplayer_audio_read(char *buf,int size){
 
19
    return fread(buf,1,size,mp3file);
 
20
}
 
21
 
 
22
#define BUFFLEN 4608
 
23
static unsigned char buffer[BUFFLEN];
 
24
 
 
25
 
 
26
int main(int argc,char* argv[]){
 
27
  int len;
 
28
  int total=0;
 
29
  float length;
 
30
  int r;
 
31
  int audio_fd;
 
32
  
 
33
  mp3file=fopen((argc>1)?argv[1]:"test.mp3","rb");
 
34
  if(!mp3file){  printf("file not found\n");  exit(1); }
 
35
  
 
36
  GetCpuCaps(&gCpuCaps);
 
37
 
 
38
  // MPEG Audio:
 
39
#ifdef USE_FAKE_MONO
 
40
  MP3_Init(0);
 
41
#else
 
42
  MP3_Init();
 
43
#endif
 
44
  MP3_samplerate=MP3_channels=0;
 
45
  len=MP3_DecodeFrame(buffer,-1);
 
46
  
 
47
  audio_fd=open("/dev/dsp", O_WRONLY);
 
48
  if(audio_fd<0){  printf("Can't open audio device\n");exit(1); }
 
49
  r=AFMT_S16_LE;ioctl (audio_fd, SNDCTL_DSP_SETFMT, &r);
 
50
  r=MP3_channels-1;ioctl (audio_fd, SNDCTL_DSP_STEREO, &r);
 
51
  r=MP3_samplerate;ioctl (audio_fd, SNDCTL_DSP_SPEED, &r);
 
52
  printf("audio_setup: using %d Hz samplerate (requested: %d)\n",r,MP3_samplerate);
 
53
  
 
54
  while(1){
 
55
      int len2;
 
56
      if(len==0) len=MP3_DecodeFrame(buffer,-1);
 
57
      if(len<=0) break; // EOF
 
58
      
 
59
      // play it
 
60
      len2=write(audio_fd,buffer,len);
 
61
      if(len2<0) break; // ERROR?
 
62
      len-=len2; total+=len2;
 
63
      if(len>0){
 
64
          // this shouldn't happen...
 
65
          memcpy(buffer,buffer+len2,len);
 
66
          putchar('!');fflush(stdout);
 
67
      }
 
68
  }
 
69
  
 
70
  fclose(mp3file);
 
71
  
 
72
}