how to create beep beep, ..., beep,beep sound. 
Author Message
 how to create beep beep, ..., beep,beep sound.

ascii 7 is a beep sound, but what should I do to create the
following sound?

        beep beep, ..., beep beep, ... , beep beep, ...

where ... means a second or half a second pause.

sleep() does not work.

By the way, I am programming under unix, not dos.



Wed, 31 Jan 1996 23:00:03 GMT  
 how to create beep beep, ..., beep,beep sound.

Quote:
> ascii 7 is a beep sound, but what should I do to create the
> following sound?

>    beep beep, ..., beep beep, ... , beep beep, ...

> where ... means a second or half a second pause.

> sleep() does not work.

> By the way, I am programming under unix, not dos.

Ok I used a program under UNIX just written to do "beep beep ..." 10 times.
It seemed as though it first waited 10 seconds then did a stream of beeps,
this not what you or I would expect. I then stuck the printf in an if-statement
and compared it to 2 making it execute the sleep if that was true. Program
worked just like it wasn't supposed to as before.

Then I though that for no good reason the program is saving up these bells
and delivering them at once after the sleeps. So after each printf and
before each sleep I placed a 'fflush (stdout)'...

It works! I can't explain why it was saving up the bells, but I'm sure
someone else can. At least this is a sure fix for the time being ;)
--
Principals of Programming Languages - A class which, when complete, the
  students speak with a LISP, SMeLl strange and can no longer C straight.




Wed, 31 Jan 1996 23:24:38 GMT  
 how to create beep beep, ..., beep,beep sound.
Someone else suggested in mail that instead of doing 'fflush (stdout)' a
single call to setvbuf can make printf unbuffered. I tried this and
it also works. I used the following call which may not be perfect but works:

setvbuf (stdout, NULL, _IONBF, 0);

Doing a '\n' will also clear the buffer, but then a newline gets printed which
may not be desired.
--
Principals of Programming Languages - A class which, when complete, the
  students speak with a LISP, SMeLl strange and can no longer C straight.




Thu, 01 Feb 1996 02:02:30 GMT  
 how to create beep beep, ..., beep,beep sound.

Quote:

>> ascii 7 is a beep sound, but what should I do to create the
>> following sound?

>>        beep beep, ..., beep beep, ... , beep beep, ...

>> where ... means a second or half a second pause.

>> sleep() does not work.

>> By the way, I am programming under unix, not dos.

>Ok I used a program under UNIX just written to do "beep beep ..." 10 times.
>It seemed as though it first waited 10 seconds then did a stream of beeps,
>this not what you or I would expect. I then stuck the printf in an if-statement
>and compared it to 2 making it execute the sleep if that was true. Program
>worked just like it wasn't supposed to as before.

>Then I though that for no good reason the program is saving up these bells
>and delivering them at once after the sleeps. So after each printf and
>before each sleep I placed a 'fflush (stdout)'...

>It works! I can't explain why it was saving up the bells, but I'm sure
>someone else can. At least this is a sure fix for the time being ;)

The reason it was saving up the bells is because output to stdout is buffered
to save time.  When you do an fflush(stdout) it clears the buffer.  If stdout
is connected to a terminal, a newline will also flush the buffer.

A way around this is to output to stderr instead of stdout.  The stream stderr
is not buffered, so you will get your bells immediately.  I assume this is
what you want, since bells to any place other than the tty is kind of
pointless.

--

Put your Nose to the Grindstone!
        -- Amalgamated Plastic Surgeons and Toolmakers, Ltd.



Thu, 01 Feb 1996 00:03:03 GMT  
 how to create beep beep, ..., beep,beep sound.

Quote:


>>It works! I can't explain why it was saving up the bells, but I'm sure
>>someone else can. At least this is a sure fix for the time being ;)

It may also depend on the terminal type.  If I send two quick \007
characters to my terminal (an IBM3151) I just get a slightly longer beep.
A dozen or so bel characters give me a noticeably longer beep.  If I want
a distinct beep/beep/pause, then I have to insert something between the
bells to cause a delay.  I thought the null character \000 would be the
ideal candidate as it was my understanding that one of the original uses
of the null was as a delay between carriage return/new line and starting
print on the next line to give the type head enough time to return to the
start of the line.

It seems, though, that the UNIX STDIO routine (or possibly PERL's, since
I did my testing in PERL) must be throwing away the nulls and not sending
them to the terminal.  At any rate, I was able to get the effect by sending
a number of space/backspace characters (about 250) between the bells.

My final code (in PERL):

$|= 1;# Make sure STDOUT is unbuffered
for(;;) { print "\007"," \010"x250, "\007"; sleep 1 }
--

Computing Services  UofNB  Box 4400     (506) 453-3590  (FAX)
Fredericton, NB,  CANADA,  E3B 5A3



Thu, 01 Feb 1996 09:12:53 GMT  
 how to create beep beep, ..., beep,beep sound.

Quote:

>It may also depend on the terminal type.  If I send two quick \007
>characters to my terminal (an IBM3151) I just get a slightly longer beep.
>A dozen or so bel characters give me a noticeably longer beep.  If I want
>a distinct beep/beep/pause, then I have to insert something between the
>bells to cause a delay.  I thought the null character \000 would be the
>ideal candidate as it was my understanding that one of the original uses
>of the null was as a delay between carriage return/new line and starting
>print on the next line to give the type head enough time to return to the
>start of the line.

Unfortunately, ANSI C provides no reliable way to produce two distinct BEL's
in fast cadence if the underlying hardware does not provide support and the
two BEL's are merged together. Sending NUL's is not a solution, because it's
practically impossible to find out, at run time, the number of NUL's required.
It depends on the length of the BEL, which is not standard and the baud rate
at which the terminal operates, if it's connected by a serial link. The other
approach, of using a short software delay does not work either, because its
length is unknown (see above) and because ANSI does not provide direct support
for less than 1 second delays. On single tasking systems, shorter delays can
be implemented using clock(), if CLOCKS_PER_SEC >> 1.

Dan
--
Dan Pop
Tel:   +41.22.767.2335

Mail:  CERN - PPE, Bat. 21 1-023, CH-1211 Geneve 23, Switzerland



Thu, 01 Feb 1996 20:12:29 GMT  
 how to create beep beep, ..., beep,beep sound.

Quote:

> Ok I used a program under UNIX just written to do "beep beep ..." 10 times.
> It seemed as though it first waited 10 seconds then did a stream of beeps,
> this not what you or I would expect. I then stuck the printf in an
> if-statement and compared it to 2 making it execute the sleep if that was
> true. Program worked just like it wasn't supposed to as before.

I'm not sure I implemented this as I should, but just perhaps, you need a \n
in order for printf to flush. I tried it this way:

   printf("%c\n", 7);
   sleep(1);
   printf("%c\n", 7);
   ...

and it seems to work.

--

Tel: Intl+972+4-313610
Disclaimer: This message will destroy itself in 5 seconds.



Thu, 01 Feb 1996 13:00:35 GMT  
 how to create beep beep, ..., beep,beep sound.

Quote:
>I'm not sure I implemented this as I should, but just perhaps, you need a \n
>in order for printf to flush. I tried it this way:

>   printf("%c\n", 7);
>   sleep(1);
>   printf("%c\n", 7);
>   ...

>and it seems to work.

Yet another bad example from Mr Schreiber :-)

The problem is that it assumes an ASCII implementation and thus it
has portability problems for those using EBCDIC (or God knows what other
character sets are still in use). It should look like:

printf("\a\n");
sleep(1);
printf("\a\n");

This solution has also the disadvantage that lots of newlines are sent to the
terminal, causing the screen contents to be scrolled. The solutions based on
the use of fflush or printing to stderr or disabling the buffering on stdout
are clearly better.

Dan
--
Dan Pop
Tel:   +41.22.767.2335

Mail:  CERN - PPE, Bat. 21 1-023, CH-1211 Geneve 23, Switzerland



Fri, 02 Feb 1996 07:06:03 GMT  
 how to create beep beep, ..., beep,beep sound.
The following code will produce 10 sets of 2 beeps each with an approximate
pause of 1 second. It should be portable on any terminal that can produce
simple sound as such and makes no assumptions (I hope) about the
implementation.

----------------------------------
#include <stdio.h>

int main (void)
{
  int i;

  for (i = 0; i < 10; i++)
     {
     printf ("\a\a");
     fflush (stdout);
     sleep (1);
     }

  return (0);

Quote:
}

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

I know I could also do an fprintf to stderr, but it's not an error ;)...
And I could have used setvbuf, but wouldn't want to mess up printf for
later output. This solves the problem and should not produce any side
effects.
--
Principals of Programming Languages - A class which, when complete, the
  students speak with a LISP, SMeLl strange and can no longer C straight.




Fri, 02 Feb 1996 07:40:44 GMT  
 
 [ 9 post ] 

 Relevant Pages 

1. To beep or not to beep.

2. DotNet Methods for Application Audio Cues (Beeps, Sounds)

3. Beep() sound effect

4. How to deactivate beep sound after compile ??

5. Beep() or Sound() like functions In Visual C 6.0

6. Beep sound in source file mode

7. beep sound

8. "beep" sound

9. Issuing beep sound on PC speaker

10. loud beep sound from PC speaker?

11. How to disable the beep sound?

12. Turn off the Beeping sound?

 

 
Powered by phpBB® Forum Software