Cameron1470 / audio-programming-drone

Audio Programming - Assignment 2 / Drone Challenge
0 stars 0 forks source link

No Audio #2

Open mhamilt opened 3 years ago

mhamilt commented 3 years ago

Pretty fundamental issue, so let's start here.

https://github.com/Cameron1470/AudioProgrammingDrone/blob/55b52cde13aaadf4e67ba006504180ef3bf32d10/Source/PluckedNote.cpp#L48-L70

The wave table setup looks okay, there are perhaps more elegant solutions.

I'd recommend maybe changing this to just a standard array to start. You know the size wtSize, so instead of

https://github.com/Cameron1470/AudioProgrammingDrone/blob/55b52cde13aaadf4e67ba006504180ef3bf32d10/Source/PluckedNote.h#L53

use

float* waveTable;

instead of

https://github.com/Cameron1470/AudioProgrammingDrone/blob/55b52cde13aaadf4e67ba006504180ef3bf32d10/Source/PluckedNote.cpp#L48

waveTable = new float[wtSize]

or for a little more safety if run generateNote() more than once.

if(waveTable != nullptr)
{
  delete[] waveTable;
}
waveTable = new float[wtSize]

for the process

https://github.com/Cameron1470/AudioProgrammingDrone/blob/55b52cde13aaadf4e67ba006504180ef3bf32d10/Source/PluckedNote.cpp#L75-L86

It should probably be something like

Instead of

https://github.com/Cameron1470/AudioProgrammingDrone/blob/55b52cde13aaadf4e67ba006504180ef3bf32d10/Source/PluckedNote.h#L51

int currentSampleIndex = 0;

and

float PluckedNote::process()
{
  float sample = waveTable[currentSampleIndex];
  currentSampleIndex++;
  currentSampleIndex %= wtSize;

  return sample;
}
mhamilt commented 3 years ago

After that, try and run it in a basic Command Line App

mhamilt commented 3 years ago
// dynamics filter loop
  for (int n = 0; n < (N + 1); n++)
  {
    x0 = (1 - dynParam) * v[n] + (dynParam * x1);
    y[n] = x0;
    x1 = x0;
  }

  int yp1 = 0;                                // initializing previous output of allpas filter
  int yp0;                                    // initializing current output of allpass filter

  // karplus-strong algorithm loop
  for (int n = (N + 1); n < wtSize; n++)
  {
    yp0 = C * (y[(n - N)] - yp1) + y[(n - N - 1)];
    y[n] = (rho * 0.5f) * (yp0 + yp1);    
    yp1 = yp0;
  }
mhamilt commented 3 years ago

Your rho calculation in MATLAB is

rho = exp(-1/(f0*tau))/(abs(cos(pi*f0/Fs)));

but you in your cpp class you use

https://github.com/Cameron1470/AudioProgrammingDrone/blob/55b52cde13aaadf4e67ba006504180ef3bf32d10/Source/PluckedNote.cpp#L27

mhamilt commented 3 years ago

Couple of problems since the last pull request

This: https://github.com/Cameron1470/AudioProgrammingDrone/blob/55b52cde13aaadf4e67ba006504180ef3bf32d10/Source/PluckedNote.cpp#L11

Should be

#include "PluckedNote.h"

main problem seems to stem from your variable type choices.

In general, if something is an index, make it an int, don't cast a variable to an int. If you want an index from a float, make a separate int variable first then use it.

These should be float type

https://github.com/Cameron1470/AudioProgrammingDrone/blob/55b52cde13aaadf4e67ba006504180ef3bf32d10/Source/PluckedNote.cpp#L46-L47

https://github.com/Cameron1470/AudioProgrammingDrone/blob/55b52cde13aaadf4e67ba006504180ef3bf32d10/Source/PluckedNote.cpp#L58-L59

mhamilt commented 3 years ago

When it comes to PBMMI based algorithms, if in doubt just print out your parameters

    std::cout << "rho:\t" << rho << '\n';
    std::cout << "wtSize:\t" << wtSize << '\n';
    std::cout << "Nexact:\t" << Nexact << '\n';
    std::cout << "N:\t\t" << N << '\n';
    std::cout << "P:\t\t" << P << '\n';
    std::cout << "C:\t\t" << C << '\n';
    std::cout << "yp1:\t" << yp1 << '\n';
    std::cout << "yp0:\t" << yp0 << '\n';
    std::cout << "x1:\t\t" << x1 << '\n';
    std::cout << "x0:\t\t" << x0 << '\n';
mhamilt commented 3 years ago

Should be fixed by https://github.com/Cameron1470/AudioProgrammingDrone/pull/3