Former-commit-id: 9ed6d64e771e77d03b91060823efb4236739914b [formerly 0efc1b14cd61f3d33fc642dbe4eb6bf05d58ec7e] [formerly dbc079525b48a2efb8a7917b4b376a318f8d5fae [formerly 7c202e02ac2a8b745208e1b852ff44d2169ebaf0]] Former-commit-id: 27a65bcbd5e499dcc741f76a5c0a31bc9ae09e60 [formerly 97ed7176fd1f0f906229d19e68aedc335a7ca420] Former-commit-id: 1779855a4f20dc4216648aaed59542fd8c6d7bc8
40 lines
1.2 KiB
C++
40 lines
1.2 KiB
C++
// Copyright (C) 2015 Jérôme Leclercq
|
|
// This file is part of the "Nazara Engine - Audio module"
|
|
// For conditions of distribution and use, see copyright notice in Config.hpp
|
|
|
|
#include <Nazara/Core/Error.hpp>
|
|
#include <Nazara/Audio/Debug.hpp>
|
|
|
|
namespace Nz
|
|
{
|
|
/*!
|
|
* \ingroup audio
|
|
* \brief Mixes channels in mono
|
|
*
|
|
* \param input Input buffer with multiples channels
|
|
* \param output Output butter for mono
|
|
* \param channelCount Number of channels
|
|
* \param frameCount Number of frames
|
|
*
|
|
* \remark The input buffer may be the same as the output one
|
|
*/
|
|
template<typename T>
|
|
void MixToMono(T* input, T* output, UInt32 channelCount, UInt64 frameCount)
|
|
{
|
|
// To avoid overflow, we use, as an accumulator, a type which is large enough: (u)int 64 bits for integers, double for floatings
|
|
typedef typename std::conditional<std::is_unsigned<T>::value, UInt64, Int64>::type BiggestInt;
|
|
typedef typename std::conditional<std::is_integral<T>::value, BiggestInt, double>::type Biggest;
|
|
|
|
for (UInt64 i = 0; i < frameCount; ++i)
|
|
{
|
|
Biggest acc = Biggest(0);
|
|
for (UInt32 j = 0; j < channelCount; ++j)
|
|
acc += input[i * channelCount + j];
|
|
|
|
output[i] = static_cast<T>(acc / channelCount);
|
|
}
|
|
}
|
|
}
|
|
|
|
#include <Nazara/Audio/DebugOff.hpp>
|