Skip to content

Commit

Permalink
Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
tvlooy committed Feb 6, 2016
1 parent e98858c commit aa12c16
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
10 changes: 7 additions & 3 deletions piano.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);

Expand Down

0 comments on commit aa12c16

Please sign in to comment.