1
0
mirror of https://github.com/TomHarte/CLK.git synced 2024-12-23 20:29:42 +00:00

The macOS port now selects stereo output if appropriate.

This commit is contained in:
Thomas Harte 2020-02-16 14:05:50 -05:00
parent 337cb4fb86
commit f99d672237
5 changed files with 27 additions and 17 deletions

View File

@ -25,10 +25,12 @@
Creates an instance of CSAudioQueue.
@param samplingRate The output audio rate.
@param isStereo @c YES if audio buffers will contain stereo audio, @c NO otherwise.
@returns An instance of CSAudioQueue if successful; @c nil otherwise.
*/
- (nonnull instancetype)initWithSamplingRate:(Float64)samplingRate;
- (nonnull instancetype)initWithSamplingRate:(Float64)samplingRate isStereo:(BOOL)isStereo NS_DESIGNATED_INITIALIZER;
- (nonnull instancetype)init __attribute((unavailable));
/*!
Enqueues a buffer for playback.

View File

@ -73,7 +73,7 @@ static void audioOutputCallback(
#pragma mark - Standard object lifecycle
- (instancetype)initWithSamplingRate:(Float64)samplingRate {
- (instancetype)initWithSamplingRate:(Float64)samplingRate isStereo:(BOOL)isStereo {
self = [super init];
if(self) {
@ -123,10 +123,6 @@ static void audioOutputCallback(
return self;
}
- (instancetype)init {
return [self initWithSamplingRate:[[self class] preferredSamplingRate]];
}
- (void)dealloc {
[CSAudioQueueDeallocLock lock];
if(_audioQueue) {

View File

@ -228,11 +228,12 @@ class MachineDocument:
// TODO: this needs to be threadsafe. FIX!
let maximumSamplingRate = CSAudioQueue.preferredSamplingRate()
let selectedSamplingRate = self.machine.idealSamplingRate(from: NSRange(location: 0, length: NSInteger(maximumSamplingRate)))
let isStereo = self.machine.isStereo()
if selectedSamplingRate > 0 {
self.audioQueue = CSAudioQueue(samplingRate: Float64(selectedSamplingRate))
self.audioQueue = CSAudioQueue(samplingRate: Float64(selectedSamplingRate), isStereo:isStereo)
self.audioQueue.delegate = self
self.machine.audioQueue = self.audioQueue
self.machine.setAudioSamplingRate(selectedSamplingRate, bufferSize:audioQueue.preferredBufferSize)
self.machine.setAudioSamplingRate(selectedSamplingRate, bufferSize:audioQueue.preferredBufferSize, stereo:isStereo)
}
}

View File

@ -58,7 +58,8 @@ typedef NS_ENUM(NSInteger, CSMachineKeyboardInputMode) {
- (nullable instancetype)initWithAnalyser:(nonnull CSStaticAnalyser *)result missingROMs:(nullable inout NSMutableArray<CSMissingROM *> *)missingROMs NS_DESIGNATED_INITIALIZER;
- (float)idealSamplingRateFromRange:(NSRange)range;
- (void)setAudioSamplingRate:(float)samplingRate bufferSize:(NSUInteger)bufferSize;
- (BOOL)isStereo;
- (void)setAudioSamplingRate:(float)samplingRate bufferSize:(NSUInteger)bufferSize stereo:(BOOL)stereo;
- (void)setView:(nullable CSOpenGLView *)view aspectRatio:(float)aspectRatio;

View File

@ -262,17 +262,27 @@ struct ActivityObserver: public Activity::Observer {
}
}
- (void)setAudioSamplingRate:(float)samplingRate bufferSize:(NSUInteger)bufferSize {
@synchronized(self) {
[self setSpeakerDelegate:&_speakerDelegate sampleRate:samplingRate bufferSize:bufferSize];
}
}
- (BOOL)setSpeakerDelegate:(Outputs::Speaker::Speaker::Delegate *)delegate sampleRate:(float)sampleRate bufferSize:(NSUInteger)bufferSize {
- (BOOL)isStereo {
@synchronized(self) {
Outputs::Speaker::Speaker *speaker = _machine->crt_machine()->get_speaker();
if(speaker) {
speaker->set_output_rate(sampleRate, (int)bufferSize, false);
return speaker->get_is_stereo();
}
return NO;
}
}
- (void)setAudioSamplingRate:(float)samplingRate bufferSize:(NSUInteger)bufferSize stereo:(BOOL)stereo {
@synchronized(self) {
[self setSpeakerDelegate:&_speakerDelegate sampleRate:samplingRate bufferSize:bufferSize stereo:stereo];
}
}
- (BOOL)setSpeakerDelegate:(Outputs::Speaker::Speaker::Delegate *)delegate sampleRate:(float)sampleRate bufferSize:(NSUInteger)bufferSize stereo:(BOOL)stereo {
@synchronized(self) {
Outputs::Speaker::Speaker *speaker = _machine->crt_machine()->get_speaker();
if(speaker) {
speaker->set_output_rate(sampleRate, (int)bufferSize, stereo);
speaker->set_delegate(delegate);
return YES;
}