CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 1 of 2 12 LastLast
Results 1 to 15 of 16
  1. #1
    Join Date
    Dec 2006
    Posts
    13

    Direct Soundcard Control

    All, I am trying to directly control the built-in soundcard in my laptop. I know how to play MP3s and WAVs and such. I want to be about to directly control the soundcard and produce my own waveforms and also have amplitude control of all soundcard output.
    Any ideas or function calls?
    Keith

  2. #2
    Join Date
    Jun 2005
    Location
    JHB South Africa
    Posts
    3,772

    Re: Direct Soundcard Control

    To produce your own waveforms you will need to use mathematical functions to create the byte stream and you can then use the Playsound API to play it..

    it you need more help with this, just holer..

    Gremmy.....
    Articles VB6 : Break the 2G limit - Animation 1, 2 VB.NET : 2005/8 : Moving Images , Animation 1 , 2 , 3 , User Controls
    WPF Articles : 3D Animation 1 , 2 , 3
    Code snips: VB6 Hex Edit, IP Chat, Copy Prot., Crop, Zoom : .NET IP Chat (V4), Adv. ContextMenus, click Hotspot, Scroll Controls
    Find me in ASP.NET., VB6., VB.NET , Writing Articles, My Genealogy, Forum
    All VS.NET: posts refer to VS.NET 2008 (Pro) unless otherwise stated.

  3. #3
    Join Date
    Dec 2006
    Posts
    13

    Re: Direct Soundcard Control

    Gremmy,
    Thanks for the reply, but..., the examples just show how to play a wav file. I want to be able to setup the attack, sustain, decay, and release of A single wave form and control the output. Kindof like the old Commodre computers allowed you to do. If I wanted to send out a triangle wave, a square wave, a sawtooth wave, stepped sine, pure sine, etc... and be able to vary the frequency, how do I control the soundcard directly. For example, during the early days of PCs a sound card would have a buss address of around H300 then you could control different registers by POKEing values into different addresses, hense controlling the soundcards output.

    I am trying to generate IRIG-B though software and the soundcard output (which can be done) instead of by my hardware.

    Hope this is understandable!!!

    thanks,
    Keith

  4. #4
    Join Date
    Jun 2005
    Location
    JHB South Africa
    Posts
    3,772

    Re: Direct Soundcard Control

    Oooo i loved the C64 sound....

    I'll see if i can put together a little project for you..

    Gremmy...
    Articles VB6 : Break the 2G limit - Animation 1, 2 VB.NET : 2005/8 : Moving Images , Animation 1 , 2 , 3 , User Controls
    WPF Articles : 3D Animation 1 , 2 , 3
    Code snips: VB6 Hex Edit, IP Chat, Copy Prot., Crop, Zoom : .NET IP Chat (V4), Adv. ContextMenus, click Hotspot, Scroll Controls
    Find me in ASP.NET., VB6., VB.NET , Writing Articles, My Genealogy, Forum
    All VS.NET: posts refer to VS.NET 2008 (Pro) unless otherwise stated.

  5. #5
    Join Date
    Dec 2006
    Posts
    13

    Re: Direct Soundcard Control

    Thanks, I understand the function calls, but I want to do more than play, stop, ff, rew, etc.....
    Keith

  6. #6
    Join Date
    Dec 2006
    Posts
    13

    Re: Direct Soundcard Control

    Gremmy, You know, If I could figure out how to send just 1 cycle of a sine wave at 1KHz or (1ms) at different amplification levels, then the rest should be easy. What do you think?
    Keith

  7. #7
    Join Date
    Jun 2005
    Location
    JHB South Africa
    Posts
    3,772

    Re: Direct Soundcard Control

    You just need the mathematicle function to produce this wave at, lets say 11khz, in a array..

    you then can alter the array values accordingly, then pass the array to playsnd...

    at the mo this looks like the best way to turn...

    gremmy...
    Articles VB6 : Break the 2G limit - Animation 1, 2 VB.NET : 2005/8 : Moving Images , Animation 1 , 2 , 3 , User Controls
    WPF Articles : 3D Animation 1 , 2 , 3
    Code snips: VB6 Hex Edit, IP Chat, Copy Prot., Crop, Zoom : .NET IP Chat (V4), Adv. ContextMenus, click Hotspot, Scroll Controls
    Find me in ASP.NET., VB6., VB.NET , Writing Articles, My Genealogy, Forum
    All VS.NET: posts refer to VS.NET 2008 (Pro) unless otherwise stated.

  8. #8
    Join Date
    Dec 2006
    Posts
    13

    Re: Direct Soundcard Control

    OK, I can create the array with the correct values, but how do I pass it to playsound, when it is looking for a filename to play? Sorry for the illiteritcy (sp?) Keith

  9. #9
    Join Date
    Jun 2005
    Location
    JHB South Africa
    Posts
    3,772

    Re: Direct Soundcard Control

    Playsound does accept memory locations...

    attached is a old shelved project of mine, with alot of sample code to help you...

    have fun with it...

    Almost time for me to hit the sack, but over the weekend i will look into making a project closer to what your trying to do..

    Gremmy...
    Attached Files Attached Files
    Articles VB6 : Break the 2G limit - Animation 1, 2 VB.NET : 2005/8 : Moving Images , Animation 1 , 2 , 3 , User Controls
    WPF Articles : 3D Animation 1 , 2 , 3
    Code snips: VB6 Hex Edit, IP Chat, Copy Prot., Crop, Zoom : .NET IP Chat (V4), Adv. ContextMenus, click Hotspot, Scroll Controls
    Find me in ASP.NET., VB6., VB.NET , Writing Articles, My Genealogy, Forum
    All VS.NET: posts refer to VS.NET 2008 (Pro) unless otherwise stated.

  10. #10
    Join Date
    Dec 2006
    Posts
    13

    Re: Direct Soundcard Control

    Gremmy,
    I found some code for what I think is DirectSound. The Sine...zip file is the original, and I have similified it to test4gremmy.zip

    (Sine...zip is VB6 & test4gremmy.zip is VB5) (I don't have VB6)

    Problem, I can get 1 pulse out (1 single sinewave at 1khz), but then I don't get another pulse out until 20ms later. Even with playing with the timer to 1ms. Is there a min time for Timer? and is there a min. time for the Directsound calls?
    Also, where can I get a list of all the functions and description of the Directsound function calls?
    Thanks,

    Keith
    Attached Files Attached Files

  11. #11
    Join Date
    Jun 2005
    Location
    JHB South Africa
    Posts
    3,772

    Re: Direct Soundcard Control

    Hey this is a good find....

    Okay i hear the problem that you have with this..

    I will dig around the code a little and see what i can come up with...

    Gremmy....
    Articles VB6 : Break the 2G limit - Animation 1, 2 VB.NET : 2005/8 : Moving Images , Animation 1 , 2 , 3 , User Controls
    WPF Articles : 3D Animation 1 , 2 , 3
    Code snips: VB6 Hex Edit, IP Chat, Copy Prot., Crop, Zoom : .NET IP Chat (V4), Adv. ContextMenus, click Hotspot, Scroll Controls
    Find me in ASP.NET., VB6., VB.NET , Writing Articles, My Genealogy, Forum
    All VS.NET: posts refer to VS.NET 2008 (Pro) unless otherwise stated.

  12. #12
    Join Date
    Jun 2005
    Location
    JHB South Africa
    Posts
    3,772

    Re: Direct Soundcard Control

    Okay i got it...

    very simple...

    in the Form Activate sub change the following line...
    Code:
        DSB(0).Play DSBPLAY_DEFAULT
    TO
    Code:
        DSB(0).Play DSBPLAY_LOOPING
    and comment out the same line in the Timer event....

    This will give you the constant tone, your looking for...

    Cheers ...

    Gremmy...
    Articles VB6 : Break the 2G limit - Animation 1, 2 VB.NET : 2005/8 : Moving Images , Animation 1 , 2 , 3 , User Controls
    WPF Articles : 3D Animation 1 , 2 , 3
    Code snips: VB6 Hex Edit, IP Chat, Copy Prot., Crop, Zoom : .NET IP Chat (V4), Adv. ContextMenus, click Hotspot, Scroll Controls
    Find me in ASP.NET., VB6., VB.NET , Writing Articles, My Genealogy, Forum
    All VS.NET: posts refer to VS.NET 2008 (Pro) unless otherwise stated.

  13. #13
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    Re: Direct Soundcard Control

    Timers are effective only down to 10-20ms. That would be the additional lag that you get.
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  14. #14
    Join Date
    Dec 2006
    Posts
    13

    Re: Direct Soundcard Control

    Hi Gremmy, Correct, I can get a nice constant tone out, but.... I need to have control of the amplitude (volume) to an accuracy of each cycle. Even putting the following:

    dsb(0).play dsbplay_default
    dsb(0).play dsbplay_default

    back to back, I still get a lag of 20ms before the 2nd command is executed, (sometimes it isn't executed at all) The function call must take all the computer process time until it is finished with whatever it has to do, which I don't know what that is.

    There is software out there that can produce IRIG-B signal out the speaker port, but they are reading the computer time and then producing an output. This is kindof what I want, but I want to count down to an event, and output the time in an IRIG-B format.

    I just don't know if they did it in C or VB. I did read that with C you have more control over hardware items, but I don't know if that is exactly true.
    and, they are not so eager to let me in on their secret.

    I will keep plugging away, and see what I come up with.

    Thanks,
    Keith

  15. #15
    Join Date
    Jun 2005
    Location
    JHB South Africa
    Posts
    3,772

    Re: Direct Soundcard Control

    I whould say leave the tone to play constant, and in your timer event use the setvolume to play with the amplitude..

    I've moded your project a little to show how this can be done ...

    Have fun


    Gremmy...
    Attached Files Attached Files
    Articles VB6 : Break the 2G limit - Animation 1, 2 VB.NET : 2005/8 : Moving Images , Animation 1 , 2 , 3 , User Controls
    WPF Articles : 3D Animation 1 , 2 , 3
    Code snips: VB6 Hex Edit, IP Chat, Copy Prot., Crop, Zoom : .NET IP Chat (V4), Adv. ContextMenus, click Hotspot, Scroll Controls
    Find me in ASP.NET., VB6., VB.NET , Writing Articles, My Genealogy, Forum
    All VS.NET: posts refer to VS.NET 2008 (Pro) unless otherwise stated.

Page 1 of 2 12 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured