Skip to content

Commit e433236

Browse files
committed
Use float precision instead of pure int for better range
1 parent 35a9bff commit e433236

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

examples/bluez-volume-sync.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22

3-
const BLUEZ_TO_PA_FACTOR = 512;
3+
const BLUEZ_TO_PA_FACTOR = 65535/127;
44

55
require_once __DIR__.'/../vendor/autoload.php';
66
$ffi = require_once __DIR__.'/../load.php';
@@ -15,7 +15,7 @@
1515
FFI::addr($err));
1616
$ffi->dbus_connection_flush($conn);
1717
if ($ffi->dbus_error_is_set(FFI::addr($err))) {
18-
fprintf(stderr, "Match Error (%s)\n", $err->message);
18+
fprintf(STDERR, "Match Error (%s)\n", $err->message);
1919
exit(1);
2020
}
2121

@@ -70,7 +70,7 @@
7070
}
7171

7272
$addr = preg_replace('@^.*/dev_(.*?)(/.*)$@', '$1', $message->path);
73-
$paVolume = BLUEZ_TO_PA_FACTOR * (int) $volume;
73+
$paVolume = (int) (BLUEZ_TO_PA_FACTOR * (int) $volume);
7474
echo "Set volume to ".round($paVolume / 65535 * 100).'%'.PHP_EOL;
7575
exec("pactl set-source-volume bluez_source.{$addr}.a2dp_source {$paVolume}");
7676
}

0 commit comments

Comments
 (0)