Bug Fix: Fix output logging, switch log method

Output logging, a debugging feature that is only enabled at build time
if I need to chase down some audio mixing or output bug, was not logging
anything at all. Change to use Cocoa file writing methods, and actually
implement the output writer function again.

This code is left disabled 99% of the time anyway, and especially in
release builds. Like the node logging code elsewhere, it has the
potential to be very noisy and consume massive amounts of disk space.

Signed-off-by: Christopher Snowhill <kode54@gmail.com>
This commit is contained in:
Christopher Snowhill 2025-03-26 19:06:02 -07:00
parent d1ff9ba0c0
commit 576b199382
2 changed files with 13 additions and 7 deletions

View file

@ -28,9 +28,6 @@ using std::atomic_long;
#import <CogAudio/HeadphoneFilter.h>
//#define OUTPUT_LOG
#ifdef OUTPUT_LOG
#import <stdio.h>
#endif
@class OutputNode;
@ -102,7 +99,7 @@ using std::atomic_long;
ChunkList *outputBuffer;
#ifdef OUTPUT_LOG
FILE *_logFile;
NSFileHandle *_logFile;
#endif
}

View file

@ -19,6 +19,10 @@
#import <CogAudio/VisualizationController.h>
#ifdef OUTPUT_LOG
#import <NSFileHandle+CreateFile.h>
#endif
extern void scale_by_volume(float *buffer, size_t count, float volume);
static NSString *CogPlaybackDidBeginNotificiation = @"CogPlaybackDidBeginNotificiation";
@ -146,7 +150,7 @@ static void *kOutputCoreAudioContext = &kOutputCoreAudioContext;
#ifdef OUTPUT_LOG
NSString *logName = [NSTemporaryDirectory() stringByAppendingPathComponent:@"CogAudioLog.raw"];
_logFile = fopen([logName UTF8String], "wb");
_logFile = [NSFileHandle fileHandleForWritingAtPath:logName createFile:YES];
#endif
}
@ -648,7 +652,7 @@ current_device_listener(AudioObjectID inObjectID, UInt32 inNumberAddresses, cons
__block NSMutableArray *faders = self->fadedBuffers;
#ifdef OUTPUT_LOG
__block FILE *logFile = _logFile;
__block NSFileHandle *logFile = _logFile;
#endif
_au.outputProvider = ^AUAudioUnitStatus(AudioUnitRenderActionFlags *_Nonnull actionFlags, const AudioTimeStamp *_Nonnull timestamp, AUAudioFrameCount frameCount, NSInteger inputBusNumber, AudioBufferList *_Nonnull inputData) {
@ -742,6 +746,11 @@ current_device_listener(AudioObjectID inObjectID, UInt32 inNumberAddresses, cons
scale_by_volume(outSamples, frameCount * channels, volumeScale * _self->volume);
[_self updateLatency:secondsRendered];
#ifdef OUTPUT_LOG
NSData *outData = [NSData dataWithBytes:outSamples length:frameCount * format->mBytesPerPacket];
[logFile writeData:outData];
#endif
}
#ifdef _DEBUG
@ -924,7 +933,7 @@ current_device_listener(AudioObjectID inObjectID, UInt32 inNumberAddresses, cons
}
#ifdef OUTPUT_LOG
if(_logFile) {
fclose(_logFile);
[_logFile closeFile];
_logFile = NULL;
}
#endif