Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

numberOfConsecutiveZeros > 0 if block has multiple channels all starting with a zero #4

Open
chrhaase opened this issue Feb 3, 2023 · 3 comments

Comments

@chrhaase
Copy link

chrhaase commented Feb 3, 2023

Hi @sudara !

Really digging your audio block test helpers repo. Thanks for that!
I've run into a bug when filling a multichannel block with a sine. Both channels will be starting at zero and this is causing a REQUIRE_THAT (blockIsFilled (block)) check to fail.

I believe it could be fixed like this (simply skipping the first sample):

    template <typename SampleType>
    static inline size_t numberOfConsecutiveZeros (const AudioBlock<SampleType>& block)
    {
        size_t consecutiveZeros = 0;
        for (int c = 0; c < (int) block.getNumChannels(); ++c)
        {
            for (int i = 1; i < (int) block.getNumSamples(); ++i)
            {
                auto lastSample = block.getSample (c, i - 1);
                auto currentSample = block.getSample (c, i);
                if (currentSample == 0 && lastSample == 0)
                    consecutiveZeros++;
            }
        }
        return consecutiveZeros;
    }
@sudara
Copy link
Owner

sudara commented Feb 3, 2023

Hi @chrhaase,

Thanks for filing an issue! Ah, I forgot that the test helpers depend on this sparklines repo! Yikes!

I definitely wrote that lil helper to allow something like a sine wave work, which is why at the end it only reports zeros if there were > 1 of them in a row.

But I'm betting you are running a multi channel audio block?

Edit: Ah, didn't read clearly enough. I think skipping the first one... might report different numbers, maybe we'd just have to track them on a per-channel basis vs. globally...

Sounds like we need tests for the test helpers 🤣

@chrhaase
Copy link
Author

chrhaase commented Feb 4, 2023

Yeah, but isn't the intention a bit more clear when skipping the first? Then zeros are only counted if they are actually next to another zero. Or maybe I misunderstood? :)

What do you mean by reporting different numbers? Maybe it's actually ambiguous to ask the question of consecutive zeros for a multi-channel block - are zeros only counted if all channels are zero for a given sample or are each channel counted individually. Is this what you're getting at? Maybe I'm overthinking it... :)

For isFilled, though.. I guess the most intuitive to count each channel individually? So that a block is only filled if every channel block is filled. That's at least what I think I'd expect.

@sudara
Copy link
Owner

sudara commented Feb 7, 2023

What do you mean by reporting different numbers?

I guess in the sparkline context, an empty block would report as something like [0(64)] — so in this context, we'd need to prioritize that count being correct.

For isFilled, though.. I guess the most intuitive to count each channel individually? So that a block is only filled if every channel block is filled. That's at least what I think I'd expect.

Agreed!

I think what makes most sense to me is to break this method apart into the different use cases its serving right now... I'll take a look soon!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants