Permalink
Browse files

audio: added configurable sampling rate

  • Loading branch information...
fzurita committed Mar 5, 2016
1 parent 150f574 commit 1f0af5d7ddb865adda43240de8480a2d9f5763c3
@@ -111,6 +111,8 @@ static unsigned int speed_factor = 100;
static int SwapChannels = 0;
/* Number of secondary buffers to target */
static int TargetSecondaryBuffers = 20;
+/* Selected samplin rate */
+static int SamplingRateSelection = 0;
/* Output Audio frequency */
static int OutputFreq;
/* Indicate that the audio plugin failed to initialize, so the emulator can keep running without sound */
@@ -313,6 +315,13 @@ void OnInitFailure(void)
static void InitializeAudio(int freq)
{
+
+ /* reload these because they gets re-assigned from data below, and InitializeAudio can be called more than once */
+ PrimaryBufferSize = ConfigGetParamInt(l_ConfigAudio, "PRIMARY_BUFFER_SIZE");
+ SecondaryBufferSize = ConfigGetParamInt(l_ConfigAudio, "SECONDARY_BUFFER_SIZE");
+ TargetSecondaryBuffers = ConfigGetParamInt(l_ConfigAudio, "SECONDARY_BUFFER_NBR");
+ SamplingRateSelection = ConfigGetParamInt(l_ConfigAudio, "SAMPLING_RATE");
+
SLuint32 sample_rate;
/* Sometimes a bad frequency is requested so ignore it */
@@ -325,38 +334,58 @@ static void InitializeAudio(int freq)
/* This is important for the sync */
GameFreq = freq;
- /*
- if((freq/1000) <= 11)
- {
- OutputFreq = 11025;
- sample_rate = SL_SAMPLINGRATE_11_025;
- }
- else if((freq/1000) <= 22)
- {
- OutputFreq = 22050;
- sample_rate = SL_SAMPLINGRATE_22_05;
- }
- else if((freq/1000) <= 32)
+ if(SamplingRateSelection == 0)
{
- OutputFreq = 32000;
- sample_rate = SL_SAMPLINGRATE_32;
+ if((freq/1000) <= 11)
+ {
+ OutputFreq = 11025;
+ sample_rate = SL_SAMPLINGRATE_11_025;
+ }
+ else if((freq/1000) <= 22)
+ {
+ OutputFreq = 22050;
+ sample_rate = SL_SAMPLINGRATE_22_05;
+ }
+ else if((freq/1000) <= 32)
+ {
+ OutputFreq = 32000;
+ sample_rate = SL_SAMPLINGRATE_32;
+ }
+ else
+ {
+ OutputFreq = 44100;
+ sample_rate = SL_SAMPLINGRATE_44_1;
+ }
}
else
{
- OutputFreq = 44100;
- sample_rate = SL_SAMPLINGRATE_44_1;
- }*/
-
- OutputFreq = 48000;
- sample_rate = SL_SAMPLINGRATE_48;
+ switch(SamplingRateSelection)
+ {
+ case 16:
+ OutputFreq = 16000;
+ sample_rate = SL_SAMPLINGRATE_16;
+ break;
+ case 24:
+ OutputFreq = 24000;
+ sample_rate = SL_SAMPLINGRATE_24;
+ break;
+ case 32:
+ OutputFreq = 32000;
+ sample_rate = SL_SAMPLINGRATE_32;
+ break;
+ case 441:
+ OutputFreq = 44100;
+ sample_rate = SL_SAMPLINGRATE_44_1;
+ break;
+ case 48:
+ OutputFreq = 48000;
+ sample_rate = SL_SAMPLINGRATE_48;
+ break;
+ }
+ }
DebugMessage(M64MSG_VERBOSE, "Requesting frequency: %iHz.", OutputFreq);
- /* reload these because they gets re-assigned from data below, and InitializeAudio can be called more than once */
- PrimaryBufferSize = ConfigGetParamInt(l_ConfigAudio, "PRIMARY_BUFFER_SIZE");
- SecondaryBufferSize = ConfigGetParamInt(l_ConfigAudio, "SECONDARY_BUFFER_SIZE");
- TargetSecondaryBuffers = ConfigGetParamInt(l_ConfigAudio, "SECONDARY_BUFFER_NBR");
-
/* Close everything because InitializeAudio can be called more than once */
CloseAudio();
@@ -491,15 +520,13 @@ static void InitializeAudio(int freq)
static void ReadConfig(void)
{
- const char *resampler_id;
-
/* read the configuration values into our static variables */
GameFreq = ConfigGetParamInt(l_ConfigAudio, "DEFAULT_FREQUENCY");
SwapChannels = ConfigGetParamBool(l_ConfigAudio, "SWAP_CHANNELS");
PrimaryBufferSize = ConfigGetParamInt(l_ConfigAudio, "PRIMARY_BUFFER_SIZE");
SecondaryBufferSize = ConfigGetParamInt(l_ConfigAudio, "SECONDARY_BUFFER_SIZE");
TargetSecondaryBuffers = ConfigGetParamInt(l_ConfigAudio, "SECONDARY_BUFFER_NBR");
- resampler_id = ConfigGetParamString(l_ConfigAudio, "RESAMPLE");
+ SamplingRateSelection = ConfigGetParamInt(l_ConfigAudio, "SAMPLING_RATE");
}
/* Mupen64Plus plugin functions */
@@ -599,6 +626,7 @@ EXPORT m64p_error CALL PluginStartup(m64p_dynlib_handle CoreLibHandle, void *Con
ConfigSetDefaultInt(l_ConfigAudio, "PRIMARY_BUFFER_SIZE", PRIMARY_BUFFER_SIZE, "Size of primary buffer in output samples. This is where audio is loaded after it's extracted from n64's memory.");
ConfigSetDefaultInt(l_ConfigAudio, "SECONDARY_BUFFER_SIZE", SECONDARY_BUFFER_SIZE, "Size of secondary buffer in output samples. This is OpenSLES's hardware buffer.");
ConfigSetDefaultInt(l_ConfigAudio, "SECONDARY_BUFFER_NBR" , SECONDARY_BUFFER_NBR, "Number of secondary buffers.");
+ ConfigSetDefaultInt(l_ConfigAudio, "SAMPLING_RATE" , 0, "Sampling rate, (0=game original, 16, 24, 32, 441, 48");
if (bSaveConfig && ConfigAPIVersion >= 0x020100)
ConfigSaveSection("Audio-OpenSLES");
View
@@ -477,8 +477,28 @@
<item>256</item>
<item>128</item>
</string-array>
-
+
<string name="audioSLESBufferSize_default" translatable="false">1024</string>
+
+ <!-- Audio SLES Sampling Rate -->
+ <string-array name="audioSLESRate_entries" translatable="false">
+ <item>@string/audioSLESRate_entry_orig</item>
+ <item>@string/audioSLESRate_entry16</item>
+ <item>@string/audioSLESRate_entry24</item>
+ <item>@string/audioSLESRate_entry32</item>
+ <item>@string/audioSLESRate_entry441</item>
+ <item>@string/audioSLESRate_entry48</item>
+ </string-array>
+ <string-array name="audioSLESRate_values" translatable="false">
+ <item>0</item>
+ <item>16</item>
+ <item>24</item>
+ <item>32</item>
+ <item>441</item>
+ <item>48</item>
+ </string-array>
+
+ <string name="audioSLESRate_default" translatable="false">0</string>
<!-- R4300 Emulator -->
<string-array name="r4300Emulator_entries" translatable="false">
View
@@ -447,10 +447,13 @@
<string name="audioSLESBufferSize_entry256">256</string>
<string name="audioSLESBufferSize_entry128">128</string>
<string name="audioSLESBufferNbr_title">Audio buffer number</string>
- <string name="audioSLESBufferNbr_entry2">2</string>
- <string name="audioSLESBufferNbr_entry3">3</string>
- <string name="audioSLESBufferNbr_entry4">4</string>
- <string name="audioSLESBufferNbr_entry5">5</string>
+ <string name="audioSLESRate_title">Sampling Rate</string>
+ <string name="audioSLESRate_entry_orig">Set by game</string>
+ <string name="audioSLESRate_entry16">16kHz</string>
+ <string name="audioSLESRate_entry24">24kHz</string>
+ <string name="audioSLESRate_entry32">32kHz</string>
+ <string name="audioSLESRate_entry441">44.1kHz</string>
+ <string name="audioSLESRate_entry48">48kHz</string>
<string name="localeOverride_entrySystemDefault">System default</string>
<!-- Seek Bar Preferences (selected value and units will become the summary -->
@@ -148,6 +148,13 @@
mupen64:stepSize="1"
mupen64:saveType="string"
mupen64:units=" buffers" />
+ <paulscode.android.mupen64plusae.preference.CompatListPreference
+ android:defaultValue="@string/audioSLESRate_default"
+ android:entries="@array/audioSLESRate_entries"
+ android:entryValues="@array/audioSLESRate_values"
+ android:key="audioSLESSamplingRate"
+ android:summary="@string/selectedValue"
+ android:title="@string/audioSLESRate_title" />
<android.support.v7.preference.CheckBoxPreference
android:defaultValue="true"
android:key="audioSynchronize"
@@ -66,6 +66,7 @@ public static void syncConfigFiles( GamePrefs game, GlobalPrefs global, AppData
mupen64plus_cfg.put( "Audio-OpenSLES", "SWAP_CHANNELS", boolToTF( global.audioSwapChannels ) ); // Swaps left and right channels
mupen64plus_cfg.put( "Audio-OpenSLES", "SECONDARY_BUFFER_SIZE", String.valueOf( global.audioSLESSecondaryBufferSize ) ); // Size of secondary buffer in output samples. This is OpenSLES's hardware buffer.
mupen64plus_cfg.put( "Audio-OpenSLES", "SECONDARY_BUFFER_NBR", String.valueOf( global.audioSLESSecondaryBufferNbr ) ); // Number of secondary buffer.
+ mupen64plus_cfg.put( "Audio-OpenSLES", "SAMPLING_RATE", String.valueOf( global.audioSLESSamplingRate ) ); // Sampling rate
mupen64plus_cfg.put( "Core", "Version", "1.010000" ); // Mupen64Plus Core config parameter set version number. Please don't change this version number.
mupen64plus_cfg.put( "Core", "OnScreenDisplay", "False" ); // Draw on-screen display if True, otherwise don't draw OSD
@@ -200,6 +200,9 @@
/** Number of SLES secondary buffers. */
public final int audioSLESSecondaryBufferNbr;
+ /** Number of SLES sampling rate. */
+ public final int audioSLESSamplingRate;
+
/** True if big-screen navigation mode is enabled. */
public final boolean isBigScreenMode;
@@ -397,6 +400,7 @@ public GlobalPrefs( Context context, AppData appData )
audioSDLSecondaryBufferSize = getSafeInt( mPreferences, "audioSDLBufferSize", 2048 );
audioSLESSecondaryBufferSize = getSafeInt( mPreferences, "audioSLESBufferSize", 1024 );
audioSLESSecondaryBufferNbr = getSafeInt( mPreferences, "audioSLESBufferNbr2", 20 );
+ audioSLESSamplingRate = getSafeInt( mPreferences, "audioSLESSamplingRate", 0 );
if( audioPlugin.enabled )
isFramelimiterEnabled = !mPreferences.getBoolean( "audioSynchronize", true );
@@ -65,6 +65,7 @@
private static final String AUDIO_SDL_BUFFER_SIZE = "audioSDLBufferSize";
private static final String AUDIO_SLES_BUFFER_SIZE = "audioSLESBufferSize";
private static final String AUDIO_SLES_BUFFER_NBR = "audioSLESBufferNbr2";
+ private static final String AUDIO_SLES_SAMPLING_RATE = "audioSLESSamplingRate";
private static final String AUDIO_SYNCHRONIZE = "audioSynchronize";
private static final String AUDIO_SWAP_CHANNELS = "audioSwapChannels";
private static final String NAVIGATION_MODE = "navigationMode";
@@ -234,6 +235,7 @@ private void refreshViews()
PrefUtil.enablePreference( this, AUDIO_SDL_BUFFER_SIZE, mGlobalPrefs.audioPlugin.name.equals( AUDIO_SDL_PLUGIN ) );
PrefUtil.enablePreference( this, AUDIO_SLES_BUFFER_SIZE, mGlobalPrefs.audioPlugin.name.equals( AUDIO_SLES_PLUGIN ) );
PrefUtil.enablePreference( this, AUDIO_SLES_BUFFER_NBR, mGlobalPrefs.audioPlugin.name.equals( AUDIO_SLES_PLUGIN ) );
+ PrefUtil.enablePreference( this, AUDIO_SLES_SAMPLING_RATE, mGlobalPrefs.audioPlugin.name.equals( AUDIO_SLES_PLUGIN ) );
PrefUtil.enablePreference( this, AUDIO_SYNCHRONIZE, mGlobalPrefs.audioPlugin.enabled );
PrefUtil.enablePreference( this, AUDIO_SWAP_CHANNELS, mGlobalPrefs.audioPlugin.enabled );

0 comments on commit 1f0af5d

Please sign in to comment.