mirror of
https://github.com/Ryujinx/libsoundio.git
synced 2024-12-22 23:55:34 +00:00
parent
d168a7d192
commit
8f1e1b8752
35
src/alsa.c
35
src/alsa.c
|
@ -1312,34 +1312,7 @@ static int outstream_open_alsa(struct SoundIoPrivate *si, struct SoundIoOutStrea
|
|||
return SoundIoErrorOpeningDevice;
|
||||
}
|
||||
|
||||
int period_count;
|
||||
if (device->is_raw) {
|
||||
period_count = 4;
|
||||
unsigned int microseconds = 0.25 * outstream->software_latency * 1000000.0;
|
||||
if ((err = snd_pcm_hw_params_set_period_time_near(osa->handle, hwparams, µseconds, NULL)) < 0) {
|
||||
outstream_destroy_alsa(si, os);
|
||||
return SoundIoErrorOpeningDevice;
|
||||
}
|
||||
} else {
|
||||
period_count = 2;
|
||||
double period_duration = 0.5 * outstream->software_latency;
|
||||
snd_pcm_uframes_t period_frames =
|
||||
ceil_dbl_to_uframes(period_duration * (double)outstream->sample_rate);
|
||||
|
||||
if ((err = snd_pcm_hw_params_set_period_size_near(osa->handle, hwparams, &period_frames, NULL)) < 0) {
|
||||
outstream_destroy_alsa(si, os);
|
||||
return SoundIoErrorOpeningDevice;
|
||||
}
|
||||
}
|
||||
|
||||
snd_pcm_uframes_t period_size;
|
||||
if ((snd_pcm_hw_params_get_period_size(hwparams, &period_size, NULL)) < 0) {
|
||||
outstream_destroy_alsa(si, os);
|
||||
return SoundIoErrorOpeningDevice;
|
||||
}
|
||||
osa->period_size = period_size;
|
||||
|
||||
osa->buffer_size_frames = osa->period_size * period_count;
|
||||
osa->buffer_size_frames = outstream->software_latency * outstream->sample_rate;
|
||||
if ((err = snd_pcm_hw_params_set_buffer_size_near(osa->handle, hwparams, &osa->buffer_size_frames)) < 0) {
|
||||
outstream_destroy_alsa(si, os);
|
||||
return SoundIoErrorOpeningDevice;
|
||||
|
@ -1352,6 +1325,12 @@ static int outstream_open_alsa(struct SoundIoPrivate *si, struct SoundIoOutStrea
|
|||
return (err == -EINVAL) ? SoundIoErrorIncompatibleDevice : SoundIoErrorOpeningDevice;
|
||||
}
|
||||
|
||||
if ((snd_pcm_hw_params_get_period_size(hwparams, &osa->period_size, NULL)) < 0) {
|
||||
outstream_destroy_alsa(si, os);
|
||||
return SoundIoErrorOpeningDevice;
|
||||
}
|
||||
|
||||
|
||||
// set channel map
|
||||
osa->chmap->channels = ch_count;
|
||||
for (int i = 0; i < ch_count; i += 1) {
|
||||
|
|
|
@ -59,7 +59,7 @@ struct SoundIoOutStreamAlsa {
|
|||
struct pollfd *poll_fds;
|
||||
struct SoundIoOsThread *thread;
|
||||
atomic_flag thread_exit_flag;
|
||||
int period_size;
|
||||
snd_pcm_uframes_t period_size;
|
||||
int write_frame_count;
|
||||
bool is_paused;
|
||||
atomic_flag clear_buffer_flag;
|
||||
|
|
Loading…
Reference in a new issue