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.
11 //usage:#define beep_trivial_usage
12 //usage: "-f FREQ -l LEN -d DELAY -r COUNT -n"
13 //usage:#define beep_full_usage "\n\n"
15 //usage: "\n -f Frequency in Hz"
16 //usage: "\n -l Length in ms"
17 //usage: "\n -d Delay in ms"
18 //usage: "\n -r Repetitions"
19 //usage: "\n -n Start new tone"
24 #ifndef CLOCK_TICK_RATE
25 # define CLOCK_TICK_RATE 1193180
29 #ifndef CONFIG_FEATURE_BEEP_FREQ
32 # define FREQ (CONFIG_FEATURE_BEEP_FREQ)
34 #ifndef CONFIG_FEATURE_BEEP_LENGTH_MS
37 # define LENGTH (CONFIG_FEATURE_BEEP_LENGTH_MS)
40 #define REPETITIONS (1)
42 int beep_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
43 int beep_main(int argc, char **argv)
45 int speaker = get_console_fd_or_die();
46 unsigned tickrate_div_freq = tickrate_div_freq; /* for compiler */
47 unsigned length = length;
48 unsigned delay = delay;
55 tickrate_div_freq = CLOCK_TICK_RATE / FREQ;
60 c = getopt(argc, argv, "f:l:d:r:n");
62 * pipe stdin to stdout, but also beep after each line (-s) or char (-c)
66 /* TODO: what "-f 0" should do? */
67 tickrate_div_freq = (unsigned)CLOCK_TICK_RATE / xatou(optarg);
70 length = xatou(optarg);
75 * specify a delay of N milliseconds between repetitions.
76 * -d specifies that this delay should only occur between beeps,
77 * that is, it should not occur after the last repetition.
78 * -D indicates that the delay should occur after every repetition
80 delay = xatou(optarg);
92 //bb_info_msg("rep[%d] freq=%d, length=%d, delay=%d", rep, freq, length, delay);
93 xioctl(speaker, KIOCSOUND, (void*)(uintptr_t)tickrate_div_freq);
94 usleep(1000 * length);
95 ioctl(speaker, KIOCSOUND, (void*)0);
101 if (ENABLE_FEATURE_CLEAN_UP)
106 * so, e.g. Beethoven's 9th symphony "Ode an die Freude" would be
115 #./beep -f$d -l200 -r2 -n -f$e -l100 -d 10 -n -f$c -l400 -f$g -l200
116 ./beep -f$e -l200 -r2 \
117 -n -d 100 -f$f -l200 \