1024 サンプルの配列に対して FFT を実行する関数を作成しました。この関数の出力を使用してスペクトログラムをプロットしようとしています。
グラフには非常に一貫性のない入力があり、ほとんどの時間を 0 で費やしており、何かが表示されているときは、音楽とはほとんど関係がないように見えます。デモ用に 2 つのスクリーンショットを含めました。
いくつかのスクリーンショットと、FFT の実行に使用されるコードを含めました。生成された出力が非常に悪い理由について誰か考えがありますか?
また、スペクトログラムのローエンドが「ピーキー」であることにも気付きました。
奇妙な出力:

出力なし (すべての描画フレームの 1/2 から 2/3 で発生):

コード:
// Get the samples
AudioSampleType *samples = [_songModel nextSamplesWithLength: _fftN];
if (samples == nil)
return nil;
// Convert AudioSampleTypes (SInt16s) into floats between -1.0 and 1.0
// (required by the DSP library).
for (int i = 0; i < _fftN; i++)
_inputReal[i] = (samples[i] + 0.5) / 32767.5;
// Window the input
vDSP_vmul(_inputReal, 1, _hanningWindow, 1, _windowedReal, 1, _fftN);
// Convert our real input into even-odd form
vDSP_ctoz((COMPLEX *)_windowedReal, 2, &_fourierOutput, 1, _fftHalfN);
// Perform the fast fourier transform
vDSP_fft_zrip(_fftSetup, &_fourierOutput, 1, _fftLog2n, FFT_FORWARD);
// Calculate magnitudes (will output to the real part of the COMPLEX_SPLIT)
vDSP_zvmags(&_fourierOutput, 1, _fourierOutput.realp, 1, _fftHalfN);
// Build and return the input and output of the analysis
return [[FrequencyData alloc] initWithSignal:_inputReal
signalLength:_fftN
frequencyMagnitudes:_fourierOutput.realp
magnitudeLength:_fftHalfN];
編集
セットアップ コード:
_fftN = 1 << _fftLog2n;
_fftHalfN = _fftN / 2;
_stride = 1;
_fourierOutput.realp = (float *) malloc(_fftHalfN * sizeof(float));
_fourierOutput.imagp = (float *) malloc(_fftHalfN * sizeof(float));
_hanningWindow = (float *) malloc(_fftN * sizeof(float));
vDSP_hann_window(_hanningWindow, _fftN, 0);
_inputReal = (float *) malloc(_fftN * sizeof(float));
_windowedReal = (float *) malloc(_fftN * sizeof(float));
_fftSetup = vDSP_create_fftsetup(_fftLog2n, FFT_RADIX2);