📄 src.cpp
字号:
//**********************************************************************
//
// Filename: src.cpp
//
// Description: Class for the sample rate converter.
//
// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
// ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
// PARTICULAR PURPOSE.
//
// Use of this source code is subject to the terms of the Cirrus end-user
// license agreement (EULA) under which you licensed this SOFTWARE PRODUCT.
// If you did not accept the terms of the EULA, you are not authorized to
// use this source code. For a copy of the EULA, please see the
// LICENSE.RTF on your install media.
//
// Copyright(c) Cirrus Logic Corporation 2002, All Rights Reserved
//
//**********************************************************************
#include <windows.h>
#include "src.h"
#include "filt0181.h"
#include "filt0250.h"
#include "filt0500.h"
// #include "filt0919.h"
// #include "filt1378.h"
// #include "filt1838.h"
// #include "filt2000.h"
// #include "filt2756.h"
// #include "filt3675.h"
// #include "filt4000.h"
// #include "filt5513.h"
static void FilterMono13
(
tSRC *pSRC,
ULONG *pulInData,
short *psOutData,
long *plInSamples,
long *plOutSamples,
BOOL b8Bit
);
static void FilterMono6
(
tSRC *pSRC,
ULONG *pulInData,
short *psOutData,
long *plInSamples,
long *plOutSamples,
BOOL b8Bit
);
static void FilterStereo13
(
tSRC *pSRC,
ULONG *pulInData,
short *psOutData,
long *plInSamples,
long *plOutSamples,
BOOL b8Bit
);
static void FilterStereo6
(
tSRC *pSRC,
ULONG *pulInData,
short *psOutData,
long *plInSamples,
long *plOutSamples,
BOOL b8Bit
);
//****************************************************************************
//
// SRCInit initializes the persistent state of the sample rate converter. It
// must be called before SRCFilter. It is the responsibility of the caller to
// allocate the memory needed by the sample rate converter for the persistent
// state structure.
//
//****************************************************************************
int SRCInit
(
tSRC *pSRC,
unsigned long ulInputRate,
unsigned long ulOutputRate,
BOOL b8Bit,
BOOL bMono
)
{
long lNumPolyPhases, lSampleIncrement, lNumTaps;
//
// Choose the polyphase filter based on the ratio of input rate to output
// rate.
//
switch((ulOutputRate << 16) / ulInputRate)
{
//
// Ratio of ~0.1814 (44.1kHz -> 8kHz).
//
case 0x00002E70:
{
lNumPolyPhases = SRCFilter_0_1814.sNumPolyPhases;
lNumTaps = SRCFilter_0_1814.sNumTaps;
lSampleIncrement = SRCFilter_0_1814.sSampleIncrement;
pSRC->psFilter = (short *)SRCFilter_0_1814.sCoefs;
break;
}
//
// Ratio of 0.25 (44.1kHz -> 11.025kHz).
//
case 0x00004000:
{
lNumPolyPhases = SRCFilter_0_25.sNumPolyPhases;
lNumTaps = SRCFilter_0_25.sNumTaps;
lSampleIncrement = SRCFilter_0_25.sSampleIncrement;
pSRC->psFilter = (short *)SRCFilter_0_25.sCoefs;
break;
}
//
// Ratio of 0.5 (44.1kHz -> 22.05kHz).
//
case 0x00008000:
{
lNumPolyPhases = SRCFilter_0_5.sNumPolyPhases;
lNumTaps = SRCFilter_0_5.sNumTaps;
lSampleIncrement = SRCFilter_0_5.sSampleIncrement;
pSRC->psFilter = (short *)SRCFilter_0_5.sCoefs;
break;
}
#if 0
//
// Ratio of 0.91875 (48kHz -> 44.1kHz).
//
case 0x0000EB33:
{
lNumPolyPhases = SRCFilter_0_91875.sNumPolyPhases;
lNumTaps = SRCFilter_0_91875.sNumTaps;
lSampleIncrement = SRCFilter_0_91875.sSampleIncrement;
pSRC->psFilter = (short *)SRCFilter_0_91875.sCoefs;
break;
}
//
// Ratio of 1.378125 (32khz -> 44.1kHz).
//
case 0x000160CC:
{
lNumPolyPhases = SRCFilter_1_378125.sNumPolyPhases;
lNumTaps = SRCFilter_1_378125.sNumTaps;
lSampleIncrement = SRCFilter_1_378125.sSampleIncrement;
pSRC->psFilter = (short *)SRCFilter_1_378125.sCoefs;
break;
}
//
// Ratio of 1.8375 (24kHz -> 44.1kHz).
//
case 0x0001D666:
{
lNumPolyPhases = SRCFilter_1_8375.sNumPolyPhases;
lNumTaps = SRCFilter_1_8375.sNumTaps;
lSampleIncrement = SRCFilter_1_8375.sSampleIncrement;
pSRC->psFilter = (short *)SRCFilter_1_8375.sCoefs;
break;
}
//
// Ratio of 2.0 (22.05kHz -> 44.1kHz).
//
case 0x00020000:
{
lNumPolyPhases = SRCFilter_2_0.sNumPolyPhases;
lNumTaps = SRCFilter_2_0.sNumTaps;
lSampleIncrement = SRCFilter_2_0.sSampleIncrement;
pSRC->psFilter = (short *)SRCFilter_2_0.sCoefs;
break;
}
//
// Ratio of 2.75625 (16kHz -> 44.1kHz).
//
case 0x0002C199:
{
lNumPolyPhases = SRCFilter_2_75625.sNumPolyPhases;
lNumTaps = SRCFilter_2_75625.sNumTaps;
lSampleIncrement = SRCFilter_2_75625.sSampleIncrement;
pSRC->psFilter = (short *)SRCFilter_2_75625.sCoefs;
break;
}
//
// Ratio of 3.675 (12kHz -> 44.1kHz).
//
case 0x0003ACCC:
{
lNumPolyPhases = SRCFilter_3_675.sNumPolyPhases;
lNumTaps = SRCFilter_3_675.sNumTaps;
lSampleIncrement = SRCFilter_3_675.sSampleIncrement;
pSRC->psFilter = (short *)SRCFilter_3_675.sCoefs;
break;
}
//
// Ratio of 4.0 (11.025kHz -> 44.1kHz).
//
case 0x00040000:
{
lNumPolyPhases = SRCFilter_4_0.sNumPolyPhases;
lNumTaps = SRCFilter_4_0.sNumTaps;
lSampleIncrement = SRCFilter_4_0.sSampleIncrement;
pSRC->psFilter = (short *)SRCFilter_4_0.sCoefs;
break;
}
//
// Ratio of 5.5125 (8kHz -> 44.1kHz).
//
case 0x00058333:
{
lNumPolyPhases = SRCFilter_5_5125.sNumPolyPhases;
lNumTaps = SRCFilter_5_5125.sNumTaps;
lSampleIncrement = SRCFilter_5_5125.sSampleIncrement;
pSRC->psFilter = (short *)SRCFilter_5_5125.sCoefs;
break;
}
#endif // 0
//
// An unsupported sample rate ratio was specified. Return an error.
//
default:
{
return(0);
}
}
//
// Make sure that the number of taps in the filter matches the number of
// taps supported by our filtering code.
//
if((lNumTaps != 13) && (lNumTaps != 6))
{
return(0);
}
//
// Initialize the persistent SRC state.
//
pSRC->sNumTaps = (short)lNumTaps;
pSRC->sFilterOffset = 0;
pSRC->sFilterIncr = short(lSampleIncrement * lNumTaps);
pSRC->sFilterSize = short(lNumPolyPhases * lNumTaps);
pSRC->bMono = bMono;
pSRC->b8Bit = b8Bit;
//
// We've successfully initialized the requested sample rate converter.
//
return(1);
}
//****************************************************************************
// Filter
//****************************************************************************
// Calls FilterMono6 or FilterMono13.
//
//
void Filter
(
tSRC *pSRC,
ULONG *pulInData,
short *psOutData,
long *plInSamples,
long *plOutSamples
)
{
if(pSRC->bMono)
{
if(pSRC->sNumTaps == 6)
{
FilterMono6
(
pSRC,
pulInData,
psOutData,
plInSamples,
plOutSamples,
pSRC->b8Bit
);
}
else
{
FilterMono13
(
pSRC,
pulInData,
psOutData,
plInSamples,
plOutSamples,
pSRC->b8Bit
);
}
}
else
{
if(pSRC->sNumTaps == 6)
{
FilterStereo6
(
pSRC,
pulInData,
psOutData,
plInSamples,
plOutSamples,
pSRC->b8Bit
);
}
else
{
FilterStereo13
(
pSRC,
pulInData,
psOutData,
plInSamples,
plOutSamples,
pSRC->b8Bit
);
}
}
}
//****************************************************************************
// FilterMono13
//****************************************************************************
// FilterMono13 performs the actual sample rate conversion for a single mono
// stream of data using a 13-tap filter.
//
// IN tSRC - Pointer to the SRC structure.
// IN plInData - Pointer to the Input Buffer, 24 bit left justified.
// IN psOutData - Pointer to the output buffer.
// IN/OUT plInSamples - Number of Sample avaliable/left in Input Buffer.
// IN/OUT plOutSamples - Number of Sample avaliable/left in Output buffer.
// IN b8Bit - Is the Output 8 bit.
//
//
static void FilterMono13
(
tSRC *pSRC,
ULONG *pulInData,
short *psOutData,
long *plInSamples,
long *plOutSamples,
BOOL b8Bit
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -