mirror of
https://github.com/Ardour/ardour.git
synced 2025-12-09 08:14:58 +01:00
replicate the remove-all-trailing whitespace commit(s) in master
This commit is contained in:
parent
589f2a1ab8
commit
bc487bb4b0
235 changed files with 5833 additions and 5840 deletions
|
|
@ -2,14 +2,14 @@
|
|||
File: CASpectralProcessor.cpp
|
||||
Abstract: CASpectralProcessor.h
|
||||
Version: 1.1
|
||||
|
||||
|
||||
Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple
|
||||
Inc. ("Apple") in consideration of your agreement to the following
|
||||
terms, and your use, installation, modification or redistribution of
|
||||
this Apple software constitutes acceptance of these terms. If you do
|
||||
not agree with these terms, please do not use, install, modify or
|
||||
redistribute this Apple software.
|
||||
|
||||
|
||||
In consideration of your agreement to abide by the following terms, and
|
||||
subject to these terms, Apple grants you a personal, non-exclusive
|
||||
license, under Apple's copyrights in this original Apple software (the
|
||||
|
|
@ -25,13 +25,13 @@
|
|||
implied, are granted by Apple herein, including but not limited to any
|
||||
patent rights that may be infringed by your derivative works or by other
|
||||
works in which the Apple Software may be incorporated.
|
||||
|
||||
|
||||
The Apple Software is provided by Apple on an "AS IS" basis. APPLE
|
||||
MAKES NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION
|
||||
THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS
|
||||
FOR A PARTICULAR PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND
|
||||
OPERATION ALONE OR IN COMBINATION WITH YOUR PRODUCTS.
|
||||
|
||||
|
||||
IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL
|
||||
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
|
|
@ -40,11 +40,11 @@
|
|||
AND WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING NEGLIGENCE),
|
||||
STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN ADVISED OF THE
|
||||
POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
|
||||
Copyright (C) 2014 Apple Inc. All Rights Reserved.
|
||||
|
||||
|
||||
*/
|
||||
|
||||
|
||||
//#include "AudioFormulas.h"
|
||||
#include "CASpectralProcessor.h"
|
||||
#include "CABitOperations.h"
|
||||
|
|
@ -57,23 +57,23 @@
|
|||
|
||||
CASpectralProcessor::CASpectralProcessor(UInt32 inFFTSize, UInt32 inHopSize, UInt32 inNumChannels, UInt32 inMaxFrames)
|
||||
: mFFTSize(inFFTSize), mHopSize(inHopSize), mNumChannels(inNumChannels), mMaxFrames(inMaxFrames),
|
||||
mLog2FFTSize(Log2Ceil(mFFTSize)),
|
||||
mLog2FFTSize(Log2Ceil(mFFTSize)),
|
||||
mFFTMask(mFFTSize - 1),
|
||||
mFFTByteSize(mFFTSize * sizeof(Float32)),
|
||||
mIOBufSize(NextPowerOfTwo(mFFTSize + mMaxFrames)),
|
||||
mIOMask(mIOBufSize - 1),
|
||||
mInputSize(0),
|
||||
mInputPos(0), mOutputPos(-mFFTSize & mIOMask),
|
||||
mInputPos(0), mOutputPos(-mFFTSize & mIOMask),
|
||||
mInFFTPos(0), mOutFFTPos(0),
|
||||
mSpectralFunction(0), mUserData(0)
|
||||
{
|
||||
mWindow.alloc(mFFTSize, false);
|
||||
SineWindow(); // set default window.
|
||||
|
||||
|
||||
mChannels.alloc(mNumChannels);
|
||||
mSpectralBufferList.allocBytes(OFFSETOF(SpectralBufferList, mDSPSplitComplex[mNumChannels]), true);
|
||||
mSpectralBufferList->mNumberSpectra = mNumChannels;
|
||||
for (UInt32 i = 0; i < mNumChannels; ++i)
|
||||
for (UInt32 i = 0; i < mNumChannels; ++i)
|
||||
{
|
||||
mChannels[i].mInputBuf.alloc(mIOBufSize, true);
|
||||
mChannels[i].mOutputBuf.alloc(mIOBufSize, true);
|
||||
|
|
@ -84,7 +84,7 @@ CASpectralProcessor::CASpectralProcessor(UInt32 inFFTSize, UInt32 inHopSize, UIn
|
|||
}
|
||||
|
||||
mFFTSetup = vDSP_create_fftsetup (mLog2FFTSize, FFT_RADIX2);
|
||||
|
||||
|
||||
}
|
||||
|
||||
CASpectralProcessor::~CASpectralProcessor()
|
||||
|
|
@ -101,8 +101,8 @@ void CASpectralProcessor::Reset()
|
|||
mOutputPos = -mFFTSize & mIOMask;
|
||||
mInFFTPos = 0;
|
||||
mOutFFTPos = 0;
|
||||
|
||||
for (UInt32 i = 0; i < mNumChannels; ++i)
|
||||
|
||||
for (UInt32 i = 0; i < mNumChannels; ++i)
|
||||
{
|
||||
memset(mChannels[i].mInputBuf(), 0, mIOBufSize * sizeof(Float32));
|
||||
memset(mChannels[i].mOutputBuf(), 0, mIOBufSize * sizeof(Float32));
|
||||
|
|
@ -113,13 +113,13 @@ void CASpectralProcessor::Reset()
|
|||
const double two_pi = 2. * M_PI;
|
||||
|
||||
void CASpectralProcessor::HanningWindow()
|
||||
{
|
||||
{
|
||||
// this is also vector optimized
|
||||
|
||||
double w = two_pi / (double)(mFFTSize - 1);
|
||||
for (UInt32 i = 0; i < mFFTSize; ++i)
|
||||
{
|
||||
mWindow[i] = (0.5 - 0.5 * cos(w * (double)i));
|
||||
mWindow[i] = (0.5 - 0.5 * cos(w * (double)i));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -136,9 +136,9 @@ void CASpectralProcessor::Process(UInt32 inNumFrames, AudioBufferList* inInput,
|
|||
{
|
||||
// copy from buffer list to input buffer
|
||||
CopyInput(inNumFrames, inInput);
|
||||
|
||||
|
||||
// if enough input to process, then process.
|
||||
while (mInputSize >= mFFTSize)
|
||||
while (mInputSize >= mFFTSize)
|
||||
{
|
||||
CopyInputToFFT(); // copy from input buffer to fft buffer
|
||||
DoWindowing();
|
||||
|
|
@ -170,18 +170,18 @@ void CASpectralProcessor::CopyInput(UInt32 inNumFrames, AudioBufferList* inInput
|
|||
{
|
||||
UInt32 numBytes = inNumFrames * sizeof(Float32);
|
||||
UInt32 firstPart = mIOBufSize - mInputPos;
|
||||
|
||||
|
||||
|
||||
if (firstPart < inNumFrames) {
|
||||
UInt32 firstPartBytes = firstPart * sizeof(Float32);
|
||||
UInt32 secondPartBytes = numBytes - firstPartBytes;
|
||||
for (UInt32 i=0; i<mNumChannels; ++i) {
|
||||
for (UInt32 i=0; i<mNumChannels; ++i) {
|
||||
memcpy(mChannels[i].mInputBuf + mInputPos, inInput->mBuffers[i].mData, firstPartBytes);
|
||||
memcpy(mChannels[i].mInputBuf, (UInt8*)inInput->mBuffers[i].mData + firstPartBytes, secondPartBytes);
|
||||
}
|
||||
} else {
|
||||
UInt32 numBytes = inNumFrames * sizeof(Float32);
|
||||
for (UInt32 i=0; i<mNumChannels; ++i) {
|
||||
for (UInt32 i=0; i<mNumChannels; ++i) {
|
||||
memcpy(mChannels[i].mInputBuf + mInputPos, inInput->mBuffers[i].mData, numBytes);
|
||||
}
|
||||
}
|
||||
|
|
@ -221,7 +221,7 @@ void CASpectralProcessor::PrintSpectralBufferList()
|
|||
UInt32 half = mFFTSize >> 1;
|
||||
for (UInt32 i=0; i<mNumChannels; ++i) {
|
||||
DSPSplitComplex &freqData = mSpectralBufferList->mDSPSplitComplex[i];
|
||||
|
||||
|
||||
for (UInt32 j=0; j<half; j++){
|
||||
printf(" bin[%d]: %lf + %lfi\n", (int) j, freqData.realp[j], freqData.imagp[j]);
|
||||
}
|
||||
|
|
@ -277,7 +277,7 @@ void CASpectralProcessor::DoFwdFFT()
|
|||
{
|
||||
//printf("->DoFwdFFT %g %g\n", mChannels[0].mFFTBuf()[0], mChannels[0].mFFTBuf()[200]);
|
||||
UInt32 half = mFFTSize >> 1;
|
||||
for (UInt32 i=0; i<mNumChannels; ++i)
|
||||
for (UInt32 i=0; i<mNumChannels; ++i)
|
||||
{
|
||||
vDSP_ctoz((DSPComplex*)mChannels[i].mFFTBuf(), 2, &mSpectralBufferList->mDSPSplitComplex[i], 1, half);
|
||||
vDSP_fft_zrip(mFFTSetup, &mSpectralBufferList->mDSPSplitComplex[i], 1, mLog2FFTSize, FFT_FORWARD);
|
||||
|
|
@ -289,10 +289,10 @@ void CASpectralProcessor::DoInvFFT()
|
|||
{
|
||||
//printf("->DoInvFFT %g %g\n", mChannels[0].mFFTBuf()[0], mChannels[0].mFFTBuf()[200]);
|
||||
UInt32 half = mFFTSize >> 1;
|
||||
for (UInt32 i=0; i<mNumChannels; ++i)
|
||||
for (UInt32 i=0; i<mNumChannels; ++i)
|
||||
{
|
||||
vDSP_fft_zrip(mFFTSetup, &mSpectralBufferList->mDSPSplitComplex[i], 1, mLog2FFTSize, FFT_INVERSE);
|
||||
vDSP_ztoc(&mSpectralBufferList->mDSPSplitComplex[i], 1, (DSPComplex*)mChannels[i].mFFTBuf(), 2, half);
|
||||
vDSP_ztoc(&mSpectralBufferList->mDSPSplitComplex[i], 1, (DSPComplex*)mChannels[i].mFFTBuf(), 2, half);
|
||||
float scale = 0.5 / mFFTSize;
|
||||
vDSP_vsmul(mChannels[i].mFFTBuf(), 1, &scale, mChannels[i].mFFTBuf(), 1, mFFTSize );
|
||||
}
|
||||
|
|
@ -301,7 +301,7 @@ void CASpectralProcessor::DoInvFFT()
|
|||
|
||||
void CASpectralProcessor::SetSpectralFunction(SpectralFunction inFunction, void* inUserData)
|
||||
{
|
||||
mSpectralFunction = inFunction;
|
||||
mSpectralFunction = inFunction;
|
||||
mUserData = inUserData;
|
||||
}
|
||||
|
||||
|
|
@ -313,29 +313,29 @@ void CASpectralProcessor::ProcessSpectrum(UInt32 inFFTSize, SpectralBufferList*
|
|||
|
||||
#pragma mark ___Utility___
|
||||
|
||||
void CASpectralProcessor::GetMagnitude(AudioBufferList* list, Float32* min, Float32* max)
|
||||
{
|
||||
UInt32 half = mFFTSize >> 1;
|
||||
void CASpectralProcessor::GetMagnitude(AudioBufferList* list, Float32* min, Float32* max)
|
||||
{
|
||||
UInt32 half = mFFTSize >> 1;
|
||||
for (UInt32 i=0; i<mNumChannels; ++i) {
|
||||
DSPSplitComplex &freqData = mSpectralBufferList->mDSPSplitComplex[i];
|
||||
|
||||
DSPSplitComplex &freqData = mSpectralBufferList->mDSPSplitComplex[i];
|
||||
|
||||
Float32* b = (Float32*) list->mBuffers[i].mData;
|
||||
|
||||
vDSP_zvabs(&freqData,1,b,1,half);
|
||||
|
||||
vDSP_maxmgv(b, 1, &max[i], half);
|
||||
vDSP_minmgv(b, 1, &min[i], half);
|
||||
|
||||
}
|
||||
|
||||
vDSP_zvabs(&freqData,1,b,1,half);
|
||||
|
||||
vDSP_maxmgv(b, 1, &max[i], half);
|
||||
vDSP_minmgv(b, 1, &min[i], half);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void CASpectralProcessor::GetFrequencies(Float32* freqs, Float32 sampleRate)
|
||||
{
|
||||
UInt32 half = mFFTSize >> 1;
|
||||
UInt32 half = mFFTSize >> 1;
|
||||
|
||||
for (UInt32 i=0; i< half; i++){
|
||||
freqs[i] = ((Float32)(i))*sampleRate/((Float32)mFFTSize);
|
||||
freqs[i] = ((Float32)(i))*sampleRate/((Float32)mFFTSize);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -344,10 +344,10 @@ bool CASpectralProcessor::ProcessForwards(UInt32 inNumFrames, AudioBufferList* i
|
|||
{
|
||||
// copy from buffer list to input buffer
|
||||
CopyInput(inNumFrames, inInput);
|
||||
|
||||
|
||||
bool processed = false;
|
||||
// if enough input to process, then process.
|
||||
while (mInputSize >= mFFTSize)
|
||||
while (mInputSize >= mFFTSize)
|
||||
{
|
||||
CopyInputToFFT(); // copy from input buffer to fft buffer
|
||||
DoWindowing();
|
||||
|
|
@ -355,21 +355,21 @@ bool CASpectralProcessor::ProcessForwards(UInt32 inNumFrames, AudioBufferList* i
|
|||
ProcessSpectrum(mFFTSize, mSpectralBufferList()); // here you would copy the fft results out to a buffer indicated in mUserData, say for sonogram drawing
|
||||
processed = true;
|
||||
}
|
||||
|
||||
|
||||
return processed;
|
||||
}
|
||||
|
||||
bool CASpectralProcessor::ProcessBackwards(UInt32 inNumFrames, AudioBufferList* outOutput)
|
||||
{
|
||||
|
||||
{
|
||||
|
||||
ProcessSpectrum(mFFTSize, mSpectralBufferList());
|
||||
DoInvFFT();
|
||||
DoWindowing();
|
||||
OverlapAddOutput();
|
||||
|
||||
OverlapAddOutput();
|
||||
|
||||
// copy from output buffer to buffer list
|
||||
CopyOutput(inNumFrames, outOutput);
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue