Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

alsa: configure buffer size like it's done in libout123 (#20) #32

Merged
merged 1 commit into from
Mar 17, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions src/audio/alsa/audiodrv.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* This file is part of sidplayfp, a console SID player.
*
* Copyright 2013 Leandro Nini
* Copyright 2013-2024 Leandro Nini
* Copyright 2000-2006 Simon White
*
* This program is free software; you can redistribute it and/or modify
@@ -84,21 +84,21 @@ bool Audio_ALSA::open(AudioConfig &cfg)
tmpCfg.frequency = rate;
}

_alsa_to_frames_divisor = tmpCfg.channels;
snd_pcm_uframes_t buffer_frames = 4096;
checkResult(snd_pcm_hw_params_set_period_size_near(_audioHandle, hw_params, &buffer_frames, 0));
snd_pcm_uframes_t buffer_size = tmpCfg.frequency / 5;
checkResult(snd_pcm_hw_params_set_buffer_size_near(_audioHandle, hw_params, &buffer_size));
tmpCfg.bufSize = buffer_size;

snd_pcm_uframes_t period_size = buffer_size / 3;
checkResult(snd_pcm_hw_params_set_period_size_near(_audioHandle, hw_params, &period_size, 0));

checkResult(snd_pcm_hw_params(_audioHandle, hw_params));

snd_pcm_hw_params_free(hw_params);
hw_params = 0;

checkResult(snd_pcm_prepare(_audioHandle));
tmpCfg.bufSize = buffer_frames * _alsa_to_frames_divisor;

try
{
_sampleBuffer = new short[tmpCfg.bufSize];
_sampleBuffer = new short[snd_pcm_frames_to_bytes(_audioHandle, tmpCfg.bufSize)];
}
catch (std::bad_alloc const &ba)
{
@@ -144,7 +144,7 @@ bool Audio_ALSA::write(uint_least32_t size)
return false;
}

int err = snd_pcm_writei(_audioHandle, _sampleBuffer, size / _alsa_to_frames_divisor);
int err = snd_pcm_writei(_audioHandle, _sampleBuffer, size);
if (err < 0)
{
err = snd_pcm_recover(_audioHandle, err, 0);
4 changes: 3 additions & 1 deletion src/audio/alsa/audiodrv.h
Original file line number Diff line number Diff line change
@@ -31,6 +31,9 @@
# define AudioDriver Audio_ALSA
#endif

#define ALSA_PCM_NEW_HW_PARAMS_API


#include <alsa/asoundlib.h>
#include "../AudioBase.h"

@@ -39,7 +42,6 @@ class Audio_ALSA: public AudioBase
{
private: // ------------------------------------------------------- private
snd_pcm_t *_audioHandle;
int _alsa_to_frames_divisor;

private:
void outOfOrder();