beep (C++,dos,win) - beep at any frequency, duration or musical note

Description

beep - beep at default A440Hz for 250ms or optional frequency and/or optional duration or musical note and octave. I suppose you could tune your guitar with it. to break, hit Ctrl-C (not recommended though). djgpp, and MinGW compiled executables with sources [DOS 32-bit, windows 32+64-bit]). The DOS version's timings will be different under windows because it's a DOS emulation.

It is available as a single beep.zip file which contains the source and executeables. It is under the GPL3 license. lsm file.

Downloads

Download Now
beep.zip (version 1.5, 8/10/2011)


Documentation

The program has been compiled for 32 and 64-bit machines using MinGW-w64 and for dos using djgpp, and I have added vista/7 support.

beep is derscribed below. beep does just what it says. you can pick the frequency and duration. that means you can make beepy music with it.

in fact, I include a happy birthday music batch file (the music is not copyrighted) you can run. plays happy birthday for you and shows the words as it plays. if you want to see the notes go by, you can always remove @echo off from the very top line of the file. and you can play it for your kids! most computer speakers are not very loud (which may be nice for parents). you can use a text editor such as notepad to customize the child's name, use [windows-logo-flag-key]-E to browse to birthday.bat and right click on birthday.bat and pick edit. you just use [windows-logo-flag-key]-E to browse to birthday.bat and double-click it. Remember you windows folks will probably want to delete the dos\ directory in this package.

this program arose out of the need for a program that beeps from the command-line so I know when a batch job is done. I thought, "why don't I take it a step further and make it do notes and octaves, I've got a whole frequency gamut from 37 to 32767 Hz..." so I did A0-G8 and then decided to make it case insensitive to make things easy on people. later on, I wanted to make the birthday song play in a batch file, and I realized I couldn't unless I had sharps and flats. So I added that. This was all put in version 1.0. It also has a help menu and version number that you can request from the command-line.

Some people's ears are musically inclined, and must hear notes that are on-pitch. So I made sure the default pitch and music note frequencies were rounded properly (banker's rounding) to the closest integer (no choice about integers even though note frequencies are real numbers, that's the way the frequencies are fed into the system call's beep functions), and in some cases I had to make calculations for duration. I can't do 4/4 time and dotted notes and quarter notes at this point because I don't know how fast in milliseconds that allegro actually is. (Is that defined somewhere?) I *might* put in some sort of music note duration and time signature and the speed thing (what's it called? I forget).

in any case, the difference between the Windows version and the DOS version in terms of timing is significant, given the same numbers. the DOS version is about 1/3 longer and I think I know why. I think my calculations are correct. I think it has to do with the OS I am running under (XP). running DOS programs under XP gives you different timings when you are going by clock ticks that would normally be going by in nanosecond resolution. So you can think of XP as running DOS under an emulator. slow. and probably why I am getting the difference in duration.

the windows timing is simply fed into the win32 function Beep(). the DOS duration must be calculated, converted into clock ticks, and duration done in a while loop for timing. fun. and cpu intensive. it was either that or have my resolution in seconds in DOS using sleep(), which wasn't my favorite choice.

also, because of Windows XP's disk cache and unpredictability in terms of execution timing of EXE's and whether a process gets put on hold, the birthday.bat's timings may sound quite the way you expect. don't worry about it, it's normal. just enjoy the fact that you can even do such a batch file and play around with it. it's cheaper than buying a MIDI sequencer at $50-99. But if you are serious about that, I would suggest using Cakewalk's Sonar or Apple's GarageBand or ProTools LE or CuBase. My personal choice is Sonar, and I prefer to get the high end music editor if I can get it. You can buy these from http://Sweetwater.com. (I don't make any money off that, but I like them, they give me candy in the order box the last time I ordered).

If all you wanted was a program that went "beep", you got more than you bargained for.
Enjoy.

--------------------------------------------------------------------------------
beep - beep at default 440Hz for 250ms or optional frequency and/or optional dur
ation.
usage: beep [/h[elp]] [-[-]h[elp]] [/v[er[sion]] [-[-]v[er[sion]]
       beep [/f[req[uency]] frequencyInHertz|notename] [-[-]f[req[uency]] freque
ncyInHertz|notename] [-[-]d[ur[ation]] durationInMilliseconds] [/d[ur[ation]] du
rationInMilliseconds]

-frequency frequencyInHertz specifies the frequency of the sound.  this is an in
teger64.  frequencyInHertz must be in the range 37-32767. notename can be in the
 range from A0 to G0..A8 to G8.
-duration durationInMilliseconds specifies the duration.  this is an integer64.
0 is not allowed as a duration.
Anything not specified will use the defaults (440Hz for 250ms).
The numbers specified, integer64, is case insensitive and can be in hexadecimal
(start with 0x), octal (start with 0 or 0o or 0o or 0q), binary (start with 0b),
 and can optionally end with SI units (:b, :kb, :mb, :gb, :tb, :pb, :eb) or end
with computer units (:b, :ki, :kib, :mi, :mib, :gi, :gib, :ti, :tib, :pi, :pib,
:ei, :eib) and these will be a multiplier.
An 'A' is 440Hz.  next octave up is 2x that or 880Hz.  next octave down is 440Hz
/2=220Hz.  things sound better when you use musical notes (plus, you don't aggra
vate people who are musically inclined).
To make a music with -frequency, you put a note letter A through G (case insensi
tive) followed by an optional sharp, #, b, flat followed by an octave in the ran
ge 0-8 inclusive.
so for example, -frequency aflat3 -duration 300 OR -frequency g8 for silence OR
-f D#4
example musical notes: Ab0 g#0 Csharp0 Dflat0 B2 C2..G8, G8 or frequency 32:k is
 silence but your dog might not appreciate it.
If you Ctrl-C or Ctrl-Break (break) this program and it leaves you with a foreve
r beep, simply run beep with no parameters and it will stop after 1 second.
Examples: beep -f 494
          beep -freq 0x1b8 -duration 1:k  (440 hz, the 1:k is 1000 milliseoonds
and will last for 1 second)
          beep -freq c2 -duration 500  (note C octave 3, 0-based octaves)
          beep -f 30:k -duration 5:k (silence for 5 seconds, well, maybe a coupl
e of clicks)
Copyright 2011 Jim Michaels. Under GPL3 license.
--------------------------------------------------------------------------------
C:\prj\beep\beep-1.5\win>beep -frequency 1:k -duration 5:k

C:\prj\beep\beep-1.5\win>beep -f c0

C:\prj\beep\beep-1.5\win>beep -f g8

C:\prj\beep\beep-1.5\win>beep -f 880 -dur 500

C:\prj\beep\beep-1.5\win>beep -f 0x370

C:\prj\beep\beep-1.5\win>beep -f 01560

C:\prj\beep\beep-1.5\win>beep -f asharp3

C:\prj\beep\beep-1.5\win>beep -f A#4

c:\prj\beep\beep-1.5\win>beep -f aflat3

c:\prj\beep\beep-1.5\win>beep -f Ab3

----------------------------------------------------------------------

License

Copyright 1993,2008,2009 Jim Michaels

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.