Skip to content

Commit

Permalink
explicitly mark sample type as Float32
Browse files Browse the repository at this point in the history
since AudioUnitSampleType is now deprecated
  • Loading branch information
admsyn committed Jul 13, 2014
1 parent 468375a commit c0bc918
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 14 deletions.
10 changes: 5 additions & 5 deletions src/ofxAudioUnitDSPNode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ struct DSPNodeContext
circularBuffers.resize(bufferCount);

for(int i = 0; i < circularBuffers.size(); i++) {
TPCircularBufferInit(&circularBuffers[i], samplesToBuffer * sizeof(AudioUnitSampleType));
TPCircularBufferInit(&circularBuffers[i], samplesToBuffer * sizeof(Float32));
}
_bufferSize = samplesToBuffer;
}
Expand Down Expand Up @@ -202,20 +202,20 @@ unsigned int ofxAudioUnitDSPNode::getBufferSize() const
#pragma mark - Getting Samples

// ----------------------------------------------------------
void ExtractSamplesFromCircularBuffer(std::vector<AudioUnitSampleType> &outBuffer, TPCircularBuffer * circularBuffer)
void ExtractSamplesFromCircularBuffer(std::vector<Float32> &outBuffer, TPCircularBuffer * circularBuffer)
// ----------------------------------------------------------
{
if(!circularBuffer) {
outBuffer.clear();
} else {
int32_t circBufferSize;
AudioUnitSampleType * circBufferTail = (AudioUnitSampleType *)TPCircularBufferTail(circularBuffer, &circBufferSize);
AudioUnitSampleType * circBufferHead = circBufferTail + (circBufferSize / sizeof(AudioUnitSampleType));
Float32 * circBufferTail = (Float32 *)TPCircularBufferTail(circularBuffer, &circBufferSize);
Float32 * circBufferHead = circBufferTail + (circBufferSize / sizeof(Float32));
outBuffer.assign(circBufferTail, circBufferHead);
}
}

void ofxAudioUnitDSPNode::getSamplesFromChannel(std::vector<AudioUnitSampleType> &samples, unsigned int channel) const
void ofxAudioUnitDSPNode::getSamplesFromChannel(std::vector<Float32> &samples, unsigned int channel) const
{
if(_impl->ctx.circularBuffers.size() > channel) {
ExtractSamplesFromCircularBuffer(samples, &_impl->ctx.circularBuffers[channel]);
Expand Down
2 changes: 1 addition & 1 deletion src/ofxAudioUnitDSPNode.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class ofxAudioUnitDSPNode
void setSource(AURenderCallbackStruct callback, UInt32 channels = 2);

protected:
void getSamplesFromChannel(std::vector<AudioUnitSampleType> &samples, unsigned int channel) const;
void getSamplesFromChannel(std::vector<Float32> &samples, unsigned int channel) const;

// sets the internal circular buffer size
void setBufferSize(unsigned int samplesToBuffer);
Expand Down
2 changes: 1 addition & 1 deletion src/ofxAudioUnitFftNode.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,6 @@ class ofxAudioUnitFftNode : public ofxAudioUnitDSPNode {
FFTSetup _fftSetup;
COMPLEX_SPLIT _fftData;
float * _window;
std::vector<AudioUnitSampleType> _sampleBuffer;
std::vector<Float32> _sampleBuffer;
void freeBuffers();
};
8 changes: 4 additions & 4 deletions src/ofxAudioUnitInput.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ ofxAudioUnitInput::ofxAudioUnitInput(unsigned int samplesToBuffer)
#endif

for(int i = 0; i < ASBD.mChannelsPerFrame; i++) {
TPCircularBufferInit(&_impl->ctx.circularBuffers[i], samplesToBuffer * sizeof(AudioUnitSampleType));
TPCircularBufferInit(&_impl->ctx.circularBuffers[i], samplesToBuffer * sizeof(Float32));
}
}

Expand Down Expand Up @@ -329,7 +329,7 @@ OSStatus RenderCallback(void *inRefCon,
if(circBuffer) {
TPCircularBufferProduceBytes(circBuffer,
ctx->bufferList->mBuffers[i].mData,
inNumberFrames * sizeof(AudioUnitSampleType));
inNumberFrames * sizeof(Float32));
}
}
}
Expand All @@ -352,8 +352,8 @@ OSStatus PullCallback(void *inRefCon,

for(int i = 0; i < buffersToCopy; i++) {
int32_t circBufferSize;
AudioUnitSampleType * circBufferTail = (AudioUnitSampleType *) TPCircularBufferTail(&ctx->circularBuffers[i], &circBufferSize);
bool circBufferHasEnoughSamples = circBufferSize / sizeof(AudioUnitSampleType) >= inNumberFrames ? true : false;
Float32 * circBufferTail = (Float32 *) TPCircularBufferTail(&ctx->circularBuffers[i], &circBufferSize);
bool circBufferHasEnoughSamples = circBufferSize / sizeof(Float32) >= inNumberFrames ? true : false;

if(!circBufferHasEnoughSamples) {
// clear buffer, so bytes that don't get written are silence instead of noise
Expand Down
2 changes: 1 addition & 1 deletion src/ofxAudioUnitTap.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class ofxAudioUnitTap : public ofxAudioUnitDSPNode
virtual ~ofxAudioUnitTap();

// Container for samples returned from an ofxAudioUnitTap
typedef std::vector<AudioUnitSampleType> MonoSamples;
typedef std::vector<Float32> MonoSamples;

struct StereoSamples
{
Expand Down
4 changes: 2 additions & 2 deletions src/ofxAudioUnitUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ static AudioBufferList * AudioBufferListAlloc(UInt32 channels, UInt32 samplesPer

for(UInt32 i = 0; i < bufferList->mNumberBuffers; i++) {
bufferList->mBuffers[i].mNumberChannels = 1;
bufferList->mBuffers[i].mDataByteSize = samplesPerChannel * sizeof(AudioUnitSampleType);
bufferList->mBuffers[i].mData = calloc(samplesPerChannel, sizeof(AudioUnitSampleType));
bufferList->mBuffers[i].mDataByteSize = samplesPerChannel * sizeof(Float32);
bufferList->mBuffers[i].mData = calloc(samplesPerChannel, sizeof(Float32));
}
return bufferList;
}
Expand Down

0 comments on commit c0bc918

Please sign in to comment.