Changeset 5e9bdca
- Timestamp:
- Dec 20, 2018, 4:58:22 PM (6 years ago)
- Branches:
- feature/autosink, feature/cnn, feature/crepe, fix/ffmpeg5, master
- Children:
- a2019c4
- Parents:
- f5adffe
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/io/sink_vorbis.c
rf5adffe r5e9bdca 37 37 #include <time.h> // time 38 38 39 #define MAX_SIZE 204839 #define MAX_SIZE 4096 40 40 41 41 struct _aubio_sink_vorbis_t { … … 64 64 void del_aubio_sink_vorbis (aubio_sink_vorbis_t *s); 65 65 66 static uint_t aubio_sink_vorbis_write_page(aubio_sink_vorbis_t *s); 67 66 68 aubio_sink_vorbis_t * new_aubio_sink_vorbis (const char_t *uri, 67 69 uint_t samplerate) … … 118 120 s->fid = fopen((const char *)s->path, "wb"); 119 121 if (!s->fid) { 120 AUBIO_ERR("sink_vorbis: Error opening file %s (%s)\n", 121 s->path, strerror(errno)); 122 char errorstr[256]; 123 AUBIO_STRERROR(errno, errorstr, sizeof(errorstr)); 124 AUBIO_ERR("sink_vorbis: Error opening file \'%s\' (%s)\n", 125 s->path, errorstr); 122 126 return AUBIO_FAIL; 123 127 } … … 144 148 // write header 145 149 { 146 int ret = 0;147 size_t wrote;148 150 ogg_packet header; 149 151 ogg_packet header_comm; … … 160 162 while (1) 161 163 { 162 ret = ogg_stream_flush(&s->os, &s->og); 163 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 } 164 if (!ogg_stream_flush(&s->os, &s->og)) break; 165 if (aubio_sink_vorbis_write_page(s)) return AUBIO_FAIL; 173 166 } 174 167 } … … 212 205 } 213 206 214 void aubio_sink_vorbis_write(aubio_sink_vorbis_t *s) 215 {207 static 208 uint_t aubio_sink_vorbis_write_page(aubio_sink_vorbis_t *s) { 216 209 int result; 217 210 size_t wrote; 211 wrote = fwrite(s->og.header, 1, s->og.header_len, s->fid); 212 result = (wrote == (unsigned)s->og.header_len); 213 wrote = fwrite(s->og.body, 1, s->og.body_len, s->fid); 214 result &= (wrote == (unsigned)s->og.body_len); 215 if (result == 0) { 216 char errorstr[256]; 217 AUBIO_STRERROR(errno, errorstr, sizeof(errorstr)); 218 AUBIO_ERR("sink_vorbis: failed writing \'%s\' to disk (%s)\n", 219 s->path, errorstr); 220 return AUBIO_FAIL; 221 } 222 return AUBIO_OK; 223 } 224 225 static 226 void aubio_sink_vorbis_write(aubio_sink_vorbis_t *s) 227 { 218 228 // pre-analysis 219 229 while (vorbis_analysis_blockout(&s->vd, &s->vb) == 1) { … … 227 237 228 238 while (1) { 229 result = ogg_stream_pageout (&s->os, &s->og); 230 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 } 239 if (!ogg_stream_pageout (&s->os, &s->og)) break; 240 aubio_sink_vorbis_write_page(s); 239 241 if (ogg_page_eos(&s->og)) break; 240 242 } … … 291 293 } 292 294 // tell vorbis how many frames were written 293 vorbis_analysis_wrote(&s->vd, (long) write);295 vorbis_analysis_wrote(&s->vd, (long)length); 294 296 } 295 297 … … 306 308 307 309 if (s->fid && fclose(s->fid)) { 308 AUBIO_ERR("sink_vorbis: Error closing file %s (%s)\n", 309 s->path, strerror(errno)); 310 char errorstr[256]; 311 AUBIO_STRERROR(errno, errorstr, sizeof(errorstr)); 312 AUBIO_ERR("sink_vorbis: Error closing file \'%s\' (%s)\n", 313 s->path, errorstr); 310 314 return AUBIO_FAIL; 311 315 }
Note: See TracChangeset
for help on using the changeset viewer.