API change: optional resynthesis
The main encode call no longer takes a pointer for the optional resynthesis. It's now done with a call to celt_encode_resynthesis().
This commit is contained in:
parent
e949b72049
commit
d56c610cac
5 changed files with 67 additions and 21 deletions
|
@ -544,10 +544,10 @@ static void mdct_shape(const CELTMode *mode, celt_norm *X, int start,
|
|||
|
||||
|
||||
#ifdef FIXED_POINT
|
||||
int celt_encode(CELTEncoder * restrict st, const celt_int16 * pcm, celt_int16 * optional_synthesis, int frame_size, unsigned char *compressed, int nbCompressedBytes)
|
||||
int celt_encode_resynthesis(CELTEncoder * restrict st, const celt_int16 * pcm, celt_int16 * optional_resynthesis, int frame_size, unsigned char *compressed, int nbCompressedBytes)
|
||||
{
|
||||
#else
|
||||
int celt_encode_float(CELTEncoder * restrict st, const celt_sig * pcm, celt_sig * optional_synthesis, int frame_size, unsigned char *compressed, int nbCompressedBytes)
|
||||
int celt_encode_resynthesis_float(CELTEncoder * restrict st, const celt_sig * pcm, celt_sig * optional_resynthesis, int frame_size, unsigned char *compressed, int nbCompressedBytes)
|
||||
{
|
||||
#endif
|
||||
int i, c, N, NN, N4;
|
||||
|
@ -631,7 +631,7 @@ int celt_encode_float(CELTEncoder * restrict st, const celt_sig * pcm, celt_sig
|
|||
transient_shift = 0;
|
||||
isTransient = 0;
|
||||
|
||||
resynth = st->pitch_available>0 || optional_synthesis!=NULL;
|
||||
resynth = st->pitch_available>0 || optional_resynthesis!=NULL;
|
||||
|
||||
if (M > 1 && transient_analysis(in, N+st->overlap, C, &transient_time, &transient_shift, &st->frame_max))
|
||||
{
|
||||
|
@ -910,8 +910,8 @@ int celt_encode_float(CELTEncoder * restrict st, const celt_sig * pcm, celt_sig
|
|||
|
||||
/* De-emphasis and put everything back at the right place
|
||||
in the synthesis history */
|
||||
if (optional_synthesis != NULL) {
|
||||
deemphasis(st->out_mem, optional_synthesis, N, C, preemph, st->preemph_memD);
|
||||
if (optional_resynthesis != NULL) {
|
||||
deemphasis(st->out_mem, optional_resynthesis, N, C, preemph, st->preemph_memD);
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -924,7 +924,7 @@ int celt_encode_float(CELTEncoder * restrict st, const celt_sig * pcm, celt_sig
|
|||
|
||||
#ifdef FIXED_POINT
|
||||
#ifndef DISABLE_FLOAT_API
|
||||
int celt_encode_float(CELTEncoder * restrict st, const float * pcm, float * optional_synthesis, int frame_size, unsigned char *compressed, int nbCompressedBytes)
|
||||
int celt_encode_resynthesis_float(CELTEncoder * restrict st, const float * pcm, float * optional_resynthesis, int frame_size, unsigned char *compressed, int nbCompressedBytes)
|
||||
{
|
||||
int j, ret, C, N, LM, M;
|
||||
VARDECL(celt_int16, in);
|
||||
|
@ -954,11 +954,11 @@ int celt_encode_float(CELTEncoder * restrict st, const float * pcm, float * opti
|
|||
in[j] = FLOAT2INT16(pcm[j]);
|
||||
|
||||
if (optional_synthesis != NULL) {
|
||||
ret=celt_encode(st,in,in,frame_size,compressed,nbCompressedBytes);
|
||||
ret=celt_encode_resynthesis(st,in,in,frame_size,compressed,nbCompressedBytes);
|
||||
for (j=0;j<C*N;j++)
|
||||
optional_synthesis[j]=in[j]*(1/32768.);
|
||||
} else {
|
||||
ret=celt_encode(st,in,NULL,frame_size,compressed,nbCompressedBytes);
|
||||
ret=celt_encode_resynthesis(st,in,NULL,frame_size,compressed,nbCompressedBytes);
|
||||
}
|
||||
RESTORE_STACK;
|
||||
return ret;
|
||||
|
@ -966,7 +966,7 @@ int celt_encode_float(CELTEncoder * restrict st, const float * pcm, float * opti
|
|||
}
|
||||
#endif /*DISABLE_FLOAT_API*/
|
||||
#else
|
||||
int celt_encode(CELTEncoder * restrict st, const celt_int16 * pcm, celt_int16 * optional_synthesis, int frame_size, unsigned char *compressed, int nbCompressedBytes)
|
||||
int celt_encode_resynthesis(CELTEncoder * restrict st, const celt_int16 * pcm, celt_int16 * optional_resynthesis, int frame_size, unsigned char *compressed, int nbCompressedBytes)
|
||||
{
|
||||
int j, ret, C, N, LM, M;
|
||||
VARDECL(celt_sig, in);
|
||||
|
@ -995,18 +995,28 @@ int celt_encode(CELTEncoder * restrict st, const celt_int16 * pcm, celt_int16 *
|
|||
in[j] = SCALEOUT(pcm[j]);
|
||||
}
|
||||
|
||||
if (optional_synthesis != NULL) {
|
||||
ret = celt_encode_float(st,in,in,frame_size,compressed,nbCompressedBytes);
|
||||
if (optional_resynthesis != NULL) {
|
||||
ret = celt_encode_resynthesis_float(st,in,in,frame_size,compressed,nbCompressedBytes);
|
||||
for (j=0;j<C*N;j++)
|
||||
optional_synthesis[j] = FLOAT2INT16(in[j]);
|
||||
optional_resynthesis[j] = FLOAT2INT16(in[j]);
|
||||
} else {
|
||||
ret = celt_encode_float(st,in,NULL,frame_size,compressed,nbCompressedBytes);
|
||||
ret = celt_encode_resynthesis_float(st,in,NULL,frame_size,compressed,nbCompressedBytes);
|
||||
}
|
||||
RESTORE_STACK;
|
||||
return ret;
|
||||
}
|
||||
#endif
|
||||
|
||||
int celt_encode(CELTEncoder * restrict st, const celt_int16 * pcm, int frame_size, unsigned char *compressed, int nbCompressedBytes)
|
||||
{
|
||||
return celt_encode_resynthesis(st, pcm, NULL, frame_size, compressed, nbCompressedBytes);
|
||||
}
|
||||
|
||||
int celt_encode_float(CELTEncoder * restrict st, const float * pcm, int frame_size, unsigned char *compressed, int nbCompressedBytes)
|
||||
{
|
||||
return celt_encode_resynthesis_float(st, pcm, NULL, frame_size, compressed, nbCompressedBytes);
|
||||
}
|
||||
|
||||
int celt_encoder_ctl(CELTEncoder * restrict st, int request, ...)
|
||||
{
|
||||
va_list ap;
|
||||
|
|
|
@ -175,7 +175,7 @@ EXPORT void celt_encoder_destroy(CELTEncoder *st);
|
|||
* only be used if it is known that the far end supports
|
||||
* extended dynmaic range. There must be exactly
|
||||
* frame_size samples per channel.
|
||||
@param optional_synthesis If not NULL, the encoder copies the audio signal that
|
||||
@param optional_resynthesis If not NULL, the encoder copies the audio signal that
|
||||
* the decoder would decode. It is the same as calling the
|
||||
* decoder on the compressed data, just faster.
|
||||
* This may alias pcm.
|
||||
|
@ -189,13 +189,33 @@ EXPORT void celt_encoder_destroy(CELTEncoder *st);
|
|||
* the length returned be somehow transmitted to the decoder. Otherwise, no
|
||||
* decoding is possible.
|
||||
*/
|
||||
EXPORT int celt_encode_float(CELTEncoder *st, const float *pcm, float *optional_synthesis, int frame_size, unsigned char *compressed, int nbCompressedBytes);
|
||||
EXPORT int celt_encode_resynthesis_float(CELTEncoder *st, const float *pcm, float *optional_resynthesis, int frame_size, unsigned char *compressed, int nbCompressedBytes);
|
||||
|
||||
/** Encodes a frame of audio.
|
||||
@param st Encoder state
|
||||
@param pcm PCM audio in float format, with a normal range of ±1.0.
|
||||
* Samples with a range beyond ±1.0 are supported but will
|
||||
* be clipped by decoders using the integer API and should
|
||||
* only be used if it is known that the far end supports
|
||||
* extended dynmaic range. There must be exactly
|
||||
* frame_size samples per channel.
|
||||
@param compressed The compressed data is written here. This may not alias pcm or
|
||||
* optional_synthesis.
|
||||
@param nbCompressedBytes Maximum number of bytes to use for compressing the frame
|
||||
* (can change from one frame to another)
|
||||
@return Number of bytes written to "compressed". Will be the same as
|
||||
* "nbCompressedBytes" unless the stream is VBR and will never be larger.
|
||||
* If negative, an error has occurred (see error codes). It is IMPORTANT that
|
||||
* the length returned be somehow transmitted to the decoder. Otherwise, no
|
||||
* decoding is possible.
|
||||
*/
|
||||
EXPORT int celt_encode_float(CELTEncoder *st, const float *pcm, int frame_size, unsigned char *compressed, int nbCompressedBytes);
|
||||
|
||||
/** Encodes a frame of audio.
|
||||
@param st Encoder state
|
||||
@param pcm PCM audio in signed 16-bit format (native endian). There must be
|
||||
* exactly frame_size samples per channel.
|
||||
@param optional_synthesis If not NULL, the encoder copies the audio signal that
|
||||
@param optional_resynthesis If not NULL, the encoder copies the audio signal that
|
||||
* the decoder would decode. It is the same as calling the
|
||||
* decoder on the compressed data, just faster.
|
||||
* This may alias pcm.
|
||||
|
@ -209,7 +229,23 @@ EXPORT int celt_encode_float(CELTEncoder *st, const float *pcm, float *optional_
|
|||
* the length returned be somehow transmitted to the decoder. Otherwise, no
|
||||
* decoding is possible.
|
||||
*/
|
||||
EXPORT int celt_encode(CELTEncoder *st, const celt_int16 *pcm, celt_int16 *optional_synthesis, int frame_size, unsigned char *compressed, int nbCompressedBytes);
|
||||
EXPORT int celt_encode_resynthesis(CELTEncoder *st, const celt_int16 *pcm, celt_int16 *optional_resynthesis, int frame_size, unsigned char *compressed, int nbCompressedBytes);
|
||||
|
||||
/** Encodes a frame of audio.
|
||||
@param st Encoder state
|
||||
@param pcm PCM audio in signed 16-bit format (native endian). There must be
|
||||
* exactly frame_size samples per channel.
|
||||
@param compressed The compressed data is written here. This may not alias pcm or
|
||||
* optional_synthesis.
|
||||
@param nbCompressedBytes Maximum number of bytes to use for compressing the frame
|
||||
* (can change from one frame to another)
|
||||
@return Number of bytes written to "compressed". Will be the same as
|
||||
* "nbCompressedBytes" unless the stream is VBR and will never be larger.
|
||||
* If negative, an error has occurred (see error codes). It is IMPORTANT that
|
||||
* the length returned be somehow transmitted to the decoder. Otherwise, no
|
||||
* decoding is possible.
|
||||
*/
|
||||
EXPORT int celt_encode(CELTEncoder *st, const celt_int16 *pcm, int frame_size, unsigned char *compressed, int nbCompressedBytes);
|
||||
|
||||
/** Query and set encoder parameters
|
||||
@param st Encoder state
|
||||
|
|
|
@ -133,7 +133,7 @@ int main(int argc, char *argv[])
|
|||
err = fread(in, sizeof(short), frame_size*channels, fin);
|
||||
if (feof(fin))
|
||||
break;
|
||||
len = celt_encode(enc, in, in, frame_size, data, bytes_per_packet);
|
||||
len = celt_encode_resynthesis(enc, in, in, frame_size, data, bytes_per_packet);
|
||||
if (len <= 0)
|
||||
{
|
||||
fprintf (stderr, "celt_encode() returned %d\n", len);
|
||||
|
|
|
@ -99,7 +99,7 @@ int async_tandem(int rate, int frame_size, int channels, int bitrate_min,
|
|||
for (j = channels; j < frame_size * channels - 1; j++)
|
||||
pcm[j] = ((rand() % 4096) - 2048) + .9 * pcm[j - channels];
|
||||
|
||||
ret = celt_encode(enc, pcm, NULL, frame_size, data, bytes_per_frame);
|
||||
ret = celt_encode(enc, pcm, frame_size, data, bytes_per_frame);
|
||||
if (ret != bytes_per_frame) {
|
||||
fprintf(stderr, "Error: during init celt_encode returned %d\n", ret);
|
||||
exit(1);
|
||||
|
@ -123,7 +123,7 @@ int async_tandem(int rate, int frame_size, int channels, int bitrate_min,
|
|||
for (j = 0; j < channels; j++)
|
||||
pcm[j] = carry[j];
|
||||
|
||||
ret = celt_encode(enc, pcm, NULL, frame_size, data, bytes_per_frame);
|
||||
ret = celt_encode(enc, pcm, frame_size, data, bytes_per_frame);
|
||||
if (ret != bytes_per_frame) {
|
||||
fprintf(stderr, "Error: at %d bytes_per_frame celt_encode returned %d\n",
|
||||
bytes_per_frame, ret);
|
||||
|
|
|
@ -664,7 +664,7 @@ int main(int argc, char **argv)
|
|||
id++;
|
||||
/*Encode current frame*/
|
||||
|
||||
nbBytes = celt_encode(st, input, NULL, frame_size, bits, bytes_per_packet);
|
||||
nbBytes = celt_encode(st, input, frame_size, bits, bytes_per_packet);
|
||||
if (nbBytes<0)
|
||||
{
|
||||
fprintf(stderr, "Got error %d while encoding. Aborting.\n", nbBytes);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue