[CELT-dev] A (minor) bug and a request

John Ridges jridges at masque.com
Thu May 21 13:17:29 PDT 2009


Hi JM,

I use #define SCALEIN(a) (a) and #define SCALEOUT(a) (a) so that I get 
the Speex floating point range. In my application I use Speex for the 
very lowest bitrates and switch to CELT for the higher bitrates, and it 
was easier to change CELT than everything else.

I'd be happy to submit the following patch (I'm using an MSVC 
environment, and don't have a proper diff, so forgive me that I'm not 
giving you line numbers):
In celt.h add the following lines:

/** Reset the encoder/decoder memories to zero*/
#define CELT_RESET_STATE        4

/** Query and set decoder parameters
 @param st Decoder state
 @param request Parameter to change or query
 @param value Pointer to a 32-bit int value
 @return Error code
*/
EXPORT int celt_decoder_ctl(CELTDecoder * st, int request, ...);

In celt.c add the following code to the celt_encoder_ctl function:

      case CELT_RESET_STATE:
      {
         const CELTMode *mode = st->mode;
         int C = mode->nbChannels;

         if (st->pitch_available > 0) st->pitch_available = 1;

         CELT_MEMSET(st->in_mem, 0, st->overlap*C);
         CELT_MEMSET(st->out_mem, 0, (MAX_PERIOD+st->overlap)*C);

         CELT_MEMSET(st->oldBandE, 0, C*mode->nbEBands);

         CELT_MEMSET(st->preemph_memE, 0, C);
         CELT_MEMSET(st->preemph_memD, 0, C);
         st->delayedIntra = 1;
      }
      break;

and add the following code to the end of celt.c:

int celt_decoder_ctl(CELTDecoder * restrict st, int request, ...)
{
   va_list ap;
   va_start(ap, request);
   switch (request)
   {
      case CELT_RESET_STATE:
      {
         const CELTMode *mode = st->mode;
         int C = mode->nbChannels;

         CELT_MEMSET(st->decode_mem, 0, (DECODE_BUFFER_SIZE+st->overlap)*C);
          
         CELT_MEMSET(st->oldBandE, 0, C*mode->nbEBands);

         CELT_MEMSET(st->preemph_memD, 0, C);

         st->last_pitch_index = 0;
      }
      break;
      default:
         goto bad_request;
   }
   va_end(ap);
   return CELT_OK;
#if 0    /* Put this back in if you ever need "bad_arg" */
bad_arg:
   va_end(ap);
   return CELT_BAD_ARG;
#endif
bad_request:
   va_end(ap);
   return CELT_UNIMPLEMENTED;
}

This code does a very naive reset of the state. It is possible (even 
likely) that I'm resetting more than is necessary, but I would have to 
know a lot more about how CELT works to determine that.

Regards,

John Ridges


Jean-Marc Valin wrote:
> Hi John,
>
> John Ridges a écrit :
>   
>> I believe that the first line in the function FLOAT2INT16 in celt.c 
>> which is now:
>> x = x*32768.;
>> should be:
>> x = SCALEIN(x);
>> This only makes a difference if you change the SCALEIN and SCALEOUT 
>> macros (which I do).
>>     
>
> OK, will make sure it's the right thing (appears to be) and fix that.
> Just curious, what value do you use and why?
>
>   
>> The new feature I would like to request is the addition of a 
>> CELT_RESET_STATE control for both the encoder and decoder. I cache 
>> encoder and decoder instances and would like to be able to reset them to 
>> a newly minted state when I change streams.
>>     
>
> Yes, this has been on the TODO list for a while (unfortunately not on
> top). You (or anyone else) can speed that up by sending a patch.
>
> Cheers,
>
> 	Jean-Marc
>
>
>   



More information about the celt-dev mailing list