shithub: opus

Download patch

ref: 14f5e7cd09ca4728d394ddc78bdc03abb55ba06e
parent: d501f6143caa7adf6a2782a086f195016d9cf588
author: Jean-Marc Valin <[email protected]>
date: Thu Feb 21 18:59:17 EST 2008

Updated the header and celtenc/celtdec tools to the new way modes are handled.

--- a/README
+++ b/README
@@ -8,7 +8,7 @@
 % make
 
 To test the encoder:
-% testcelt [-mono|-stereo] <rate> input.sw output.sw
+% testcelt <rate> <channels> <frame size> <overlap> <bytes per packet> input.sw output.sw
 
 where input.sw is a 16-bit (machine endian) audio file sampled at 
 44.1 kHz or 48 kHz. The output file is already decompressed. 
--- a/configure.ac
+++ b/configure.ac
@@ -7,7 +7,7 @@
 CELT_MAJOR_VERSION=0
 CELT_MINOR_VERSION=2
 CELT_MICRO_VERSION=0
-CELT_EXTRA_VERSION=-git
+CELT_EXTRA_VERSION=
 CELT_VERSION=$CELT_MAJOR_VERSION.$CELT_MINOR_VERSION.$CELT_MICRO_VERSION$CELT_EXTRA_VERSION
 
 CELT_LT_CURRENT=0
--- a/libcelt/celt_header.h
+++ b/libcelt/celt_header.h
@@ -47,15 +47,16 @@
    char         codec_version[20]; /**< Version used (as string) */
    celt_int32_t version_id;        /**< Version id (negative for until stream is frozen) */
    celt_int32_t header_size;       /**< Size of this header */
-   celt_int32_t mode;              /**< Mode used for encoding (to be removed) */
    celt_int32_t sample_rate;       /**< Sampling rate of the original audio */
    celt_int32_t nb_channels;       /**< Number of channels */
+   celt_int32_t frame_size;        /**< Samples per frame (per channel) */
+   celt_int32_t overlap;           /**< Overlapping samples (per channel) */
    celt_int32_t bytes_per_packet;  /**< Number of bytes per compressed packet (0 if unknown) */
    celt_int32_t extra_headers;     /**< Number of additional headers that follow this header */
 } CELTHeader;
 
 /** Creates a basic header struct */
-void celt_header_init(CELTHeader *header, celt_int32_t rate, celt_int32_t nb_channels, const CELTMode *m);
+void celt_header_init(CELTHeader *header, const CELTMode *m);
 
 int celt_header_to_packet(const CELTHeader *header, unsigned char *packet, celt_uint32_t size);
 
--- a/libcelt/header.c
+++ b/libcelt/header.c
@@ -35,6 +35,7 @@
 
 #include "celt_header.h"
 #include "os_support.h"
+#include "modes.h"
 
 /*typedef struct {
    char         codec_id[8];
@@ -61,16 +62,17 @@
    return ret;
 }
 
-void celt_header_init(CELTHeader *header, celt_int32_t rate, celt_int32_t nb_channels, const CELTMode *m)
+void celt_header_init(CELTHeader *header, const CELTMode *m)
 {
    CELT_COPY(header->codec_id, "CELT    ", 8);
    CELT_COPY(header->codec_version, "experimental        ", 20);
 
-   header->version_id = 0x80000000;
+   header->version_id = 0x80000001;
    header->header_size = 56;
-   header->mode = 0;
-   header->sample_rate = rate;
-   header->nb_channels = nb_channels;
+   header->sample_rate = m->Fs;
+   header->nb_channels = m->nbChannels;
+   header->frame_size = m->mdctSize;
+   header->overlap = m->overlap;
    header->bytes_per_packet = -1;
    header->extra_headers = 0;
 }
@@ -91,9 +93,10 @@
    h = (celt_int32_t*)(packet+28);
    *h++ = _le_32 (header->version_id);
    *h++ = _le_32 (header->header_size);
-   *h++ = _le_32 (header->mode);
    *h++ = _le_32 (header->sample_rate);
    *h++ = _le_32 (header->nb_channels);
+   *h++ = _le_32 (header->frame_size);
+   *h++ = _le_32 (header->overlap);
    *h++ = _le_32 (header->bytes_per_packet);
    *h++ = _le_32 (header->extra_headers);
 
--- a/tools/celtdec.c
+++ b/tools/celtdec.c
@@ -286,29 +286,22 @@
    printf ("Copyright (C) 2008 Jean-Marc Valin\n");
 }
 
-static CELTDecoder *process_header(ogg_packet *op, celt_int32_t enh_enabled, celt_int32_t *frame_size, int *granule_frame_size, celt_int32_t *rate, int *nframes, int forceMode, int *channels, int *extra_headers, int quiet)
+static CELTDecoder *process_header(ogg_packet *op, celt_int32_t enh_enabled, celt_int32_t *frame_size, int *granule_frame_size, celt_int32_t *rate, int *nframes, int forceMode, int *channels, int *extra_headers, int quiet, CELTMode **mode)
 {
    CELTDecoder *st;
-   const CELTMode *mode;
    CELTHeader header;
-   int modeID;
       
    celt_header_from_packet((char*)op->packet, op->bytes, &header);
-      
-   if (header.mode==0)
+
+   if (header.nb_channels>2 || header.nb_channels<1)
    {
-      mode = celt_mono;
-      *channels = 1;
-   } else if (header.mode==1)
-   {
-      mode = celt_stereo;
-      *channels = 2;
-   } else {
-      fprintf (stderr, "Invalid mode: %d\n", header.mode);
+      fprintf (stderr, "Unsupported number of channels: %d\n", header.nb_channels);
       return NULL;
    }
+   *mode = celt_mode_create(header.sample_rate, header.nb_channels, header.frame_size, header.overlap, NULL);
+   *channels = header.nb_channels;
 
-   st = celt_decoder_create(mode);
+   st = celt_decoder_create(*mode);
    if (!st)
    {
       fprintf (stderr, "Decoder initialization failed.\n");
@@ -315,12 +308,11 @@
       return NULL;
    }
    
-   celt_mode_info(mode, CELT_GET_FRAME_SIZE, frame_size);
+   celt_mode_info(*mode, CELT_GET_FRAME_SIZE, frame_size);
    *granule_frame_size = *frame_size;
 
    if (!*rate)
       *rate = header.sample_rate;
-   /* Adjust rate if --force-* options are used */
 
    *nframes = 1;
 
@@ -350,6 +342,7 @@
    short output[MAX_FRAME_SIZE];
    int frame_size=0, granule_frame_size=0;
    void *st=NULL;
+   CELTMode *mode=NULL;
    unsigned char bits[1000];
    int packet_count=0;
    int stream_init = 0;
@@ -537,7 +530,7 @@
             /*If first packet, process as CELT header*/
             if (packet_count==0)
             {
-               st = process_header(&op, enh_enabled, &frame_size, &granule_frame_size, &rate, &nframes, forceMode, &channels, &extra_headers, quiet);
+               st = process_header(&op, enh_enabled, &frame_size, &granule_frame_size, &rate, &nframes, forceMode, &channels, &extra_headers, quiet, &mode);
                if (!st)
                   exit(1);
                //FIXME: Do that properly
@@ -660,9 +653,10 @@
    }
 
    if (st)
-      celt_decoder_destroy(st);
-   else 
    {
+      celt_decoder_destroy(st);
+      celt_mode_destroy(mode);
+   } else {
       fprintf (stderr, "This doesn't look like a CELT file\n");
    }
    if (stream_init)
--- a/tools/celtenc.c
+++ b/tools/celtenc.c
@@ -241,7 +241,7 @@
    celt_int32_t frame_size;
    int quiet=0;
    int nbBytes;
-   const CELTMode *mode=celt_mono;
+   CELTMode *mode;
    void *st;
    unsigned char bits[MAX_FRAME_BYTES];
    int with_skeleton = 0;
@@ -432,7 +432,6 @@
 
    if (chan == 1)
    {
-      mode = celt_mono;
       if (bitrate < 0)
          bitrate = 64;
       if (bitrate < 40)
@@ -442,7 +441,6 @@
    }
    else if (chan == 2)
    {
-      mode = celt_stereo;
       if (bitrate < 0)
          bitrate = 128;
       if (bitrate < 64)
@@ -453,17 +451,16 @@
       fprintf (stderr, "Only mono and stereo are supported\n");
       return 1;
    }
+   mode = celt_mode_create(rate, chan, 256, 128, NULL);
+   if (!mode)
+      return 1;
    celt_mode_info(mode, CELT_GET_FRAME_SIZE, &frame_size);
    
    bytes_per_packet = (bitrate*1000*frame_size/rate+4)/8;
    
-   celt_header_init(&header, rate, 1, mode);
+   celt_header_init(&header, mode);
    header.nb_channels = chan;
-   if (chan == 1)
-      header.mode = 0;
-   else if (chan == 2)
-      header.mode = 1;
-      
+
    {
       char *st_string="mono";
       if (chan==2)
@@ -663,6 +660,7 @@
    }
 
    celt_encoder_destroy(st);
+   celt_mode_destroy(mode);
    ogg_stream_clear(&os);
 
    if (close_in)