[Mplayer-cvslog] CVS: main/libac3 test2.c,NONE,1.1 Makefile,1.2,1.3

GEREOFFY arpi_esp at users.sourceforge.net
Sun May 13 22:26:20 CEST 2001


Update of /cvsroot/mplayer/main/libac3
In directory usw-pr-cvs1:/tmp/cvs-serv28837

Modified Files:
	Makefile 
Added Files:
	test2.c 
Log Message:
test2 (playback test) added

--- NEW FILE ---

#include <stdio.h>
#include <stdlib.h>

#include <fcntl.h>
#include <sys/ioctl.h>
#include <unistd.h>
#include <sys/soundcard.h>

#include "libac3/ac3.h"
#include "config.h"

static FILE* ac3file=NULL;

#define IN_BUF_SIZE (2048*32)

static unsigned char in_buf[IN_BUF_SIZE];

// AC3 decoder buffer callback:
static void ac3_fill_buffer(uint8_t **start,uint8_t **end){
    int len=fread(in_buf,1,IN_BUF_SIZE,ac3file);
    if(len<=0){
          *start = *end = NULL;        // EOF
          return;
    }
    *start=in_buf;
    *end=&in_buf[len];
//    printf("!!!\n");
}

int main(int argc,char* argv[]){
  int len;
  int total=0;
  float length;
  int r;
  int audio_fd;
  ac3_frame_t* ac3_frame=NULL;
  
  ac3file=fopen((argc>1)?argv[1]:"test2.ac3","rb");
  if(!ac3file){  printf("file not found\n");  exit(1); }

  // Dolby AC3 audio:
  ac3_config.fill_buffer_callback = ac3_fill_buffer;
  ac3_config.num_output_ch = 2;
  ac3_config.flags = 0;
#ifdef HAVE_MMX
  ac3_config.flags |= AC3_MMX_ENABLE;
#endif
#ifdef HAVE_3DNOW
  ac3_config.flags |= AC3_3DNOW_ENABLE;
#endif
  ac3_init();
  ac3_frame = ac3_decode_frame();
  if(!ac3_frame){  printf("Can't decode this file...\n");exit(1); }

  audio_fd=open("/dev/dsp", O_WRONLY);
  if(audio_fd<0){  printf("Can't open audio device\n");exit(1); }
  r=AFMT_S16_LE;ioctl (audio_fd, SNDCTL_DSP_SETFMT, &r);
  r=1;ioctl (audio_fd, SNDCTL_DSP_STEREO, &r);
  r=ac3_frame->sampling_rate;ioctl (audio_fd, SNDCTL_DSP_SPEED, &r);
  printf("audio_setup: using %d Hz samplerate (requested: %d)\n",r,ac3_frame->sampling_rate);
  
  while(1){
      int len2;
      if(!ac3_frame) ac3_frame = ac3_decode_frame();
      if(!ac3_frame) break; // EOF
      len=256*6*4;  // 2048*3
            
      // play it
      len2=write(audio_fd,ac3_frame->audio_data,len);
      if(len2<0) break; // ERROR?
      if(len2<len) printf("???\n"); // shouldn't happen
      ac3_frame=NULL;
  }
  
  fclose(ac3file);
  
}

Index: Makefile
===================================================================
RCS file: /cvsroot/mplayer/main/libac3/Makefile,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -r1.2 -r1.3
*** Makefile	2001/03/02 21:49:16	1.2
--- Makefile	2001/05/13 20:26:18	1.3
***************
*** 13,20 ****
  
  .c.o:
! 	$(CC) -c $(CFLAGS) $(INCLUDE) -o $@ $<
  
  $(LIBNAME):	.depend $(OBJS)
  	$(AR) r $(LIBNAME) $(OBJS)
  
  all:	$(LIBNAME)
--- 13,23 ----
  
  .c.o:
! 	$(CC) -c $(CFLAGS) -o $@ $<
  
  $(LIBNAME):	.depend $(OBJS)
  	$(AR) r $(LIBNAME) $(OBJS)
+ 
+ test2:        $(LIBNAME) test2.c
+ 	$(CC) $(CFLAGS) test2.c -o test2 -L. -lac3 
  
  all:	$(LIBNAME)


_______________________________________________
Mplayer-cvslog mailing list
Mplayer-cvslog at lists.sourceforge.net
http://lists.sourceforge.net/lists/listinfo/mplayer-cvslog



More information about the MPlayer-cvslog mailing list