]> git.tuebingen.mpg.de Git - paraslash.git/commitdiff
opus: Use uint16_t for preskip and gain.
authorAndre Noll <maan@tuebingen.mpg.de>
Sun, 7 Feb 2016 21:52:55 +0000 (22:52 +0100)
committerAndre Noll <maan@tuebingen.mpg.de>
Mon, 28 Mar 2016 17:23:58 +0000 (17:23 +0000)
These values are obtained by reading a 16 bit value from a buffer,
so uint16_t is the right type for these fields.

opus_common.c
opus_common.h
opusdec_filter.c

index 67a8841e8b8ce7fe172043a144332cb1db4c577f..374df8375acffda9fa637999f4ecad7f2321535b 100644 (file)
@@ -62,7 +62,7 @@ static int read_uint32(struct packet *p, ogg_uint32_t *val)
        return 1;
 }
 
        return 1;
 }
 
-static int read_uint16(struct packet *p, ogg_uint16_t *val)
+static int read_uint16(struct packet *p, uint16_t *val)
 {
        if (p->pos > p->maxlen - 2)
                return 0;
 {
        if (p->pos > p->maxlen - 2)
                return 0;
@@ -89,7 +89,6 @@ int opus_parse_header(const char *packet, int len, struct opus_header *h)
        char str[9];
        struct packet p;
        unsigned char ch, channel_mapping;
        char str[9];
        struct packet p;
        unsigned char ch, channel_mapping;
-       ogg_uint16_t shortval;
 
        p.data = packet;
        p.maxlen = len;
 
        p.data = packet;
        p.maxlen = len;
@@ -113,16 +112,14 @@ int opus_parse_header(const char *packet, int len, struct opus_header *h)
        if (h->channels == 0)
                return -E_OPUS_HEADER;
 
        if (h->channels == 0)
                return -E_OPUS_HEADER;
 
-       if (!read_uint16(&p, &shortval))
+       if (!read_uint16(&p, &h->preskip))
                return -E_OPUS_HEADER;
                return -E_OPUS_HEADER;
-       h->preskip = shortval;
 
        if (!read_uint32(&p, &h->input_sample_rate))
                return -E_OPUS_HEADER;
 
 
        if (!read_uint32(&p, &h->input_sample_rate))
                return -E_OPUS_HEADER;
 
-       if (!read_uint16(&p, &shortval))
+       if (!read_uint16(&p, &h->gain))
                return -E_OPUS_HEADER;
                return -E_OPUS_HEADER;
-       h->gain = (short)shortval;
 
        if (!read_chars(&p, &ch, 1))
                return -E_OPUS_HEADER;
 
        if (!read_chars(&p, &ch, 1))
                return -E_OPUS_HEADER;
index 2bcf5919f934622278dc2f9ba85b0516cf1d3767..bdc67edd47cc2c446b5bd45a5572a4b81393b5a2 100644 (file)
@@ -16,11 +16,11 @@ struct opus_header {
        /** 1..255 */
        int channels;
        /** Number of bytes to skip from the beginning. */
        /** 1..255 */
        int channels;
        /** Number of bytes to skip from the beginning. */
-       int preskip;
+       uint16_t preskip;
        /** Sample rate of the input stream, used by the audio format handler. */
        ogg_uint32_t input_sample_rate;
        /** In dB, should be zero whenever possible. */
        /** Sample rate of the input stream, used by the audio format handler. */
        ogg_uint32_t input_sample_rate;
        /** In dB, should be zero whenever possible. */
-       int gain;
+       uint16_t gain;
        /** Number of logical streams (usually 1). */
        int nb_streams;
        /** Number of streams to decode as 2 channel streams. */
        /** Number of logical streams (usually 1). */
        int nb_streams;
        /** Number of streams to decode as 2 channel streams. */
index 6a93f41f6b25f9e9d36b58726708861a52ed6b89..282229855d0d97519f886483c249d8e3f4b00b4f 100644 (file)
@@ -70,7 +70,7 @@ struct opusdec_context {
        ogg_page ogg_page;
        bool eos;
        int channels;
        ogg_page ogg_page;
        bool eos;
        int channels;
-       int preskip;
+       uint16_t preskip;
        bool have_opus_stream;
        bool have_more;
        ogg_int32_t opus_serialno;
        bool have_opus_stream;
        bool have_more;
        ogg_int32_t opus_serialno;
@@ -142,9 +142,10 @@ static int opusdec_init(ogg_packet *op, struct opusdec_context *ctx)
 static void opusdec_add_output(short *pcm, int frames_available,
                struct btr_node *btrn, struct opusdec_context *ctx)
 {
 static void opusdec_add_output(short *pcm, int frames_available,
                struct btr_node *btrn, struct opusdec_context *ctx)
 {
-       int tmp_skip, num_frames, bytes;
+       int num_frames, bytes;
+       uint16_t tmp_skip;
 
 
-       tmp_skip = PARA_MIN(ctx->preskip, frames_available);
+       tmp_skip = PARA_MIN((int)ctx->preskip, frames_available);
        ctx->preskip -= tmp_skip;
        num_frames = frames_available - tmp_skip;
        if (num_frames <= 0)
        ctx->preskip -= tmp_skip;
        num_frames = frames_available - tmp_skip;
        if (num_frames <= 0)