Skip to content

Commit

Permalink
Change sample rate and buffersize to support ultra-high frequency
Browse files Browse the repository at this point in the history
  • Loading branch information
jekky committed May 4, 2012
1 parent 26e2ef2 commit 8bfd87a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
2 changes: 1 addition & 1 deletion RIOInterface.h
Expand Up @@ -28,7 +28,7 @@

#define kInputBus 1
#define kOutputBus 0
#define kBufferSize 512
#define kBufferSize 1024
#define kBufferCount 1
#define N 10

Expand Down
13 changes: 10 additions & 3 deletions RIOInterface.mm
Expand Up @@ -155,16 +155,21 @@ OSStatus RenderFFTCallback (void *inRefCon,
int bin = -1;
for (int i=0; i<n; i+=2) {
float curFreq = MagnitudeSquared(outputBuffer[i], outputBuffer[i+1]);
float freq = (i+1)/2*(THIS->sampleRate/bufferCapacity);
if (freq>18900.00 && curFreq>1.0)
printf("***** DEBUG freq: %f and energy: %f\n", freq, curFreq);
if (curFreq > dominantFrequency) {
dominantFrequency = curFreq;
bin = (i+1)/2;
}
}
memset(outputBuffer, 0, n*sizeof(SInt16));

//printf("***** DEBUG sampleRate=%f, bufferCapacity=%d, idealFrequency=%f \n", THIS->sampleRate, bufferCapacity, THIS->sampleRate/bufferCapacity);

// Update the UI with our newly acquired frequency value.
[THIS->listener frequencyChangedWithValue:bin*(THIS->sampleRate/bufferCapacity)];
printf("Dominant frequency: %f bin: %d \n", bin*(THIS->sampleRate/bufferCapacity), bin);
//printf("Dominant frequency: %f bin: %d \n", bin*(THIS->sampleRate/bufferCapacity), bin);
}


Expand Down Expand Up @@ -223,13 +228,15 @@ - (void)initializeAudioSession {
NSError *err = nil;
AVAudioSession *session = [AVAudioSession sharedInstance];

sampleRate = 44100.00;
[session setPreferredHardwareSampleRate:sampleRate error:&err];
[session setCategory:AVAudioSessionCategoryPlayAndRecord error:&err];
[session setActive:YES error:&err];

// After activation, update our sample rate. We need to update because there
// is a possibility the system cannot grant our request.
sampleRate = [session currentHardwareSampleRate];
printf("***** DEBUG: Hardware sampleRate=%f ... \n", sampleRate);

[self realFFTSetup];
}
Expand Down Expand Up @@ -318,8 +325,8 @@ - (void)createAUProcessingGraph {
bufferList->mNumberBuffers = 1;
bufferList->mBuffers[0].mNumberChannels = 1;

bufferList->mBuffers[0].mDataByteSize = 512*bytesPerSample;
bufferList->mBuffers[0].mData = calloc(512, bytesPerSample);
bufferList->mBuffers[0].mDataByteSize = 2048*bytesPerSample;
bufferList->mBuffers[0].mData = calloc(2048, bytesPerSample);
}


Expand Down

0 comments on commit 8bfd87a

Please sign in to comment.