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

added getPan, setPan and setPanAbsolute #91

Merged
merged 4 commits into from
Jun 5, 2024
Merged

added getPan, setPan and setPanAbsolute #91

merged 4 commits into from
Jun 5, 2024

Conversation

alnitak
Copy link
Owner

@alnitak alnitak commented Jun 4, 2024

Description

Type of Change

  • ✨ New feature (non-breaking change which adds functionality)
  • 🛠️ Bug fix (non-breaking change which fixes an issue)
  • ❌ Breaking change (fix or feature that would cause existing functionality to change)
  • 🧹 Code refactor
  • ✅ Build configuration change
  • 📝 Documentation
  • 🗑️ Chore

@alnitak alnitak requested a review from filiph June 4, 2024 12:48
Copy link
Collaborator

@filiph filiph left a comment

Choose a reason for hiding this comment

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

Looks good! I have some nit comments.

// Note that because of the float<=>double conversion precision error
// (SoLoud lib uses floats), the returned value is not precise. Here we set
// a rounding of 5 digits
final ret = (_getPan(handle) * 100000).toInt() / 100000;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Frankly, I don't understand why we need to do this rounding. Is it not enough to just return the double?

Copy link
Owner Author

Choose a reason for hiding this comment

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

Since SoLoud lib uses floats and on Dart we use doubles, a conversion is needed. This conversion produces some aberration of the decimals as for standard IEEE 754 (hope I pointed out the right link to explain this).

So it happens this:

  • from Dart we ask for a double with getPan() that we think is a 0.8 double (using setPan())
  • on cpp we get a 0.8 float which on Dart becomes a double.

this "converted" double becomes something like 0.800000042353 which has a 7-digit precision and could cause some troubles when testing it.

I think 5-digit precision is enough for the pan value. Of course, this can be done on cpp side instead.

Copy link
Collaborator

Choose a reason for hiding this comment

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

FWIW, if this is about testing, I'd just document this in the function signature ("Note that if you setPan() to 0.8 and then getPan(), you might get a slightly different number, such as 0.800000042353. This is expected since the internal audio engine uses float instead of double, and so there are rounding errors.").

Then, in unit tests, just use the closeTo() operand to deal with the tiny changes.

Copy link
Owner Author

Choose a reason for hiding this comment

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

Doing so we add something that the dev should remember when seeing a strange number given back. If you think this is the way, no problem to fix it.

Saying that I realized that this happens also for other functions like setVolume() - getVolume()! So, that ok :)

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yeah, I think it's great to be aware of this and document this, but I don't think it's our place to quantize values for the developer in order to make the values "look right". I totally understand the sentiment, of course. I just think it's adding a functionality people might not necessarily want that needlessly adds more things to the package, too.

lib/src/soloud.dart Show resolved Hide resolved
Comment on lines +453 to +456
if (pan > 1.0f)
pan = 1.0f;
if (pan < -1.0f)
pan = -1.0f;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Oh, I see that we're sanitizing the input here in C code. Since this is likely not a performance bottleneck, I'd rather sanitize it in Dart land, since that's closer to the user's debugger.

Copy link
Owner Author

Choose a reason for hiding this comment

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

You are right! Better to let the dev know what he is trying to do :)

Comment on lines +462 to +466
if (panLeft > 1.0f) panLeft = 1.0f;
if (panLeft < -1.0f) panLeft = -1.0f;
if (panRight > 1.0f) panRight = 1.0f;
if (panRight < -1.0f) panRight = -1.0f;
soloud.setPanAbsolute(handle, panLeft, panRight);
Copy link
Collaborator

Choose a reason for hiding this comment

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

same here for panAbsolute: ideally sanitize (and assert) in Dart-land

@filiph
Copy link
Collaborator

filiph commented Jun 5, 2024

can you check if it grabs the state changes on iOS? For example when you put the app in the background or when the app is back in the foreground or maybe when a call is incoming while flutter_soloud is playing something, you should see a Log.fine() message (Audio engine state changed: [event]). This is out of scope of the PR, but I have added it while adding the others for simplicity. Thank you!

I don't see the change here. Is this something that landed in another PR?

I should have my iOS testing setup ready in a few minutes. Can test.

@alnitak
Copy link
Owner Author

alnitak commented Jun 5, 2024

I don't see the change here. Is this something that landed in another PR?

Yes, please test PR #89. A lot of changes on cpp side there.

@alnitak alnitak merged commit afde516 into main Jun 5, 2024
1 check passed
@alnitak alnitak deleted the pan branch June 5, 2024 13:44
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.

feat: Add functions to directly get and set pan
2 participants