📄 dolby_adapt.c
字号:
#include <stdio.h>
#include <stdlib.h>
#include "dolby_def.h"
#include "weave.h"
#include "block.h"
#define NORM_TYPE 0
#define START_TYPE 1
#define SHORT_TYPE 2
#define STOP_TYPE 3
extern int frame_cnt;
#define N_SHORT_IN_START 4
#define START_OFFSET 0
#define SHORT_IN_START_OFFSET 5
#define N_SHORT_IN_STOP 3
#define STOP_OFFSET 3
#define SHORT_IN_STOP_OFFSET 0
#define N_SHORT_IN_4STOP 4
/*****************************************************************************
*
* unfold
* create full spectrum by reflecting-inverting first half over to second
* input: see below
* output: see below
* local static: none
* globals: none
*
*****************************************************************************/
void __inline unfold (
Float *data_in, /* input: 1/2 spectrum */
Float *data_out, /* output: full spectrum */
int inLeng) /* input: length of input vector */
{
register int i;
/* fill transBuff w/ full MDCT sequence from freqInPtr */
for (i=0;i<inLeng;i++) {
data_out[i] = *data_in;
data_out[2*inLeng-i-1] = -(*data_in);
data_in++;
}
} /* end of unfold */
/*****************************************************************************
*
* freq2time_adapt
* transform freq. domain data to time domain.
* Overlap and add transform output to recreate time sequence.
* Blocks composed of multiple segments (i.e. all but long) have
* input spectrums interleaved.
* input: see below
* output: see below
* local static:
* timeBuff time domain data fifo
* globals: none
*
*****************************************************************************/
void freq2time_adapt (
byte blockType, /* input: blockType 0-3 */
Wnd_Shape *wnd_shape, /* input/output */
Float *freqInPtr, /* input: interleaved spectrum */
Float *timeBuff, /* transform state needed for each channel */
Float *ftimeOutPtr) /* output: 1/2 block of new time values */
{
static int dolbyShortOffset = 1;
static Float transBuff [2*BLOCK_LEN_LONG], *transBuffPtr;
int i, j;
Float *timeBuffPtr, *destPtr;
static Float timeOutPtr[BLOCK_LEN_LONG];
int windShape;
windShape = wnd_shape->this_bk; /* window_shape [ch]; */
if (blockType == NORM_TYPE) {
unfold (freqInPtr, transBuff, BLOCK_LEN_LONG);
/* Do 1 LONG transform */
ITransformBlock (transBuff, LONG_BLOCK, wnd_shape, timeBuff); /* ch ); */
/* Add first half and old data */
transBuffPtr = transBuff;
timeBuffPtr = timeBuff; /* [ch]; */
destPtr = timeOutPtr;
for (i = 0; i < BLOCK_LEN_LONG; i++) {
*destPtr++ = *transBuffPtr++ + *timeBuffPtr++;
}
/* Save second half as old data */
timeBuffPtr = timeBuff; /* [ch]; */
for (i = 0; i < BLOCK_LEN_LONG; i++) {
*timeBuffPtr++ = *transBuffPtr++;
}
}
else if (blockType == SHORT_TYPE) {
/* Do 8 SHORT transforms */
if (dolbyShortOffset)
destPtr = timeBuff + 4 * BLOCK_LEN_SHORT; /* DBS */
else
destPtr = timeBuff + (BLOCK_LEN_LONG - BLOCK_LEN_SHORT) / 2; /* 448 */
for (i = 0; i < 8; i++) {
unfold (freqInPtr, transBuff, BLOCK_LEN_SHORT );
/*was freqinPtr++, 8 .. mfd */
freqInPtr += BLOCK_LEN_SHORT; /* added mfd */
ITransformBlock (transBuff, SHORT_BLOCK, wnd_shape, timeBuff);
/* Add first half of short window and old data */
transBuffPtr = transBuff;
for (j = 0; j < BLOCK_LEN_SHORT; j++) {
*destPtr++ += *transBuffPtr++;
}
/* Save second half of short window */
for (j = 0; j < BLOCK_LEN_SHORT; j++) {
*destPtr++ = *transBuffPtr++;
}
destPtr -= BLOCK_LEN_SHORT;
}
/* Copy data to output buffer */
destPtr = timeOutPtr;
timeBuffPtr = timeBuff; /* [ch]; */
for (i = 0; i < BLOCK_LEN_LONG; i++) {
*destPtr++ = *timeBuffPtr++;
}
/* Update timeBuff fifo */
destPtr = timeBuff; /* [ch]; */
for (i = 0; i < BLOCK_LEN_LONG; i++) {
*destPtr++ = *timeBuffPtr++;
}
}
else if (blockType == START_TYPE) {
unfold(freqInPtr, transBuff, BLOCK_LEN_LONG);
ITransformBlock (transBuff, START_FLAT_BLOCK, wnd_shape, timeBuff);
/* Add first half and old data */
transBuffPtr = transBuff;
timeBuffPtr = timeBuff;
destPtr = timeOutPtr;
for (i = 0; i < BLOCK_LEN_LONG; i++) {
*destPtr++ = *transBuffPtr++ + *timeBuffPtr++;
}
/* Save second half as old data */
timeBuffPtr = timeBuff;
for (i = 0; i < BLOCK_LEN_LONG; i++) {
*timeBuffPtr++ = *transBuffPtr++;
}
dolbyShortOffset = 0;
}
else if (blockType == STOP_TYPE) {
unfold (freqInPtr, transBuff, BLOCK_LEN_LONG);
/* Do 1 LONG transforms */
ITransformBlock (transBuff, STOP_FLAT_BLOCK, wnd_shape, timeBuff);
/* Add first half and old data */
transBuffPtr = transBuff;
timeBuffPtr = timeBuff;
destPtr = timeOutPtr;
for (i = 0; i < BLOCK_LEN_LONG - NFLAT; i++) {
*destPtr++ = *transBuffPtr++ + *timeBuffPtr++;
}
for ( ; i < BLOCK_LEN_LONG; i++) {
*destPtr++ = *transBuffPtr++;
}
/* Save second half as old data */
timeBuffPtr = timeBuff;
for (i = 0; i < BLOCK_LEN_LONG; i++ ) {
*timeBuffPtr++ = *transBuffPtr++;
}
}
for (i = 0; i < BLOCK_LEN_LONG; i++) {
*(ftimeOutPtr++) = (timeOutPtr[i]);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -