Changeset 14a5b9a
- Timestamp:
- Dec 20, 2018, 5:29:37 PM (6 years ago)
- Branches:
- feature/autosink, feature/cnn, feature/cnn_org, feature/constantq, feature/crepe, feature/crepe_org, feature/pitchshift, feature/timestretch, fix/ffmpeg5, master
- Children:
- a2b7187
- Parents:
- 85e20fa
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/io/sink_wavwrite.c
r85e20fa r14a5b9a 163 163 unsigned char buf[5]; 164 164 uint_t byterate, blockalign; 165 size_t written = 0; 165 166 166 167 /* open output file */ 167 168 s->fid = fopen((const char *)s->path, "wb"); 168 169 if (!s->fid) { 169 AUBIO_ERR("sink_wavwrite: could not open %s (%s)\n", s->path, strerror(errno)); 170 char errorstr[256]; 171 AUBIO_STRERROR(errno, errorstr, sizeof(errorstr)); 172 AUBIO_ERR("sink_wavwrite: could not open %s (%s)\n", s->path, errorstr); 170 173 goto beach; 171 174 } 172 175 173 176 // ChunkID 174 fwrite("RIFF", 4, 1, s->fid);177 written += fwrite("RIFF", 4, 1, s->fid); 175 178 176 179 // ChunkSize (0 for now, actual size will be written in _close) 177 fwrite(write_little_endian(0, buf, 4), 4, 1, s->fid);180 written += fwrite(write_little_endian(0, buf, 4), 4, 1, s->fid); 178 181 179 182 // Format 180 fwrite("WAVE", 4, 1, s->fid);183 written += fwrite("WAVE", 4, 1, s->fid); 181 184 182 185 // Subchunk1ID 183 fwrite("fmt ", 4, 1, s->fid);186 written += fwrite("fmt ", 4, 1, s->fid); 184 187 185 188 // Subchunk1Size 186 fwrite(write_little_endian(16, buf, 4), 4, 1, s->fid);189 written += fwrite(write_little_endian(16, buf, 4), 4, 1, s->fid); 187 190 188 191 // AudioFormat 189 fwrite(write_little_endian(1, buf, 2), 2, 1, s->fid);192 written += fwrite(write_little_endian(1, buf, 2), 2, 1, s->fid); 190 193 191 194 // NumChannels 192 fwrite(write_little_endian(s->channels, buf, 2), 2, 1, s->fid);195 written += fwrite(write_little_endian(s->channels, buf, 2), 2, 1, s->fid); 193 196 194 197 // SampleRate 195 fwrite(write_little_endian(s->samplerate, buf, 4), 4, 1, s->fid);198 written += fwrite(write_little_endian(s->samplerate, buf, 4), 4, 1, s->fid); 196 199 197 200 // ByteRate 198 201 byterate = s->samplerate * s->channels * s->bitspersample / 8; 199 fwrite(write_little_endian(byterate, buf, 4), 4, 1, s->fid);202 written += fwrite(write_little_endian(byterate, buf, 4), 4, 1, s->fid); 200 203 201 204 // BlockAlign 202 205 blockalign = s->channels * s->bitspersample / 8; 203 fwrite(write_little_endian(blockalign, buf, 2), 2, 1, s->fid);206 written += fwrite(write_little_endian(blockalign, buf, 2), 2, 1, s->fid); 204 207 205 208 // BitsPerSample 206 fwrite(write_little_endian(s->bitspersample, buf, 2), 2, 1, s->fid);209 written += fwrite(write_little_endian(s->bitspersample, buf, 2), 2, 1, s->fid); 207 210 208 211 // Subchunk2ID 209 fwrite("data", 4, 1, s->fid);212 written += fwrite("data", 4, 1, s->fid); 210 213 211 214 // Subchunk1Size (0 for now, actual size will be written in _close) 212 fwrite(write_little_endian(0, buf, 4), 4, 1, s->fid); 215 written += fwrite(write_little_endian(0, buf, 4), 4, 1, s->fid); 216 217 // fwrite(*, *, 1, s->fid) was called 13 times, check success 218 if (written != 13) { 219 char errorstr[256]; 220 AUBIO_STRERROR(errno, errorstr, sizeof(errorstr)); 221 AUBIO_WRN("sink_wavwrite: writing header to %s failed, expected %d" 222 " write but got only %d (%s)\n", s->path, 13, written, errorstr); 223 return AUBIO_FAIL; 224 } 213 225 214 226 s->scratch_size = s->max_size * s->channels;
Note: See TracChangeset
for help on using the changeset viewer.