1 /* vi: set sw=4 ts=4: */
3 * beep implementation for busybox
5 * Copyright (C) 2009 Bernhard Reutner-Fischer
7 * Licensed under GPLv2 or later, see file LICENSE in this source tree.
10 //config: bool "beep (2.4 kb)"
12 //config: select PLATFORM_LINUX
14 //config: The beep applets beeps in a given freq/Hz.
16 //config:config FEATURE_BEEP_FREQ
17 //config: int "default frequency"
18 //config: range 20 50000 # allowing 0 here breaks the build
19 //config: default 4000
20 //config: depends on BEEP
22 //config: Frequency for default beep.
24 //config:config FEATURE_BEEP_LENGTH_MS
25 //config: int "default length"
26 //config: range 0 2147483647
28 //config: depends on BEEP
30 //config: Length in ms for default beep.
32 //applet:IF_BEEP(APPLET(beep, BB_DIR_USR_BIN, BB_SUID_DROP))
34 //kbuild:lib-$(CONFIG_BEEP) += beep.o
36 //usage:#define beep_trivial_usage
37 //usage: "-f FREQ -l LEN -d DELAY -r COUNT -n"
38 //usage:#define beep_full_usage "\n\n"
39 //usage: " -f Frequency in Hz"
40 //usage: "\n -l Length in ms"
41 //usage: "\n -d Delay in ms"
42 //usage: "\n -r Repetitions"
43 //usage: "\n -n Start new tone"
48 #ifndef CLOCK_TICK_RATE
49 # define CLOCK_TICK_RATE 1193180
53 #ifndef CONFIG_FEATURE_BEEP_FREQ
56 # define FREQ (CONFIG_FEATURE_BEEP_FREQ)
58 #ifndef CONFIG_FEATURE_BEEP_LENGTH_MS
61 # define LENGTH (CONFIG_FEATURE_BEEP_LENGTH_MS)
64 #define REPETITIONS (1)
66 int beep_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
67 int beep_main(int argc, char **argv)
69 int speaker = get_console_fd_or_die();
70 unsigned tickrate_div_freq = tickrate_div_freq; /* for compiler */
71 unsigned length = length;
72 unsigned delay = delay;
79 tickrate_div_freq = CLOCK_TICK_RATE / FREQ;
84 c = getopt(argc, argv, "f:l:d:r:n");
86 * pipe stdin to stdout, but also beep after each line (-s) or char (-c)
90 /* TODO: what "-f 0" should do? */
91 tickrate_div_freq = (unsigned)CLOCK_TICK_RATE / xatou(optarg);
94 length = xatou(optarg);
99 * specify a delay of N milliseconds between repetitions.
100 * -d specifies that this delay should only occur between beeps,
101 * that is, it should not occur after the last repetition.
102 * -D indicates that the delay should occur after every repetition
104 delay = xatou(optarg);
116 //bb_error_msg("rep[%d] freq=%d, length=%d, delay=%d", rep, freq, length, delay);
117 xioctl(speaker, KIOCSOUND, (void*)(uintptr_t)tickrate_div_freq);
118 usleep(1000 * length);
119 ioctl(speaker, KIOCSOUND, (void*)0);
121 usleep(1000 * delay);
125 if (ENABLE_FEATURE_CLEAN_UP)
130 * so, e.g. Beethoven's 9th symphony "Ode an die Freude" would be
139 #./beep -f$d -l200 -r2 -n -f$e -l100 -d 10 -n -f$c -l400 -f$g -l200
140 ./beep -f$e -l200 -r2 \
141 -n -d 100 -f$f -l200 \