Changeset 0440778 for src/io/sink_wavwrite.c
- Timestamp:
- Dec 17, 2018, 3:44:29 PM (6 years ago)
- Branches:
- feature/autosink, feature/cnn, feature/crepe, fix/ffmpeg5, master
- Children:
- 68b991e
- Parents:
- e6a5aa5 (diff), d81e16d (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/io/sink_wavwrite.c
re6a5aa5 r0440778 88 88 goto beach; 89 89 } 90 if ((sint_t)samplerate < 0) { 91 AUBIO_ERR("sink_wavwrite: Can not create %s with samplerate %d\n", path, samplerate); 92 goto beach; 93 } 94 95 if (s->path) AUBIO_FREE(s->path); 90 96 91 s->path = AUBIO_ARRAY(char_t, strnlen(path, PATH_MAX) + 1); 97 92 strncpy(s->path, path, strnlen(path, PATH_MAX) + 1); … … 136 131 s->samplerate = samplerate; 137 132 // automatically open when both samplerate and channels have been set 138 if ( s->samplerate != 0 &&s->channels != 0) {133 if (/* s->samplerate != 0 && */ s->channels != 0) { 139 134 return aubio_sink_wavwrite_open(s); 140 135 } … … 149 144 s->channels = channels; 150 145 // automatically open when both samplerate and channels have been set 151 if (s->samplerate != 0 && s->channels != 0) {146 if (s->samplerate != 0 /* && s->channels != 0 */) { 152 147 return aubio_sink_wavwrite_open(s); 153 148 } … … 234 229 235 230 void aubio_sink_wavwrite_do(aubio_sink_wavwrite_t *s, fvec_t * write_data, uint_t write){ 236 uint_t i = 0, written_frames = 0; 237 238 if (write > s->max_size) { 239 AUBIO_WRN("sink_wavwrite: trying to write %d frames to %s, " 240 "but only %d can be written at a time\n", write, s->path, s->max_size); 241 write = s->max_size; 242 } 243 244 for (i = 0; i < write; i++) { 245 s->scratch_data[i] = HTOLES(FLOAT_TO_SHORT(write_data->data[i])); 246 } 247 written_frames = fwrite(s->scratch_data, 2, write, s->fid); 231 uint_t c = 0, i = 0, written_frames = 0; 232 uint_t length = aubio_sink_validate_input_length("sink_wavwrite", s->path, 233 s->max_size, write_data->length, write); 234 235 for (c = 0; c < s->channels; c++) { 236 for (i = 0; i < length; i++) { 237 s->scratch_data[i * s->channels + c] = HTOLES(FLOAT_TO_SHORT(write_data->data[i])); 238 } 239 } 240 written_frames = fwrite(s->scratch_data, 2, length * s->channels, s->fid); 248 241 249 242 if (written_frames != write) { … … 258 251 uint_t c = 0, i = 0, written_frames = 0; 259 252 260 if (write > s->max_size) { 261 AUBIO_WRN("sink_wavwrite: trying to write %d frames to %s, " 262 "but only %d can be written at a time\n", write, s->path, s->max_size); 263 write = s->max_size; 264 } 265 266 for (c = 0; c < s->channels; c++) { 267 for (i = 0; i < write; i++) { 253 uint_t channels = aubio_sink_validate_input_channels("sink_wavwrite", s->path, 254 s->channels, write_data->height); 255 uint_t length = aubio_sink_validate_input_length("sink_wavwrite", s->path, 256 s->max_size, write_data->length, write); 257 258 for (c = 0; c < channels; c++) { 259 for (i = 0; i < length; i++) { 268 260 s->scratch_data[i * s->channels + c] = HTOLES(FLOAT_TO_SHORT(write_data->data[c][i])); 269 261 } 270 262 } 271 written_frames = fwrite(s->scratch_data, 2, write* s->channels, s->fid);263 written_frames = fwrite(s->scratch_data, 2, length * s->channels, s->fid); 272 264 273 265 if (written_frames != write * s->channels) { … … 298 290 299 291 void del_aubio_sink_wavwrite(aubio_sink_wavwrite_t * s){ 300 if (!s) return; 301 aubio_sink_wavwrite_close(s); 302 if (s->path) AUBIO_FREE(s->path); 303 AUBIO_FREE(s->scratch_data); 292 AUBIO_ASSERT(s); 293 if (s->fid) 294 aubio_sink_wavwrite_close(s); 295 if (s->path) 296 AUBIO_FREE(s->path); 297 if (s->scratch_data) 298 AUBIO_FREE(s->scratch_data); 304 299 AUBIO_FREE(s); 305 300 }
Note: See TracChangeset
for help on using the changeset viewer.