diff options
Diffstat (limited to 'media-libs/pcaudiolib')
5 files changed, 287 insertions, 0 deletions
diff --git a/media-libs/pcaudiolib/Manifest b/media-libs/pcaudiolib/Manifest index 58fcce7b01eb..75fe3f2b5aae 100644 --- a/media-libs/pcaudiolib/Manifest +++ b/media-libs/pcaudiolib/Manifest @@ -1,5 +1,9 @@ +AUX 0001-Fix-audio-choppiness-on-some-systems.patch 1081 BLAKE2B da04d5e419417364a81d4de6ffa4209100559a0a0e1f8ea5df876e9a4aa3fb80fbc90fa63bf2aaff22f96b72778b04900af929715bfd831217b1550d84f27944 SHA512 e753262d4a9ff25bd2544d6a4c590a6694a734e635d14d6907066b08fc757eb895535fb60ade14f04df10cce3d2fcacb52b12dbecef2659bdee7d1655d081ffa +AUX 0002-Fix-latency-related-buffer-sizing.patch 3032 BLAKE2B 6e92899e43d5c6ef26b68618018c9046d3545bc498b73a1ce7a89e28db5a5542242a5759c10ea8c9316cd2c1356c6326c7c03871ed5fab739b8099b61ad81a44 SHA512 befbbd4a92a20da93ff16388afba2d2d345aec501070e6cd7c570499481c72a495afb86d7174a31cdc671e4f60da9bcd4e027e0d8099c57622393a93c1755caf +AUX 0003-Copy-audio-buffer-and-send-for-playback-without-bloc.patch 3002 BLAKE2B b09f46862f57950735b47863da8035d00a7d9ada48d20a7576f7cb50c5886dceb2547cb17a31704704da827eb5bc0a5d9b8ef4eb95b52375d97f125d9b54017a SHA512 197a4b52dc3de402e03fcc177db0f128624a525774f064b6e0fca4aaa6bf39c4dea574437056ca05a5209658ca01968c756cbcf130144ad2dd0badcea7c948bd DIST pcaudiolib-1.1.tar.gz 34049 BLAKE2B 7c6ce1532c47db30db2b80be690453257148be9a7115cd24dabda3dfcaca667d5c3a8278276f278556406144461cda48905ce581f0fde2f8429b3f829a948a36 SHA512 d503c11b355601e1e05f0f438a0cd9ce277d19fd53d3f7edf26f6e17f1f8184e8b2112a282e8ed74db8646bb5534d2a9a3c707b1742ce02ef13fd89669785007 DIST pcaudiolib-1.2.tar.gz 34310 BLAKE2B a16e50fd789a88f10a56323afd2637c13e2383392cc287aad4cd8ef3f1f475c2754dca53e0fd5453b5fc9ee45392a0b9b6d8d7a2d0e88214e6194bbc2ce1e1ff SHA512 0a0fe2a21a8410ad5196272cc579137764d5a4beba16b3c5cf46cd2967132bb48def4c7977a7ae48ff1a0a6d53e454affc6c5add503e73e7805f15aa93231af3 EBUILD pcaudiolib-1.1.ebuild 906 BLAKE2B 476584493a6df9208eabaae5624ff8dd7b8baf0fd446925d36aa8a745d8ca65de7dd63c956e7c491056b7922a67685c8d28dc2e0802eda65d8b3fe5ad38b671d SHA512 6bf05d943836af577e4e707513707e7fd089ca86e290b9684a1fe5c7285096ca36ceb906e2360929275290f6454cad3e8040b1c94fc89613325d743ca15c01bd +EBUILD pcaudiolib-1.2-r1.ebuild 1129 BLAKE2B 1f387685c1704214c47bc080522e2e9ad4842da59570fc9cf2104229a836ebbe0b49c9e7a0ba839685890718176188647997c081dc7eab9bcaeff03060290de8 SHA512 6f41622ef78942dbe60bae06a1eff84d739b309ffccc727e470447ede9d71f071efd188bf45b101f7f2d5a256810f9cdff385e359259c0bf2e77e8d25b41becd EBUILD pcaudiolib-1.2.ebuild 913 BLAKE2B ed457308eefb1dc8dae0df707d4fe75d061c5b7acc03421d6a1ba086d714fc5c5e636389609c9ae0e2549417c5aa090afa885dcfa00de62d0f0e2552a2003868 SHA512 3aca7ce944a82177edc4a065afe4a55bc9bf535e5674db17ee16f5b20aeb765dbc4c4c3d7eb463681e2bc5359ab5dc2537bb04941d5a0e2f7af77255e07c9d6b MISC metadata.xml 588 BLAKE2B e148577ddfbf9688495e1a620708903f0bbe126ea9bff194e6b0f75a0e2a36ec52567f4d7a86381f89fb6c2e828ae372217e983d30810bb62dc60c0692420fed SHA512 d5de3f26535c7b147515cd9952951ed16be99345d309c7110c36a93fcd3f44f43373293d082c60170dfe5e05956d22b4c2cc1dd7343b3c28188f935ba8feaadf diff --git a/media-libs/pcaudiolib/files/0001-Fix-audio-choppiness-on-some-systems.patch b/media-libs/pcaudiolib/files/0001-Fix-audio-choppiness-on-some-systems.patch new file mode 100644 index 000000000000..b8c147454df9 --- /dev/null +++ b/media-libs/pcaudiolib/files/0001-Fix-audio-choppiness-on-some-systems.patch @@ -0,0 +1,36 @@ +From 478bb69d51a945123a18dedf4bee7a3bede67f40 Mon Sep 17 00:00:00 2001 +From: Nicolas Pitre <nico@fluxnic.net> +Date: Sat, 2 Apr 2022 22:04:30 -0400 +Subject: [PATCH] Fix audio choppiness on some systems + +Commit a41d46e816d2 ("Fix cancellation snappiness") made espeak unusable +on the RaspberryPi due to extreme audio choppiness. This can sometimes +be observed on some PC-type systems as well, albeit much less +prominently. + +Relax the timing to the smallest value that makes it work again on the +RaspberryPi. +--- + src/audio_priv.h | 6 ++++-- + 1 file changed, 4 insertions(+), 2 deletions(-) + +diff --git a/src/audio_priv.h b/src/audio_priv.h +index 669a037..0c2ce3c 100644 +--- a/src/audio_priv.h ++++ b/src/audio_priv.h +@@ -53,8 +53,10 @@ struct audio_object + }; + + /* We try to aim for 10ms cancelation latency, which will be perceived as +- * "snappy" by users */ +-#define LATENCY 10 ++ * "snappy" by users. However, some systems (e.g. RPi) do produce chopped ++ * audio when this value is smaller than 60. ++ */ ++#define LATENCY 60 + + #if defined(_WIN32) || defined(_WIN64) + +-- +2.35.1 + diff --git a/media-libs/pcaudiolib/files/0002-Fix-latency-related-buffer-sizing.patch b/media-libs/pcaudiolib/files/0002-Fix-latency-related-buffer-sizing.patch new file mode 100644 index 000000000000..4af7da5c33a4 --- /dev/null +++ b/media-libs/pcaudiolib/files/0002-Fix-latency-related-buffer-sizing.patch @@ -0,0 +1,78 @@ +From 72da4a54a5afbbdadfa6d8131e0f4a9f08cf4394 Mon Sep 17 00:00:00 2001 +From: Nicolas Pitre <nico@fluxnic.net> +Date: Wed, 6 Jul 2022 00:30:42 -0400 +Subject: [PATCH] Fix latency-related buffer sizing + +Turns out that eSpeak-NG (the main user of this lib) enforces a minimum +buffer size of 60ms which is also the default size. This explains why +smaller LATENCY values were inducing choppiness in the audio on some +systems. Adjust the comment accordingly,. + +Also make sure computed buffer sizes don't land in the middle of a +sample frame. Doing (samplerate * channels * LATENCY) / 1000 is wrong. + +Both ALSA and PulseAudio provide nice abstractions for buffer sizing +so let's use them directly. In the ALSA case in particular, we want the +period to be 60ms, not the whole buffer, so to interleave speech audio +computation and audio playback. +--- + src/alsa.c | 5 +++-- + src/audio_priv.h | 5 +---- + src/pulseaudio.c | 2 +- + 3 files changed, 5 insertions(+), 7 deletions(-) + +diff --git a/src/alsa.c b/src/alsa.c +index c856788..a0da0f0 100644 +--- a/src/alsa.c ++++ b/src/alsa.c +@@ -99,7 +99,8 @@ alsa_object_open(struct audio_object *object, + + snd_pcm_hw_params_t *params = NULL; + snd_pcm_hw_params_malloc(¶ms); +- snd_pcm_uframes_t bufsize = (rate * channels * LATENCY) / 1000; ++ unsigned int period_time = LATENCY * 1000; ++ int dir = 0; + + int err = 0; + if ((err = snd_pcm_open(&self->handle, self->device ? self->device : "default", SND_PCM_STREAM_PLAYBACK, 0)) < 0) +@@ -114,7 +115,7 @@ alsa_object_open(struct audio_object *object, + goto error; + if ((err = snd_pcm_hw_params_set_channels(self->handle, params, channels)) < 0) + goto error; +- if ((err = snd_pcm_hw_params_set_buffer_size_near(self->handle, params, &bufsize)) < 0) ++ if ((err = snd_pcm_hw_params_set_period_time_near(self->handle, params, &period_time, &dir)) < 0) + goto error; + if ((err = snd_pcm_hw_params(self->handle, params)) < 0) + goto error; +diff --git a/src/audio_priv.h b/src/audio_priv.h +index 0c2ce3c..dbccb1c 100644 +--- a/src/audio_priv.h ++++ b/src/audio_priv.h +@@ -52,10 +52,7 @@ struct audio_object + int error); + }; + +-/* We try to aim for 10ms cancelation latency, which will be perceived as +- * "snappy" by users. However, some systems (e.g. RPi) do produce chopped +- * audio when this value is smaller than 60. +- */ ++/* 60ms is the minimum and default buffer size used by eSpeak */ + #define LATENCY 60 + + #if defined(_WIN32) || defined(_WIN64) +diff --git a/src/pulseaudio.c b/src/pulseaudio.c +index 2f80c62..da6c49f 100644 +--- a/src/pulseaudio.c ++++ b/src/pulseaudio.c +@@ -80,7 +80,7 @@ pulseaudio_object_open(struct audio_object *object, + battr.maxlength = (uint32_t) -1; + battr.minreq = (uint32_t) -1; + battr.prebuf = (uint32_t) -1; +- battr.tlength = pa_bytes_per_second(&self->ss) * LATENCY / 1000; ++ battr.tlength = pa_usec_to_bytes(LATENCY * 1000, &self->ss); + self->s = pa_simple_new(NULL, + self->application_name, + PA_STREAM_PLAYBACK, +-- +2.35.1 + diff --git a/media-libs/pcaudiolib/files/0003-Copy-audio-buffer-and-send-for-playback-without-bloc.patch b/media-libs/pcaudiolib/files/0003-Copy-audio-buffer-and-send-for-playback-without-bloc.patch new file mode 100644 index 000000000000..5bc4eddc7edd --- /dev/null +++ b/media-libs/pcaudiolib/files/0003-Copy-audio-buffer-and-send-for-playback-without-bloc.patch @@ -0,0 +1,118 @@ +From e0ff53614074feabc637598000f5799b480179c3 Mon Sep 17 00:00:00 2001 +From: zment <jani.karkkainen@gmail.com> +Date: Tue, 16 Aug 2022 20:18:31 +0300 +Subject: [PATCH] Copy audio buffer and send for playback without blocking, + fixes Windows audio choppyness + +--- + src/xaudio2.cpp | 60 +++++++++++++++++++++++++++++++++++++++++-------- + 1 file changed, 51 insertions(+), 9 deletions(-) + +diff --git a/src/xaudio2.cpp b/src/xaudio2.cpp +index 72190b4..bb9d5be 100644 +--- a/src/xaudio2.cpp ++++ b/src/xaudio2.cpp +@@ -35,6 +35,25 @@ struct xaudio2_object + LPWSTR devicename; + }; + ++class VoiceCallbacks : public IXAudio2VoiceCallback ++{ ++public: ++ void OnBufferEnd(void* pBufferContext) { ++ if (pBufferContext != NULL) ++ { ++ free((void*)pBufferContext); ++ } ++ } ++ ++ // Stubs for all interface callbacks ++ void OnStreamEnd() { } ++ void OnVoiceProcessingPassEnd() { } ++ void OnVoiceProcessingPassStart(UINT32 SamplesRequired) { } ++ void OnBufferStart(void* pBufferContext) { } ++ void OnLoopEnd(void* pBufferContext) { } ++ void OnVoiceError(void* pBufferContext, HRESULT Error) { } ++} voiceCallbacks; ++ + void + xaudio2_object_close(struct audio_object *object); + +@@ -59,7 +78,7 @@ xaudio2_object_open(struct audio_object *object, + if (FAILED(hr)) + goto error; + +- hr = self->audio->CreateSourceVoice(&self->source, self->format); ++ hr = self->audio->CreateSourceVoice(&self->source, self->format, 0, 2.0f, &voiceCallbacks); + if (FAILED(hr)) + goto error; + +@@ -110,6 +129,16 @@ xaudio2_object_drain(struct audio_object *object) + { + struct xaudio2_object *self = to_xaudio2_object(object); + ++ while (true) ++ { ++ Sleep(10); ++ ++ XAUDIO2_VOICE_STATE state = { 0 }; ++ self->source->GetState(&state); ++ if (state.pCurrentBufferContext == NULL && state.BuffersQueued == 0) ++ break; ++ } ++ + return S_OK; + } + +@@ -128,27 +157,40 @@ xaudio2_object_write(struct audio_object *object, + { + struct xaudio2_object *self = to_xaudio2_object(object); + +- XAUDIO2_BUFFER buffer = {0}; ++ BYTE* buf_data = (BYTE *)malloc(bytes); ++ memcpy(buf_data, data, bytes); ++ ++ XAUDIO2_BUFFER buffer = { 0 }; + buffer.AudioBytes = bytes; +- buffer.pAudioData = (const BYTE *)data; ++ buffer.pAudioData = buf_data; ++ buffer.pContext = buf_data; + + HRESULT hr = S_OK; + if (SUCCEEDED(hr)) + hr = self->source->SubmitSourceBuffer(&buffer); + +- if (SUCCEEDED(hr)) +- hr = self->source->Start(0); ++ XAUDIO2_VOICE_STATE state = { 0 }; ++ self->source->GetState(&state); ++ UINT32 buffersQueued = state.BuffersQueued; + +- if (SUCCEEDED(hr)) while (true) ++ while (FAILED(hr)) + { + Sleep(10); + +- XAUDIO2_VOICE_STATE state = { 0 }; + self->source->GetState(&state); +- if (state.pCurrentBufferContext == NULL && state.BuffersQueued == 0) +- return hr; ++ if (state.BuffersQueued < buffersQueued) ++ { ++ hr = self->source->SubmitSourceBuffer(&buffer); ++ ++ self->source->GetState(&state); ++ buffersQueued = state.BuffersQueued; ++ } + } + ++ ++ if (SUCCEEDED(hr)) ++ hr = self->source->Start(0); ++ + return hr; + } + +-- +2.35.1 + diff --git a/media-libs/pcaudiolib/pcaudiolib-1.2-r1.ebuild b/media-libs/pcaudiolib/pcaudiolib-1.2-r1.ebuild new file mode 100644 index 000000000000..6525aa93e2a9 --- /dev/null +++ b/media-libs/pcaudiolib/pcaudiolib-1.2-r1.ebuild @@ -0,0 +1,51 @@ +# Copyright 1999-2022 Gentoo Authors +# Distributed under the terms of the GNU General Public License v2 + +EAPI=8 + +inherit autotools + +DESCRIPTION="Portable C Audio Library" +HOMEPAGE="https://github.com/espeak-ng/pcaudiolib" +SRC_URI="https://github.com/espeak-ng/pcaudiolib/archive/${PV}.tar.gz -> ${P}.tar.gz" + +LICENSE="GPL-3+ ZLIB" +SLOT="0" +KEYWORDS="~alpha ~amd64 ~arm ~arm64 ~hppa ~ia64 ~loong ~ppc ~ppc64 ~riscv ~sparc ~x86" +IUSE="+alsa oss pulseaudio" + +REQUIRED_USE="|| ( alsa oss pulseaudio )" + +RDEPEND=" + alsa? ( >=media-libs/alsa-lib-1.0.18 ) + pulseaudio? ( media-sound/pulseaudio ) +" +DEPEND="${RDEPEND}" +BDEPEND="virtual/pkgconfig" + +PATCHES=( + "${FILESDIR}/0001-Fix-audio-choppiness-on-some-systems.patch" + "${FILESDIR}/0002-Fix-latency-related-buffer-sizing.patch" + "${FILESDIR}/0003-Copy-audio-buffer-and-send-for-playback-without-bloc.patch" + ) + +src_prepare() { + default + eautoreconf +} + +src_configure() { + local econf_args + econf_args=( + $(use_with oss) + $(use_with alsa) + $(use_with pulseaudio) + --disable-static + ) + econf "${econf_args[@]}" +} + +src_install() { + default + find "${ED}" -name '*.la' -delete || die +} |