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

REFAC(client): Introduce and use AudioPreprocessor #6511

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

Conversation

davidebeatrici
Copy link
Member

No description provided.

@Hartmnt
Copy link
Member

Hartmnt commented Jul 17, 2024

So the point of this is to rip the speex pre-processor code out of AudioInput.cpp and abstract it, such that it can be swapped for a different pre-processor in the future, right?

Copy link
Member

@Krzmbrzl Krzmbrzl left a comment

Choose a reason for hiding this comment

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

I'm not a big fan of using fixed-width integers without need. Imo, all the integers in the interface should be of type int (or unsigned int) to let the compiler use the native integer size for the given architecture.
Explicitly encoding the integer's width only provides extra information to someone reading the code that they don't need because in this case here it is completely irrelevant as all integers that are expected to be passed around are well below the maximum possible value of an int on all platforms that Mumble can be compiled on. This only causes head-scratching when someone has to refactor the code as they will start wondering where exactly the requirement for a 32-bit integer is coming from and why e.g. a 64-bit integer can't be used.

All-in-all though, LGTM

src/mumble/AudioInput.cpp Show resolved Hide resolved
src/mumble/AudioPreprocessor.cpp Outdated Show resolved Hide resolved
src/mumble/AudioPreprocessor.h Show resolved Hide resolved
src/mumble/AudioPreprocessor.h Outdated Show resolved Hide resolved
src/mumble/AudioStats.cpp Outdated Show resolved Hide resolved
@Krzmbrzl
Copy link
Member

@Hartmnt the immediate goal is to be able to reuse it to implement #6428 but of course the possibility to more easily drop in a different audio processor backend is a nice benefit too :)

@davidebeatrici
Copy link
Member Author

@Hartmnt the immediate goal is to be able to reuse it to implement #6428 but of course the possibility to more easily drop in a different audio processor backend is a nice benefit too :)

Correct. If in the future we want to implement another preprocessor, this new class is a good abstraction base.

I'm not a big fan of using fixed-width integers without need. Imo, all the integers in the interface should be of type int (or unsigned int) to let the compiler use the native integer size for the given architecture. Explicitly encoding the integer's width only provides extra information to someone reading the code that they don't need because in this case here it is completely irrelevant as all integers that are expected to be passed around are well below the maximum possible value of an int on all platforms that Mumble can be compiled on. This only causes head-scratching when someone has to refactor the code as they will start wondering where exactly the requirement for a 32-bit integer is coming from and why e.g. a 64-bit integer can't be used.

speex_preprocess_ctl() treats the argument as a pointer to int32_t, except special cases (e.g. float). Ideally we should use the narrowest data type possible based on the range of values that is accepted by a specific call.

Documentation for each function would also help understanding that.

As for the use of int and unsigned int: it indeed ensures that the variable is the default size for the given architecture, but you don't gain any added performance from that. You actually risk potentially wasting memory.

@Krzmbrzl
Copy link
Member

but you don't gain any added performance from that. You actually risk potentially wasting memory.

That's not true in the general case but that's also not my point. My point is completely about readability of the code and how much information to put into tue source code. Ideally, we only want relevant information in the source code and if the exact size of an integer is not important, adding the size into the source code decreased the signal-to-noise ratio, making the code harder to parse and modify.

@davidebeatrici
Copy link
Member Author

Technically speaking the size of a variable is always important. Good practice generally consists in defaulting to the smallest size that can hold the biggest value you expect to be assigned to the variable.

There are of course some exceptions, such as when designing a public API. In that case you have to consider the future proofing aspect and thus may want to go with a bigger size even if not required right now.

@davidebeatrici davidebeatrici force-pushed the audiopreprocessor branch 2 times, most recently from 51bffa0 to c1337bb Compare July 18, 2024 01:42
@Krzmbrzl
Copy link
Member

Technically speaking the size of a variable is always important. Good practice generally consists in defaulting to the smallest size that can hold the biggest value you expect to be assigned to the variable.

I don't think always choosing the smallest possible size does any good (almost never do the logical range of valid inputs coincide with the range of possible values that can be encoded with an integer of a given size) and as long as you do that, the size loses importance for 99% of functions as arguments typically range in the order of 100s to maybe 1000s which fits into pretty much all integer sizes.

@davidebeatrici
Copy link
Member Author

If you're referring to the readability aspect then no, knowing the size of a variable doesn't tell you the actual value range that is expected. It's still a hint though.

@davidebeatrici
Copy link
Member Author

@Krzmbrzl

Digest: sha256:0f969ceabb97af1232ceffeac308fbdee9f0cd0113289ca3ead6e01af9e8d6df
Status: Downloaded newer image for ghcr.io/jidicula/clang-format:10
clang-format version 10.0.0-4ubuntu1 
./src/mumble/AudioPreprocessor.h:203:46: error: code should be clang-formatted [-Wclang-format-violations]
        AudioPreprocessor(const AudioPreprocessor &)            = delete;
                                                    ^
Failed on file: ./src/mumble/AudioPreprocessor.h

This looks wrong to me... can we update the clang-format image?

@Krzmbrzl
Copy link
Member

This looks wrong to me... can we update the clang-format image?

Only if you find a way to not break existing PRs (aka: a way to automatically adapt PRs to new formatting standards). I wanted to look into a script/bot that can do this for a while but never actually came around to implementing it. I'm sure it wouldn't be too complicated given that clang-format can format diffs but it'd have to be implemented in a way that makes it easy to use on all existing open PRs.

@davidebeatrici
Copy link
Member Author

Formatted with clang-format 10, in order for CI to succeed.

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

Successfully merging this pull request may close these issues.

3 participants