Skip to content

Commit

Permalink
apply windowing function internally
Browse files Browse the repository at this point in the history
  • Loading branch information
charlesneimog committed Sep 24, 2024
1 parent a55764b commit 52c6604
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 11 deletions.
1 change: 1 addition & 0 deletions Sources/OScofo/OScofo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ bool OScofo::ProcessBlock(std::vector<double> &AudioBuffer) {
if (!m_Score.ScoreIsLoaded()) {
return true;
}

m_MIR.GetDescription(AudioBuffer, m_Desc);
m_CurrentScorePosition = m_MDP.GetEvent(m_Desc);
return true;
Expand Down
23 changes: 17 additions & 6 deletions Sources/OScofo/mir.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@
// ╭─────────────────────────────────────╮
// │Constructor and Destructor Functions │
// ╰─────────────────────────────────────╯
OScofoMIR::OScofoMIR(float Sr, float WindowSize, float HopSize) {
OScofoMIR::OScofoMIR(float Sr, float FftSize, float HopSize) {
LOGE() << "OScofoMIR::OScofoMIR";

m_HopSize = HopSize;
m_WindowSize = WindowSize;
m_FftSize = FftSize;
m_Sr = Sr;

int WindowHalf = WindowSize / 2;
m_FFTIn = (double *)fftw_alloc_real(WindowSize);
int WindowHalf = FftSize / 2;
m_FFTIn = (double *)fftw_alloc_real(FftSize);
if (!m_FFTIn) {
throw std::runtime_error("OScofoMIR::OScofoMIR fftw_alloc_real failed");
}
Expand All @@ -25,7 +25,13 @@ OScofoMIR::OScofoMIR(float Sr, float WindowSize, float HopSize) {
throw std::runtime_error("OScofoMIR::OScofoMIR fftw_alloc_complex failed");
}

m_FFTPlan = fftw_plan_dft_r2c_1d(m_WindowSize, m_FFTIn, m_FFTOut, FFTW_MEASURE);
m_FFTPlan = fftw_plan_dft_r2c_1d(m_FftSize, m_FFTIn, m_FFTOut, FFTW_MEASURE);

// blackman
m_WindowingFunc.resize(m_FftSize);
for (int i = 0; i < m_FftSize; i++) {
m_WindowingFunc[i] = 0.5 * (1.0 - cos(2.0 * M_PI * i / (m_FftSize - 1)));
}
}

// ─────────────────────────────────────
Expand Down Expand Up @@ -150,7 +156,12 @@ void OScofoMIR::GetRMS(const std::vector<double> &In, Description &Desc) {
// ╭─────────────────────────────────────╮
// │ Main Function │
// ╰─────────────────────────────────────╯
void OScofoMIR::GetDescription(const std::vector<double> &In, Description &Desc) {
void OScofoMIR::GetDescription(std::vector<double> &In, Description &Desc) {
// apply windowing function
for (int i = 0; i < m_FftSize; i++) {
In[i] *= m_WindowingFunc[i];
}

GetRMS(In, Desc);
GetFFTDescriptions(In, Desc);
}
4 changes: 2 additions & 2 deletions Sources/OScofo/mir.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class OScofoMIR {
void ResetElapsedTime();
void UpdateTempoInEvent();
double TimePrediction();
void GetDescription(const std::vector<double> &In, Description &Desc);
void GetDescription(std::vector<double> &In, Description &Desc);
void GetMidi(double Tunning);
double GetEventTimeElapsed();
double GetTempoInEvent();
Expand All @@ -46,7 +46,7 @@ class OScofoMIR {
void GetRMS(const std::vector<double> &In, Description &Desc);

// Audio
double m_WindowSize;
double m_FftSize;
double m_BlockSize;
double m_HopSize;
double m_Sr;
Expand Down
6 changes: 3 additions & 3 deletions Sources/PureData/o.scofo~.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -175,9 +175,9 @@ static t_int *DspPerform(t_int *w) {
// }
//

for (int i = 0; i < x->FFTSize; i++) {
x->inBuffer[i] *= 0.5 * (1.0 - cos(2.0 * M_PI * i / (x->FFTSize - 1)));
}
// for (int i = 0; i < x->FFTSize; i++) {
// x->inBuffer[i] *= 0.5 * (1.0 - cos(2.0 * M_PI * i / (x->FFTSize - 1)));
// }

bool ok = x->OpenScofo->ProcessBlock(x->inBuffer);
if (!ok) {
Expand Down

0 comments on commit 52c6604

Please sign in to comment.