Fix audio distortions on MVE playback with pipewire backend

Don't define fixed buffer length for audio device, SDL2 calculates desired length itself.
Minor cleanups and fixes to virtual class and constructor.
This commit is contained in:
Azamat H. Hackimov 2024-08-29 16:29:46 +03:00
parent 2db85ca6ec
commit 3f588adb0a
4 changed files with 8 additions and 13 deletions

View File

@ -16,21 +16,15 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <functional>
#include "movie_sound.h"
namespace D3 {
MovieSoundDevice::MovieSoundDevice(int sample_rate, uint16_t sample_size, uint8_t channels, uint32_t buf_size,
bool is_compressed) {
SDL_AudioFormat format = (sample_size == 2) ? AUDIO_S16LSB : AUDIO_U8;
SDL_AudioSpec spec;
MovieSoundDevice::MovieSoundDevice(int sample_rate, uint16_t sample_size, uint8_t channels, bool is_compressed) {
SDL_AudioSpec spec{};
spec.freq = sample_rate;
spec.format = format;
spec.format = (sample_size == 2) ? AUDIO_S16LSB : AUDIO_U8;
spec.channels = channels;
spec.size = buf_size;
spec.callback = nullptr;
spec.userdata = this;
m_device_id = SDL_OpenAudioDevice(nullptr, 0, &spec, nullptr, 0);
m_is_compressed = is_compressed;

View File

@ -37,11 +37,10 @@ public:
* @param sample_rate sample rate in Hz (22050, 44100...)
* @param sample_size sample size (8, 16)
* @param channels count of channels (1 for mono, 2 for stereo)
* @param buf_size buffer size for SDL audio device
* @param is_compressed mark stream as compressed (on streaming will be used decompression functions)
*/
MovieSoundDevice(int sample_rate, uint16_t sample_size, uint8_t channels, uint32_t buf_size, bool is_compressed);
~MovieSoundDevice();
MovieSoundDevice(int sample_rate, uint16_t sample_size, uint8_t channels, bool is_compressed);
~MovieSoundDevice() override;
/**
* Check if sound device is properly initialized

View File

@ -184,7 +184,7 @@ static int create_audiobuf_handler(unsigned char major, unsigned char minor, uns
is_compressed = true;
}
snd_ds = std::make_unique<D3::MovieSoundDevice>(sample_rate, sample_size, channels, 4096, is_compressed);
snd_ds = std::make_unique<D3::MovieSoundDevice>(sample_rate, sample_size, channels, is_compressed);
#endif
return 1;

View File

@ -29,6 +29,8 @@ protected:
bool m_is_compressed = false;
public:
virtual ~ISoundDevice() = default;
/// Play stream
virtual void Play() {};
/// Stop stream