Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add audio output volume control #230

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion iNDS/AppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -596,7 +596,9 @@ - (WCEasySettingsViewController *)getSettingsViewController

// Audio
WCEasySettingsSection *audioSection = [[WCEasySettingsSection alloc] initWithTitle:@"Audio" subTitle:@""];
audioSection.items = @[[[WCEasySettingsSwitch alloc] initWithIdentifier:@"disableSound"
audioSection.items = @[[[WCEasySettingsSlider alloc] initWithIdentifier:@"outputVolume"
title:@"Output Volume"],
[[WCEasySettingsSwitch alloc] initWithIdentifier:@"disableSound"
title:@"Disable Sound"],
[[WCEasySettingsSwitch alloc] initWithIdentifier:@"allowExternalAudio"
title:@"Allow External Audio"],
Expand Down
10 changes: 8 additions & 2 deletions iNDS/core/emu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -301,14 +301,20 @@ void EMU_enableSound(bool enabled)
/*
SPU seems to need to be kickstarted. If left disabled when initializing the ROM,
then we can't expect to magically enable it partway through. To solve this, we
just let it run for a cycle if we disable sound.
just let it run for a cycle if we disable sound. We only kick the SPU when soundEnabled has changed, to prevent unnecessarily kickstarting the SPU.

More information see iNDS-Team/iNDS#35
*/
if (!enabled) SPU_Emulate_user(true);
if(!enabled && soundEnabled != enabled) SPU_Emulate_user(true);
soundEnabled = enabled;
}

void EMU_setAudioOutputVolume(double volume)
{
int vol = volume * 100;
SPU_SetVolume(vol);
}

void EMU_setFrameSkip(int skip)
{
if (skip == -1) {
Expand Down
1 change: 1 addition & 0 deletions iNDS/core/emu.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ bool EMU_doRomLoad(const char* path, const char* logical);
bool EMU_loadRom(const char* path);
void EMU_change3D(int type);
void EMU_changeSound(int type);
void EMU_setAudioOutputVolume(double volume);
void EMU_enableSound(bool enable);
bool EMU_frameSkip(bool force);
void EMU_setFrameSkip(int skip);
Expand Down
8 changes: 3 additions & 5 deletions iNDS/core/sndcoreaudio.mm
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
static bool audioQueueStarted = false;
static AudioQueueBufferRef aqBuffer[NUM_BUFFERS];
static AudioQueueRef audioQueue;
static float volume = 1.0;

void SNDCoreAudioCallback(void *data, AudioQueueRef mQueue, AudioQueueBufferRef mBuffer) {
mBuffer->mAudioDataByteSize = sndBufferSize;
Expand Down Expand Up @@ -119,14 +120,11 @@ void SNDCoreAudioMuteAudio() {
}

void SNDCoreAudioUnMuteAudio() {
AudioQueueSetParameter(audioQueue, kAudioQueueParam_Volume, 1.0);
AudioQueueSetParameter(audioQueue, kAudioQueueParam_Volume, volume);
}

void SNDCoreAudioSetVolume(int volume) {
/*
This function was not implemented, but if it was implemented,
this is how to do it.
float scaled = volume / 100.0;
::volume = scaled;
AudioQueueSetParameter(audioQueue, kAudioQueueParam_Volume, scaled);
*/
}
4 changes: 4 additions & 0 deletions iNDS/iNDSEmulatorViewController.mm
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,10 @@ - (void)defaultsChanged:(NSNotification*)notification
// (Mute on && don't ignore it) or user has sound disabled
BOOL muteSound = [defaults boolForKey:@"disableSound"];
EMU_enableSound(!muteSound);

double outputVolume = [defaults doubleForKey:@"outputVolume"];
EMU_setAudioOutputVolume(outputVolume);

AVAudioSessionCategoryOptions opts = AVAudioSessionCategoryOptionDefaultToSpeaker | AVAudioSessionCategoryOptionAllowBluetoothA2DP;
if([defaults boolForKey:@"allowExternalAudio"]){
opts |= AVAudioSessionCategoryOptionMixWithOthers;
Expand Down
2 changes: 2 additions & 0 deletions iNDS/settings/Defaults.plist
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
<true/>
<key>frameSkip</key>
<integer>-1</integer>
<key>outputVolume</key>
<integer>1</integer>
<key>disableSound</key>
<false/>
<key>allowExternalAudio</key>
Expand Down