Changeset 68b991e
- Timestamp:
- Dec 17, 2018, 4:41:01 PM (6 years ago)
- Branches:
- feature/autosink, feature/cnn, feature/crepe, fix/ffmpeg5, master
- Children:
- 41d14b8
- Parents:
- 0440778
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/io/sink_flac.c
r0440778 r68b991e 35 35 #include <FLAC/stream_encoder.h> 36 36 37 #include <vorbis/vorbisenc.h>38 37 #include <string.h> // strerror 39 38 #include <errno.h> // errno … … 79 78 80 79 #if 0 81 static void aubio_sink_ vorbis_callback(const FLAC__StreamEncoder* encoder,80 static void aubio_sink_flac_callback(const FLAC__StreamEncoder* encoder, 82 81 FLAC__uint64 bytes_written, FLAC__uint64 samples_written, 83 82 unsigned frames_writtten, unsigned total_frames_estimate, … … 89 88 { 90 89 aubio_sink_flac_t * s = AUBIO_NEW(aubio_sink_flac_t); 90 91 if (!uri) { 92 AUBIO_ERROR("sink_flac: Aborted opening null path\n"); 93 goto failure; 94 } 91 95 92 96 s->path = AUBIO_ARRAY(char_t, strnlen(uri, PATH_MAX) + 1); … … 196 200 init_status = FLAC__stream_encoder_init_file(s->encoder, s->path, 197 201 NULL, NULL); 198 //aubio_sink_ vorbis_callback, s);202 //aubio_sink_flac_callback, s); 199 203 if (init_status == FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_SAMPLE_RATE) { 200 204 AUBIO_ERR("sink_flac: failed initilizing encoder for %s" … … 259 263 { 260 264 uint_t c, v; 265 uint_t length = aubio_sink_validate_input_length("sink_flac", s->path, 266 MAX_WRITE_SIZE, write_data->length, write); 261 267 // fill buffer 262 268 if (!write) { 263 269 return; 264 } else if (write > MAX_WRITE_SIZE) {265 AUBIO_ERR("sink_flac: max_write request %dm asked for %d,"266 " failed writing to %s\n", write, MAX_WRITE_SIZE, s->path);267 return;268 270 } else { 269 271 for (c = 0; c < s->channels; c++) { 270 for (v = 0; v < write; v++) {272 for (v = 0; v < length; v++) { 271 273 s->buffer[v * s->channels + c] = FLOAT_TO_SHORT(write_data->data[v]); 272 274 } … … 275 277 // send to encoder 276 278 FLAC__stream_encoder_process_interleaved(s->encoder, 277 (const FLAC__int32*)s->buffer, write);279 (const FLAC__int32*)s->buffer, length); 278 280 } 279 281 … … 282 284 { 283 285 uint_t c, v; 284 uint_t channels = MIN(s->channels, write_data->height); 286 uint_t channels = aubio_sink_validate_input_channels("sink_flac", s->path, 287 s->channels, write_data->height); 288 uint_t length = aubio_sink_validate_input_length("sink_flac", s->path, 289 MAX_WRITE_SIZE, write_data->length, write); 285 290 // fill buffer 286 291 if (!write) { 287 292 return; 288 } else if (write > MAX_WRITE_SIZE) {289 AUBIO_ERR("sink_flac: max_write request %dm asked for %d,"290 " failed writing to %s\n", write, MAX_WRITE_SIZE, s->path);291 return;292 293 } else { 293 294 for (c = 0; c < channels; c++) { 294 for (v = 0; v < write; v++) {295 for (v = 0; v < length; v++) { 295 296 s->buffer[v * s->channels + c] = FLOAT_TO_SHORT(write_data->data[c][v]); 296 297 } … … 298 299 // send to encoder 299 300 FLAC__stream_encoder_process_interleaved(s->encoder, 300 (const FLAC__int32*)s->buffer, write);301 (const FLAC__int32*)s->buffer, length); 301 302 } 302 303 } … … 305 306 { 306 307 uint_t ret = AUBIO_OK; 308 309 if (!s->fid) return AUBIO_FAIL; 307 310 308 311 if (s->encoder) { … … 325 328 } 326 329 327 if (s->fid ) {328 if (fclose(s->fid)) {329 AUBIO_ERR("sink_flac: Error closing file %s (%s)\n",330 s->path, strerror(errno));331 ret &= AUBIO_FAIL;332 }333 } 330 if (s->fid && fclose(s->fid)) { 331 AUBIO_ERR("sink_flac: Error closing file %s (%s)\n", 332 s->path, strerror(errno)); 333 ret &= AUBIO_FAIL; 334 } 335 s->fid = NULL; 336 334 337 return ret; 335 338 } 336 339 337 340 #if 0 338 static void aubio_sink_ vorbis_callback(const FLAC__StreamEncoder* encoder UNUSED,341 static void aubio_sink_flac_callback(const FLAC__StreamEncoder* encoder UNUSED, 339 342 FLAC__uint64 bytes_written, FLAC__uint64 samples_written, 340 343 unsigned frames_written, unsigned total_frames_estimate,
Note: See TracChangeset
for help on using the changeset viewer.