mirror of
https://github.com/badaix/snapcast.git
synced 2025-06-13 00:01:52 +02:00
Merge branch 'resample' into develop
This commit is contained in:
commit
d77d4dadd5
3 changed files with 57 additions and 3 deletions
|
@ -46,6 +46,12 @@ else()
|
||||||
endif (ALSA_FOUND)
|
endif (ALSA_FOUND)
|
||||||
endif (MACOSX)
|
endif (MACOSX)
|
||||||
|
|
||||||
|
pkg_search_module(SOXR soxr)
|
||||||
|
if (SOXR_FOUND)
|
||||||
|
list(APPEND CLIENT_LIBRARIES ${SOXR_LIBRARIES})
|
||||||
|
list(APPEND CLIENT_INCLUDE ${SOXR_INCLUDE_DIRS})
|
||||||
|
endif (SOXR_FOUND)
|
||||||
|
|
||||||
# if OGG then tremor or vorbis
|
# if OGG then tremor or vorbis
|
||||||
if (OGG_FOUND)
|
if (OGG_FOUND)
|
||||||
list(APPEND CLIENT_SOURCES decoder/ogg_decoder.cpp)
|
list(APPEND CLIENT_SOURCES decoder/ogg_decoder.cpp)
|
||||||
|
|
|
@ -36,6 +36,9 @@ Stream::Stream(const SampleFormat& sampleFormat)
|
||||||
miniBuffer_.setSize(20);
|
miniBuffer_.setSize(20);
|
||||||
// cardBuffer_.setSize(50);
|
// cardBuffer_.setSize(50);
|
||||||
|
|
||||||
|
input_rate_ = format_.rate;
|
||||||
|
format_.rate = 48000;
|
||||||
|
output_rate_ = static_cast<double>(format_.rate);
|
||||||
/*
|
/*
|
||||||
48000 x
|
48000 x
|
||||||
------- = -----
|
------- = -----
|
||||||
|
@ -43,7 +46,16 @@ Stream::Stream(const SampleFormat& sampleFormat)
|
||||||
|
|
||||||
x = 1,000016667 / (1,000016667 - 1)
|
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<double>(input_rate_), static_cast<double>(format_.rate), format_.channels, &error, &iospec, &q_spec, NULL);
|
||||||
|
if (error)
|
||||||
|
{
|
||||||
|
LOG(ERROR) << "Error soxr_create: " << error << "\n";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -76,8 +88,40 @@ void Stream::addChunk(msg::PcmChunk* chunk)
|
||||||
{
|
{
|
||||||
while (chunks_.size() * chunk->duration<cs::msec>().count() > 10000)
|
while (chunks_.size() * chunk->duration<cs::msec>().count() > 10000)
|
||||||
chunks_.pop();
|
chunks_.pop();
|
||||||
chunks_.push(shared_ptr<msg::PcmChunk>(chunk));
|
|
||||||
// LOG(DEBUG) << "new chunk: " << chunk->duration<cs::msec>().count() << ", Chunks: " << chunks_.size() << "\n";
|
if (std::abs(input_rate_ - output_rate_) <= 0.0000001)
|
||||||
|
{
|
||||||
|
chunks_.push(shared_ptr<msg::PcmChunk>(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<double>(output_rate_) / static_cast<double>(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<double>(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<msg::PcmChunk>(out));
|
||||||
|
}
|
||||||
|
delete chunk;
|
||||||
|
}
|
||||||
|
LOG(TRACE) << "new chunk: " << chunk->duration<cs::msec>().count() << ", Chunks: " << chunks_.size() << "\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -26,6 +26,7 @@
|
||||||
#include "message/pcm_chunk.hpp"
|
#include "message/pcm_chunk.hpp"
|
||||||
#include <deque>
|
#include <deque>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
#include <soxr.h>
|
||||||
|
|
||||||
|
|
||||||
/// Time synchronized audio stream
|
/// Time synchronized audio stream
|
||||||
|
@ -83,6 +84,9 @@ private:
|
||||||
unsigned long playedFrames_;
|
unsigned long playedFrames_;
|
||||||
long correctAfterXFrames_;
|
long correctAfterXFrames_;
|
||||||
chronos::msec bufferMs_;
|
chronos::msec bufferMs_;
|
||||||
|
size_t input_rate_;
|
||||||
|
double output_rate_;
|
||||||
|
soxr_t soxr_;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue