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

Standardising various variable types #27

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

Conversation

joshbarrass
Copy link
Owner

@joshbarrass joshbarrass commented Feb 14, 2024

Define two type aliases: sample_count_t, which represents a number of samples (and also sample rates, since these are technically # samples / second); and sample_t, which represents a single mono sample of audio data. These clarify a little more in the code itself what various variables represent, make it easier to standardise the type across different functions, and allow the type to be changed more easily if desired for whatever reason.

Sample counts are standardised to use long. The C++ standard should guarantee we can store up to at least 2147483647, which should be sufficient for almost all audio files at most sample rates. As a back of the napkin calculation, 2147483647 samples @ 44100Hz is 13.5hrs, and 2147483647 samples @ 220500Hz (which should be complete overkill here!) is 2.7hrs. These are far longer than any individual GSF I've encountered, and would allow an extremely long loop before any overflow effects would be encountered. In reality, GCC tends to use 8-bit longs, which has a maximum of 9223372036854775807, leading to maximum sample numbers corresponding to millions of years of continuous playback. I suspect this will be more than long enough (:

Samples, as we are using 16-bit audio, are simply int16_t. The type alias is more for clarity than any other reason.

I'll use this in a local build for a while to make sure nothing is obviously broken, then I can look at merging this.

Closes #26.

@joshbarrass
Copy link
Owner Author

Could be interesting to add the long size in the plugin info as a reference.

@joshbarrass
Copy link
Owner Author

I think it might actually be worth defining a type alias specifically for number of samples. This would make it clearer in the code what the variable corresponds to (whether it's just a big number or specifically a sample count), and it would make it easier to adjust the type in the future if so desired.

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.

Type used for number of samples is inconsistent
1 participant