pcspkr/vt_ioctl: PC speaker volume control
Subsystems (3)
PATCH 1/1 pcspkr/vt_ioctl: PC speaker volume control
The attached patch allows the system to control the volume of the system bell. It adds a new ioctl code (KDSETVOLUME at 0x4B2E) to the set in terminals. This ioctl takes an argument which specifies the new volume level. It also adds a new event (SND_VOLUME) into the EV_SND set (the parameter is the new volume).
The bell itself is controlled by switching the output of the i8253 between 0, 1 or a high frequency toggle between 1 and 0 which due to capacitance gives rough analogue levels. It uses hrtimer to trigger the changes. If volume is set to maximum then the original code is used. If volume is set to 0 then no noise is generated.
Comments desired.
To test:
--------
#include <stdio.h>
#include <linux/kd.h>
#include <sys/ioctl.h>
#include <fcntl.h>
int main(int argc, char **argv)
{
long volume, pitch, ms;
int fd;
fd = open("/dev/tty0", O_RDONLY);
pitch = 400; volume = 10; ms = 100;
if (pitch) pitch = 1193180 / pitch;
ioctl(fd, KDSETVOLUME, volume);
ioctl(fd, KDMKTONE, (ms<<16)|pitch);
}
PATCH:
---------
drivers/char/keyboard.c | 12 +++ drivers/char/vt_ioctl.c | 9 +++ drivers/input/misc/pcspkr.c | 166 ++++++++++++++++++++++++++++++++++-------- include/linux/input.h | 1 + include/linux/kd.h | 1 + include/linux/vt_kern.h | 1 + 6 files changed, 158 insertions(+), 32 deletions(-)
drivers/char/keyboard.c +12 -0
@@ -220,6 +220,18 @@ int setkeycode(unsigned int scancode, unsigned int keycode)/* * Making beeps and bells. */ +void kd_set_volume (unsigned int volume) +{ +struct input_handle *handle; + +list_for_each_entry (handle, &kbd_handler.h_list, h_node) { +if (test_bit (EV_SND , handle->dev->evbit)) { +if (test_bit (SND_VOLUME , handle->dev->sndbit)) +input_inject_event (handle,EV_SND ,SND_VOLUME , volume); + } + } +} +static void kd_nosound (unsigned long ignored) {struct input_handle *handle;
drivers/char/vt_ioctl.c +9 -0
@@ -421,6 +421,15 @@ int vt_ioctl(struct tty_struct *tty, struct file * file,break ; } +case KDSETVOLUME : +if (!perm) + goto eperm; +/* +* Set the system beep/tone volume +*/ +kd_set_volume (arg); +break ; +case KDGKBTYPE :/* * this is naive.
drivers/input/misc/pcspkr.c +134 -32
227 lines not on this page · raw message
include/linux/input.h +1 -0
@@ -688,6 +688,7 @@ struct input_absinfo {#define SND_CLICK 0x00#define SND_BELL 0x01#define SND_TONE 0x02 +#define SND_VOLUME 0x03#define SND_MAX 0x07#define SND_CNT (SND_MAX+1)
include/linux/kd.h +1 -0
@@ -21,6 +21,7 @@ struct consolefontdesc {#define GIO_CMAP 0x4B70/* gets colour palette on VGA+ */ #define PIO_CMAP 0x4B71/* sets colour palette on VGA+ */ +#define KDSETVOLUME 0x4B2E/* set system beep/tone volume */ #define KIOCSOUND 0x4B2F/* start sound generation (0 for off) */ #define KDMKTONE 0x4B30/* generate tone */
include/linux/vt_kern.h +1 -0
@@ -25,6 +25,7 @@#define BROKEN_GRAPHICS_PROGRAMS 1#endif +extern void kd_set_volume (unsigned int volume);extern void kd_mksound (unsigned int hz,unsigned int ticks);extern int kbd_rate (struct kbd_repeat *rep);extern int fg_console, last_console, want_console;
Quoted 1 line · Charlie Brej
The attached patch allows the system to control the volume of the system bell.
Has anyone looked at this? Should I send it to someone in particular or is there no interest in it?
Quoted 6 lines · Charlie Brej
Quoted 2 lines · Charlie Brej
The attached patch allows the system to control the volume of the system bell.
Has anyone looked at this? Should I send it to someone in particular or is there no interest in it?
Well how I should I put it... there is the PC speaker sound driver from Stas Sergeev, with which beeps can already be produced in varying volume levels -- just feed it the appropriate PCM data. Of course, console usually does not play WAV files. :o)