Changeset 87636d0
- Timestamp:
- Mar 12, 2014, 4:32:32 AM (11 years ago)
- Branches:
- feature/autosink, feature/cnn, feature/cnn_org, feature/constantq, feature/crepe, feature/crepe_org, feature/pitchshift, feature/pydocstrings, feature/timestretch, fix/ffmpeg5, master, pitchshift, sampler, timestretch, yinfft+
- Children:
- 46148d3
- Parents:
- 46b00690
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/io/source_wavread.c
r46b00690 r87636d0 53 53 uint_t eof; 54 54 55 size_t seek_start; 56 55 57 unsigned char *short_output; 56 58 fmat_t *output; … … 68 70 aubio_source_wavread_t * new_aubio_source_wavread(char_t * path, uint_t samplerate, uint_t hop_size) { 69 71 aubio_source_wavread_t * s = AUBIO_NEW(aubio_source_wavread_t); 72 size_t bytes_read = 0, bytes_expected = 44; 70 73 unsigned char buf[5]; 71 74 unsigned int format, channels, sr, byterate, blockalign, bitspersample;//, data_size; … … 95 98 96 99 // ChunkID 97 fread(buf, 4, 1, s->fid);100 bytes_read += fread(buf, 1, 4, s->fid); 98 101 buf[4] = '\0'; 99 102 if ( strcmp((const char *)buf, "RIFF") != 0 ) { … … 103 106 104 107 // ChunkSize 105 fread(buf, 4, 1, s->fid);108 bytes_read += fread(buf, 1, 4, s->fid); 106 109 107 110 // Format 108 fread(buf, 4, 1, s->fid);111 bytes_read += fread(buf, 1, 4, s->fid); 109 112 buf[4] = '\0'; 110 113 if ( strcmp((const char *)buf, "WAVE") != 0 ) { … … 114 117 115 118 // Subchunk1ID 116 fread(buf, 4, 1, s->fid);119 bytes_read += fread(buf, 1, 4, s->fid); 117 120 buf[4] = '\0'; 118 121 if ( strcmp((const char *)buf, "fmt ") != 0 ) { … … 122 125 123 126 // Subchunk1Size 124 fread(buf, 4, 1, s->fid);127 bytes_read += fread(buf, 1, 4, s->fid); 125 128 format = read_little_endian(buf, 4); 126 129 if ( format != 16 ) { … … 135 138 136 139 // AudioFormat 137 fread(buf, 2, 1, s->fid);140 bytes_read += fread(buf, 1, 2, s->fid); 138 141 if ( buf[0] != 1 || buf[1] != 0) { 139 142 AUBIO_ERR("source_wavread: AudioFormat should be PCM, in %s\n", s->path); … … 142 145 143 146 // NumChannels 144 fread(buf, 2, 1, s->fid);147 bytes_read += fread(buf, 1, 2, s->fid); 145 148 channels = read_little_endian(buf, 2); 146 149 147 150 // SampleRate 148 fread(buf, 4, 1, s->fid);151 bytes_read += fread(buf, 1, 4, s->fid); 149 152 sr = read_little_endian(buf, 4); 150 153 151 154 // ByteRate 152 fread(buf, 4, 1, s->fid);155 bytes_read += fread(buf, 1, 4, s->fid); 153 156 byterate = read_little_endian(buf, 4); 154 157 155 158 // BlockAlign 156 fread(buf, 2, 1, s->fid);159 bytes_read += fread(buf, 1, 2, s->fid); 157 160 blockalign = read_little_endian(buf, 2); 158 161 159 162 // BitsPerSample 160 fread(buf, 2, 1, s->fid);163 bytes_read += fread(buf, 1, 2, s->fid); 161 164 bitspersample = read_little_endian(buf, 2); 162 165 #if 0 … … 201 204 202 205 // Subchunk2ID 203 fread(buf, 4, 1, s->fid);206 bytes_read += fread(buf, 1, 4, s->fid); 204 207 buf[4] = '\0'; 205 208 if ( strcmp((const char *)buf, "data") != 0 ) { … … 209 212 210 213 // Subchunk2Size 211 fread(buf, 4, 1, s->fid);214 bytes_read += fread(buf, 1, 4, s->fid); 212 215 //data_size = buf[0] + (buf[1] << 8) + (buf[2] << 16) + (buf[3] << 24); 213 216 //AUBIO_MSG("found %d frames in %s\n", 8 * data_size / bitspersample / channels, s->path); 217 218 // check the total number of bytes read is correct 219 if ( bytes_read != bytes_expected ) { 220 AUBIO_ERR("source_wavread: short read (%zd instead of %zd) in %s\n", 221 bytes_read, bytes_expected, s->path); 222 goto beach; 223 } 224 s->seek_start = bytes_read; 214 225 215 226 s->output = new_fmat(s->input_channels, AUBIO_WAVREAD_BUFSIZE); … … 341 352 342 353 uint_t aubio_source_wavread_seek (aubio_source_wavread_t * s, uint_t pos) { 343 uint_t ret = fseek(s->fid, 44+ pos * s->blockalign, SEEK_SET);354 uint_t ret = fseek(s->fid, s->seek_start + pos * s->blockalign, SEEK_SET); 344 355 s->eof = 0; 345 356 s->read_index = 0;
Note: See TracChangeset
for help on using the changeset viewer.