🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.os.msdos.programmer
Article #7946

Re: using C to access the Soundblaster

#7946
From: Kazimir Kylheku
Date: Mon, 25 Mar 1996 19:10
59 lines
3794 bytes
In article <4ig9su$jn9@garcia.efn.org>, Sonny Ovens <sovens@efn.org> wrote:
>Does anybody out there have a sample of some code that woud record voice 
>through the soundblaster, to a file? I am using C/C++. I am having 
>problems doing it myself, since I really dont know where to start. I am 

You don't start in comp.lang.c. This newsgroup is for the discussion of the C
language, not sound blaster cards.

>using the BLAST13 library, Although I would like to see something using 
>any library available. All I need is the simplest program possible.
>Also, does anybody have any Ideas on how to have the soundblaster tell me 
>the frequency of a tone that is at the input of the sound card? I want my 
>program to run diferent functions when certian tones are present at the 
>input. Not DTMF tones, just a regular sine wave type tone. I will have it 
>activate if the tone remains the same for .75 seconds, to avoid the SB 
>interpreting voice tones as tones I want to decode.

A newsgroup about signal processing would be appropriate for this topic. It's
not particular to the C language, or MSDOS.

I see that you did crosspost to comp.dsp already.

If you have one or a small number of definite frequencies that you wish to
check for you can simply see how the signal correlates with an artificial
reference waveform of the given frequency.

Basically, you project the input signal onto a basis consisting of a sine and a
cosine function of the frequency you are trying to detect. Pretend that the
signals and reference waveforms are giant vectors and you are taking a long
running dot product---you multiply the signal with the sine, and with the
cosine and accumulate the results into two separate running sums. Essentially,
you are projecting the signal vector into the vector space spanned by the sine
and cosine vector: you measure to what extent the signal has a component in the
sine and in the cosine. These two are an orthogonal vector basis, because they
are at 90 degrees to each other.

If the input signal frequency is close to the frequency of your sine and cosine
function, it will ``harmonize'' with the two and you will get some numbers which
roughly tells you the coefficients of the sine and cosine component present in
your signal.  You can take these two numbers as a 2D vector whose direction
gives you the phase angle, and length gives you the amplitude.

If you sample sections that are too short, the presence of noise may mask the
signal too much. If you sample for too long, you will reject more and more
frequencies that are close to what you are looking for, increasingly selecting
for the precise frequency. Frequencies that are not quite equal to the one you
are filtering for will cause a rotation of the phase vector (related to the
beats you hear when you play two notes on a guitar that are close in
frequency), which will cause cancellation over the long run. You have to
experiment a little bit.

You also have to normalize the results by dividing by the length of the sine
and cosine vector. You can do this by dividing by the sum of the squares of the
cosine and sine samples alone.

Checking thus for the presence of some frequency or group of frequencies is
easy, but determining an arbitrary pitch is not trivial.

-- 
Technical Details
Message-ID: <4j6r34INNei7@anvil.ugrad.cs.ubc.ca>
Path: arc1-ca.pugleaf.net!anvil.ugrad.cs.ubc.ca!not-for-mail
References: <4ig9su$jn9@garcia.efn.org>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!anvil.ugrad.cs.ubc.ca!not-for-mail
From: c2a192@ugrad.cs.ubc.ca (Kazimir Kylheku)
Newsgroups: comp.os.msdos.programmer,comp.dsp,comp.lang.c
Subject: Re: using C to access the Soundblaster
Date: 25 Mar 1996 11:10:28 -0800
Organization: Computer Science, University of B.C., Vancouver, B.C., Canada
Message-ID: <4j6r34INNei7@anvil.ugrad.cs.ubc.ca>
References: <4ig9su$jn9@garcia.efn.org>
NNTP-Posting-Host: anvil.ugrad.cs.ubc.ca
Keywords: soundblaster