diff --git a/README.md b/README.md index 0ce7ca8..f1b2e49 100644 --- a/README.md +++ b/README.md @@ -1,13 +1,13 @@ # Piano -This is a PHP extension to "play the piano" from PHP userland. +This is a PHP extension to "play the piano" (beeps) from PHP userland. -## How does it work +## How does it work? - This only works on Linux. - This only works on PHP 7. - - This module uses the PC speaker, so make sure you have the Linux kernal module ```pcspkr``` loaded. - - This is not by default so check with ```lsmod``` and ```sudo insmod pcspkr``` if needed. + - This module uses the PC speaker, so make sure you have the Linux kernel module ```pcspkr``` loaded. + - This is not by default so check with ```lsmod``` and ``` sudo insmod /lib/modules/`uname -r`/kernel/drivers/input/misc/pcspkr.ko``` if needed. - Start php with sudo because we will try to write to ```/dev/console```. ## Build diff --git a/piano.c b/piano.c index 57665c0..ddee1da 100644 --- a/piano.c +++ b/piano.c @@ -34,7 +34,7 @@ ZEND_GET_MODULE(piano) /* Module init */ PHP_MINIT_FUNCTION(piano) { - REGISTER_LONG_CONSTANT("PIANO_0", 1, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("PIANO_0", 0, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("PIANO_C", 261, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("PIANO_D", 293, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("PIANO_E", 329, CONST_CS | CONST_PERSISTENT); @@ -66,8 +66,12 @@ PHP_FUNCTION(play_piano) { exit(1); } - /* the PC uses a base rate of 1,193,180 Hz, generated by an oscillator chip */ - ioctl(console_fd, KIOCSOUND, 1193180 / freq); + if (freq == 0) { + ioctl(console_fd, KIOCSOUND, 0); + } else { + /* the PC uses a base rate of 1,193,180 Hz, generated by an oscillator chip */ + ioctl(console_fd, KIOCSOUND, 1193180 / freq); + } /* beep for given duration */ usleep(ms * 1000);