diff --git a/example/tests/tests.dart b/example/tests/tests.dart index 3aa5853..78e3a92 100644 --- a/example/tests/tests.dart +++ b/example/tests/tests.dart @@ -411,12 +411,13 @@ Future testPan() async { SoLoud.instance.setPan(handle, -0.8); var pan = SoLoud.instance.getPan(handle); - assert(pan == -0.8, 'setPan() or getPan() failed!'); + assert(closeTo(pan, -0.8, 0.00001), 'setPan() or getPan() failed!'); + await delay(1000); SoLoud.instance.setPan(handle, 0.8); pan = SoLoud.instance.getPan(handle); - assert(pan == 0.8, 'setPan() or getPan() failed!'); + assert(closeTo(pan, 0.8, 0.00001), 'setPan() or getPan() failed!'); await delay(1000); deinit(); @@ -525,6 +526,10 @@ Future loadAsset() async { }); } +bool closeTo(num value, num expected, num epsilon) { + return (value - expected).abs() <= epsilon.abs(); +} + void printError(Object error, StackTrace stack) { stderr.writeln('TEST error: $error\nstack: $stack'); exitCode = 1; diff --git a/lib/src/bindings_player_ffi.dart b/lib/src/bindings_player_ffi.dart index d2079cd..285b435 100644 --- a/lib/src/bindings_player_ffi.dart +++ b/lib/src/bindings_player_ffi.dart @@ -746,10 +746,8 @@ class FlutterSoLoudFfi { /// middle and and 1 is right. double getPan(int handle) { // 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; - return ret; + // (SoLoud lib uses floats), the returned value is not precise. + return _getPan(handle); } late final _getPanPtr = diff --git a/lib/src/soloud.dart b/lib/src/soloud.dart index b6a1aa4..41fd463 100644 --- a/lib/src/soloud.dart +++ b/lib/src/soloud.dart @@ -1179,6 +1179,12 @@ interface class SoLoud { /// and `1.0` meaning full volume. /// /// Throws [SoLoudNotInitializedException] if the engine is not initialized. + /// + /// Note that if you `setGlobalVolume()` to `0.8` and then + /// `getGlobalVolume()`, 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. double getGlobalVolume() { if (!isInitialized) { throw const SoLoudNotInitializedException(); @@ -1192,6 +1198,12 @@ interface class SoLoud { /// to `1.0` (meaning full volume). /// /// Throws [SoLoudNotInitializedException] if the engine is not initialized. + /// + /// Note that if you `setGlobalVolume()` to `0.8` and then + /// `getGlobalVolume()`, 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. void setGlobalVolume(double volume) { if (!isInitialized) { throw const SoLoudNotInitializedException(); @@ -1211,6 +1223,11 @@ interface class SoLoud { /// and `1.0` means its playing at full volume. /// /// Throws [SoLoudNotInitializedException] if the engine is not initialized. + /// + /// Note that if you `setVolume()` to `0.8` and then `getVolume()`, 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. double getVolume(SoundHandle handle) { if (!isInitialized) { throw const SoLoudNotInitializedException(); @@ -1225,6 +1242,11 @@ interface class SoLoud { /// to `1.0` (meaning it should play at full volume). /// /// Throws [SoLoudNotInitializedException] if the engine is not initialized. + /// + /// Note that if you `setVolume()` to `0.8` and then `getVolume()`, 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. void setVolume(SoundHandle handle, double volume) { if (!isInitialized) { throw const SoLoudNotInitializedException(); @@ -1239,6 +1261,11 @@ interface class SoLoud { /// middle and and 1 is right. /// /// Throws [SoLoudNotInitializedException] if the engine is not initialized. + /// + /// 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. double getPan(SoundHandle handle) { if (!isInitialized) { throw const SoLoudNotInitializedException(); @@ -1253,6 +1280,11 @@ interface class SoLoud { /// middle and and 1 is right. /// /// Throws [SoLoudNotInitializedException] if the engine is not initialized. + /// + /// 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. void setPan(SoundHandle handle, double pan) { if (!isInitialized) { throw const SoLoudNotInitializedException();