Keep playback audio compatible with the Android voice build
This commit is contained in:
1 parent
d905b716c3
commit
f94bfc58b4
2 files changed
+10
-4
No files matched your search
+2
-1
@@ -1,7 +1,8 @@
|
||||
bin_PROGRAMS = utun
|
||||
noinst_LIBRARIES = libutun.a
|
||||
|
||||
EXTRA_DIST = lwip_tcp/COPYING dnsmasq/COPYING dnsmasq/COPYING-v3 routing_layer/address_profile.h routing_layer/route_ping_doc.md
|
||||
EXTRA_DIST = lwip_tcp/COPYING dnsmasq/COPYING dnsmasq/COPYING-v3 routing_layer/address_profile.h routing_layer/route_ping_doc.md \
|
||||
stream/stream_playback_audio.h stream/stream_playback_audio.cpp
|
||||
|
||||
stream_core_files = \
|
||||
stream/stream.h \
|
||||
|
||||
@@ -13,10 +13,14 @@ extern "C" {
|
||||
|
||||
namespace {
|
||||
constexpr unsigned rate = 48000, framesPerPacket = 960, maxFrames = 8192, mapCapacity = 1024;
|
||||
struct Span { double first = 0, last = 0, ptsFirst = 0, ptsLast = 0; };
|
||||
struct Span {
|
||||
double first, last, ptsFirst, ptsLast;
|
||||
Span(double begin = 0, double end = 0, double ptsBegin = 0, double ptsEnd = 0)
|
||||
: first(begin), last(end), ptsFirst(ptsBegin), ptsLast(ptsEnd) {}
|
||||
};
|
||||
double mapped(const Span& span, double position) {
|
||||
if (span.last <= span.first) return span.ptsLast;
|
||||
double fraction = std::clamp((position - span.first) / (span.last - span.first), 0.0, 1.0);
|
||||
double fraction = std::max(0.0, std::min(1.0, (position - span.first) / (span.last - span.first)));
|
||||
return span.ptsFirst + fraction * (span.ptsLast - span.ptsFirst);
|
||||
}
|
||||
}
|
||||
@@ -156,7 +160,8 @@ int stream_playback_audio_pull(struct stream_playback_audio* a, int16_t* pcm, un
|
||||
frames = std::min(frames, std::min(available, a->stretch.numSamples()));
|
||||
if (!frames) return 0;
|
||||
unsigned got = a->stretch.receiveSamples(a->samples, frames);
|
||||
for (unsigned i = 0; i < got * 2; i++) pcm[i] = (int16_t)std::lrint(std::clamp(a->samples[i] * 32767.0f, -32768.0f, 32767.0f));
|
||||
for (unsigned i = 0; i < got * 2; i++)
|
||||
pcm[i] = (int16_t)std::lrint(std::max(-32768.0f, std::min(32767.0f, a->samples[i] * 32767.0f)));
|
||||
double position = a->producedOutput, end = position + got;
|
||||
for (unsigned i = 0; i < a->inputCount && position < end; i++) {
|
||||
const auto& span = a->input[(a->inputHead + i) % mapCapacity];
|
||||
|
||||
Reference in new issue
Block a user