示例#1
0
int aac_open(auds_t *auds, char *fname)
{
	aac_t *aac=malloc(sizeof(aac_t));
	if(!aac) return -1;
	memset(aac,0,sizeof(aac_t));
	auds->stream=(aac_t*)aac;
	aac->fname=(char *)malloc(strlen(fname)+1);
	if(!aac->fname) goto erexit;
	strcpy(aac->fname,fname);
	aac->buffer=(u_int8_t *)malloc(MAX_SAMPLES_IN_CHUNK*4+16);
	if(!aac->buffer) goto erexit;
	auds->sigchld_cb=sigchld_callback;
	auds->sample_rate=DEFAULT_SAMPLE_RATE;
	read_header(auds, fname);
	if(access(FIFO_NAME,F_OK) && mkfifo(FIFO_NAME,0600)<0){
		ERRMSG("can't make a named fifo:%s\n",FIFO_NAME);
		goto erexit;
	}
	run_decoder(aac);
	auds->chunk_size=aud_clac_chunk_size(auds->sample_rate);
	return 0;
 erexit:
	aac_close(auds);
	return -1;
}
示例#2
0
int pcm_open(auds_t *auds, char *fname)
{
	pcm_t *pcm=malloc(sizeof(pcm_t));
	if(!pcm) return -1;
	memset(pcm,0,sizeof(pcm_t));
	auds->stream=(void *)pcm;
	pcm->dfd=open(fname, O_RDONLY|O_NONBLOCK);
	if(pcm->dfd<0) goto erexit;
	auds->sample_rate=DEFAULT_SAMPLE_RATE;
	auds->chunk_size=aud_clac_chunk_size(auds->sample_rate);
	pcm->buffer=(__u8 *)malloc(MAX_SAMPLES_IN_CHUNK*4+16);
	if(!pcm->buffer) goto erexit;
	return 0;
 erexit:
	pcm_close(auds);
	return -1;
}
示例#3
0
int wav_open(auds_t *auds, char *fname)
{
	wav_t *wav=malloc(sizeof(wav_t));
	if(!wav) return -1;
	memset(wav,0,sizeof(wav_t));
	auds->stream=(void *)wav;
	wav->inf=fopen(fname,"r");
	if(!wav->inf) goto erexit;
	if(read_wave_header(wav, &auds->sample_rate, &auds->channels)==-1) goto erexit;
	auds->chunk_size=aud_clac_chunk_size(auds->sample_rate);
	wav->buffer=(__u8 *)malloc(MAX_SAMPLES_IN_CHUNK*4+16);
	if(!wav->buffer) goto erexit;
	return 0;
 erexit:
	wav_close(auds);
	return -1;
}
示例#4
0
int wav_open(auds_t *auds, char *fname)
{
        struct stat finfo;
	wav_t *wav=malloc(sizeof(wav_t));
	if(!wav) return -1;
	memset(wav,0,sizeof(wav_t));
	auds->stream=(void *)wav;
	wav->inf=fopen(fname,"r");
	if(!wav->inf) goto erexit;
        if ( csync!=0 )
        {
	   wav->inf2=fopen(fname,"r");
	   if(!wav->inf2) goto erexit;
        }
	if(read_wave_header(wav, &auds->sample_rate, &auds->channels)==-1) goto erexit;
	auds->chunk_size=aud_clac_chunk_size(auds->sample_rate);
	wav->buffer=(uint8_t *)malloc(MAX_SAMPLES_IN_CHUNK*4+16);
	if(!wav->buffer) goto erexit;

        if(stat(fname,&finfo)<0)
        {
          ERRMSG( "Couldn't get file size\n" );
          fduration=0;
        }
        else
        {
          fduration=(finfo.st_size-sizeof(wave_header_t))/(sizeof(short)*auds->channels*auds->sample_rate);
          flength=(finfo.st_size-sizeof(wave_header_t))/(sizeof(short)*auds->channels);
          DBGMSG( "duration in seconds : %d\n", fduration );
        }

        DBGMSG( "Start time is %ld\n", startinms );
        if ( startinms != -1 )
        {
           long nbbytes = sizeof(short)*auds->channels*auds->sample_rate;
           nbbytes *= startinms/1000;
           DBGMSG( "inf : Seeking to %ld bytes\n", nbbytes );

           if ( fseek( wav->inf, nbbytes, SEEK_CUR ) < 0 )
           {
              ERRMSG( "Couldn't seek specified start time : %s", strerror( errno ) );
              wav_close(auds);
              return -1;
           }

           if ( csync!=0 )
           {
              nbbytes = sizeof(short)*auds->channels*auds->sample_rate;
              int mcsync = (int)(csync*1000.0);
              nbbytes *= (startinms+mcsync)/1000;
              DBGMSG( "inf2 : seeking to %ld from current\n", nbbytes );

              if ( fseek( wav->inf2, nbbytes, SEEK_CUR ) < 0 )
              {
                 ERRMSG( "Couldn't seek specified start time : %s", strerror( errno ) );
                 wav_close(auds);
                 return -1;
              }
           }
        }
        else
        {
           if ( csync!=0 )
           {
              int nbbytes = sizeof(short)*auds->channels*auds->sample_rate;
              int mcsync = (int)(csync*1000.0);
              nbbytes *= mcsync/1000;
              DBGMSG( "inf2 : seeking to %d from current\n", nbbytes );
              if ( fseek( wav->inf2, nbbytes, SEEK_CUR ) < 0 )
              {
                 ERRMSG( "fseek ahead failed : reason : %s", strerror( errno ) );
                 goto erexit;
              }
           }
        }

	return 0;
 erexit:
	wav_close(auds);
	return -1;
}