mirror of
https://github.com/clangen/musikcube.git
synced 2024-10-02 13:02:35 +00:00
* Added correct Latency() calculation to AlsaOut
* Changed default Linux output device to PulseAudio
This commit is contained in:
parent
7dc7cf5062
commit
a02f94ef0c
@ -73,13 +73,14 @@ static inline bool playable(snd_pcm_t* pcm) {
|
||||
using namespace musik::core::sdk;
|
||||
|
||||
AlsaOut::AlsaOut()
|
||||
: pcmHandle(NULL)
|
||||
: pcmHandle(nullptr)
|
||||
, device("default")
|
||||
, channels(2)
|
||||
, rate(44100)
|
||||
, volume(1.0)
|
||||
, quit(false)
|
||||
, paused(false)
|
||||
, latency(0)
|
||||
, initialized(false) {
|
||||
std::cerr << "AlsaOut::AlsaOut() called" << std::endl;
|
||||
this->writeThread.reset(new boost::thread(boost::bind(&AlsaOut::WriteLoop, this)));
|
||||
@ -107,7 +108,8 @@ void AlsaOut::CloseDevice() {
|
||||
if (this->pcmHandle) {
|
||||
std::cerr << "AlsaOut: closing PCM handle\n";
|
||||
snd_pcm_close(this->pcmHandle);
|
||||
this->pcmHandle = NULL;
|
||||
this->pcmHandle = nullptr;
|
||||
this->latency = 0.0;
|
||||
}
|
||||
}
|
||||
|
||||
@ -177,6 +179,25 @@ void AlsaOut::Destroy() {
|
||||
delete this;
|
||||
}
|
||||
|
||||
double AlsaOut::Latency() {
|
||||
if (latency <= 0.0f) {
|
||||
LOCK("latency_calc");
|
||||
|
||||
if (this->pcmHandle && this->rate && this->channels) {
|
||||
snd_pcm_uframes_t bufferSize = 0, periodSize = 0;
|
||||
snd_pcm_get_params(this->pcmHandle, &bufferSize, &periodSize);
|
||||
|
||||
if (bufferSize) {
|
||||
this->latency =
|
||||
(double) bufferSize /
|
||||
(double) (this->rate * this->channels * sizeof(float));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return this->latency;
|
||||
}
|
||||
|
||||
void AlsaOut::Stop() {
|
||||
std::list<std::shared_ptr<BufferContext> > toNotify;
|
||||
|
||||
@ -260,6 +281,7 @@ void AlsaOut::WriteLoop() {
|
||||
|
||||
/* software volume; alsa doesn't support this internally. this is about
|
||||
as terrible as an algorithm can be -- it's just a linear ramp. */
|
||||
//std::cerr << "volume=" << volume << std::endl;
|
||||
if (volume != 1.0f) {
|
||||
float *buffer = next->buffer->BufferPointer();
|
||||
for (size_t i = 0; i < samples; i++) {
|
||||
@ -335,7 +357,7 @@ void AlsaOut::SetFormat(IBuffer *buffer) {
|
||||
|
||||
if (this->channels != buffer->Channels() ||
|
||||
this->rate != buffer->SampleRate() ||
|
||||
this->pcmHandle == NULL)
|
||||
this->pcmHandle == nullptr)
|
||||
{
|
||||
this->channels = buffer->Channels();
|
||||
this->rate = buffer->SampleRate();
|
||||
|
@ -60,7 +60,7 @@ class AlsaOut : public musik::core::sdk::IOutput {
|
||||
virtual void SetVolume(double volume);
|
||||
virtual double GetVolume();
|
||||
virtual void Stop();
|
||||
virtual double Latency() { return 0.0; }
|
||||
virtual double Latency();
|
||||
virtual void Drain();
|
||||
|
||||
virtual bool Play(
|
||||
@ -88,6 +88,7 @@ class AlsaOut : public musik::core::sdk::IOutput {
|
||||
size_t channels;
|
||||
size_t rate;
|
||||
double volume;
|
||||
double latency;
|
||||
volatile bool quit, paused, initialized;
|
||||
|
||||
std::unique_ptr<boost::thread> writeThread;
|
||||
|
@ -54,7 +54,7 @@ static const std::string defaultOutput = "Wasapi IOutput";
|
||||
#elif defined(__APPLE__)
|
||||
static const std::string defaultOutput = "CoreAudio IOutput";
|
||||
#else
|
||||
static const std::string defaultOutput = "Alsa IOutput";
|
||||
static const std::string defaultOutput = "PulseAudio IOutput";
|
||||
#endif
|
||||
|
||||
#define LOWER(x) std::transform(x.begin(), x.end(), x.begin(), tolower);
|
||||
|
Loading…
Reference in New Issue
Block a user