external/libnogg/tools/nogg-benchmark.c
static long decoder_read(DecoderHandle *decoder, int16_t *buf, long count)
{
    long result = 0;

    switch (decoder->library) {

      case LIBNOGG: {
        const int channels = vorbis_channels(decoder->handle);
        while (count >= channels) {
            long this_result;
            vorbis_error_t error;
            do {
                this_result = (vorbis_read_int16(decoder->handle, buf,
                                                 count/channels, &error)
                               * channels);
            } while (this_result == 0
                     && error == VORBIS_ERROR_DECODE_RECOVERED);
            decoder->error = (error != 0 && error != VORBIS_ERROR_STREAM_END
                              && error != VORBIS_ERROR_DECODE_RECOVERED);
            if (this_result == 0 || decoder->error) {
                break;
            }
            result += this_result;
            buf += this_result;
            count -= this_result;
        }
        break;
      }

      case LIBVORBIS: {
        vorbis_info *info = ov_info(decoder->handle, -1);
        const int channels = info->channels;
        while (count >= channels) {
            long this_result;
            do {
                int bitstream_unused;
                this_result = ov_read(
                    decoder->handle, (char *)buf,
                    (int)(count/channels) * (2*channels), /*bigendianp*/ 0,
                    /*word*/ 2, /*sgned*/ 1, &bitstream_unused);
            } while (this_result == OV_HOLE);
            decoder->error = (this_result < 0);
            if (this_result <= 0) {
                break;
            }
            this_result /= 2;
            result += this_result;
            buf += this_result;
            count -= this_result;
        }
        break;
      }

      case TREMOR: {
#ifdef HAVE_TREMOR
        tremor_vorbis_info *info = tremor_ov_info(decoder->handle, -1);
        const int channels = info->channels;
        while (count >= channels) {
            long this_result;
            do {
                int bitstream_unused;
                this_result = tremor_ov_read(
                    decoder->handle, (char *)buf,
                    (int)(count/channels) * (2*channels), &bitstream_unused);
            } while (this_result == OV_HOLE);
            decoder->error = (this_result < 0);
            if (this_result <= 0) {
                break;
            }
            this_result /= 2;
            result += this_result;
            buf += this_result;
            count -= this_result;
        }
#endif
        break;
      }

    }

    return result;
}
/**
 * decoder_read:  Read PCM samples from a decoder handle.  The number of
 * samples read will always be a multiple of the number of channels in the
 * stream, and thus a return value of less than the requested number of
 * samples does not necessarily indicate end-of-stream.
 *
 * [Parameters]
 *     decoder: Decoder handle to read from.
 *     buf: Buffer into which to read samples.
 *     count: Maximum number of samples to read.
 * [Return value]
 *     Number of samples returned, or 0 on end-of-stream or error.
 */
Read PCM samples from a decoder handle.  The number of
samples read will always be a multiple of the number of channels in the
stream, and thus a return value of less than the requested number of
samples does not necessarily indicate end-of-stream.

[Parameters]
decoder: Decoder handle to read from.
buf: Buffer into which to read samples.
count: Maximum number of samples to read.
[Return value]
Number of samples returned, or 0 on end-of-stream or error.
Read PCM samples from a decoder handle . The number of samples read will always be a multiple of the number of channels in the stream and thus a return value of less than the requested number of samples does not necessarily indicate end - of - stream . [ Parameters ] decoder : Decoder handle to read from . buf : Buffer into which to read samples . count : Maximum number of samples to read . [ Return value ] Number of samples returned or 0 on end - of - stream or error .
static long decoder_read(DecoderHandle *decoder, int16_t *buf, long count)
{
    long result = 0;
    switch (decoder->library) {
      case LIBNOGG: {
        const int channels = vorbis_channels(decoder->handle);
        while (count >= channels) {
            long this_result;
            vorbis_error_t error;
            do {
                this_result = (vorbis_read_int16(decoder->handle, buf,
                                                 count/channels, &error)
                               * channels);
            } while (this_result == 0
                     && error == VORBIS_ERROR_DECODE_RECOVERED);
            decoder->error = (error != 0 && error != VORBIS_ERROR_STREAM_END
                              && error != VORBIS_ERROR_DECODE_RECOVERED);
            if (this_result == 0 || decoder->error) {
                break;
            }
            result += this_result;
            buf += this_result;
            count -= this_result;
        }
        break;
      }
      case LIBVORBIS: {
        vorbis_info *info = ov_info(decoder->handle, -1);
        const int channels = info->channels;
        while (count >= channels) {
            long this_result;
            do {
                int bitstream_unused;
                this_result = ov_read(
                    decoder->handle, (char *)buf,
                    (int)(count/channels) * (2*channels),  0,
                     2,  1, &bitstream_unused);
            } while (this_result == OV_HOLE);
            decoder->error = (this_result < 0);
            if (this_result <= 0) {
                break;
            }
            this_result /= 2;
            result += this_result;
            buf += this_result;
            count -= this_result;
        }
        break;
      }
      case TREMOR: {
#ifdef HAVE_TREMOR
        tremor_vorbis_info *info = tremor_ov_info(decoder->handle, -1);
        const int channels = info->channels;
        while (count >= channels) {
            long this_result;
            do {
                int bitstream_unused;
                this_result = tremor_ov_read(
                    decoder->handle, (char *)buf,
                    (int)(count/channels) * (2*channels), &bitstream_unused);
            } while (this_result == OV_HOLE);
            decoder->error = (this_result < 0);
            if (this_result <= 0) {
                break;
            }
            this_result /= 2;
            result += this_result;
            buf += this_result;
            count -= this_result;
        }
#endif
        break;
      }
    }
    return result;
}
static long decoder_read ( DecoderHandle * decoder , int16_t * buf , long count ) { long result = 0 ; switch ( decoder -> library ) { case LIBNOGG : { const int channels = vorbis_channels ( decoder -> handle ) ; while ( count >= channels ) { long this_result ; vorbis_error_t error ; do { this_result = ( vorbis_read_int16 ( decoder -> handle , buf , count / channels , & error ) * channels ) ; } while ( this_result == 0 && error == VORBIS_ERROR_DECODE_RECOVERED ) ; decoder -> error = ( error != 0 && error != VORBIS_ERROR_STREAM_END && error != VORBIS_ERROR_DECODE_RECOVERED ) ; if ( this_result == 0 || decoder -> error ) { break ; } result += this_result ; buf += this_result ; count -= this_result ; } break ; } case LIBVORBIS : { vorbis_info * info = ov_info ( decoder -> handle , -1 ) ; const int channels = info -> channels ; while ( count >= channels ) { long this_result ; do { int bitstream_unused ; this_result = ov_read ( decoder -> handle , ( char * ) buf , ( int ) ( count / channels ) * ( 2 * channels ) , 0 , 2 , 1 , & bitstream_unused ) ; } while ( this_result == OV_HOLE ) ; decoder -> error = ( this_result < 0 ) ; if ( this_result <= 0 ) { break ; } this_result /= 2 ; result += this_result ; buf += this_result ; count -= this_result ; } break ; } case TREMOR : { #ifdef HAVE_TREMOR tremor_vorbis_info * info = tremor_ov_info ( decoder -> handle , -1 ) ; const int channels = info -> channels ; while ( count >= channels ) { long this_result ; do { int bitstream_unused ; this_result = tremor_ov_read ( decoder -> handle , ( char * ) buf , ( int ) ( count / channels ) * ( 2 * channels ) , & bitstream_unused ) ; } while ( this_result == OV_HOLE ) ; decoder -> error = ( this_result < 0 ) ; if ( this_result <= 0 ) { break ; } this_result /= 2 ; result += this_result ; buf += this_result ; count -= this_result ; } #endif break ; } } return result ; }
decoder_read:  Read PCM samples from a decoder handle.
decoder_read : Read PCM samples from a decoder handle .
/*bigendianp*/ /*word*/ /*sgned*/