1 /* vi: set sw=4 ts=4: */
3 * beep implementation for busybox
5 * Copyright (C) 2009 Bernhard Reutner-Fischer
7 * Licensed under the GPL v2 or later, see the file LICENSE in this tarball.
13 #ifndef CLOCK_TICK_RATE
14 # define CLOCK_TICK_RATE 1193180
18 #ifndef CONFIG_FEATURE_BEEP_FREQ
21 # define FREQ (CONFIG_FEATURE_BEEP_FREQ)
23 #ifndef CONFIG_FEATURE_BEEP_LENGTH_MS
26 # define LENGTH (CONFIG_FEATURE_BEEP_LENGTH_MS)
29 #define REPETITIONS (1)
31 int beep_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
32 int beep_main(int argc, char **argv)
34 int speaker = get_console_fd_or_die();
35 unsigned tickrate_div_freq = tickrate_div_freq; /* for compiler */
36 unsigned length = length;
37 unsigned delay = delay;
44 tickrate_div_freq = CLOCK_TICK_RATE / FREQ;
49 c = getopt(argc, argv, "f:l:d:r:n");
51 * pipe stdin to stdout, but also beep after each line (-s) or char (-c)
55 /* TODO: what "-f 0" should do? */
56 tickrate_div_freq = (unsigned)CLOCK_TICK_RATE / xatou(optarg);
59 length = xatou(optarg);
64 * specify a delay of N milliseconds between repetitions.
65 * -d specifies that this delay should only occur between beeps,
66 * that is, it should not occur after the last repetition.
67 * -D indicates that the delay should occur after every repetition
69 delay = xatou(optarg);
81 //bb_info_msg("rep[%d] freq=%d, length=%d, delay=%d", rep, freq, length, delay);
82 xioctl(speaker, KIOCSOUND, (void*)(uintptr_t)tickrate_div_freq);
83 usleep(1000 * length);
84 ioctl(speaker, KIOCSOUND, (void*)0);
90 if (ENABLE_FEATURE_CLEAN_UP)
95 * so, e.g. Beethoven's 9th symphony "Ode an die Freude" would be
104 #./beep -f$d -l200 -r2 -n -f$e -l100 -d 10 -n -f$c -l400 -f$g -l200
105 ./beep -f$e -l200 -r2 \
106 -n -d 100 -f$f -l200 \