Add audio activation settings to iOS

This commit is contained in:
Lior Halphon
2024-04-12 13:46:29 +03:00
parent 4a42dc073b
commit b63ddc6e3d
3 changed files with 49 additions and 30 deletions

View File

@@ -283,6 +283,15 @@ static NSString const *typeLightTemp = @"typeLightTemp";
]; ];
NSArray<NSDictionary *> *audioMenu = @[ NSArray<NSDictionary *> *audioMenu = @[
@{
@"header": @"Enable Audio",
@"items": @[
@{@"type": typeRadio, @"pref": @"GBAudioMode", @"title": @"Never", @"value": @"off",},
@{@"type": typeRadio, @"pref": @"GBAudioMode", @"title": @"Controlled by Silent Mode", @"value": @"switch",},
@{@"type": typeRadio, @"pref": @"GBAudioMode", @"title": @"Always", @"value": @"on",},
],
},
@{ @{
@"header": @"High-pass Filter", @"header": @"High-pass Filter",
@"items": @[ @"items": @[

View File

@@ -143,6 +143,13 @@ static void rumbleCallback(GB_gameboy_t *gb, double amp)
[self addDefaultObserver:^(id newValue) { [self addDefaultObserver:^(id newValue) {
GB_set_rewind_length(gb, [newValue unsignedIntValue]); GB_set_rewind_length(gb, [newValue unsignedIntValue]);
} forKey:@"GBRewindLength"]; } forKey:@"GBRewindLength"];
[self addDefaultObserver:^(id newValue) {
[[AVAudioSession sharedInstance] setCategory:[newValue isEqual:@"on"]? AVAudioSessionCategoryPlayback : AVAudioSessionCategorySoloAmbient
mode:AVAudioSessionModeMeasurement // Reduces latency on BT
routeSharingPolicy:AVAudioSessionRouteSharingPolicyDefault
options:AVAudioSessionCategoryOptionAllowBluetoothA2DP | AVAudioSessionCategoryOptionAllowAirPlay
error:nil];
} forKey:@"GBAudioMode"];
} }
- (void)addDefaultObserver:(void(^)(id newValue))block forKey:(NSString *)key - (void)addDefaultObserver:(void(^)(id newValue))block forKey:(NSString *)key
@@ -526,6 +533,7 @@ static void rumbleCallback(GB_gameboy_t *gb, double amp)
{ {
GB_set_pixels_output(&_gb, _gbView.pixels); GB_set_pixels_output(&_gb, _gbView.pixels);
GB_set_sample_rate(&_gb, 96000); GB_set_sample_rate(&_gb, 96000);
if (![[[NSUserDefaults standardUserDefaults] stringForKey:@"GBAudioMode"] isEqual:@"off"]) {
_audioClient = [[GBAudioClient alloc] initWithRendererBlock:^(UInt32 sampleRate, UInt32 nFrames, GB_sample_t *buffer) { _audioClient = [[GBAudioClient alloc] initWithRendererBlock:^(UInt32 sampleRate, UInt32 nFrames, GB_sample_t *buffer) {
[_audioLock lock]; [_audioLock lock];
@@ -557,6 +565,7 @@ static void rumbleCallback(GB_gameboy_t *gb, double amp)
} }
[_audioLock unlock]; [_audioLock unlock];
} andSampleRate:96000]; } andSampleRate:96000];
}
[_audioClient start]; [_audioClient start];
if (GB_has_accelerometer(&_gb)) { if (GB_has_accelerometer(&_gb)) {

View File

@@ -9,6 +9,7 @@ int main(int argc, char * argv[])
[[NSUserDefaults standardUserDefaults] registerDefaults:@{ [[NSUserDefaults standardUserDefaults] registerDefaults:@{
@"GBFilter": @"NearestNeighbor", @"GBFilter": @"NearestNeighbor",
@"GBColorCorrection": @(GB_COLOR_CORRECTION_MODERN_BALANCED), @"GBColorCorrection": @(GB_COLOR_CORRECTION_MODERN_BALANCED),
@"GBAudioMode": @"switch",
@"GBHighpassFilter": @(GB_HIGHPASS_ACCURATE), @"GBHighpassFilter": @(GB_HIGHPASS_ACCURATE),
@"GBRewindLength": @(10), @"GBRewindLength": @(10),
@"GBFrameBlendingMode": @(GB_FRAME_BLENDING_MODE_ACCURATE), @"GBFrameBlendingMode": @(GB_FRAME_BLENDING_MODE_ACCURATE),