GithubHelp home page GithubHelp logo

Comments (9)

xavriley avatar xavriley commented on July 20, 2024 5

Amazing - everything is working now that I've implemented that. Thanks for your patience and your help! 😄

I'll close this - for the benefit of anyone else reading it was never an issue in the first place. My problem was that the pitch_detector is stateful so it needs to be persisted across audio blocks.

P.S. I highly suggest mastering modern c++! It's the best language for DSP and you'll have a definite advantage by becoming an expert on it.

👍 I learnt a bunch of stuff working on this - I'll search out some books on the subject

from q.

djowel avatar djowel commented on July 20, 2024 2

Apologies for two more (possibly dumb) questions but

There's no such thing as a dumb question :)

a) how are you running the test suite? and edit: I figured this out 😅 Q/build/test/Debug/test_pitch_detector_ex
b) how are you generating those graphs?

The tests generate some results in the results directory in the tests directory where the executable is. The results are multichannel wav files that I use for diagnosis. I just open the files using Adobe Audition (Audacity or whatever).

I have Q compiling via Xcode and it says that tests are passing but it would be useful to trigger them individually. I normally work from a command line so I'm not too familiar with Xcode workflows. Thanks again.

I highly suggest CLion! It uses Cmake for project specification and id great for debugging:

https://www.jetbrains.com/help/clion/unit-testing-tutorial.html

I'll show you a snapshot of mine in action:

Screen Shot 2020-07-01 at 4 22 25 PM

So with that green triangle, I can run, or debug only that specific test. I often make conditional breakpoints on problem points. For example, the CSV file includes time info. On problem points, I set the conditional breakpoint to stop at the exact time. It's silly to step through hundreds of thousands of samples!

OH, and CLion works the same on ALL platforms I regularly work on (MacOS, Windows and Linux).

from q.

djowel avatar djowel commented on July 20, 2024

I will continue to look into this but I'd be interested if you have any idea why this might be happening?

OK, I'll look into it tomorrow.

from q.

djowel avatar djowel commented on July 20, 2024

I will continue to look into this but I'd be interested if you have any idea why this might be happening?

OK, I'll look into it tomorrow.

Confirmed. I am investigating now. Thanks for reporting BTW!

from q.

djowel avatar djowel commented on July 20, 2024

Confirmed. I am investigating now. Thanks for reporting BTW!

Oh wait, I spoke too soon. The error I got initially was expected because the test was comparing the CSV file from a "golden" CSV file, and of course they are different since the detection period changed. If I run the pitch_detector_ex test in Q with:

TEST_CASE("Test_basic")
{
   process("sin_440", 64_Hz, 512_Hz);
...

... I get

440.193 | 0.926136 | 0.0329705
439.947 | 0.928977 | 0.0488889
439.947 | 0.93608 | 0.0648299
439.859 | 0.926136 | 0.080839
439.694 | 0.924716 | 0.0957596
438.56 | 0.926136 | 0.111723

Compare this to the golden CVS file:

0 | 0.867188 | 0.0173923
439.429 | 0.997396 | 0.0260998
439.429 | 1 | 0.0351247
439.898 | 1 | 0.0442177
439.898 | 0.997396 | 0.0533333
439.883 | 0.997396 | 0.0609297
439.822 | 0.940104 | 0.0696372
439.36 | 0.864583 | 0.0784127
438.993 | 0.867188 | 0.0876417

So indeed, it is detecting the short sine wave pulse. As expected, the "periodicity" measure is not that good (that's a short decaying pulse), but still the results are usable.

BTW, did you update GIT to the latest from develop or master? If not, that might explain the issue you are having.

Oh and also, you might want to look at the test generated wav files. Assuming you are using the same sin_440.wav, here's what I have:

Screen Shot 2020-07-01 at 6 48 32 AM

Notice that very short sine burst. Yet the pitch detector is still detecting them.

from q.

xavriley avatar xavriley commented on July 20, 2024

Great - thanks for investigating. From what I'm seeing here it seems more likely there's an issue with how I'm feeding in data via the vamp plugin so I'll look into that.

I was on 7ae3e85a7758 on the develop branch so that is fairly recent.

Apologies for two more (possibly dumb) questions but

a) how are you running the test suite? and edit: I figured this out 😅 Q/build/test/Debug/test_pitch_detector_ex
b) how are you generating those graphs?

I have Q compiling via Xcode and it says that tests are passing but it would be useful to trigger them individually. I normally work from a command line so I'm not too familiar with Xcode workflows. Thanks again.

from q.

xavriley avatar xavriley commented on July 20, 2024

An update here - I figured out what was going wrong. The vamp plugin system splits the input into blocks (1024 samples long by default). I was initialising the pitch_detector for each block rather than just creating it once at the beginning of the process. That meant that my results were only operating on 1024 samples at a time, so it's kind of amazing that there was any output at all 😅. On the plus side, I'm more familiar with the codebase now and I have all the tests working and producing wavs etc.

Now that I've figured that out, I'm trying to setup pitch_detection as a member variable but I need to re-assign it because of the way Vamp handles parameters. If I try to reassign it later in the class I get the following:

error: object of type 'cycfi::q::pitch_detector' cannot be assigned because its copy assignment operator is implicitly
      deleted
    m_pd = cycfi::q::pitch_detector(m_lowestPitch, m_highestPitch, m_inputSampleRate, -45_dB);

As far as I can tell, there's no way to destroy or reset an instance of pitch_detector. Would it be useful to consider adding a .reset() method or similar? Again I'm new to C++ so my apologies if I'm missing something obvious.

from q.

djowel avatar djowel commented on July 20, 2024

As far as I can tell, there's no way to destroy or reset an instance of pitch_detector. Would it be useful to consider adding a .reset() method or similar? Again I'm new to C++ so my apologies if I'm missing something obvious.

Use a std::shared_ptr or a std::unique_ptr :-) Example:

my_ptr = std::make_shared<q::pitch_detector>(m_lowestPitch, m_highestPitch, m_inputSampleRate, -45_dB);

Later, you can explicitly destroy it (not really necessary because it manages its lifetime):

my_ptr.reset(); // destroy the old one

Or can reassign a new one:

my_ptr = a_fresh_one; // reassign a new one

P.S. I highly suggest mastering modern c++! It's the best language for DSP and you'll have a definite advantage by becoming an expert on it.

from q.

djowel avatar djowel commented on July 20, 2024

P.S. I highly suggest mastering modern c++! It's the best language for DSP and you'll have a definite advantage by becoming an expert on it.

👍 I learnt a bunch of stuff working on this - I'll search out some books on the subject

Don't hesitate to ask. Modern C++ is my expertise, and I am a strong advocate. There's a lot of crap out there. Make sure it's Modern c++ and not those dated old OOP ugliness from the 90s.

from q.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.