Former-commit-id: cb3155ca088d24c4515a7e773454010f3e6df1e7 [formerly d9803b6bffbfc1c8d490dd9ae451a363faaaedfc] [formerly eef64e8fdcd1383970286e0756d31383afd0e756 [formerly 7431388ed48a2c516f305834f8f8fed0ad3e56b8]] Former-commit-id: fee589f9cfc45c9a3387e41026f372047886d381 [formerly 9742d88c55031414cba3b54403a61909a9f3c85e] Former-commit-id: f8f6b903238a7cad2946e75d497c22a5be9117c0
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>
|