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

Remove ValueBuffer #7170

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open

Remove ValueBuffer #7170

wants to merge 7 commits into from

Conversation

Snowiiii
Copy link
Contributor

@Snowiiii Snowiiii commented Mar 27, 2024

ValueBuffer is just and wrapper around std::vector, but we dont use any Special methods from it so we should use std::vector instead

@Snowiiii Snowiiii changed the title Make ValueBuffer unsigned use size_t in ValueBuffer Mar 28, 2024
@sakertooth
Copy link
Contributor

I'm pretty much in favor of removing ValueBuffer altogether and replacing its usage with std::vector<float> directly. The functions that take/return ValueBuffer by pointer can instead take/return a float*, though this endeavor will be much more intricate than this one however.

@Snowiiii Snowiiii changed the title use size_t in ValueBuffer Remove ValueBuffer Mar 29, 2024
const float pan = (panBuf ? panBuf->value(f) : m_ampControls.m_panModel.value()) * 0.01f;
const float left = (leftBuf ? leftBuf->value(f) : m_ampControls.m_leftModel.value()) * 0.01f;
const float right = (rightBuf ? rightBuf->value(f) : m_ampControls.m_rightModel.value()) * 0.01f;
const float volume = (volumeBuf ? volumeBuf->at(f % volumeBuf->size()) : m_ampControls.m_volumeModel.value()) * 0.01f;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm curious if the modulo was covering for some bug in ValueBuffer before.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

which bug?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The issue is that this is hiding out of bounds array access. The question is why is this needed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just implemented the Old behaviour from ValueBuffer which was:

float ValueBuffer::value(int offset) const
{
	return at(offset % length());
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, and the question is why was modulo being used here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah the notes not rendering was fixed. Can you load and play an intensive project like Krem Kaakkuja with no modulo/clamp? If so, then I think we can remove the modulo/clamp.

works without any problems.
image

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@DomClark I think we can remove the clamp, too, now. What do you think?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@PhysSong for additional opinion :)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you should use static code analysis to check every occurrence where the value function is used. In all these cases it must be assured that no out of bounds read is possible. If in doubt, I would suggest to add an assert before such calls and then make tests where this assert is being tested.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should leave it an runtime check

plugins/Amplifier/Amplifier.cpp Outdated Show resolved Hide resolved
plugins/Amplifier/Amplifier.cpp Outdated Show resolved Hide resolved
use cmath instead of bits/stdc++.h>
@sakertooth
Copy link
Contributor

sakertooth commented Apr 3, 2024

Will mention again that I am strongly against passing a std::vector<float> by pointer due to its unnecessary restrictiveness, which makes the API less flexible.

We truly need to get support for std::span, but it makes a lot more sense for the API at least for now to take a array by a raw pointer and a size, or it can be combined into a struct and then passed/returned.

Edit: I can somehow understand why it may be simpler to return the vector, but for passing a vector into function as an argument I really am not in favor of.

@Snowiiii
Copy link
Contributor Author

@DomClark @PhysSong I would like to start working on other PRs but first want this to Close/Get Merged, In the current State everything works fine and further improvement can be done via separate PRs or commits

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

Successfully merging this pull request may close these issues.

None yet

6 participants