Exemplo n.º 1
0
static int libdax_audioxtr_identify_au(struct libdax_audioxtr *o, int flag)
{
 int ret,encoding;
 char buf[24];

 /* Check wether this is a Sun Audio, .au file */
 /* info used: http://ccrma.stanford.edu/courses/422/projects/WaveFormat/ */

 if(o->fd!=0) {
   ret= lseek(o->fd,0,SEEK_SET);
   if(ret==-1)
     return(0);
 }
 ret= read(o->fd, buf, 24);
 if(ret<24)
   return(0);

 if(strncmp(buf,".snd",4)!=0)
   return(0);
 strcpy(o->fmt,".au");
 o->msb_first= 1;
 o->au_data_location= libdax_audioxtr_to_int(o,(unsigned char *)buf+4,4,1);
 o->au_data_size= libdax_audioxtr_to_int(o,(unsigned char *)buf+8,4,1);
 encoding= libdax_audioxtr_to_int(o,(unsigned char *)buf+12,4,1);
 if(encoding==2)
   o->bits_per_sample= 8;
 else if(encoding==3)
   o->bits_per_sample= 16;
 else if(encoding==4)
   o->bits_per_sample= 24;
 else if(encoding==5)
   o->bits_per_sample= 32;
 else
   o->bits_per_sample= -encoding;
 o->sample_rate= libdax_audioxtr_to_int(o,(unsigned char *)buf+16,4,1);
 o->num_channels= libdax_audioxtr_to_int(o,(unsigned char *)buf+20,4,1);
 if(o->au_data_size!=0xffffffff)
   o->data_size= o->au_data_size;
 else
   o->data_size= 0;
 sprintf(o->fmt_info,
         ".au , num_channels=%d , sample_rate=%d , bits_per_sample=%d",
         o->num_channels,o->sample_rate,o->bits_per_sample);

 /* <<< for testing only */; 
 return(1);

 return(o->bits_per_sample>0); /* Audio format must be linear PCM */
}
Exemplo n.º 2
0
static int libdax_audioxtr_identify_wav(struct libdax_audioxtr *o, int flag)
{
 int ret;
 char buf[45];

 /* check wether this is a MS WAVE file .wav */
 /* info used: http://ccrma.stanford.edu/courses/422/projects/WaveFormat/ */

 if(o->fd!=0) {
   ret= lseek(o->fd,0,SEEK_SET);
   if(ret==-1)
     return(0);
 }
 ret= read(o->fd, buf, 44);
 if(ret<44)
   return(0);
 buf[44]= 0; /* as stopper for any string operations */

 if(strncmp(buf,"RIFF",4)!=0)                                     /* ChunkID */
   return(0);
 if(strncmp(buf+8,"WAVE",4)!=0)                                    /* Format */ 
   return(0);
 if(strncmp(buf+12,"fmt ",4)!=0)                              /* Subchunk1ID */
   return(0);
 if(buf[16]!=16 || buf[17]!=0 || buf[18]!=0 || buf[19]!=0)  /* Subchunk1Size */
   return(0);
 if(buf[20]!=1 || buf[21]!=0)  /* AudioFormat must be 1 (Linear quantization) */
   return(0);

 strcpy(o->fmt,".wav");
 o->msb_first= 0;
 o->num_channels=  libdax_audioxtr_to_int(o,(unsigned char *) buf+22,2,0);
 o->sample_rate= libdax_audioxtr_to_int(o,(unsigned char *) buf+24,4,0);
 o->bits_per_sample= libdax_audioxtr_to_int(o,(unsigned char *)buf+34,2,0);
 sprintf(o->fmt_info,
         ".wav , num_channels=%d , sample_rate=%d , bits_per_sample=%d",
         o->num_channels,o->sample_rate,o->bits_per_sample);
 o->wav_subchunk2_size= libdax_audioxtr_to_int(o,(unsigned char *)buf+40,4,0);
 o->data_size= o->wav_subchunk2_size;
 return(1);
}