Merge pull request #279 from jpcima/fft-odd-fix
Ensure to pass FFT an even-sized buffer
This commit is contained in:
commit
d365c6953c
2 changed files with 11 additions and 1 deletions
|
|
@ -28,7 +28,7 @@ namespace sfz
|
||||||
*/
|
*/
|
||||||
template <class Type, size_t MaxChannels = sfz::config::numChannels,
|
template <class Type, size_t MaxChannels = sfz::config::numChannels,
|
||||||
unsigned int Alignment = SIMDConfig::defaultAlignment,
|
unsigned int Alignment = SIMDConfig::defaultAlignment,
|
||||||
size_t PaddingLeft_ = 0, size_t PaddingRight = 0>
|
size_t PaddingLeft_ = 0, size_t PaddingRight_ = 0>
|
||||||
class AudioBuffer {
|
class AudioBuffer {
|
||||||
public:
|
public:
|
||||||
using value_type = typename std::remove_cv<Type>::type;
|
using value_type = typename std::remove_cv<Type>::type;
|
||||||
|
|
@ -40,6 +40,8 @@ public:
|
||||||
enum {
|
enum {
|
||||||
//! Increased left padding to preserve required alignment
|
//! Increased left padding to preserve required alignment
|
||||||
PaddingLeft = PaddingLeft_ + (Alignment - (PaddingLeft_ % Alignment)) % Alignment,
|
PaddingLeft = PaddingLeft_ + (Alignment - (PaddingLeft_ % Alignment)) % Alignment,
|
||||||
|
//! Padding to the right
|
||||||
|
PaddingRight = PaddingRight_,
|
||||||
//! Total padding left and right
|
//! Total padding left and right
|
||||||
PaddingTotal = PaddingLeft + PaddingRight,
|
PaddingTotal = PaddingLeft + PaddingRight,
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,7 @@
|
||||||
#include "Wavetables.h"
|
#include "Wavetables.h"
|
||||||
#include "FilePool.h"
|
#include "FilePool.h"
|
||||||
#include "MathHelpers.h"
|
#include "MathHelpers.h"
|
||||||
|
#include "absl/meta/type_traits.h"
|
||||||
#include <kiss_fftr.h>
|
#include <kiss_fftr.h>
|
||||||
|
|
||||||
namespace sfz {
|
namespace sfz {
|
||||||
|
|
@ -373,6 +374,13 @@ bool WavetablePool::createFileWave(FilePool& filePool, const std::string& filena
|
||||||
DBG("[sfizz] Only the first channel of " << filename << " will be used to create the wavetable");
|
DBG("[sfizz] Only the first channel of " << filename << " will be used to create the wavetable");
|
||||||
|
|
||||||
auto audioData = fileHandle->preloadedData->getConstSpan(0);
|
auto audioData = fileHandle->preloadedData->getConstSpan(0);
|
||||||
|
|
||||||
|
// an even size is required for FFT
|
||||||
|
static_assert(absl::remove_reference_t<decltype(*fileHandle->preloadedData)>::PaddingRight > 0,
|
||||||
|
"Right padding is required on the audio file buffer");
|
||||||
|
if (audioData.size() & 1)
|
||||||
|
audioData = absl::MakeConstSpan(audioData.data(), audioData.size() + 1);
|
||||||
|
|
||||||
size_t fftSize = audioData.size();
|
size_t fftSize = audioData.size();
|
||||||
size_t specSize = fftSize / 2 + 1;
|
size_t specSize = fftSize / 2 + 1;
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue