📄 src.cpp
字号:
// See if we've passed the entire filter, indicating that we've
// consumed one of the input samples.
//
while(pSRC->sFilterOffset >= pSRC->sFilterSize)
{
//
// We have, so wrap the filter offset (i.e. treat the filter as if
// it were a circular buffer in memory).
//
pSRC->sFilterOffset -= pSRC->sFilterSize;
//
// Consume the input sample.
//
pulInData+=2;
//
// Decrement the count of input samples available.
//
lInSamples--;
//
// Increment the count of input samples consumed.
//
lConsumed++;
//
// If there are no more input samples, then stop processing data.
//
if(lInSamples == 0)
{
//
// Return the number of samples produced and consumed.
//
*plInSamples = lConsumed;
*plOutSamples = lProduced;
//
// Return to the caller.
//
return;
}
}
//
// Get a pointer to the filter and to the sample data.
//
psPtr1 = pSRC->psFilter + pSRC->sFilterOffset;
//psPtr2 = psInDataLeft;
//psPtr3 = psInDataRight;
pulPtr2 = (PULONG)pulInData;
// psPtr3 = plInData + 1;
//
// Run the filter over the sample data. The number of MACs here must
// agree with NUMTAPS.
//
//
// The left and right data may need to be swapped.
//
sCoeff = *psPtr1++;
lOutDataLeft = sCoeff * short((*pulPtr2--)>>8);
lOutDataRight = sCoeff * short((*pulPtr2--)>>8);
sCoeff = *psPtr1++;
lOutDataLeft += sCoeff * short((*pulPtr2--)>>8);
lOutDataRight += sCoeff * short((*pulPtr2--)>>8);
sCoeff = *psPtr1++;
lOutDataLeft += sCoeff * short((*pulPtr2--)>>8);
lOutDataRight += sCoeff * short((*pulPtr2--)>>8);
sCoeff = *psPtr1++;
lOutDataLeft += sCoeff * short((*pulPtr2--)>>8);
lOutDataRight += sCoeff * short((*pulPtr2--)>>8);
sCoeff = *psPtr1++;
lOutDataLeft += sCoeff * short((*pulPtr2--)>>8);
lOutDataRight += sCoeff * short((*pulPtr2--)>>8);
sCoeff = *psPtr1++;
lOutDataLeft += sCoeff * short((*pulPtr2--)>>8);
lOutDataRight += sCoeff * short((*pulPtr2--)>>8);
sCoeff = *psPtr1++;
lOutDataLeft += sCoeff * short((*pulPtr2--)>>8);
lOutDataRight += sCoeff * short((*pulPtr2--)>>8);
sCoeff = *psPtr1++;
lOutDataLeft += sCoeff * short((*pulPtr2--)>>8);
lOutDataRight += sCoeff * short((*pulPtr2--)>>8);
sCoeff = *psPtr1++;
lOutDataLeft += sCoeff * short((*pulPtr2--)>>8);
lOutDataRight += sCoeff * short((*pulPtr2--)>>8);
sCoeff = *psPtr1++;
lOutDataLeft += sCoeff * short((*pulPtr2--)>>8);
lOutDataRight += sCoeff * short((*pulPtr2--)>>8);
sCoeff = *psPtr1++;
lOutDataLeft += sCoeff * short((*pulPtr2--)>>8);
lOutDataRight += sCoeff * short((*pulPtr2--)>>8);
sCoeff = *psPtr1++;
lOutDataLeft += sCoeff * short((*pulPtr2--)>>8);
lOutDataRight += sCoeff * short((*pulPtr2--)>>8);
sCoeff = *psPtr1++;
lOutDataLeft += sCoeff * short((*pulPtr2--)>>8);
lOutDataRight += sCoeff * short((*pulPtr2--)>>8);
//
// Clip the filtered samples if necessary.
//
if((lOutDataLeft + 0x40000000) < 0)
{
lOutDataLeft = (lOutDataLeft & 0x80000000) ? 0xc0000000 :
0x3fffffff;
}
if((lOutDataRight + 0x40000000) < 0)
{
lOutDataRight = (lOutDataRight & 0x80000000) ? 0xc0000000 :
0x3fffffff;
}
//
// Write out the sample.
//
//*psOutDataLeft++ = (short)(lOutDataLeft >> 15);
//*psOutDataRight++ = (short)(lOutDataRight >> 15);
//
// Write out the sample.
//
if(b8Bit)
{
*pucOutData++ = UCHAR((lOutDataLeft>>23) & 0xFF) + 0x80;
*pucOutData++ = UCHAR((lOutDataRight>>23) & 0xFF) + 0x80;
}
else
{
*psOutData++ = (short)(lOutDataLeft >> 15);
*psOutData++ = (short)(lOutDataRight >> 15);
}
//
// Decrement the count of output sample space available.
//
lOutSamples--;
//
// Increment the count of output samples produced.
//
lProduced++;
//
// Increment the offset into the filter.
//
pSRC->sFilterOffset += pSRC->sFilterIncr;
}
//
// Return the number of samples produced and consumed.
//
*plInSamples = lConsumed;
*plOutSamples = lProduced;
}
//****************************************************************************
// FilterStereo6
//****************************************************************************
// FilterStereo6 performs the actual sample rate conversion using a
// 6-tap filter.
//
// IN tSRC - Pointer to the SRC structure.
// IN pusInData - Pointer to the Input Buffer.
// IN pusOutData - Pointer to the output buffer.
// IN/OUT plInSamples - Number of Sample avaliable/consumed in Input Buffer.
// IN/OUT plOutSamples - Number of Sample avaliable/consumed in Output buffer.
// IN b8Bit - Is the Output 8 bit.
//
//
static void FilterStereo6
(
tSRC *pSRC,
ULONG *pulInData,
short *psOutData,
long *plInSamples,
long *plOutSamples,
BOOL b8Bit
)
{
register long lOutDataLeft, lOutDataRight;
register short *psPtr1;
register unsigned long *pulPtr2;
register short sCoeff;
long lInSamples, lConsumed, lOutSamples, lProduced;
PUCHAR pucOutData = (PUCHAR)psOutData;
//
// Get the initial values of the sample counters.
//
lInSamples = *plInSamples;
lConsumed = 0;
lOutSamples = *plOutSamples;
lProduced = 0;
//
// Run the sample rate converter filter for the specified number of
// samples.
//
while(lOutSamples && lInSamples)
{
//
// See if we've passed the entire filter, indicating that we've
// consumed one of the input samples.
//
while(pSRC->sFilterOffset >= pSRC->sFilterSize)
{
//
// We have, so wrap the filter offset (i.e. treat the filter as if
// it were a circular buffer in memory).
//
pSRC->sFilterOffset -= pSRC->sFilterSize;
//
// Consume the input sample.
//
pulInData+=2;
//
// Decrement the count of input samples available.
//
lInSamples--;
//
// Increment the count of input samples consumed.
//
lConsumed++;
//
// If there are no more input samples, then stop processing data.
//
if(lInSamples == 0)
{
//
// Return the number of samples produced and consumed.
//
*plInSamples = lConsumed;
*plOutSamples = lProduced;
//
// Return to the caller.
//
return;
}
}
//
// Get a pointer to the filter and to the sample data.
//
psPtr1 = pSRC->psFilter + pSRC->sFilterOffset;
pulPtr2 = pulInData;
//
// Run the filter over the sample data.
//
sCoeff = *psPtr1++;
lOutDataLeft = sCoeff * short((*pulPtr2--)>>8);
lOutDataRight = sCoeff * short((*pulPtr2--)>>8);
sCoeff = *psPtr1++;
lOutDataLeft += sCoeff * short((*pulPtr2--)>>8);
lOutDataRight += sCoeff * short((*pulPtr2--)>>8);
sCoeff = *psPtr1++;
lOutDataLeft += sCoeff * short((*pulPtr2--)>>8);
lOutDataRight += sCoeff * short((*pulPtr2--)>>8);
sCoeff = *psPtr1++;
lOutDataLeft += sCoeff * short((*pulPtr2--)>>8);
lOutDataRight += sCoeff * short((*pulPtr2--)>>8);
sCoeff = *psPtr1++;
lOutDataLeft += sCoeff * short((*pulPtr2--)>>8);
lOutDataRight += sCoeff * short((*pulPtr2--)>>8);
sCoeff = *psPtr1++;
lOutDataLeft += sCoeff * short((*pulPtr2--)>>8);
lOutDataRight += sCoeff * short((*pulPtr2--)>>8);
//
// Clip the filtered samples if necessary.
//
if((lOutDataLeft + 0x40000000) < 0)
{
lOutDataLeft = (lOutDataLeft & 0x80000000) ? 0xc0000000 :
0x3fffffff;
}
if((lOutDataRight + 0x40000000) < 0)
{
lOutDataRight = (lOutDataRight & 0x80000000) ? 0xc0000000 :
0x3fffffff;
}
//
// Write out the sample.
//
//*psOutDataLeft++ = (short)(lOutDataLeft >> 15);
//*psOutDataRight++ = (short)(lOutDataRight >> 15);
//
// Write out the sample.
//
if(b8Bit)
{
*pucOutData++ = UCHAR((lOutDataLeft>>23) & 0xFF) + 0x80;
*pucOutData++ = UCHAR((lOutDataRight>>23) & 0xFF) + 0x80;
}
else
{
*psOutData++ = (short)(lOutDataLeft >> 15);
*psOutData++ = (short)(lOutDataRight >> 15);
}
//
// Decrement the count of output sample space available.
//
lOutSamples--;
//
// Increment the count of output samples produced.
//
lProduced++;
//
// Increment the offset into the filter.
//
pSRC->sFilterOffset += pSRC->sFilterIncr;
}
//
// Return the number of samples produced and consumed.
//
*plInSamples = lConsumed;
*plOutSamples = lProduced;
}
//****************************************************************************
//
// SRCNumSamplesAvailable returns the approximate number of output samples
// that can be produced given the number of input samples.
//
//****************************************************************************
long SRCNumSamplesAvailable(tSRC *pSRC, long lSamples)
{
//
// Return the number of output samples still available.
//
if(lSamples < pSRC->sNumTaps)
{
return(0);
}
else
{
return((((lSamples - pSRC->sNumTaps + 1) * pSRC->sFilterSize) +
pSRC->sFilterIncr - 1 - pSRC->sFilterOffset) /
pSRC->sFilterIncr);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -