Skip to content

Commit 55ce20b

Browse files
committed
prepare for OPUS hybrid mode
1 parent 4ee590b commit 55ce20b

File tree

3 files changed

+30
-8
lines changed

3 files changed

+30
-8
lines changed

src/opus_decoder/celt.h

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,8 @@ inline int32_t PSHR(int32_t a, uint32_t shift){return (a + ((int32_t)1 << (shift
277277
#define ADD32(a,b) ((int32_t)(a)+(int32_t)(b))
278278
/** Subtract two 32-bit values */
279279
#define SUB32(a,b) ((int32_t)(a)-(int32_t)(b))
280+
/** Arithmetic shift-right of a 32-bit value */
281+
#define SHR32(a,shift) ((a) >> (shift))
280282

281283
/** Add two 32-bit values, ignore any overflows */
282284
#define ADD32_ovflw(a,b) ((int32_t)((uint32_t)(a)+(uint32_t)(b)))
@@ -334,6 +336,7 @@ int32_t celt_rcp(int32_t x);
334336
#define MAX_PSEUDO 40
335337
#define LOG_MAX_PSEUDO 6
336338
#define ALLOC_NONE 1
339+
#define Q15ONE 32767
337340

338341
/* Prototypes and inlines*/
339342

@@ -501,6 +504,23 @@ inline int32_t pulses2bits(int32_t band, int32_t LM, int32_t pulses){
501504
return pulses == 0 ? 0 : cache[pulses]+1;
502505
}
503506

507+
inline void smooth_fade(const int16_t *in1, const int16_t *in2,
508+
int16_t *out, int overlap, int channels,
509+
const int16_t *window, int32_t Fs)
510+
{
511+
int i, c;
512+
int inc = 48000/Fs;
513+
for (c=0;c<channels;c++)
514+
{
515+
for (i=0;i<overlap;i++)
516+
{
517+
int16_t w = MULT16_16_Q15(window[i*inc], window[i*inc]);
518+
out[i*channels+c] = SHR32(MAC16_16(MULT16_16(w,in2[i*channels+c]),
519+
Q15ONE-w, in1[i*channels+c]), 15);
520+
}
521+
}
522+
}
523+
504524
void comb_filter_const(int32_t *y, int32_t *x, int32_t T, int32_t N, int16_t g10, int16_t g11, int16_t g12);
505525
void comb_filter(int32_t *y, int32_t *x, int32_t T0, int32_t T1, int32_t N, int16_t g0, int16_t g1, int32_t tapset0,
506526
int32_t tapset1);

src/opus_decoder/opus_decoder.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -371,6 +371,7 @@ int32_t opus_decode_frame(uint8_t *inbuf, int16_t *outbuf, int32_t packetLen, ui
371371
log_w("Hybrid mode not yet supported");
372372
return samplesPerFrame;
373373
int decodedSamples = 0;
374+
int start_band = 0;
374375
int32_t silk_frame_size;
375376
int F2_5, F5, F10, F20;
376377
F20 = packetLen / 50;
@@ -397,8 +398,9 @@ int32_t opus_decode_frame(uint8_t *inbuf, int16_t *outbuf, int32_t packetLen, ui
397398
default: break;
398399
}
399400
}
400-
celt_decoder_ctl(CELT_SET_START_BAND_REQUEST, s_endband);
401-
celt_decoder_ctl(CELT_SET_END_BAND_REQUEST, s_endband);
401+
start_band = 17;
402+
celt_decoder_ctl(CELT_SET_START_BAND_REQUEST, start_band);
403+
// celt_decoder_ctl(CELT_SET_END_BAND_REQUEST, s_endband);
402404
ret = celt_decode_with_ec((int16_t*)outbuf, samplesPerFrame);
403405
}
404406
return ret;

src/opus_decoder/opus_decoder.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,13 @@ bool OPUSDecoder_AllocateBuffers();
3838
void OPUSDecoder_FreeBuffers();
3939
void OPUSDecoder_ClearBuffers();
4040
void OPUSsetDefaults();
41-
int32_t OPUSDecode(uint8_t* inbuf, int32_t* bytesLeft, short* outbuf);
41+
int32_t OPUSDecode(uint8_t* inbuf, int32_t* bytesLeft, int16_t* outbuf);
4242
int32_t opusDecodePage0(uint8_t* inbuf, int32_t* bytesLeft, uint32_t segmentLength);
43-
int32_t opusDecodePage3(uint8_t* inbuf, int32_t* bytesLeft, uint32_t segmentLength, short *outbuf);
44-
int8_t opus_FramePacking_Code0(uint8_t *inbuf, int32_t *bytesLeft, short *outbuf, int32_t packetLen, uint16_t samplesPerFrame);
45-
int8_t opus_FramePacking_Code1(uint8_t *inbuf, int32_t *bytesLeft, short *outbuf, int32_t packetLen, uint16_t samplesPerFrame, uint8_t* frameCount);
46-
int8_t opus_FramePacking_Code2(uint8_t *inbuf, int32_t *bytesLeft, short *outbuf, int32_t packetLen, uint16_t samplesPerFrame, uint8_t* frameCount);
47-
int8_t opus_FramePacking_Code3(uint8_t *inbuf, int32_t *bytesLeft, short *outbuf, int32_t packetLen, uint16_t samplesPerFrame, uint8_t* frameCount);
43+
int32_t opusDecodePage3(uint8_t* inbuf, int32_t* bytesLeft, uint32_t segmentLength, int16_t *outbuf);
44+
int8_t opus_FramePacking_Code0(uint8_t *inbuf, int32_t *bytesLeft, int16_t *outbuf, int32_t packetLen, uint16_t samplesPerFrame);
45+
int8_t opus_FramePacking_Code1(uint8_t *inbuf, int32_t *bytesLeft, int16_t *outbuf, int32_t packetLen, uint16_t samplesPerFrame, uint8_t* frameCount);
46+
int8_t opus_FramePacking_Code2(uint8_t *inbuf, int32_t *bytesLeft, int16_t *outbuf, int32_t packetLen, uint16_t samplesPerFrame, uint8_t* frameCount);
47+
int8_t opus_FramePacking_Code3(uint8_t *inbuf, int32_t *bytesLeft, int16_t *outbuf, int32_t packetLen, uint16_t samplesPerFrame, uint8_t* frameCount);
4848
uint8_t OPUSGetChannels();
4949
uint32_t OPUSGetSampRate();
5050
uint8_t OPUSGetBitsPerSample();

0 commit comments

Comments
 (0)