Changeset d327b6f for src/io/sink_vorbis.c
- Timestamp:
- Dec 20, 2018, 8:34:33 PM (6 years ago)
- Branches:
- feature/autosink, feature/cnn, feature/crepe, fix/ffmpeg5, master
- Children:
- f7f946a
- Parents:
- 9630fa8 (diff), b8fa393 (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
r9630fa8 rd327b6f 29 29 #ifdef HAVE_VORBISENC 30 30 31 #include "fmat.h" 31 32 #include "io/ioutils.h" 32 #include "fmat.h"33 33 34 34 #include <vorbis/vorbisenc.h> … … 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.