Audacity 3.2.0
PowerSpectrumGetter.cpp
Go to the documentation of this file.
1/* SPDX-License-Identifier: GPL-2.0-or-later */
2/*!********************************************************************
3
4 Audacity: A Digital Audio Editor
5
6 PowerSpectrumGetter.cpp
7
8 Matthieu Hodgkinson
9
10**********************************************************************/
11#include "PowerSpectrumGetter.h"
12
13#include <cassert>
14#include <pffft.h>
15
17{
18 pffft_destroy_setup(p);
19}
20
22{
23 return pffft_aligned_malloc(nb_bytes);
24}
25
27{
28 pffft_aligned_free(p);
29}
30
32{
33 return PffftFloats{ data() + c };
34}
35
37{
38 return PffftConstFloats{ data() + c };
39}
40
42 : mFftSize { fftSize }
43 , mSetup { pffft_new_setup(fftSize, PFFFT_REAL) }
44 , mWork(fftSize)
45{
46}
47
49{
50}
51
53 PffftFloats alignedBuffer, PffftFloats alignedOutput)
54{
55 const auto buffer = alignedBuffer.get();
56 const auto output = alignedOutput.get();
57 pffft_transform_ordered(mSetup.get(),
58 buffer, buffer, mWork.data(), PFFFT_FORWARD);
59 output[0] = buffer[0] * buffer[0];
60 for (auto i = 1; i < mFftSize / 2; ++i)
61 output[i] =
62 buffer[i * 2] * buffer[i * 2] + buffer[i * 2 + 1] * buffer[i * 2 + 1];
63 output[mFftSize / 2] = buffer[1] * buffer[1];
64}
PffftFloatVector mWork
PowerSpectrumGetter(int fftSize)
PffftSetupHolder mSetup
void operator()(PffftFloats alignedBuffer, PffftFloats alignedOutput)
Computes the power spectrum of buffer into output.
static void Pffft_aligned_free(void *)
static void * Pffft_aligned_malloc(size_t nb_bytes)
A read-only pointer to an aligned range of floats.
PffftFloats aligned(PffftAlignedCount c={})
A pointer to an aligned range of floats.
float * get() const noexcept
void Pffft_destroy_setup(PFFFT_Setup *)