Core Audio output: Add debugging code for logging output to disk, only enabled at compile time as necessary

CQTexperiment
Christopher Snowhill 2022-01-19 00:41:42 -08:00
parent 5c17dc9207
commit 31e5cd9337
2 changed files with 31 additions and 1 deletions

View File

@ -19,6 +19,11 @@
#import "Semaphore.h" #import "Semaphore.h"
//#define OUTPUT_LOG
#ifdef OUTPUT_LOG
#import <stdio.h>
#endif
@class OutputNode; @class OutputNode;
@interface OutputCoreAudio : NSObject { @interface OutputCoreAudio : NSObject {
@ -51,6 +56,10 @@
size_t _bufferSize; size_t _bufferSize;
AudioUnit _eq; AudioUnit _eq;
#ifdef OUTPUT_LOG
FILE *_logFile;
#endif
} }
- (id)initWithController:(OutputNode *)c; - (id)initWithController:(OutputNode *)c;

View File

@ -152,6 +152,10 @@ static OSStatus renderCallback( void *inRefCon, AudioUnitRenderActionFlags *ioAc
writeSemaphore = [[Semaphore alloc] init]; writeSemaphore = [[Semaphore alloc] init];
readSemaphore = [[Semaphore alloc] init]; readSemaphore = [[Semaphore alloc] init];
#ifdef OUTPUT_LOG
_logFile = fopen("/tmp/CogAudioLog.raw", "wb");
#endif
[[NSUserDefaultsController sharedUserDefaultsController] addObserver:self forKeyPath:@"values.outputDevice" options:0 context:NULL]; [[NSUserDefaultsController sharedUserDefaultsController] addObserver:self forKeyPath:@"values.outputDevice" options:0 context:NULL];
[[NSUserDefaultsController sharedUserDefaultsController] addObserver:self forKeyPath:@"values.GraphicEQenable" options:0 context:NULL]; [[NSUserDefaultsController sharedUserDefaultsController] addObserver:self forKeyPath:@"values.GraphicEQenable" options:0 context:NULL];
[[NSUserDefaultsController sharedUserDefaultsController] addObserver:self forKeyPath:@"values.GraphicEQpreset" options:0 context:NULL]; [[NSUserDefaultsController sharedUserDefaultsController] addObserver:self forKeyPath:@"values.GraphicEQpreset" options:0 context:NULL];
@ -589,6 +593,10 @@ default_device_changed(AudioObjectID inObjectID, UInt32 inNumberAddresses, const
__block AudioStreamBasicDescription *format = &deviceFormat; __block AudioStreamBasicDescription *format = &deviceFormat;
__block BOOL *eqEnabled = &self->eqEnabled; __block BOOL *eqEnabled = &self->eqEnabled;
__block void *refCon = (__bridge void *)self; __block void *refCon = (__bridge void *)self;
#ifdef OUTPUT_LOG
__block FILE *logFile = _logFile;
#endif
_au.outputProvider = ^AUAudioUnitStatus(AudioUnitRenderActionFlags * _Nonnull actionFlags, const AudioTimeStamp * _Nonnull timestamp, AUAudioFrameCount frameCount, NSInteger inputBusNumber, AudioBufferList * _Nonnull inputData) _au.outputProvider = ^AUAudioUnitStatus(AudioUnitRenderActionFlags * _Nonnull actionFlags, const AudioTimeStamp * _Nonnull timestamp, AUAudioFrameCount frameCount, NSInteger inputBusNumber, AudioBufferList * _Nonnull inputData)
{ {
@ -631,6 +639,12 @@ default_device_changed(AudioObjectID inObjectID, UInt32 inNumberAddresses, const
} }
} }
#ifdef OUTPUT_LOG
if (logFile) {
fwrite(inputData->mBuffers[0].mData, 1, inputData->mBuffers[0].mDataByteSize, logFile);
}
#endif
inputData->mBuffers[0].mNumberChannels = channels; inputData->mBuffers[0].mNumberChannels = channels;
return 0; return 0;
@ -726,11 +740,18 @@ default_device_changed(AudioObjectID inObjectID, UInt32 inNumberAddresses, const
AudioComponentInstanceDispose(_eq); AudioComponentInstanceDispose(_eq);
_eq = NULL; _eq = NULL;
} }
#ifdef OUTPUT_LOG
if (_logFile)
{
fclose(_logFile);
_logFile = NULL;
}
#endif
} }
- (void)dealloc - (void)dealloc
{ {
[self stop]; [self stop];
[[NSUserDefaultsController sharedUserDefaultsController] removeObserver:self forKeyPath:@"values.outputDevice"]; [[NSUserDefaultsController sharedUserDefaultsController] removeObserver:self forKeyPath:@"values.outputDevice"];
[[NSUserDefaultsController sharedUserDefaultsController] removeObserver:self forKeyPath:@"values.GraphicEQenable"]; [[NSUserDefaultsController sharedUserDefaultsController] removeObserver:self forKeyPath:@"values.GraphicEQenable"];