Changeset 5e9bdca for src


Ignore:
Timestamp:
Dec 20, 2018, 4:58:22 PM (6 years ago)
Author:
Paul Brossier <piem@piem.org>
Branches:
feature/autosink, feature/cnn, feature/crepe, fix/ffmpeg5, master
Children:
a2019c4
Parents:
f5adffe
Message:

[sink_flac] factorise page writes, use AUBIO_STRERROR

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/io/sink_vorbis.c

    rf5adffe r5e9bdca  
    3737#include <time.h> // time
    3838
    39 #define MAX_SIZE 2048
     39#define MAX_SIZE 4096
    4040
    4141struct _aubio_sink_vorbis_t {
     
    6464void del_aubio_sink_vorbis (aubio_sink_vorbis_t *s);
    6565
     66static uint_t aubio_sink_vorbis_write_page(aubio_sink_vorbis_t *s);
     67
    6668aubio_sink_vorbis_t * new_aubio_sink_vorbis (const char_t *uri,
    6769    uint_t samplerate)
     
    118120  s->fid = fopen((const char *)s->path, "wb");
    119121  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);
    122126    return AUBIO_FAIL;
    123127  }
     
    144148  // write header
    145149  {
    146     int ret = 0;
    147     size_t wrote;
    148150    ogg_packet header;
    149151    ogg_packet header_comm;
     
    160162    while (1)
    161163    {
    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;
    173166    }
    174167  }
     
    212205}
    213206
    214 void aubio_sink_vorbis_write(aubio_sink_vorbis_t *s)
    215 {
     207static
     208uint_t aubio_sink_vorbis_write_page(aubio_sink_vorbis_t *s) {
    216209  int result;
    217210  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
     225static
     226void aubio_sink_vorbis_write(aubio_sink_vorbis_t *s)
     227{
    218228  // pre-analysis
    219229  while (vorbis_analysis_blockout(&s->vd, &s->vb) == 1) {
     
    227237
    228238      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);
    239241        if (ogg_page_eos(&s->og)) break;
    240242      }
     
    291293    }
    292294    // tell vorbis how many frames were written
    293     vorbis_analysis_wrote(&s->vd, (long)write);
     295    vorbis_analysis_wrote(&s->vd, (long)length);
    294296  }
    295297
     
    306308
    307309  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);
    310314    return AUBIO_FAIL;
    311315  }
Note: See TracChangeset for help on using the changeset viewer.