Implemented some cdrecord pickiness for .wav extraction
This commit is contained in:
@ -38,10 +38,13 @@ int libdax_audioxtr_new(struct libdax_audioxtr **xtr, char *path, int flag)
|
||||
o->fd= -1;
|
||||
strcpy(o->fmt,"unidentified");
|
||||
o->fmt_info[0]= 0;
|
||||
o->data_size= 0;
|
||||
o->extract_count= 0;
|
||||
|
||||
o->wav_num_channels= 0;
|
||||
o->wav_sample_rate= 0;
|
||||
o->wav_bits_per_sample= 0;
|
||||
o->wav_subchunk2_size= 0;
|
||||
|
||||
ret= libdax_audioxtr_open(o,0);
|
||||
if(ret<=0)
|
||||
@ -136,6 +139,8 @@ static int libdax_audioxtr_identify(struct libdax_audioxtr *o, int flag)
|
||||
sprintf(o->fmt_info,
|
||||
".wav , num_channels=%d , sample_rate=%d , bits_per_sample=%d",
|
||||
o->wav_num_channels,o->wav_sample_rate,o->wav_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);
|
||||
}
|
||||
@ -161,6 +166,7 @@ static int libdax_audioxtr_init_reading(struct libdax_audioxtr *o, int flag)
|
||||
if(o->fd==0) /* stdin: hope no read came after libdax_audioxtr_identify() */
|
||||
return(1);
|
||||
|
||||
o->extract_count= 0;
|
||||
ret= lseek(o->fd,44,SEEK_SET);
|
||||
if(ret==-1)
|
||||
return(0);
|
||||
@ -186,6 +192,17 @@ int libdax_audioxtr_get_id(struct libdax_audioxtr *o,
|
||||
}
|
||||
|
||||
|
||||
int libdax_audioxtr_get_size(struct libdax_audioxtr *o, off_t *size, int flag)
|
||||
{
|
||||
if(strcmp(o->fmt,".wav")==0) {
|
||||
*size= o->wav_subchunk2_size;
|
||||
return(1);
|
||||
}
|
||||
*size= 0;
|
||||
return(0);
|
||||
}
|
||||
|
||||
|
||||
int libdax_audioxtr_read(struct libdax_audioxtr *o,
|
||||
char buffer[], int buffer_size, int flag)
|
||||
{
|
||||
@ -193,7 +210,14 @@ int libdax_audioxtr_read(struct libdax_audioxtr *o,
|
||||
|
||||
if(buffer_size<=0 || o->fd<0)
|
||||
return(-2);
|
||||
if(o->data_size>0 && !(flag&1))
|
||||
if(buffer_size > o->data_size - o->extract_count)
|
||||
buffer_size= o->data_size - o->extract_count;
|
||||
if(buffer_size<=0)
|
||||
return(0);
|
||||
ret= read(o->fd,buffer,buffer_size);
|
||||
if(ret>0)
|
||||
o->extract_count+= ret;
|
||||
return(ret);
|
||||
}
|
||||
|
||||
|
@ -60,12 +60,23 @@ int libdax_audioxtr_get_id(struct libdax_audioxtr *xtr,
|
||||
int *bits_per_sample, int flag);
|
||||
|
||||
|
||||
/** Obtain a prediction about the extracted size based on internal information
|
||||
of the formatted file.
|
||||
@param xtr Opaque handle to extractor
|
||||
@param size Gets filled with the predicted size
|
||||
@param flag Bitfield for control purposes (unused yet, submit 0)
|
||||
@return 1 prediction was possible , 0 no prediction could be made
|
||||
*/
|
||||
int libdax_audioxtr_get_size(struct libdax_audioxtr *o, off_t *size, int flag);
|
||||
|
||||
|
||||
/** Obtain next buffer full of extracted data in desired format (only raw audio
|
||||
for now).
|
||||
@param xtr Opaque handle to extractor
|
||||
@param buffer Gets filled with extracted data
|
||||
@param buffer_size Maximum number of bytes to be filled into buffer
|
||||
@param flag Bitfield for control purposes (unused yet, submit 0)
|
||||
@param flag Bitfield for control purposes
|
||||
bit0= do not stop at predicted end of data
|
||||
@return >0 number of valid buffer bytes,
|
||||
0 End of file
|
||||
-1 operating system reports error
|
||||
@ -134,6 +145,12 @@ struct libdax_audioxtr {
|
||||
/* Format parameter info text */
|
||||
char fmt_info[LIBDAX_AUDIOXTR_STRLEN];
|
||||
|
||||
/* Number of bytes to extract (0= unknown/unlimited) */
|
||||
off_t data_size;
|
||||
|
||||
/* Number of extracted data bytes */
|
||||
off_t extract_count;
|
||||
|
||||
|
||||
/* Format dependent parameters */
|
||||
|
||||
@ -149,6 +166,10 @@ struct libdax_audioxtr {
|
||||
/* 8 bits = 8, 16 bits = 16, etc. */
|
||||
int wav_bits_per_sample;
|
||||
|
||||
/* == NumSamples * NumChannels * BitsPerSample/8
|
||||
This is the number of bytes in the data. */
|
||||
unsigned wav_subchunk2_size;
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user