From 689f550049e7eb4db3bb3f085d5a80c4c29b83c5 Mon Sep 17 00:00:00 2001 From: badaix Date: Mon, 10 Feb 2020 21:45:05 +0100 Subject: [PATCH] Uncomment resampling --- client/stream.cpp | 90 ++++++++++++++++++++++++----------------------- client/stream.hpp | 8 ++--- 2 files changed, 50 insertions(+), 48 deletions(-) diff --git a/client/stream.cpp b/client/stream.cpp index 3744e7b7..93850427 100644 --- a/client/stream.cpp +++ b/client/stream.cpp @@ -36,9 +36,9 @@ Stream::Stream(const SampleFormat& sampleFormat) miniBuffer_.setSize(20); // cardBuffer_.setSize(50); - input_rate_ = format_.rate; - format_.rate = 48000; - output_rate_ = static_cast(format_.rate); + // input_rate_ = format_.rate; + // format_.rate = 48000; + // output_rate_ = static_cast(format_.rate); /* 48000 x ------- = ----- @@ -46,16 +46,16 @@ Stream::Stream(const SampleFormat& sampleFormat) x = 1,000016667 / (1,000016667 - 1) */ - // setRealSampleRate(format_.rate); + setRealSampleRate(format_.rate); - soxr_error_t error; - soxr_io_spec_t iospec = soxr_io_spec(SOXR_INT16_I, SOXR_INT16_I); - soxr_quality_spec_t q_spec = soxr_quality_spec(SOXR_HQ, 0); - soxr_ = soxr_create(static_cast(input_rate_), static_cast(format_.rate), format_.channels, &error, &iospec, &q_spec, NULL); - if (error) - { - LOG(ERROR) << "Error soxr_create: " << error << "\n"; - } + // soxr_error_t error; + // soxr_io_spec_t iospec = soxr_io_spec(SOXR_INT16_I, SOXR_INT16_I); + // soxr_quality_spec_t q_spec = soxr_quality_spec(SOXR_HQ, 0); + // soxr_ = soxr_create(static_cast(input_rate_), static_cast(format_.rate), format_.channels, &error, &iospec, &q_spec, NULL); + // if (error) + // { + // LOG(ERROR) << "Error soxr_create: " << error << "\n"; + // } } @@ -89,39 +89,41 @@ void Stream::addChunk(msg::PcmChunk* chunk) while (chunks_.size() * chunk->duration().count() > 10000) chunks_.pop(); - if (std::abs(input_rate_ - output_rate_) <= 0.0000001) - { - chunks_.push(shared_ptr(chunk)); - } - else - { - size_t idone; - size_t odone; - auto out = new msg::PcmChunk(format_, 0); - out->timestamp = chunk->timestamp; - out->payloadSize = ceil(chunk->payloadSize * static_cast(output_rate_) / static_cast(input_rate_)); - out->payload = (char*)malloc(out->payloadSize); + chunks_.push(shared_ptr(chunk)); + // LOG(DEBUG) << "new chunk: " << chunk->duration().count() << ", Chunks: " << chunks_.size() << "\n"; - soxr_io_spec_t iospec = soxr_io_spec(SOXR_INT16_I, SOXR_INT16_I); - soxr_quality_spec_t q_spec = soxr_quality_spec(SOXR_HQ, 0); - // auto error = soxr_oneshot(static_cast(input_rate_), output_rate_, format_.channels, chunk->payload, chunk->getFrameCount(), &idone, - // out->payload, out->payloadSize, &odone, &iospec, &q_spec, nullptr); - auto error = soxr_process(soxr_, chunk->payload, chunk->getFrameCount(), &idone, out->payload, out->getFrameCount(), &odone); - if (error) - { - LOG(ERROR) << "Error soxr_process: " << error << "\n"; - delete out; - } - else - { - out->payloadSize = odone * out->format.frameSize; - LOG(TRACE) << "Resample idone: " << idone << "/" << chunk->getFrameCount() << ", odone: " << odone << "/" - << out->payloadSize / out->format.frameSize << "\n"; - chunks_.push(shared_ptr(out)); - } - delete chunk; - } - LOG(TRACE) << "new chunk: " << chunk->duration().count() << ", Chunks: " << chunks_.size() << "\n"; + // if (std::abs(input_rate_ - output_rate_) <= 0.0000001) + // { + // chunks_.push(shared_ptr(chunk)); + // } + // else + // { + // size_t idone; + // size_t odone; + // auto out = new msg::PcmChunk(format_, 0); + // out->timestamp = chunk->timestamp; + // out->payloadSize = ceil(chunk->payloadSize * static_cast(output_rate_) / static_cast(input_rate_)); + // out->payload = (char*)malloc(out->payloadSize); + + // soxr_io_spec_t iospec = soxr_io_spec(SOXR_INT16_I, SOXR_INT16_I); + // soxr_quality_spec_t q_spec = soxr_quality_spec(SOXR_HQ, 0); + // // auto error = soxr_oneshot(static_cast(input_rate_), output_rate_, format_.channels, chunk->payload, chunk->getFrameCount(), &idone, + // // out->payload, out->payloadSize, &odone, &iospec, &q_spec, nullptr); + // auto error = soxr_process(soxr_, chunk->payload, chunk->getFrameCount(), &idone, out->payload, out->getFrameCount(), &odone); + // if (error) + // { + // LOG(ERROR) << "Error soxr_process: " << error << "\n"; + // delete out; + // } + // else + // { + // out->payloadSize = odone * out->format.frameSize; + // LOG(TRACE) << "Resample idone: " << idone << "/" << chunk->getFrameCount() << ", odone: " << odone << "/" + // << out->payloadSize / out->format.frameSize << "\n"; + // chunks_.push(shared_ptr(out)); + // } + // delete chunk; + // } } diff --git a/client/stream.hpp b/client/stream.hpp index 74d0924e..0d789758 100644 --- a/client/stream.hpp +++ b/client/stream.hpp @@ -26,7 +26,7 @@ #include "message/pcm_chunk.hpp" #include #include -#include +// #include /// Time synchronized audio stream @@ -84,9 +84,9 @@ private: unsigned long playedFrames_; long correctAfterXFrames_; chronos::msec bufferMs_; - size_t input_rate_; - double output_rate_; - soxr_t soxr_; + // size_t input_rate_; + // double output_rate_; + // soxr_t soxr_; };