A Sound Output class

Description:

In the previous article http://www.codeguru.com/multimedia/scope_input_sound_class.shtml we talked 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.

How to use it

  • In the same way that the way we use for the Input Sound you just have to include the 2 Sound Output class files in ur project
  • The sample demo program use ....the same "quick & dirty" global declaration CSoundOut SoundOut; in CSndApp.cpp.
  • Call the function OpenOutput(); in the InitInstance App procedure. (the CloseOutput() at ExitIntance is optional)

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.

Update

Thanks to peoples who have contributed to this update

As Tom Wheeler mentioned ,the CSoundOut use now 2 buffers which are feed to the sound system, I saw source code sound applications (like playing wave file)that use more than 2 buffers which are feed to the sound system. When the fisrt buffer has been played the thread is notified to send an other one to the sound system. In this way the sound system has alway a buffer to play and this avoid time leak beetwin buffers.

An other problem is that the generator samples must be continus for the 2 buffers, if the sampling frequency change and the sound signal frequency also change, it is not really simple to have the boths buffers exactly synchronized to a precise number of periodes. The CSinGenerator class derived from CSoundOut has been added which resolve this kind of problem by using a special Sinusoid Oscillator algorithm. This is not a place to develop this signal processing application ,but readers can D/L the "goertzel.zip" file from my web to get.more informations.

Download the new demo code - 40 Kb

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



Comments

  • Cannot get the docs.

    Posted by Legacy on 08/13/2003 12:00am

    Originally posted by: Glenn

    This is a great program. I am trying to change the channels addresses and some of the features to increase my knowledge of sound cards. I tried to get the doc. files on the website http://www.multimania.com/yannstrc , but this is redirected to a French website and I cannot read French. Has this website been updated? If so where can I get the complete documents.

    Thanks for a great program,

    Glenn

    Reply
  • Excellent program!

    Posted by Legacy on 06/21/2003 12:00am

    Originally posted by: Amer

    thank you for posting this program..

    • Help me

      Posted by taolacha113 on 11/14/2006 08:24am

      i want to write ths source code (to compare the file size): -to record voice from microphone and compress it by GSM 6.10 standard and save it into *.wav file can you help me !!Thank you contact : kesitinhluoibieng@yahoo.com

      Reply
    Reply
  • Detecting Noise and Silence

    Posted by Legacy on 10/24/2002 12:00am

    Originally posted by: venkatesh

    hi

    Is there any way by which i can modify your code so that
    it does not takes the background noise and is there any way of trimming silence before the actual data starts and after the actual data ends...

    Regards

    Venkatesh

    Reply
  • gene_output_sound_class.shtml

    Posted by Legacy on 03/26/2001 12:00am

    Originally posted by: Phil

    The EXE supplied will not run at all, record, generate, or play. The code looks good if you are using VC from microcrap, however I am using BCB (much better!), and yet there seems to a bug or two. Can any one help?

    It's funny, I have at least a half a dozen different examples of using the sound card and either the code does not work or the use of advanced features like double buffering and DSP are not used. And all the different example code is structured differerntly, different ways to allocate memory, different API/MCI calls.

    I need help with a program that uses two or more buffers for record, a buffer for dsp, and a buffer for play, display would be nice but not required. Hell, all I want to do is experiment with different DSP algorithms using the pc. I really don't understand why PC sound has such poor support. Any help would be nice.

    Thanks

    Reply
  • SoundOut stereo does not work

    Posted by Legacy on 02/13/2001 12:00am

    Originally posted by: rsamuel

    most applications does'nt feature a stereo soundout like urs. One that deals with that is "Digital Audio in Java" by "Craiga Lindley".
    Is there any way of obtaning stereo effect (2 channels) with Low level windows functions like WAVEFORMATX

    Reply
  • There is so good sample code that I search it so long.

    Posted by Legacy on 01/15/2001 12:00am

    Originally posted by: Jimmy

    Dear friend :
    This sample code is very good. And it can run normally. Thanks

    Reply
  • Problems with samples

    Posted by Legacy on 04/10/2000 12:00am

    Originally posted by: Pedro

    Hi Yannick. I am a Spanish developer who is using your CSoundIn class. It seems that some samples do not agree with the actual speech. We have detected some clicks inserted in the speech. It seems that the buffer is overwritten by the soundblaster before us having processed it or last samples and first samples in consecutive buffers do not match.

    If you had detected it yet, I would thank sincerely any comment on this issue.


    Thank you very much.

    Pedro.

    Reply
  • cannot lock?

    Posted by Legacy on 10/11/1999 12:00am

    Originally posted by: cfchai

    I am running ur program using VC6.0, but I face an exception error while creating the wave resource..
    
    

    where the
    [ccode]
    HRESULT hr = m_pDsb->Lock(0, 0, &lpvPtr1, &dwBytes1, 0, 0, DSBLOCK_ENTIREBUFFER);
    [/ccode]

    the return result is neither DSERR_BUFFERLOST nor DS_OK, instead a large negative value.

    Hence I couldn't hear any voice by clicking the sound button afterwards.

    How do I solve this? Thank u


    Reply
Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • IBM Worklight is a mobile application development platform that lets you extend your business to mobile devices. It is designed to provide an open, comprehensive platform to build, run and manage HTML5, hybrid and native mobile apps.

  • Live Event Date: November 20, 2014 @ 2:00 p.m. ET / 11:00 a.m. PT Are you wanting to target two or more platforms such as iOS, Android, and/or Windows? You are not alone. 90% of enterprises today are targeting two or more platforms. Attend this eSeminar to discover how mobile app developers can rely on one IDE to create applications across platforms and approaches (web, native, and/or hybrid), saving time, money, and effort and introducing apps to market faster. You'll learn the trade-offs for gaining long …

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds