Added GetSampleRate function

This commit is contained in:
Kevin Alexis Contreras 2022-06-14 14:04:47 -05:00
commit 3dc33b6f84
4 changed files with 19 additions and 18 deletions

View file

@ -11,5 +11,6 @@ namespace Ship {
virtual int Buffered(void) = 0; virtual int Buffered(void) = 0;
virtual int GetDesiredBuffered(void) = 0; virtual int GetDesiredBuffered(void) = 0;
virtual void Play(const uint8_t* buf, uint32_t len) = 0; virtual void Play(const uint8_t* buf, uint32_t len) = 0;
constexpr int GetSampleRate() const { return 44100; }
}; };
} }

View file

@ -74,7 +74,7 @@ namespace Ship
// Create stream // Create stream
pa_sample_spec ss; pa_sample_spec ss;
ss.format = PA_SAMPLE_S16LE; ss.format = PA_SAMPLE_S16LE;
ss.rate = 32000; ss.rate = this->GetSampleRate();
ss.channels = 2; ss.channels = 2;
pa_buffer_attr attr; pa_buffer_attr attr;

View file

@ -9,7 +9,7 @@ namespace Ship {
} }
SDL_AudioSpec want, have; SDL_AudioSpec want, have;
SDL_zero(want); SDL_zero(want);
want.freq = 44000; want.freq = this->GetSampleRate();
want.format = AUDIO_S16; want.format = AUDIO_S16;
want.channels = 2; want.channels = 2;
want.samples = 1024; want.samples = 1024;

View file

@ -30,8 +30,8 @@ namespace Ship {
WAVEFORMATEX desired; WAVEFORMATEX desired;
desired.wFormatTag = WAVE_FORMAT_PCM; desired.wFormatTag = WAVE_FORMAT_PCM;
desired.nChannels = 2; desired.nChannels = 2;
desired.nSamplesPerSec = 44100; desired.nSamplesPerSec = this->GetSampleRate();
desired.nAvgBytesPerSec = 44100 * 2 * 2; desired.nAvgBytesPerSec = desired.nSamplesPerSec * 2 * 2;
desired.nBlockAlign = 4; desired.nBlockAlign = 4;
desired.wBitsPerSample = 16; desired.wBitsPerSample = 16;
desired.cbSize = 0; desired.cbSize = 0;