Directly use sound sample rate instead of "quality"
git-svn-id: https://svn.code.sf.net/p/vbam/code/trunk@827 a31d4220-a93d-0410-bf67-fe4944624d44
This commit is contained in:
parent
b7197a8a92
commit
49b5ee430a
|
@ -41,7 +41,7 @@ extern bool stopState; // TODO: silence sound when true
|
|||
int const SOUND_CLOCK_TICKS_ = 167772; // 1/100 second
|
||||
|
||||
static u16 soundFinalWave [1470];
|
||||
int soundQuality = 1;
|
||||
long soundSampleRate = 44100;
|
||||
bool soundInterpolation = true;
|
||||
bool soundPaused = true;
|
||||
float soundFiltering = 0.5f;
|
||||
|
@ -448,8 +448,7 @@ static void remake_stereo_buffer()
|
|||
stereo_buffer = 0;
|
||||
|
||||
stereo_buffer = new Stereo_Buffer; // TODO: handle out of memory
|
||||
long const sample_rate = 44100 / soundQuality;
|
||||
stereo_buffer->set_sample_rate( sample_rate ); // TODO: handle out of memory
|
||||
stereo_buffer->set_sample_rate( soundSampleRate ); // TODO: handle out of memory
|
||||
stereo_buffer->clock_rate( gb_apu->clock_rate );
|
||||
|
||||
// PCM
|
||||
|
@ -534,7 +533,7 @@ bool soundInit()
|
|||
if ( !soundDriver )
|
||||
return false;
|
||||
|
||||
if (!soundDriver->init(soundQuality))
|
||||
if (!soundDriver->init(soundSampleRate))
|
||||
return false;
|
||||
|
||||
soundPaused = true;
|
||||
|
@ -543,22 +542,24 @@ bool soundInit()
|
|||
|
||||
int soundGetQuality()
|
||||
{
|
||||
return soundQuality;
|
||||
return 44100 / soundSampleRate;
|
||||
}
|
||||
|
||||
void soundSetQuality(int quality)
|
||||
{
|
||||
if ( soundQuality != quality )
|
||||
long newSampleRate = 44100 / quality;
|
||||
|
||||
if ( soundSampleRate != newSampleRate )
|
||||
{
|
||||
if ( systemCanChangeSoundQuality() )
|
||||
{
|
||||
soundShutdown();
|
||||
soundQuality = quality;
|
||||
soundSampleRate = newSampleRate;
|
||||
soundInit();
|
||||
}
|
||||
else
|
||||
{
|
||||
soundQuality = quality;
|
||||
soundSampleRate = newSampleRate;
|
||||
}
|
||||
|
||||
remake_stereo_buffer();
|
||||
|
|
|
@ -33,9 +33,9 @@ public:
|
|||
|
||||
/**
|
||||
* Initialize the sound driver.
|
||||
* @param quality Sound frequency : 1 => 44100 Hz, 2 => 22050 Hz, 4 => 11025 Hz
|
||||
* @param sampleRate In Hertz
|
||||
*/
|
||||
virtual bool init(int quality) = 0;
|
||||
virtual bool init(long sampleRate) = 0;
|
||||
|
||||
/**
|
||||
* Tell the driver that the sound stream has paused
|
||||
|
|
|
@ -94,25 +94,13 @@ void SoundSDL::write(const u16 * finalWave, int length)
|
|||
SDL_mutexV(_mutex);
|
||||
}
|
||||
|
||||
bool SoundSDL::init(int quality)
|
||||
bool SoundSDL::init(long sampleRate)
|
||||
{
|
||||
SDL_AudioSpec audio;
|
||||
|
||||
switch(quality) {
|
||||
case 1:
|
||||
audio.freq = 44100;
|
||||
_bufferLen = 1470*2;
|
||||
break;
|
||||
case 2:
|
||||
audio.freq = 22050;
|
||||
_bufferLen = 736*2;
|
||||
break;
|
||||
case 4:
|
||||
audio.freq = 11025;
|
||||
_bufferLen = 368*2;
|
||||
break;
|
||||
}
|
||||
_bufferLen = sampleRate / 15;
|
||||
|
||||
audio.freq = sampleRate;
|
||||
audio.format = AUDIO_S16SYS;
|
||||
audio.channels = 2;
|
||||
audio.samples = 1024;
|
||||
|
|
|
@ -25,7 +25,7 @@ class SoundSDL: public SoundDriver
|
|||
public:
|
||||
virtual ~SoundSDL();
|
||||
|
||||
virtual bool init(int quality);
|
||||
virtual bool init(long sampleRate);
|
||||
virtual void pause();
|
||||
virtual void reset();
|
||||
virtual void resume();
|
||||
|
|
|
@ -9,6 +9,7 @@
|
|||
#include "gb_apu/Effects_Buffer.h"
|
||||
|
||||
extern int gbHardware;
|
||||
extern long soundSampleRate; // current sound quality
|
||||
|
||||
gb_effects_config_t gb_effects_config = { false, 0.20f, 0.15f, false };
|
||||
|
||||
|
@ -125,7 +126,7 @@ static void remake_stereo_buffer()
|
|||
stereo_buffer = 0;
|
||||
|
||||
stereo_buffer = new Simple_Effects_Buffer; // TODO: handle out of memory
|
||||
if ( stereo_buffer->set_sample_rate( 44100 / soundQuality ) ) { } // TODO: handle out of memory
|
||||
if ( stereo_buffer->set_sample_rate( soundSampleRate ) ) { } // TODO: handle out of memory
|
||||
stereo_buffer->clock_rate( gb_apu->clock_rate );
|
||||
|
||||
// APU
|
||||
|
@ -217,17 +218,19 @@ void gbSoundReset()
|
|||
|
||||
void gbSoundSetQuality(int quality)
|
||||
{
|
||||
if ( soundQuality != quality )
|
||||
long newSampleRate = 44100 / quality;
|
||||
|
||||
if ( soundSampleRate != newSampleRate )
|
||||
{
|
||||
if ( systemCanChangeSoundQuality() )
|
||||
{
|
||||
soundShutdown();
|
||||
soundQuality = quality;
|
||||
soundSampleRate = newSampleRate;
|
||||
soundInit();
|
||||
}
|
||||
else
|
||||
{
|
||||
soundQuality = quality;
|
||||
soundSampleRate = newSampleRate;
|
||||
}
|
||||
|
||||
remake_stereo_buffer();
|
||||
|
|
|
@ -9,7 +9,6 @@
|
|||
|
||||
// Sets sample rate to 44100 / quality
|
||||
void gbSoundSetQuality( int quality );
|
||||
extern int soundQuality; // current sound quality
|
||||
|
||||
// Manages declicking mode. When enabled, clicks are reduced. Note that clicks
|
||||
// are normal for GB and GBC sound hardware.
|
||||
|
|
|
@ -721,7 +721,7 @@ void sdlReadPreferences(FILE *f)
|
|||
} else if(!strcmp(key, "captureFormat")) {
|
||||
captureFormat = sdlFromHex(value);
|
||||
} else if(!strcmp(key, "soundQuality")) {
|
||||
soundQuality = sdlFromHex(value);
|
||||
int soundQuality = sdlFromHex(value);
|
||||
switch(soundQuality) {
|
||||
case 1:
|
||||
case 2:
|
||||
|
@ -733,6 +733,7 @@ void sdlReadPreferences(FILE *f)
|
|||
soundQuality = 2;
|
||||
break;
|
||||
}
|
||||
soundSetQuality(soundQuality);
|
||||
} else if(!strcmp(key, "soundEnable")) {
|
||||
int res = sdlFromHex(value) & 0x30f;
|
||||
soundSetEnable(res);
|
||||
|
|
|
@ -34,7 +34,7 @@ public:
|
|||
DirectSound();
|
||||
virtual ~DirectSound();
|
||||
|
||||
bool init(int quality); // initialize the primary and secondary sound buffer
|
||||
bool init(long sampleRate); // initialize the primary and secondary sound buffer
|
||||
void pause(); // pause the secondary sound buffer
|
||||
void reset(); // stop and reset the secondary sound buffer
|
||||
void resume(); // resume the secondary sound buffer
|
||||
|
@ -85,7 +85,7 @@ DirectSound::~DirectSound()
|
|||
}
|
||||
|
||||
|
||||
bool DirectSound::init(int quality)
|
||||
bool DirectSound::init(long sampleRate)
|
||||
{
|
||||
HRESULT hr;
|
||||
DWORD freq;
|
||||
|
@ -123,7 +123,7 @@ bool DirectSound::init(int quality)
|
|||
return false;
|
||||
}
|
||||
|
||||
freq = 44100 / quality;
|
||||
freq = sampleRate;
|
||||
// calculate the number of samples per frame first
|
||||
// then multiply it with the size of a sample frame (16 bit * stereo)
|
||||
soundBufferLen = ( freq / 60 ) * 4;
|
||||
|
|
|
@ -37,7 +37,7 @@ public:
|
|||
OpenAL();
|
||||
virtual ~OpenAL();
|
||||
|
||||
bool init(int quality); // initialize the sound buffer queue
|
||||
bool init(long sampleRate); // initialize the sound buffer queue
|
||||
void pause(); // pause the secondary sound buffer
|
||||
void reset(); // stop and reset the secondary sound buffer
|
||||
void resume(); // play/resume the secondary sound buffer
|
||||
|
@ -145,7 +145,7 @@ void OpenAL::debugState()
|
|||
#endif
|
||||
|
||||
|
||||
bool OpenAL::init(int quality)
|
||||
bool OpenAL::init(long sampleRate)
|
||||
{
|
||||
winlog( "OpenAL::init\n" );
|
||||
assert( initialized == false );
|
||||
|
@ -174,7 +174,7 @@ bool OpenAL::init(int quality)
|
|||
ALFunction.alGenSources( 1, &source );
|
||||
ASSERT_SUCCESS;
|
||||
|
||||
freq = 44100 / quality;
|
||||
freq = sampleRate;
|
||||
|
||||
// calculate the number of samples per frame first
|
||||
// then multiply it with the size of a sample frame (16 bit * stereo)
|
||||
|
|
|
@ -56,7 +56,7 @@ public:
|
|||
~XAudio2_Output();
|
||||
|
||||
// Initialization
|
||||
bool init(int quality);
|
||||
bool init(long sampleRate);
|
||||
|
||||
// Sound Data Feed
|
||||
void write(const u16 * finalWave, int length);
|
||||
|
@ -137,7 +137,7 @@ XAudio2_Output::~XAudio2_Output()
|
|||
}
|
||||
|
||||
|
||||
bool XAudio2_Output::init(int quality)
|
||||
bool XAudio2_Output::init(long sampleRate)
|
||||
{
|
||||
if( failed || initialized ) return false;
|
||||
|
||||
|
@ -157,7 +157,7 @@ bool XAudio2_Output::init(int quality)
|
|||
}
|
||||
|
||||
|
||||
freq = 44100 / (UINT32)quality;
|
||||
freq = sampleRate;
|
||||
|
||||
// calculate the number of samples per frame first
|
||||
// then multiply it with the size of a sample frame (16 bit * stereo)
|
||||
|
@ -360,7 +360,7 @@ void XAudio2_Output::reset()
|
|||
|
||||
sVoice->FlushSourceBuffers();
|
||||
sVoice->Start( 0 );
|
||||
playing = true;
|
||||
playing = true;
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue