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