Sound_Output class for a Generator like


This article was contributed by Yannick Sustrac.

Description:

In the previous article http://www.codeguru.com/multimedia/scope_input_sound_class.shtml we discussed about the SoundIn class
which was provided to interface a sound card for input signal. The idea is now to create a class for an Output sound .

The Sound Output class which is provided now, to be used as a generator, is very similar to the Input class one. In fact, it has been
realised in a very short time by replacing all the "In" string in the CSoundIn class by the "Out" and by replacing the correct names in the base functions
of the Win32 Sound Api .

The CSoundOut::OpenOutput() is now the main start procedure. It initialise all the parametres of the sound card, create an EVENT object
and start the sound thread. The thread procedure is now used to signal to the sound class, (instead that a buffer is filled for the Input) ,that
it has been transmited to the Sound card and the Win Sound system is now requiring some new datas for transmiting.

The constructor of the CSoundOut:: class initialise a sin signal at 500hz in the Output Buffer. The size of the sound buffer is large enough
to have a continus signal during a long periode. The problem which remain unresolved for me is the behaviour when the sound process ends, and
signals that the buffer has to be filled. This can produce a time leak during which the signal is not feed to the sound card and unfortunatly produce a sound loose.
If you got an answer for this please informs us with Add Comment

How to use it

This is all you need to start the Sound process for audio Output.

The Scope View:

Is unchanged. it will display the Input which is a mix of the Input (Equvalent to the Mic) and the Output (Equivalent to the Wave).

Run the scope/generator demo program:

In the new Demo sample the SoundIn class is still active, a menu has been added to start/Stop the both Sound process.
Because some Sound system does'nt provide full duplex Input/Output you may be required to start & stop selectively the 2 process.
If you modify the sampling rate, you must also take into account that the Sound card use the same frequency rate for both Input/Ouput
and that the classes parametres must be set at the same one.

Before running it, let's have a look at the "reame.txt" file included in the project demo.

Download the new demo code 75k

Ps: If you are a little bit lasy to enhance the program by yourself..., you can get my full application for signal processing here:
http://www.mygale.org/~yannstrc go to Visual Sound Processing Studio page and enjoy it!

 

Posted: 24 November 1998

Add Comment


Goto Index © Copyright 1997-1998 CodeGuru  Contact : webmaster@codeguru.com