delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1999/02/17/10:42:15

From: "Andrew Davidson" <andrew AT lemure DOT freeserve DOT co DOT uk>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: Fast reading of multiple keypresses in Allegro
Date: Wed, 17 Feb 1999 13:51:38 -0000
Organization: Customer of Planet Online
Lines: 61
Message-ID: <7aenjo$mmm$1@news5.svr.pol.co.uk>
References: <8D53104ECD0CD211AF4000A0C9D60AE353FA26 AT probe-2 DOT acclaim-euro DOT net>
NNTP-Posting-Host: modem-33.tellurium.dialup.pol.co.uk
X-Trace: news5.svr.pol.co.uk 919265720 23254 62.136.25.161 (17 Feb 1999 15:35:20 GMT)
NNTP-Posting-Date: 17 Feb 1999 15:35:20 GMT
X-Complaints-To: abuse AT theplanet DOT net
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 5.00.0810.800
X-MimeOLE: Produced By Microsoft MimeOLE V5.00.0810.800
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

Shawn Hargreaves <ShawnH AT Probe DOT co DOT uk> wrote in message
news:8D53104ECD0CD211AF4000A0C9D60AE353FA26 AT probe-2 DOT acclaim-euro DOT net...
>Andrew Davidson writes:
>> I'm a bit stuck trying to read a number of simultaneous key presses
>> using Allegro's key[] structure. The code goes roughly as follows:
>>
>> if(keypressed()) {
>>     if(key[KEY_A]) set a flag;
>>     if(key[KEY_B]) set b flag;
>>     ...
>>     clear_keybuf();
>> }
>
>It doesn't make sense to mix calls to keypressed() and use of the
>key[] array within the same piece of code: these are totally different
>ways to represent the input, and don't mix well. The keypressed()
>routine, along with readkey(), provide a buffered input queue similar
>to the BIOS functions or stdin, wheras the key[] array provides raw
>access to the current up/down state of each button. Checking the
>keypressed() return value will not tell you whether any of the
>key[] flags are currently set, but only if a keypress is currently
>waiting in the readkey() input queue.
>
>You probably don't want to be calling clear_keybuf() here, either.
>That both flushes the input queue and resets all the key[] flags,
>after which they won't correctly reflect the hardware state. Don't
>do this in the middle of your input processing code. Just look at
>the key[] values on their own: they contain all the info you will
>need.

Ahh.. err... *blush*... how embarrasing :) Thanks :)

Anyway, if I'm going to make a fool of myself I suppose I'd better go all
the way and ask a little more advice...

I'm trying to create noise by playing a very short sample as fast as
possible. The sample is created using:

SAMPLE *samp;
samp=create_sample(8, 0, 1000, 1);

Which should, if I read the docs right, create me an 8 bit mono sample
playing back at 1000hz with a duration of 1. I'm not quite sure I'm getting
the frequency/duration bit right here... I'm after playing a sample that
would create little more than a faint, fast click if played once but, if
played many times can give the impression of notes. Should I use a frequency
of 1 for this or am I on the right lines?

I play the sample using:

play_sample(samp, 255, 128, 1000, 0);

is this fast enough to give the effect of a clear sound (assuming that the
cpu is not devoted to playing samples but has a fair few other things to do)
or do I need to write a custom routine to handle this using the voice
functions?

Again, thanks for any help,
Andrew


- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019