"Beep, beep, beep!"

Electronics Computer Programming Q&A
Post Reply
User avatar
MrAl
Posts: 3862
Joined: Fri Jan 11, 2002 1:01 am
Location: NewJersey
Contact:

"Beep, beep, beep!"

Post by MrAl » Wed Dec 23, 2009 8:16 am

Hello there,

I dont know how many of you remember that song of old, but that's not really the subject of this
post anyway. There is a Windows API function called "Beep" and you call it something like this:
Beep(frequency,duration)
in say the C programming language.

There is apparently a big problem with this function however. On some systems it works just fine,
and on others it doesnt. One some systems it does play a beep through the internal PC speaker
(not the external plug in multimedia speakers you usually plug into your sound card), and on
other systems it plays though the multimedia speakers and not the internal PC speaker.
That's really the problem i guess. The function is very inconsistent between systems.

Now recently i got a different motherboard and that mobo came with different sound software,
and now the sill Beep function wont play though the multimedia speakers, only the internal
PC speaker. Other people have had the opposite problem, but that's actually what i want.
With the old system it played though the sound card speakers, and now only through the
PC internal speaker (which is probably through a low level I/O port on the mobo).

So the question is, anyone know how to change this functionality?
Many people have complained about this but dont seem to have a solution, or the solution
they suggest isnt anything like it. For example, one suggestion was to use "MessageBeep"
instead, but that im afraid does NOT play different sound frequencies, it only plays a list
of predetermined sounds.
LEDs vs Bulbs, LEDs are winning.

User avatar
CeaSaR
Posts: 1688
Joined: Sat Nov 08, 2003 1:01 am
Location: Phoenixville, PA USA
Contact:

Re: "Beep, beep, beep!"

Post by CeaSaR » Wed Dec 23, 2009 9:05 am

Any time I used BEEP, it only played a single tone throught the internal mobo speaker. I ended up using
PLAY SOUND for varying frequencies. All this was in BASIC, however. I can dig up an example if you want.

*I think this is what I used, it has been a while since I've done that...

CeaSaR
Hey, what do I know?

User avatar
MrAl
Posts: 3862
Joined: Fri Jan 11, 2002 1:01 am
Location: NewJersey
Contact:

Re: "Beep, beep, beep!"

Post by MrAl » Wed Dec 23, 2009 9:14 am

Hi Ceasar,

I guess i could take a look. I would be using either C or something like it
so it would have to be convertible into C or something similar.
LEDs vs Bulbs, LEDs are winning.

User avatar
CeaSaR
Posts: 1688
Joined: Sat Nov 08, 2003 1:01 am
Location: Phoenixville, PA USA
Contact:

Re: "Beep, beep, beep!"

Post by CeaSaR » Wed Dec 23, 2009 10:38 pm

Here is the info from QB 4.5:

Code: Select all

SOUND - a device I/O statement that generates sound through the
        speaker
Syntax
  SOUND frequency,duration
    ■ frequency, a numeric expression that has an integer value between
      37 and 32,767, is the frequency of the sound in cycles/second,
      or hertz
    ■ duration, a numeric expression that has an unsigned integer value
      between 0 and 65,535, is the number of system clock ticks the
      sound lasts. There are 18.2 clock ticks per second.

SOUND Statement Details

Syntax
SOUND frequency,duration

The frequency is the desired frequency in hertz (cycles/second). It must
be a numeric expression returning an integer in the range 37-32,767.

The duration is the duration in clock ticks. (There are 18.2 clock ticks
per second regardless of CPU speed.) The duration must be a numeric
expression returning an unsigned integer in the range 0-65,535.

If the duration is zero, any current SOUND statement that is running is
turned off. If no SOUND statement is running, a SOUND statement with a
duration of zero has no effect.

SOUND Statement Programming Example

This program produces a rising and descending glissando:

CLS
FOR I = 440 TO 1000 STEP 5
   SOUND I, I/1000
NEXT
FOR I = 1000 TO 440 STEP -5
  SOUND I, I/1000
NEXT

******
PLAY - a device I/O statement that plays music

Syntax
  PLAY commandstring
    ■ commandstring is a stringexpression that contains music commands:
──────────────────────────Set Octaves and Play Tones──────────────────────────
 On  Sets current octave (n = 0-6)    │  < or >  Up or down one octave
 Nn  Plays note n (n = 0-84, 0 is a   │  A-G  Plays A, B, ..., G in current
    rest)                            │      octave (+ = sharp, - = flat)
──────────────────────────Set Tone Duration and Tempo─────────────────────────
 Ln  Sets length of a note (L1 is     │  MS  Each note plays 3/4 of length
    whole note, L4 is quarter note,  │  MN  Each note plays 7/8 of length
    etc.)  n = 1-64                  │  ML  Each note plays full length
 Tn  Sets number of quarter notes per │  Pn  Pause for the duration of
    minute (n = 32-255, 120 default  │      n quarternotes (n = 1-64)
────────────────────────────────Set Operation─────────────────────────────────
 MF  Plays music in foreground        │  MB  Plays music in background
───────────────────────────────Execute Substrings─────────────────────────────
     X + VARPTR$(string-expression)  │  Executes another command string

PLAY Statement Details

Syntax
  PLAY commandstring

The commandstring is a string expression containing one or more music
commands. The PLAY statement uses a concept similar to DRAW in that it
embeds a music macro language in one statement. A set of commands, used
as part of the PLAY statement, specifies a particular action.

  ◄Octave and Tone Commands►
  ◄Duration and Tempo Commands►
  ◄Foreground/Background Operation Commands►
  ◄Execute Substring Command►

In compiled programs, you should use the VARPTR$(variable) form for
variables. For example, the BASICA statements

  PLAY "XA$"
  PLAY "O = I"

should be written for the compiler like this:

  PLAY "X" + VARPTR$(A$)
  PLAY "O=" + VARPTR$(I)

PLAY Statement Programming Example

These examples use PLAY to play scales and a familiar melody.

Example 1

This example uses ">" to play the scales from octave 0 to octave 6,
then reverses with "<" to play the scales from octave 6 to octave 0:

SCALE$ = "CDEFGAB"
PLAY "o0 X" + VARPTR$(SCALE$)
FOR I = 1 TO 6
   PLAY ">X" + VARPTR$(SCALE$)
NEXT
PLAY "o6 X" + VARPTR$(SCALE$)
FOR I = 1 TO 6
   PLAY "<X" + VARPTR$(SCALE$)
NEXT
I think a noteworthy addition comes from VB4:

"Beep Statement

Sounds a tone through the computer's speaker.
Syntax:
Beep
Remarks:
The frequency and duration of the beep depend on your hardware and system software and vary among computers."

Obviously the standard "BEEP" statement in many languages is subject to the hardware's whims. That's why API calls
work so much better.

CeaSaR
Hey, what do I know?

User avatar
MrAl
Posts: 3862
Joined: Fri Jan 11, 2002 1:01 am
Location: NewJersey
Contact:

Re: "Beep, beep, beep!"

Post by MrAl » Thu Dec 24, 2009 12:16 pm

Hi again,


Well, i was using the Windows API and that's where i am having the problem.
The Beep command effect seems to vary from computer to computer.
That's really nasty. I wonder if someone makes a program to take the
place of this Beep command?
LEDs vs Bulbs, LEDs are winning.

Post Reply

Who is online

Users browsing this forum: No registered users and 8 guests