Change channels number and bytes per second to hardcoded value

Because these audio players can only handle 16bit mono anyway.
This commit is contained in:
wangqr 2019-10-30 01:16:28 -04:00
parent 620033915a
commit b86238456f
7 changed files with 25 additions and 20 deletions

View file

@ -127,7 +127,7 @@ void AlsaPlayer::PlaybackThread()
do_setup: do_setup:
snd_pcm_format_t pcm_format; snd_pcm_format_t pcm_format;
switch (provider->GetBytesPerSample()) switch (/*provider->GetBytesPerSample()*/ sizeof(int16_t))
{ {
case 1: case 1:
LOG_D("audio/player/alsa") << "format U8"; LOG_D("audio/player/alsa") << "format U8";
@ -143,7 +143,7 @@ do_setup:
if (snd_pcm_set_params(pcm, if (snd_pcm_set_params(pcm,
pcm_format, pcm_format,
SND_PCM_ACCESS_RW_INTERLEAVED, SND_PCM_ACCESS_RW_INTERLEAVED,
provider->GetChannels(), /*provider->GetChannels()*/ 1,
provider->GetSampleRate(), provider->GetSampleRate(),
1, // allow resample 1, // allow resample
100*1000 // 100 milliseconds latency 100*1000 // 100 milliseconds latency
@ -151,7 +151,8 @@ do_setup:
return; return;
LOG_D("audio/player/alsa") << "set pcm params"; LOG_D("audio/player/alsa") << "set pcm params";
size_t framesize = provider->GetChannels() * provider->GetBytesPerSample(); //size_t framesize = provider->GetChannels() * provider->GetBytesPerSample();
size_t framesize = sizeof(int16_t);
while (true) while (true)
{ {

View file

@ -112,8 +112,10 @@ DirectSoundPlayer::DirectSoundPlayer(agi::AudioProvider *provider, wxWindow *par
WAVEFORMATEX waveFormat; WAVEFORMATEX waveFormat;
waveFormat.wFormatTag = WAVE_FORMAT_PCM; waveFormat.wFormatTag = WAVE_FORMAT_PCM;
waveFormat.nSamplesPerSec = provider->GetSampleRate(); waveFormat.nSamplesPerSec = provider->GetSampleRate();
waveFormat.nChannels = provider->GetChannels(); //waveFormat.nChannels = provider->GetChannels();
waveFormat.wBitsPerSample = provider->GetBytesPerSample() * 8; //waveFormat.wBitsPerSample = provider->GetBytesPerSample() * 8;
waveFormat.nChannels = 1;
waveFormat.wBitsPerSample = sizeof(int16_t) * 8;
waveFormat.nBlockAlign = waveFormat.nChannels * waveFormat.wBitsPerSample / 8; waveFormat.nBlockAlign = waveFormat.nChannels * waveFormat.wBitsPerSample / 8;
waveFormat.nAvgBytesPerSec = waveFormat.nSamplesPerSec * waveFormat.nBlockAlign; waveFormat.nAvgBytesPerSec = waveFormat.nSamplesPerSec * waveFormat.nBlockAlign;
waveFormat.cbSize = sizeof(waveFormat); waveFormat.cbSize = sizeof(waveFormat);
@ -161,7 +163,7 @@ bool DirectSoundPlayer::FillBuffer(bool fill) {
HRESULT res; HRESULT res;
void *ptr1, *ptr2; void *ptr1, *ptr2;
unsigned long int size1, size2; unsigned long int size1, size2;
int bytesps = provider->GetBytesPerSample(); int bytesps = /*provider->GetBytesPerSample()*/ sizeof(int16_t);
// To write length // To write length
int toWrite = 0; int toWrite = 0;
@ -255,7 +257,7 @@ void DirectSoundPlayer::Play(int64_t start,int64_t count) {
FillBuffer(true); FillBuffer(true);
DWORD play_flag = 0; DWORD play_flag = 0;
if (count*provider->GetBytesPerSample() > bufSize) { if (count*/*provider->GetBytesPerSample()*/sizeof(int16_t) > bufSize) {
// Start thread // Start thread
thread = new DirectSoundPlayerThread(this); thread = new DirectSoundPlayerThread(this);
thread->Create(); thread->Create();

View file

@ -320,8 +320,10 @@ void DirectSoundPlayer2Thread::Run()
WAVEFORMATEX waveFormat; WAVEFORMATEX waveFormat;
waveFormat.wFormatTag = WAVE_FORMAT_PCM; waveFormat.wFormatTag = WAVE_FORMAT_PCM;
waveFormat.nSamplesPerSec = provider->GetSampleRate(); waveFormat.nSamplesPerSec = provider->GetSampleRate();
waveFormat.nChannels = provider->GetChannels(); //waveFormat.nChannels = provider->GetChannels();
waveFormat.wBitsPerSample = provider->GetBytesPerSample() * 8; //waveFormat.wBitsPerSample = provider->GetBytesPerSample() * 8;
waveFormat.nChannels = 1;
waveFormat.wBitsPerSample = sizeof(int16_t) * 8;
waveFormat.nBlockAlign = waveFormat.nChannels * waveFormat.wBitsPerSample / 8; waveFormat.nBlockAlign = waveFormat.nChannels * waveFormat.wBitsPerSample / 8;
waveFormat.nAvgBytesPerSec = waveFormat.nSamplesPerSec * waveFormat.nBlockAlign; waveFormat.nAvgBytesPerSec = waveFormat.nSamplesPerSec * waveFormat.nBlockAlign;
waveFormat.cbSize = sizeof(waveFormat); waveFormat.cbSize = sizeof(waveFormat);
@ -370,7 +372,7 @@ void DirectSoundPlayer2Thread::Run()
DWORD buffer_offset = 0; DWORD buffer_offset = 0;
bool playback_should_be_running = false; bool playback_should_be_running = false;
int current_latency = wanted_latency; int current_latency = wanted_latency;
const DWORD wanted_latency_bytes = wanted_latency*waveFormat.nSamplesPerSec*provider->GetBytesPerSample()/1000; const DWORD wanted_latency_bytes = wanted_latency*waveFormat.nSamplesPerSec*/*provider->GetBytesPerSample()*/sizeof(int16_t)/1000;
while (running) while (running)
{ {
@ -423,7 +425,7 @@ void DirectSoundPlayer2Thread::Run()
if (bytes_filled < wanted_latency_bytes) if (bytes_filled < wanted_latency_bytes)
{ {
// Very short playback length, do without streaming playback // Very short playback length, do without streaming playback
current_latency = (bytes_filled*1000) / (waveFormat.nSamplesPerSec*provider->GetBytesPerSample()); current_latency = (bytes_filled*1000) / (waveFormat.nSamplesPerSec*/*provider->GetBytesPerSample()*/sizeof(int16_t));
if (FAILED(bfr->Play(0, 0, 0))) if (FAILED(bfr->Play(0, 0, 0)))
REPORT_ERROR("Could not start single-buffer playback.") REPORT_ERROR("Could not start single-buffer playback.")
} }
@ -554,7 +556,7 @@ do_fill_buffer:
else if (bytes_filled < wanted_latency_bytes) else if (bytes_filled < wanted_latency_bytes)
{ {
// Didn't fill as much as we wanted to, let's get back to filling sooner than normal // Didn't fill as much as we wanted to, let's get back to filling sooner than normal
current_latency = (bytes_filled*1000) / (waveFormat.nSamplesPerSec*provider->GetBytesPerSample()); current_latency = (bytes_filled*1000) / (waveFormat.nSamplesPerSec*/*provider->GetBytesPerSample()*/sizeof(int16_t));
} }
else else
{ {
@ -578,7 +580,7 @@ DWORD DirectSoundPlayer2Thread::FillAndUnlockBuffers(void *buf1, DWORD buf1sz, v
{ {
// Assume buffers have been locked and are ready to be filled // Assume buffers have been locked and are ready to be filled
DWORD bytes_per_frame = provider->GetChannels() * provider->GetBytesPerSample(); DWORD bytes_per_frame = /*provider->GetChannels() * provider->GetBytesPerSample()*/sizeof(int16_t);
DWORD buf1szf = buf1sz / bytes_per_frame; DWORD buf1szf = buf1sz / bytes_per_frame;
DWORD buf2szf = buf2sz / bytes_per_frame; DWORD buf2szf = buf2sz / bytes_per_frame;

View file

@ -125,7 +125,7 @@ public:
OpenALPlayer::OpenALPlayer(agi::AudioProvider *provider) OpenALPlayer::OpenALPlayer(agi::AudioProvider *provider)
: AudioPlayer(provider) : AudioPlayer(provider)
, samplerate(provider->GetSampleRate()) , samplerate(provider->GetSampleRate())
, bpf(provider->GetChannels() * provider->GetBytesPerSample()) , bpf(/*provider->GetChannels() * provider->GetBytesPerSample()*/sizeof(int16_t))
{ {
device = alcOpenDevice(nullptr); device = alcOpenDevice(nullptr);
if (!device) throw AudioPlayerOpenError("Failed opening default OpenAL device"); if (!device) throw AudioPlayerOpenError("Failed opening default OpenAL device");

View file

@ -146,7 +146,7 @@ public:
void OSSPlayer::OpenStream() void OSSPlayer::OpenStream()
{ {
bpf = provider->GetChannels() * provider->GetBytesPerSample(); bpf = /*provider->GetChannels() * provider->GetBytesPerSample()*/sizeof(int16_t);
// Open device // Open device
wxString device = to_wx(OPT_GET("Player/Audio/OSS/Device")->GetString()); wxString device = to_wx(OPT_GET("Player/Audio/OSS/Device")->GetString());
@ -162,14 +162,14 @@ void OSSPlayer::OpenStream()
#endif #endif
// Set number of channels // Set number of channels
int channels = provider->GetChannels(); int channels = /*provider->GetChannels()*/1;
if (ioctl(dspdev, SNDCTL_DSP_CHANNELS, &channels) < 0) { if (ioctl(dspdev, SNDCTL_DSP_CHANNELS, &channels) < 0) {
throw AudioPlayerOpenError("OSS player: setting channels failed"); throw AudioPlayerOpenError("OSS player: setting channels failed");
} }
// Set sample format // Set sample format
int sample_format; int sample_format;
switch (provider->GetBytesPerSample()) { switch (/*provider->GetBytesPerSample()*/sizeof(int16_t)) {
case 1: case 1:
sample_format = AFMT_S8; sample_format = AFMT_S8;
break; break;

View file

@ -140,7 +140,7 @@ void PortAudioPlayer::OpenStream() {
const PaDeviceInfo *device_info = Pa_GetDeviceInfo((*device_ids)[i]); const PaDeviceInfo *device_info = Pa_GetDeviceInfo((*device_ids)[i]);
PaStreamParameters pa_output_p; PaStreamParameters pa_output_p;
pa_output_p.device = (*device_ids)[i]; pa_output_p.device = (*device_ids)[i];
pa_output_p.channelCount = provider->GetChannels(); pa_output_p.channelCount = /*provider->GetChannels()*/ 1;
pa_output_p.sampleFormat = paInt16; pa_output_p.sampleFormat = paInt16;
pa_output_p.suggestedLatency = device_info->defaultLowOutputLatency; pa_output_p.suggestedLatency = device_info->defaultLowOutputLatency;
pa_output_p.hostApiSpecificStreamInfo = nullptr; pa_output_p.hostApiSpecificStreamInfo = nullptr;

View file

@ -133,11 +133,11 @@ PulseAudioPlayer::PulseAudioPlayer(agi::AudioProvider *provider) : AudioPlayer(p
} }
// Set up stream // Set up stream
bpf = provider->GetChannels() * provider->GetBytesPerSample(); bpf = /*provider->GetChannels() * provider->GetBytesPerSample()*/sizeof(int16_t);
pa_sample_spec ss; pa_sample_spec ss;
ss.format = PA_SAMPLE_S16LE; // FIXME ss.format = PA_SAMPLE_S16LE; // FIXME
ss.rate = provider->GetSampleRate(); ss.rate = provider->GetSampleRate();
ss.channels = provider->GetChannels(); ss.channels = /*provider->GetChannels()*/1;
pa_channel_map map; pa_channel_map map;
pa_channel_map_init_auto(&map, ss.channels, PA_CHANNEL_MAP_DEFAULT); pa_channel_map_init_auto(&map, ss.channels, PA_CHANNEL_MAP_DEFAULT);