mirror of
https://github.com/badaix/snapcast.git
synced 2025-07-18 08:57:42 +02:00
swap template function
This commit is contained in:
parent
e06cdc9024
commit
f9c517e99d
3 changed files with 34 additions and 28 deletions
|
@ -60,19 +60,7 @@ PcmDecoder::PcmDecoder() : Decoder()
|
|||
|
||||
bool PcmDecoder::decode(msg::PcmChunk* chunk)
|
||||
{
|
||||
/* int16_t* bufferT = (int16_t*)chunk->payload;
|
||||
for (size_t n=0; n<chunk->getSampleCount(); ++n)
|
||||
{
|
||||
bufferT[n] = SWAP_16(bufferT[n]);
|
||||
}
|
||||
|
||||
if (sampleFormat.bits == 8)
|
||||
adjustVolume<int8_t>(buffer, frames*sampleFormat.channels, volume);
|
||||
else if (sampleFormat.bits == 16)
|
||||
adjustVolume<int16_t>(buffer, frames*sampleFormat.channels, volume);
|
||||
else if (sampleFormat.bits == 32)
|
||||
adjustVolume<int32_t>(buffer, frames*sampleFormat.channels, volume);
|
||||
*/ return true;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -52,21 +52,8 @@ protected:
|
|||
void adjustVolume(char *buffer, size_t count, double volume)
|
||||
{
|
||||
T* bufferT = (T*)buffer;
|
||||
if (sizeof(T) == 1)
|
||||
{
|
||||
for (size_t n=0; n<count; ++n)
|
||||
bufferT[n] = bufferT[n] * volume;
|
||||
}
|
||||
else if (sizeof(T) == 2)
|
||||
{
|
||||
for (size_t n=0; n<count; ++n)
|
||||
bufferT[n] = (T)(SWAP_16(((T)SWAP_16(bufferT[n])) * volume));
|
||||
}
|
||||
else if (sizeof(T) == 4)
|
||||
{
|
||||
for (size_t n=0; n<count; ++n)
|
||||
bufferT[n] = (T)(SWAP_32(((T)SWAP_32(bufferT[n])) * volume));
|
||||
}
|
||||
bufferT[n] = endian::swap<T>(endian::swap<T>(bufferT[n]) * volume);
|
||||
}
|
||||
|
||||
void adjustVolume(char* buffer, size_t frames);
|
||||
|
|
|
@ -11,6 +11,37 @@
|
|||
# define SWAP_64(x) x
|
||||
#endif
|
||||
|
||||
namespace endian
|
||||
{
|
||||
|
||||
template <typename T>
|
||||
T swap(const T&);
|
||||
|
||||
template <>
|
||||
inline int8_t swap(const int8_t& val)
|
||||
{
|
||||
return val;
|
||||
}
|
||||
|
||||
template <>
|
||||
inline int16_t swap(const int16_t& val)
|
||||
{
|
||||
return SWAP_16(val);
|
||||
}
|
||||
|
||||
template <>
|
||||
inline int32_t swap(const int32_t& val)
|
||||
{
|
||||
return SWAP_32(val);
|
||||
}
|
||||
|
||||
template <>
|
||||
inline int64_t swap(const int64_t& val)
|
||||
{
|
||||
return SWAP_64(val);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue