Fill both spectrum channels with data.

This commit is contained in:
Kai Blaschke
2023-03-18 03:10:17 +01:00
parent f88fe7018e
commit df7cd08bdc
3 changed files with 3 additions and 17 deletions

View File

@ -74,6 +74,7 @@ auto BeatDetect::GetFrameAudioData() const -> FrameAudioData
pcm.GetPcm(data.waveformLeft.data(), CHANNEL_L, WaveformSamples);
pcm.GetPcm(data.waveformRight.data(), CHANNEL_R, WaveformSamples);
pcm.GetSpectrum(data.spectrumLeft.data(), CHANNEL_L, SpectrumSamples);
pcm.GetSpectrum(data.spectrumRight.data(), CHANNEL_R, SpectrumSamples);
data.vol = vol;
data.volAtt = volAtt;

View File

@ -102,7 +102,6 @@ void PCM::AddPcm(
max = std::max(std::max(max, std::abs(m_pcmL[j])), std::abs(m_pcmR[j]));
}
m_start = (m_start + count) % maxSamples;
m_newSamples += count;
m_level = m_leveler.UpdateLevel(count, sum / 2, max);
}
@ -180,7 +179,7 @@ void PCM::GetSpectrum(
size_t const samples)
{
assert(channel == 0 || channel == 1);
UpdateFFT();
UpdateFftChannel(channel);
auto const& spectrum = channel == 0 ? m_spectrumL : m_spectrumR;
size_t const count = samples <= fftLength ? samples : fftLength;
@ -200,18 +199,6 @@ void PCM::ResetAutoLevel()
m_level = 1.0f;
}
void PCM::UpdateFFT()
{
if (m_newSamples == 0)
{
return;
}
UpdateFftChannel(0);
UpdateFftChannel(1);
m_newSamples = 0;
}
void PCM::UpdateFftChannel(size_t const channel)
{
assert(channel == 0 || channel == 1);

View File

@ -108,11 +108,9 @@ protected:
void CopyPcm(float* to, size_t channel, size_t count) const;
void CopyPcm(double* to, size_t channel, size_t count) const;
// update FFT data if new samples are available.
void UpdateFFT();
// Updates FFT data
void UpdateFftChannel(size_t channel);
private:
// mem-usage:
// pcmd 2x2048*4b = 16K