Fix visualization for variable audio block sizes
IN A.D. 2101, WAR WAS BEGINNING. *boom* Yeah, this was a dumb bug, I didn't realize that AUAudioUnit would just arbitrarily ignore my configured block size and request a different one. The AirPods Pro will just request 480 instead of the 512 I ask for, so let's instead support variable block sizes, and only take up to the last 4096 samples of the chunk fed to the output device. Signed-off-by: Christopher Snowhill <kode54@gmail.com>CQTexperiment
parent
5611d08df1
commit
4f5e4eca36
|
@ -63,7 +63,7 @@ static OSStatus renderCallback(void *inRefCon, AudioUnitRenderActionFlags *ioAct
|
||||||
amountToRead = inNumberFrames * bytesPerPacket;
|
amountToRead = inNumberFrames * bytesPerPacket;
|
||||||
|
|
||||||
int visTabulated = 0;
|
int visTabulated = 0;
|
||||||
float visAudio[512]; // Chunk size
|
float visAudio[inNumberFrames]; // Chunk size
|
||||||
|
|
||||||
if(_self->stopping == YES || [_self->outputController shouldContinue] == NO) {
|
if(_self->stopping == YES || [_self->outputController shouldContinue] == NO) {
|
||||||
// Chain is dead, fill out the serial number pointer forever with silence
|
// Chain is dead, fill out the serial number pointer forever with silence
|
||||||
|
@ -188,12 +188,10 @@ static OSStatus renderCallback(void *inRefCon, AudioUnitRenderActionFlags *ioAct
|
||||||
// buffer loop if it doesn't get anything, so always produce a full
|
// buffer loop if it doesn't get anything, so always produce a full
|
||||||
// buffer, and silence anything we couldn't supply.
|
// buffer, and silence anything we couldn't supply.
|
||||||
clearBuffers(ioData, (amountToRead - amountRead) / bytesPerPacket, amountRead / bytesPerPacket);
|
clearBuffers(ioData, (amountToRead - amountRead) / bytesPerPacket, amountRead / bytesPerPacket);
|
||||||
|
|
||||||
vDSP_vclr(visAudio + visTabulated, 1, 512 - visTabulated);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[_self->visController postSampleRate:_self->deviceFormat.mSampleRate];
|
[_self->visController postSampleRate:_self->deviceFormat.mSampleRate];
|
||||||
[_self->visController postVisPCM:visAudio];
|
[_self->visController postVisPCM:visAudio amount:visTabulated];
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,7 +17,7 @@ NS_ASSUME_NONNULL_BEGIN
|
||||||
+ (VisualizationController *)sharedController;
|
+ (VisualizationController *)sharedController;
|
||||||
|
|
||||||
- (void)postSampleRate:(double)sampleRate;
|
- (void)postSampleRate:(double)sampleRate;
|
||||||
- (void)postVisPCM:(const float *)inPCM;
|
- (void)postVisPCM:(const float *)inPCM amount:(int)amount;
|
||||||
- (double)readSampleRate;
|
- (double)readSampleRate;
|
||||||
- (void)copyVisPCM:(float *)outPCM visFFT:(float *)outFFT;
|
- (void)copyVisPCM:(float *)outPCM visFFT:(float *)outFFT;
|
||||||
|
|
||||||
|
|
|
@ -41,10 +41,15 @@ static VisualizationController *_sharedController = nil;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)postVisPCM:(const float *)inPCM {
|
- (void)postVisPCM:(const float *)inPCM amount:(int)amount {
|
||||||
|
int skipAmount = 0;
|
||||||
|
if(amount > 4096) {
|
||||||
|
skipAmount = amount - 4096;
|
||||||
|
amount = 4096;
|
||||||
|
}
|
||||||
@synchronized(self) {
|
@synchronized(self) {
|
||||||
cblas_scopy(4096 - 512, visAudio + 512, 1, visAudio, 1);
|
cblas_scopy(4096 - amount, visAudio + amount, 1, visAudio, 1);
|
||||||
cblas_scopy(512, inPCM, 1, visAudio + 4096 - 512, 1);
|
cblas_scopy(amount, inPCM + skipAmount, 1, visAudio + 4096 - amount, 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue