Stash a Core Audio output, kind of glitchy
This output may prove to have lower latency, but the results are too glitchy to really be usable. Not even visualization latency is handled correctly. Signed-off-by: Christopher Snowhill <kode54@gmail.com>
This commit is contained in:
parent
38ad84e86c
commit
056bb2bd26
2 changed files with 1544 additions and 0 deletions
174
Audio/Output/OutputCoreAudio.h
Normal file
174
Audio/Output/OutputCoreAudio.h
Normal file
|
@ -0,0 +1,174 @@
|
|||
//
|
||||
// OutputCoreAudio.h
|
||||
// Cog
|
||||
//
|
||||
// Created by Christopher Snowhill on 7/25/23.
|
||||
// Copyright 2023 Christopher Snowhill. All rights reserved.
|
||||
//
|
||||
|
||||
#import <AssertMacros.h>
|
||||
#import <Cocoa/Cocoa.h>
|
||||
|
||||
#import <AVFoundation/AVFoundation.h>
|
||||
#import <AudioToolbox/AudioToolbox.h>
|
||||
#import <AudioUnit/AudioUnit.h>
|
||||
#import <CoreAudio/AudioHardware.h>
|
||||
#import <CoreAudio/CoreAudioTypes.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
#import <atomic>
|
||||
using std::atomic_long;
|
||||
#else
|
||||
#import <stdatomic.h>
|
||||
#endif
|
||||
|
||||
#import "Downmix.h"
|
||||
|
||||
#import <CogAudio/CogAudio-Swift.h>
|
||||
|
||||
#import "HeadphoneFilter.h"
|
||||
|
||||
//#define OUTPUT_LOG
|
||||
#ifdef OUTPUT_LOG
|
||||
#import <stdio.h>
|
||||
#endif
|
||||
|
||||
@class OutputNode;
|
||||
|
||||
@class FSurroundFilter;
|
||||
|
||||
@class AudioChunk;
|
||||
|
||||
@interface OutputCoreAudio : NSObject {
|
||||
OutputNode *outputController;
|
||||
|
||||
dispatch_semaphore_t writeSemaphore;
|
||||
dispatch_semaphore_t readSemaphore;
|
||||
|
||||
NSLock *outputLock;
|
||||
|
||||
BOOL rsDone;
|
||||
void *rsstate, *rsold;
|
||||
double secondsLatency;
|
||||
double visPushed;
|
||||
|
||||
double lastClippedSampleRate;
|
||||
|
||||
void *rsvis;
|
||||
double lastVisRate;
|
||||
|
||||
BOOL stopInvoked;
|
||||
BOOL stopCompleted;
|
||||
BOOL running;
|
||||
BOOL stopping;
|
||||
BOOL stopped;
|
||||
BOOL started;
|
||||
BOOL paused;
|
||||
BOOL restarted;
|
||||
BOOL commandStop;
|
||||
|
||||
BOOL eqEnabled;
|
||||
BOOL eqInitialized;
|
||||
|
||||
BOOL streamFormatStarted;
|
||||
BOOL streamFormatChanged;
|
||||
|
||||
double secondsHdcdSustained;
|
||||
|
||||
BOOL defaultdevicelistenerapplied;
|
||||
BOOL currentdevicelistenerapplied;
|
||||
BOOL devicealivelistenerapplied;
|
||||
BOOL observersapplied;
|
||||
BOOL outputdevicechanged;
|
||||
|
||||
float volume;
|
||||
float eqPreamp;
|
||||
|
||||
AVAudioFormat *_deviceFormat;
|
||||
|
||||
AudioDeviceID outputDeviceID;
|
||||
AudioStreamBasicDescription deviceFormat;
|
||||
AudioStreamBasicDescription realStreamFormat; // stream format pre-hrtf
|
||||
AudioStreamBasicDescription streamFormat; // stream format last seen in render callback
|
||||
AudioStreamBasicDescription realNewFormat; // in case of resampler flush
|
||||
AudioStreamBasicDescription newFormat; // in case of resampler flush
|
||||
|
||||
AudioStreamBasicDescription visFormat; // Mono format for vis
|
||||
|
||||
uint32_t deviceChannelConfig;
|
||||
uint32_t realStreamChannelConfig;
|
||||
uint32_t streamChannelConfig;
|
||||
uint32_t realNewChannelConfig;
|
||||
uint32_t newChannelConfig;
|
||||
|
||||
AUAudioUnit *_au;
|
||||
|
||||
AudioTimeStamp timeStamp;
|
||||
|
||||
size_t _bufferSize;
|
||||
|
||||
AudioUnit _eq;
|
||||
|
||||
DownmixProcessor *downmixer;
|
||||
DownmixProcessor *downmixerForVis;
|
||||
|
||||
VisualizationController *visController;
|
||||
|
||||
BOOL enableHrtf;
|
||||
HeadphoneFilter *hrtf;
|
||||
|
||||
BOOL enableFSurround;
|
||||
BOOL FSurroundDelayRemoved;
|
||||
int inputBufferLastTime;
|
||||
FSurroundFilter *fsurround;
|
||||
|
||||
int inputRemain;
|
||||
|
||||
AudioChunk *chunkRemain;
|
||||
|
||||
int resamplerRemain, visResamplerRemain;
|
||||
|
||||
BOOL resetStreamFormat;
|
||||
|
||||
BOOL shouldPlayOutBuffer;
|
||||
|
||||
float *samplePtr;
|
||||
float tempBuffer[512 * 32];
|
||||
float rsInBuffer[8192 * 32];
|
||||
float rsTempBuffer[4096 * 32];
|
||||
float inputBuffer[4096 * 32]; // 4096 samples times maximum supported channel count
|
||||
float fsurroundBuffer[8192 * 6];
|
||||
float hrtfBuffer[4096 * 2];
|
||||
float eqBuffer[4096 * 32];
|
||||
float downmixBuffer[4096 * 8];
|
||||
|
||||
float visAudio[4096];
|
||||
float visResamplerInput[8192];
|
||||
float visTemp[8192];
|
||||
|
||||
#ifdef OUTPUT_LOG
|
||||
FILE *_logFile;
|
||||
#endif
|
||||
}
|
||||
|
||||
- (id)initWithController:(OutputNode *)c;
|
||||
|
||||
- (BOOL)setup;
|
||||
- (OSStatus)setOutputDeviceByID:(AudioDeviceID)deviceID;
|
||||
- (BOOL)setOutputDeviceWithDeviceDict:(NSDictionary *)deviceDict;
|
||||
- (void)start;
|
||||
- (void)pause;
|
||||
- (void)resume;
|
||||
- (void)stop;
|
||||
|
||||
- (double)latency;
|
||||
|
||||
- (void)setVolume:(double)v;
|
||||
|
||||
- (void)setEqualizerEnabled:(BOOL)enabled;
|
||||
|
||||
- (void)setShouldPlayOutBuffer:(BOOL)enabled;
|
||||
|
||||
- (void)sustainHDCD;
|
||||
|
||||
@end
|
1370
Audio/Output/OutputCoreAudio.m
Normal file
1370
Audio/Output/OutputCoreAudio.m
Normal file
File diff suppressed because it is too large
Load diff
Loading…
Reference in a new issue