mirror of
https://github.com/bsnes-emu/bsnes.git
synced 2025-09-02 18:02:49 +02:00
Add audio activation settings to iOS
This commit is contained in:
@@ -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": @[
|
||||||
|
@@ -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,37 +533,39 @@ 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);
|
||||||
_audioClient = [[GBAudioClient alloc] initWithRendererBlock:^(UInt32 sampleRate, UInt32 nFrames, GB_sample_t *buffer) {
|
if (![[[NSUserDefaults standardUserDefaults] stringForKey:@"GBAudioMode"] isEqual:@"off"]) {
|
||||||
[_audioLock lock];
|
_audioClient = [[GBAudioClient alloc] initWithRendererBlock:^(UInt32 sampleRate, UInt32 nFrames, GB_sample_t *buffer) {
|
||||||
|
[_audioLock lock];
|
||||||
|
|
||||||
if (_audioBufferPosition < nFrames) {
|
if (_audioBufferPosition < nFrames) {
|
||||||
_audioBufferNeeded = nFrames;
|
_audioBufferNeeded = nFrames;
|
||||||
[_audioLock waitUntilDate:[NSDate dateWithTimeIntervalSinceNow:0.125]];
|
[_audioLock waitUntilDate:[NSDate dateWithTimeIntervalSinceNow:0.125]];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_stopping) {
|
if (_stopping) {
|
||||||
memset(buffer, 0, nFrames * sizeof(*buffer));
|
memset(buffer, 0, nFrames * sizeof(*buffer));
|
||||||
|
[_audioLock unlock];
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_audioBufferPosition < nFrames) {
|
||||||
|
// Not enough audio
|
||||||
|
memset(buffer, 0, (nFrames - _audioBufferPosition) * sizeof(*buffer));
|
||||||
|
memcpy(buffer, _audioBuffer, _audioBufferPosition * sizeof(*buffer));
|
||||||
|
_audioBufferPosition = 0;
|
||||||
|
}
|
||||||
|
else if (_audioBufferPosition < nFrames + 4800) {
|
||||||
|
memcpy(buffer, _audioBuffer, nFrames * sizeof(*buffer));
|
||||||
|
memmove(_audioBuffer, _audioBuffer + nFrames, (_audioBufferPosition - nFrames) * sizeof(*buffer));
|
||||||
|
_audioBufferPosition = _audioBufferPosition - nFrames;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
memcpy(buffer, _audioBuffer + (_audioBufferPosition - nFrames), nFrames * sizeof(*buffer));
|
||||||
|
_audioBufferPosition = 0;
|
||||||
|
}
|
||||||
[_audioLock unlock];
|
[_audioLock unlock];
|
||||||
return;
|
} andSampleRate:96000];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_audioBufferPosition < nFrames) {
|
|
||||||
// Not enough audio
|
|
||||||
memset(buffer, 0, (nFrames - _audioBufferPosition) * sizeof(*buffer));
|
|
||||||
memcpy(buffer, _audioBuffer, _audioBufferPosition * sizeof(*buffer));
|
|
||||||
_audioBufferPosition = 0;
|
|
||||||
}
|
|
||||||
else if (_audioBufferPosition < nFrames + 4800) {
|
|
||||||
memcpy(buffer, _audioBuffer, nFrames * sizeof(*buffer));
|
|
||||||
memmove(_audioBuffer, _audioBuffer + nFrames, (_audioBufferPosition - nFrames) * sizeof(*buffer));
|
|
||||||
_audioBufferPosition = _audioBufferPosition - nFrames;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
memcpy(buffer, _audioBuffer + (_audioBufferPosition - nFrames), nFrames * sizeof(*buffer));
|
|
||||||
_audioBufferPosition = 0;
|
|
||||||
}
|
|
||||||
[_audioLock unlock];
|
|
||||||
} andSampleRate:96000];
|
|
||||||
|
|
||||||
[_audioClient start];
|
[_audioClient start];
|
||||||
if (GB_has_accelerometer(&_gb)) {
|
if (GB_has_accelerometer(&_gb)) {
|
||||||
|
@@ -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),
|
||||||
|
Reference in New Issue
Block a user