From 0a9bf851fd942722c53a9696bbe1b560378f8ec0 Mon Sep 17 00:00:00 2001 From: Lynix Date: Sun, 8 Feb 2015 14:35:27 +0100 Subject: [PATCH] (sndfile loader) Removed useless allocation when mixing to mono Former-commit-id: 22a4032bd2edffe51b9d9d823d7a2155a7b9fef5 --- include/Nazara/Audio/Algorithm.inl | 1 + src/Nazara/Audio/Loaders/sndfile/Loader.cpp | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/include/Nazara/Audio/Algorithm.inl b/include/Nazara/Audio/Algorithm.inl index c673d9601..ca4b28575 100644 --- a/include/Nazara/Audio/Algorithm.inl +++ b/include/Nazara/Audio/Algorithm.inl @@ -8,6 +8,7 @@ template void NzMixToMono(T* input, T* output, unsigned int channelCount, unsigned int frameCount) { + ///DOC: Le buffer d'entrée peut être le même que le buffer de sortie // Pour éviter l'overflow, on utilise comme accumulateur un type assez grand, (u)int 64 bits pour les entiers, double pour les flottants typedef typename std::conditional::value, nzUInt64, nzInt64>::type BiggestInt; typedef typename std::conditional::value, BiggestInt, double>::type Biggest; diff --git a/src/Nazara/Audio/Loaders/sndfile/Loader.cpp b/src/Nazara/Audio/Loaders/sndfile/Loader.cpp index 0d81f961e..2c70f198b 100644 --- a/src/Nazara/Audio/Loaders/sndfile/Loader.cpp +++ b/src/Nazara/Audio/Loaders/sndfile/Loader.cpp @@ -363,8 +363,8 @@ namespace // Une conversion en mono est-elle nécessaire ? if (parameters.forceMono && format != nzAudioFormat_Mono) { - std::unique_ptr monoSamples(new nzInt16[info.frames]); - NzMixToMono(samples.get(), monoSamples.get(), info.channels, info.frames); + // Nous effectuons la conversion en mono dans le même buffer (il va de toute façon être copié) + NzMixToMono(monoSamples.get(), monoSamples.get(), info.channels, info.frames); format = nzAudioFormat_Mono; samples = std::move(monoSamples);