mirror of
https://github.com/mudita/MuditaOS.git
synced 2026-01-16 10:00:03 -05:00
Add voice transcoding during phone call with two basic transforms: - sample rate downscaling by a factor of 2 with a decimator - sample rate upscaling by a factor of 2 with an interpolator (no low-pass filter) Signed-off-by: Marcin Smoczyński <smoczynski.marcin@gmail.com>
125 lines
2.2 KiB
C++
125 lines
2.2 KiB
C++
// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved.
|
|
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md
|
|
|
|
#include "TestStream.hpp"
|
|
|
|
#include <Audio/AbstractStream.hpp>
|
|
|
|
#include <memory>
|
|
#include <utility>
|
|
|
|
using ::audio::AbstractStream;
|
|
using testing::audio::TestStream;
|
|
|
|
TestStream::TestStream(std::size_t blockSize) : bufSize(blockSize)
|
|
{
|
|
data = std::make_unique<std::uint8_t[]>(bufSize);
|
|
}
|
|
|
|
const AbstractStream::Span TestStream::getDataSpan() const
|
|
{
|
|
return AbstractStream::Span{data.get(), bufSize};
|
|
}
|
|
|
|
bool TestStream::push(void *data, std::size_t dataSize)
|
|
{
|
|
return true;
|
|
}
|
|
|
|
bool TestStream::push(const AbstractStream::Span &span)
|
|
{
|
|
if (span.dataSize != bufSize) {
|
|
return false;
|
|
}
|
|
|
|
for (std::size_t i = 0; i < span.dataSize; i++) {
|
|
data.get()[i] = span.data[i];
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
bool TestStream::push()
|
|
{
|
|
return true;
|
|
}
|
|
|
|
bool TestStream::pop(AbstractStream::Span &span)
|
|
{
|
|
return true;
|
|
}
|
|
|
|
bool TestStream::reserve(AbstractStream::Span &span)
|
|
{
|
|
span = Span{.data = data.get(), .dataSize = bufSize};
|
|
return true;
|
|
}
|
|
|
|
void TestStream::commit()
|
|
{}
|
|
|
|
void TestStream::release()
|
|
{}
|
|
|
|
bool TestStream::peek(AbstractStream::Span &span)
|
|
{
|
|
return true;
|
|
}
|
|
|
|
void TestStream::consume()
|
|
{}
|
|
|
|
void TestStream::unpeek()
|
|
{}
|
|
|
|
void TestStream::reset()
|
|
{}
|
|
|
|
void TestStream::setData(uint8_t value)
|
|
{
|
|
for (std::size_t i = 0; i < bufSize; i++) {
|
|
data.get()[i] = value;
|
|
}
|
|
}
|
|
|
|
bool TestStream::checkData(const Span &span)
|
|
{
|
|
if (span.dataSize != bufSize) {
|
|
return false;
|
|
}
|
|
|
|
for (std::size_t i = 0; i < bufSize; i++) {
|
|
if (data.get()[i] != span.data[i]) {
|
|
return false;
|
|
}
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
void TestStream::registerListener(EventListener *listener)
|
|
{}
|
|
|
|
void TestStream::unregisterListeners(EventListener *listener)
|
|
{}
|
|
|
|
auto TestStream::getInputTraits() const noexcept -> Traits
|
|
{
|
|
return Traits{.blockSize = bufSize, .format = ::audio::nullFormat};
|
|
}
|
|
|
|
auto TestStream::getOutputTraits() const noexcept -> Traits
|
|
{
|
|
return Traits{.blockSize = bufSize, .format = ::audio::nullFormat};
|
|
}
|
|
|
|
bool TestStream::isEmpty() const noexcept
|
|
{
|
|
return false;
|
|
}
|
|
|
|
bool TestStream::isFull() const noexcept
|
|
{
|
|
return false;
|
|
}
|