mirror of
https://github.com/badaix/snapcast.git
synced 2025-05-22 21:46:15 +02:00
Resampling can use original rate or bit depth
This commit is contained in:
parent
0de2bbde36
commit
de75ad9b2c
4 changed files with 22 additions and 6 deletions
|
@ -33,6 +33,7 @@
|
|||
#include "client_settings.hpp"
|
||||
#include "common/aixlog.hpp"
|
||||
#include "common/signal_handler.hpp"
|
||||
#include "common/snap_exception.hpp"
|
||||
#include "common/str_compat.hpp"
|
||||
#include "common/utils.hpp"
|
||||
#include "metadata.hpp"
|
||||
|
@ -105,7 +106,7 @@ int main(int argc, char** argv)
|
|||
/*auto instanceValue =*/op.add<Value<size_t>>("i", "instance", "instance id", 1, &settings.instance);
|
||||
/*auto hostIdValue =*/op.add<Value<string>>("", "hostID", "unique host id", "", &settings.host_id);
|
||||
op.add<Value<string>>("", "player", "audio backend", "", &settings.player.player_name);
|
||||
auto sample_format = op.add<Value<string>>("", "sampleformat", "resample audio stream to sampleformat", "");
|
||||
auto sample_format = op.add<Value<string>>("", "sampleformat", "resample audio stream to <rate>:<bits>:<channels>", "");
|
||||
|
||||
try
|
||||
{
|
||||
|
@ -213,6 +214,11 @@ int main(int argc, char** argv)
|
|||
if (sample_format->is_set())
|
||||
{
|
||||
settings.player.sample_format = SampleFormat(sample_format->value());
|
||||
if (settings.player.sample_format.channels() != 2)
|
||||
throw SnapException("sampleformat channels must be 2");
|
||||
auto bits = settings.player.sample_format.bits();
|
||||
if ((bits != 0) && (bits != 16) && (bits != 24) && (bits != 32))
|
||||
throw SnapException("sampleformat bits must be 0, 16, 24, 32");
|
||||
}
|
||||
|
||||
bool active = true;
|
||||
|
|
|
@ -38,10 +38,12 @@ Stream::Stream(const SampleFormat& in_format, const SampleFormat& out_format)
|
|||
shortBuffer_.setSize(100);
|
||||
miniBuffer_.setSize(20);
|
||||
|
||||
if (out_format.rate() != 0)
|
||||
format_ = out_format;
|
||||
else
|
||||
format_ = in_format_;
|
||||
format_ = in_format_;
|
||||
if (out_format.isInitialized())
|
||||
{
|
||||
format_.setFormat(out_format.rate() != 0 ? out_format.rate() : format_.rate(), out_format.bits() != 0 ? out_format.bits() : format_.bits(),
|
||||
out_format.channels() != 0 ? out_format.channels() : format_.channels());
|
||||
}
|
||||
|
||||
/*
|
||||
48000 x
|
||||
|
|
|
@ -21,6 +21,7 @@
|
|||
#include <vector>
|
||||
|
||||
#include "common/aixlog.hpp"
|
||||
#include "common/snap_exception.hpp"
|
||||
#include "common/str_compat.hpp"
|
||||
#include "common/utils.hpp"
|
||||
#include "common/utils/string_utils.hpp"
|
||||
|
@ -61,7 +62,9 @@ void SampleFormat::setFormat(const std::string& format)
|
|||
std::vector<std::string> strs;
|
||||
strs = utils::string::split(format, ':');
|
||||
if (strs.size() == 3)
|
||||
setFormat(cpt::stoul(strs[0]), cpt::stoul(strs[1]), cpt::stoul(strs[2]));
|
||||
setFormat(strs[0] == "*" ? 0 : cpt::stoul(strs[0]), strs[1] == "*" ? 0 : cpt::stoul(strs[1]), strs[2] == "*" ? 0 : cpt::stoul(strs[2]));
|
||||
else
|
||||
throw SnapException("sampleformat must be <rate>:<bits>:<channels>");
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -46,6 +46,11 @@ public:
|
|||
void setFormat(const std::string& format);
|
||||
void setFormat(uint32_t rate, uint16_t bits, uint16_t channels);
|
||||
|
||||
bool isInitialized() const
|
||||
{
|
||||
return ((rate_ != 0) || (bits_ != 0) || (channels_ != 0));
|
||||
}
|
||||
|
||||
uint32_t rate() const
|
||||
{
|
||||
return rate_;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue