Mail Archives: djgpp/1999/02/17/10:42:15
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 -