2006-01-20 15:34:02 +00:00
|
|
|
//
|
2022-06-24 06:17:31 +00:00
|
|
|
// OutputAVFoundation.h
|
2006-01-20 15:34:02 +00:00
|
|
|
// Cog
|
|
|
|
//
|
2022-06-24 06:17:31 +00:00
|
|
|
// Created by Christopher Snowhill on 6/23/22.
|
|
|
|
// Copyright 2022 Christopher Snowhill. All rights reserved.
|
2006-01-20 15:34:02 +00:00
|
|
|
//
|
|
|
|
|
2020-03-23 08:46:41 +00:00
|
|
|
#import <AssertMacros.h>
|
2006-01-20 15:34:02 +00:00
|
|
|
#import <Cocoa/Cocoa.h>
|
|
|
|
|
2022-02-07 05:49:27 +00:00
|
|
|
#import <AVFoundation/AVFoundation.h>
|
2006-01-20 15:34:02 +00:00
|
|
|
#import <AudioToolbox/AudioToolbox.h>
|
|
|
|
#import <AudioUnit/AudioUnit.h>
|
2022-02-07 05:49:27 +00:00
|
|
|
#import <CoreAudio/AudioHardware.h>
|
2022-01-16 15:32:47 +00:00
|
|
|
#import <CoreAudio/CoreAudioTypes.h>
|
2006-01-20 15:34:02 +00:00
|
|
|
|
2022-06-06 15:18:33 +00:00
|
|
|
#ifdef __cplusplus
|
|
|
|
#import <atomic>
|
|
|
|
using std::atomic_long;
|
|
|
|
#else
|
2022-01-15 10:09:26 +00:00
|
|
|
#import <stdatomic.h>
|
2022-06-06 15:18:33 +00:00
|
|
|
#endif
|
2022-01-15 10:09:26 +00:00
|
|
|
|
2022-02-06 11:08:34 +00:00
|
|
|
#import "Downmix.h"
|
|
|
|
|
2022-02-13 07:04:03 +00:00
|
|
|
#import "VisualizationController.h"
|
|
|
|
|
2022-01-19 08:41:42 +00:00
|
|
|
//#define OUTPUT_LOG
|
|
|
|
#ifdef OUTPUT_LOG
|
|
|
|
#import <stdio.h>
|
|
|
|
#endif
|
|
|
|
|
2007-02-24 20:36:27 +00:00
|
|
|
@class OutputNode;
|
|
|
|
|
2022-06-24 06:17:31 +00:00
|
|
|
@interface OutputAVFoundation : NSObject {
|
2022-02-07 05:49:27 +00:00
|
|
|
OutputNode *outputController;
|
|
|
|
|
2022-06-24 10:43:50 +00:00
|
|
|
BOOL r8bDone;
|
2022-06-24 09:46:23 +00:00
|
|
|
void *r8bstate, *r8bold;
|
|
|
|
|
2022-06-24 10:43:50 +00:00
|
|
|
void *r8bvis;
|
|
|
|
double lastVisRate;
|
|
|
|
|
2022-02-07 05:49:27 +00:00
|
|
|
BOOL stopInvoked;
|
2022-06-25 02:14:48 +00:00
|
|
|
BOOL stopCompleted;
|
2022-02-07 05:49:27 +00:00
|
|
|
BOOL running;
|
|
|
|
BOOL stopping;
|
|
|
|
BOOL stopped;
|
|
|
|
BOOL started;
|
|
|
|
BOOL paused;
|
2022-02-08 06:44:56 +00:00
|
|
|
BOOL restarted;
|
2022-06-24 10:43:50 +00:00
|
|
|
BOOL stopFlush;
|
2022-06-25 02:14:48 +00:00
|
|
|
BOOL commandStop;
|
2022-02-07 05:49:27 +00:00
|
|
|
|
|
|
|
BOOL eqEnabled;
|
2022-06-11 01:43:56 +00:00
|
|
|
BOOL eqInitialized;
|
2022-02-07 05:49:27 +00:00
|
|
|
|
2022-06-24 06:17:31 +00:00
|
|
|
BOOL dontRemix;
|
|
|
|
|
2022-02-07 05:49:27 +00:00
|
|
|
BOOL streamFormatStarted;
|
|
|
|
|
2022-06-24 06:17:31 +00:00
|
|
|
double secondsHdcdSustained;
|
2022-02-07 05:49:27 +00:00
|
|
|
|
2022-06-17 06:28:25 +00:00
|
|
|
BOOL defaultdevicelistenerapplied;
|
|
|
|
BOOL currentdevicelistenerapplied;
|
|
|
|
BOOL devicealivelistenerapplied;
|
2022-02-07 05:49:27 +00:00
|
|
|
BOOL observersapplied;
|
2022-06-17 06:28:25 +00:00
|
|
|
BOOL outputdevicechanged;
|
2022-02-07 05:49:27 +00:00
|
|
|
|
|
|
|
float volume;
|
2022-02-14 07:37:58 +00:00
|
|
|
float eqPreamp;
|
2022-02-07 05:49:27 +00:00
|
|
|
|
|
|
|
AudioDeviceID outputDeviceID;
|
|
|
|
AudioStreamBasicDescription streamFormat; // stream format last seen in render callback
|
2022-06-24 09:46:23 +00:00
|
|
|
AudioStreamBasicDescription newFormat; // in case of resampler flush
|
2022-02-07 05:49:27 +00:00
|
|
|
|
2022-02-13 07:04:03 +00:00
|
|
|
AudioStreamBasicDescription visFormat; // Mono format for vis
|
|
|
|
|
2022-02-07 08:56:05 +00:00
|
|
|
uint32_t deviceChannelConfig;
|
|
|
|
uint32_t streamChannelConfig;
|
|
|
|
|
2022-06-24 06:17:31 +00:00
|
|
|
AVSampleBufferAudioRenderer *audioRenderer;
|
|
|
|
AVSampleBufferRenderSynchronizer *renderSynchronizer;
|
|
|
|
|
|
|
|
CMAudioFormatDescriptionRef audioFormatDescription;
|
|
|
|
|
|
|
|
AudioChannelLayoutTag streamTag;
|
|
|
|
|
|
|
|
id currentPtsObserver;
|
|
|
|
NSLock *currentPtsLock;
|
|
|
|
CMTime currentPts, lastPts;
|
|
|
|
double secondsLatency;
|
|
|
|
|
|
|
|
CMTime outputPts, trackPts, lastCheckpointPts;
|
|
|
|
AudioTimeStamp timeStamp;
|
|
|
|
|
2022-02-07 05:49:27 +00:00
|
|
|
size_t _bufferSize;
|
|
|
|
|
|
|
|
AudioUnit _eq;
|
|
|
|
|
2022-02-13 07:04:03 +00:00
|
|
|
DownmixProcessor *downmixerForVis;
|
|
|
|
|
|
|
|
VisualizationController *visController;
|
2022-02-07 05:49:27 +00:00
|
|
|
|
2022-06-24 06:17:31 +00:00
|
|
|
float inputBuffer[2048 * 32]; // 2048 samples times maximum supported channel count
|
|
|
|
float eqBuffer[2048 * 32];
|
2022-06-09 07:27:55 +00:00
|
|
|
|
2022-01-19 08:41:42 +00:00
|
|
|
#ifdef OUTPUT_LOG
|
2022-02-07 05:49:27 +00:00
|
|
|
FILE *_logFile;
|
2022-01-19 08:41:42 +00:00
|
|
|
#endif
|
2006-01-20 15:34:02 +00:00
|
|
|
}
|
|
|
|
|
2007-02-24 20:36:27 +00:00
|
|
|
- (id)initWithController:(OutputNode *)c;
|
2006-01-20 15:34:02 +00:00
|
|
|
|
|
|
|
- (BOOL)setup;
|
2020-02-17 17:20:48 +00:00
|
|
|
- (OSStatus)setOutputDeviceByID:(AudioDeviceID)deviceID;
|
|
|
|
- (BOOL)setOutputDeviceWithDeviceDict:(NSDictionary *)deviceDict;
|
2006-01-20 15:34:02 +00:00
|
|
|
- (void)start;
|
2007-02-20 01:02:23 +00:00
|
|
|
- (void)pause;
|
|
|
|
- (void)resume;
|
|
|
|
- (void)stop;
|
2006-01-20 15:34:02 +00:00
|
|
|
|
2022-02-07 05:49:27 +00:00
|
|
|
- (void)setVolume:(double)v;
|
2006-01-20 15:34:02 +00:00
|
|
|
|
2022-01-17 09:22:15 +00:00
|
|
|
- (void)setEqualizerEnabled:(BOOL)enabled;
|
|
|
|
|
2022-01-19 10:08:57 +00:00
|
|
|
- (void)sustainHDCD;
|
|
|
|
|
2006-01-20 15:34:02 +00:00
|
|
|
@end
|