Changeset d013a93 for src/io/sink_vorbis.c
- Timestamp:
- Dec 17, 2018, 4:42:29 PM (5 years ago)
- Branches:
- feature/autosink, feature/cnn, feature/crepe, fix/ffmpeg5, master
- Children:
- d286fe4
- Parents:
- 2de7cfa (diff), 09b4be9 (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_vorbis.c
r2de7cfa rd013a93 36 36 #include <errno.h> // errno 37 37 #include <time.h> // time 38 39 #define MAX_SIZE 2048 38 40 39 41 struct _aubio_sink_vorbis_t { … … 67 69 aubio_sink_vorbis_t * s = AUBIO_NEW(aubio_sink_vorbis_t); 68 70 71 if (!uri) { 72 AUBIO_ERROR("sink_vorbis: Aborted opening null path\n"); 73 goto failure; 74 } 75 69 76 s->path = AUBIO_ARRAY(char_t, strnlen(uri, PATH_MAX) + 1); 70 77 strncpy(s->path, uri, strnlen(uri, PATH_MAX) + 1); … … 110 117 111 118 s->fid = fopen((const char *)s->path, "wb"); 112 if (!s->fid) return AUBIO_FAIL; 119 if (!s->fid) { 120 AUBIO_ERR("sink_vorbis: Error opening file %s (%s)\n", 121 s->path, strerror(errno)); 122 return AUBIO_FAIL; 123 } 113 124 114 125 vorbis_info_init(&s->vi); … … 134 145 { 135 146 int ret = 0; 147 size_t wrote; 136 148 ogg_packet header; 137 149 ogg_packet header_comm; … … 150 162 ret = ogg_stream_flush(&s->os, &s->og); 151 163 if (ret==0) break; 152 fwrite(s->og.header, 1, s->og.header_len, s->fid); 153 fwrite(s->og.body, 1, s->og.body_len, s->fid); 164 wrote = fwrite(s->og.header, 1, s->og.header_len, s->fid); 165 ret = (wrote == (unsigned)s->og.header_len); 166 wrote = fwrite(s->og.body, 1, s->og.body_len, s->fid); 167 ret &= (wrote == (unsigned)s->og.body_len); 168 if (ret == 0) { 169 AUBIO_ERR("sink_vorbis: failed writing \'%s\' to disk (%s)\n", 170 s->path, strerror(errno)); 171 return AUBIO_FAIL; 172 } 154 173 } 155 174 } … … 164 183 return AUBIO_FAIL; 165 184 s->samplerate = samplerate; 166 if ( s->samplerate != 0 &&s->channels != 0)185 if (/* s->samplerate != 0 && */ s->channels != 0) 167 186 return aubio_sink_vorbis_open(s); 168 187 return AUBIO_OK; … … 177 196 s->channels = channels; 178 197 // automatically open when both samplerate and channels have been set 179 if (s->samplerate != 0 && s->channels != 0) {198 if (s->samplerate != 0 /* && s->channels != 0 */) { 180 199 return aubio_sink_vorbis_open(s); 181 200 } … … 195 214 void aubio_sink_vorbis_write(aubio_sink_vorbis_t *s) 196 215 { 216 int result; 217 size_t wrote; 197 218 // pre-analysis 198 219 while (vorbis_analysis_blockout(&s->vd, &s->vb) == 1) { … … 206 227 207 228 while (1) { 208 intresult = ogg_stream_pageout (&s->os, &s->og);229 result = ogg_stream_pageout (&s->os, &s->og); 209 230 if (result == 0) break; 210 fwrite(s->og.header, 1, s->og.header_len, s->fid); 211 fwrite(s->og.body, 1, s->og.body_len, s->fid); 231 wrote = fwrite(s->og.header, 1, s->og.header_len, s->fid); 232 result = (wrote == (unsigned)s->og.header_len); 233 wrote = fwrite(s->og.body, 1, s->og.body_len, s->fid); 234 result &= (wrote == (unsigned)s->og.body_len); 235 if (result == 0) { 236 AUBIO_WRN("sink_vorbis: failed writing \'%s\' to disk (%s)\n", 237 s->path, strerror(errno)); 238 } 212 239 if (ogg_page_eos(&s->og)) break; 213 240 } … … 220 247 { 221 248 uint_t c, v; 222 float **buffer = vorbis_analysis_buffer(&s->vd, (long)write); 249 uint_t length = aubio_sink_validate_input_length("sink_vorbis", s->path, 250 MAX_SIZE, write_data->length, write); 251 float **buffer = vorbis_analysis_buffer(&s->vd, (long)length); 223 252 // fill buffer 224 253 if (!write) { … … 229 258 } else { 230 259 for (c = 0; c < s->channels; c++) { 231 for (v = 0; v < write; v++) {260 for (v = 0; v < length; v++) { 232 261 buffer[c][v] = write_data->data[v]; 233 262 } 234 263 } 235 264 // tell vorbis how many frames were written 236 vorbis_analysis_wrote(&s->vd, (long) write);265 vorbis_analysis_wrote(&s->vd, (long)length); 237 266 } 238 267 // write to file … … 244 273 { 245 274 uint_t c, v; 246 uint_t channels = MIN(s->channels, write_data->height); 247 float **buffer = vorbis_analysis_buffer(&s->vd, (long)write); 275 uint_t channels = aubio_sink_validate_input_channels("sink_vorbis", s->path, 276 s->channels, write_data->height); 277 uint_t length = aubio_sink_validate_input_length("sink_vorbis", s->path, 278 MAX_SIZE, write_data->length, write); 279 float **buffer = vorbis_analysis_buffer(&s->vd, (long)length); 248 280 // fill buffer 249 281 if (!write) { … … 254 286 } else { 255 287 for (c = 0; c < channels; c++) { 256 for (v = 0; v < write; v++) {288 for (v = 0; v < length; v++) { 257 289 buffer[c][v] = write_data->data[c][v]; 258 290 } … … 267 299 uint_t aubio_sink_vorbis_close (aubio_sink_vorbis_t *s) 268 300 { 301 if (!s->fid) return AUBIO_FAIL; 269 302 //mark the end of stream 270 303 vorbis_analysis_wrote(&s->vd, 0); … … 272 305 aubio_sink_vorbis_write(s); 273 306 274 if ( fclose(s->fid)) {307 if (s->fid && fclose(s->fid)) { 275 308 AUBIO_ERR("sink_vorbis: Error closing file %s (%s)\n", 276 309 s->path, strerror(errno)); 277 310 return AUBIO_FAIL; 278 311 } 312 s->fid = NULL; 279 313 return AUBIO_OK; 280 314 }
Note: See TracChangeset
for help on using the changeset viewer.