Beep function

  • Thread starter Thread starter Ahmed Fat-hi
  • Start date Start date
A

Ahmed Fat-hi

I need function that generates simple tone with frequency
1562.5 HZ to be played on the audio

device for duration 1920 microseconds.

i can not use the Beep function since it has the following
declaration

BOOL Beep(
DWORD dwFreq, // sound frequency in HZ
DWORD dwDuration // sound duration in milliseconds
);


I can not get the precigion i want because i need the
frequency to be float (1562.5) and i need

the inteval to be in microseconds(1920 microseconds) not
milliseconds as in Beep.

can u help me?

thanx
Ahmed Fat-hi
 
I need function that generates simple tone with frequency
1562.5 HZ to be played on the audio
device for duration 1920 microseconds.

To achieve this kind of precision, you have generate this audio wave by
hand.
Prepare the sound buffer for the highest frequency (Fs) supported by your
soundcard (usually 44.1 kHz or 48 kHz).
You need to generate exactly three periods (n) of a wave at the frequency
(Fg) 1562.5 Hz.

Given this:
Fs = 44100 or 48000 Hz
Fg = 1562.5 Hz
n = 3

Required sound buffer size:
s = n * Fs / Fg = 85 or 92 samples

Create the buffer and fill it with required samples of a sine wave:

signed int16 buffer;
const int max_amplitude = 16383;
int i;
for (i=0; i < s; i++)
buffer = max_amplitude * sin(i * 2 * pi * Fg / Fs);

Then, using DirectSound or one of the waveOut* functions, play the buffer.

--
pozdrawia
(e-mail address removed)
Anything was possible last night. That was the trouble
with last nights. They were always followed by this mornings.
- Terry Pratchett, "Small Gods"
 
Back
Top