Choose between different sound cards for playback in VB.net
Choose between different sound cards for playback in VB.net
Choose between different sound cards for playback in VB.net
Choose between different sound cards for playback in VB.net
Choose between different sound cards for playback in VB.net
Choose between different sound cards for playback in VB.net Choose between different sound cards for playback in VB.net Choose between different sound cards for playback in VB.net Choose between different sound cards for playback in VB.net Choose between different sound cards for playback in VB.net Choose between different sound cards for playback in VB.net Choose between different sound cards for playback in VB.net Choose between different sound cards for playback in VB.net
Choose between different sound cards for playback in VB.net Choose between different sound cards for playback in VB.net
Choose between different sound cards for playback in VB.net
Go Back  Xtreme Visual Basic Talk > > > Choose between different sound cards for playback in VB.net


Reply
 
Thread Tools Display Modes
  #1  
Old 05-02-2010, 10:48 PM
therealtomlapp therealtomlapp is offline
Freshman
 
Join Date: Jan 2009
Location: New Jersey
Posts: 40
Default Choose between different sound cards for playback in VB.net


I have a program that I have been building for quite some time, which is sort of a media center type of program. One of the features it includes is a CallerID and call management system that I have integrated into it. I am actually turning the ringers off on my phones, and the program will have it's own ringer instead. One reason i'm doing that is, it is programmed only to ring if I actually have the number already in my phonebook (i.e. no more telemarketers), and other features like quiet time (after a preset time, let's say 11:00 the phone won't ring). So anyhow I have 2 sound cards in my system. One sound card is connected to my living room home theater, which would be for watching tv, movies, etc. The other sound card is going to a separate amplifier that will power speakers that are throughout the house. I want to be able to programatically tell my program to output sound on the secondary sound card. It will be just a simple wav file, and hopefully speech as well (using the system.speech.speechsynthesizer). So no matter if your watching a movie, or playing xbox (meaning the stereo will no longer be playing audio from the computer), when the phone rings you will hear the ringer over the speakers, along with a voice saying "Joe Schmoe is calling". I don't know if I can specifically have it play certain sounds over one card, or if it is a per application setting. For instance, if you are watching a movie (meaning the movie is playing through the windows media player control, inside of my program), and the phone rings, I want the phone to ring on the other card without changing the audio from the movie. If i'm not able to do it that way, and if the program itself is only able to play through one card at a time, I will simply make the caller id portion it's own separate application, that way I could make it happen. If I could just keep it as all one app, that would obviously be preferred.
Reply With Quote
  #2  
Old 05-03-2010, 12:07 AM
Qua's Avatar
QuaChoose between different sound cards for playback in VB.net Qua is offline
Impetuous & volatile

* Expert *
 
Join Date: Apr 2005
Posts: 2,177
Default

Too tired to read through all of your post (due to lack of line breaks), but I assume that you want to enumerate- and play sounds on different sound card interfaces. This is not natively possible in .NET. This means that you will have to either P/Invoke into the winmm.dll windows API to perform these functions or find a library that has already done this for you.

As for libraries that you could look into (taken from this thread):
It is possible for a single application to output audio to several interfaces simultaniously, so no need to create a second application.
__________________
Reading is the foundation for all knowledge - Unknown.
Reply With Quote
  #3  
Old 05-03-2010, 12:20 AM
therealtomlapp therealtomlapp is offline
Freshman
 
Join Date: Jan 2009
Location: New Jersey
Posts: 40
Default

Ok, good that I can keep it all together as one app. You are correct about what I am looking to do. I will google for the api that allows me to change it via the winmm.dll library.

Correct me if i'm wrong but i'm assuming that when I do change it using the api, the change is only going to apply to sounds that are played afterwards. For instance

(at this point, sound card #1 is selected)
First the program plays a movie using the windows media player control

(then, whatever code changes to sound card #2 is executed)
Then the program plays the audio file.

Since the movie began playing BEFORE the change, it still remains on sound card #1, while the audio file is played on #2. Am I correct when saying that?
Reply With Quote
  #4  
Old 05-03-2010, 12:34 AM
therealtomlapp therealtomlapp is offline
Freshman
 
Join Date: Jan 2009
Location: New Jersey
Posts: 40
Default

So far I did the following:

Code:
Private Declare Function waveOutGetNumDevs Lib "winmm.dll" () As Long

MsgBox(waveOutGetNumDevs)
Ran that just to be sure, and it returned a number 4, which is correct as far as playback devices, so i'm definitely getting close. The question is does anyone know how to select which device through winmm.dll, because I can't seem to find that one.
Reply With Quote
  #5  
Old 05-03-2010, 10:23 AM
therealtomlapp therealtomlapp is offline
Freshman
 
Join Date: Jan 2009
Location: New Jersey
Posts: 40
Default

Honestly i'm starting to realize that I am actually better off having the caller id portion as a completely separate app. The reason for this is, the app is going to play a wav sound (ringer), as well as speech through the speechsynthesizer, and I don't know how complicated it would be to route both of those to another sound card while maintaining audio playing from media (movies, music, etc). So basically if I can execute code that would just make the entire app play on a different sound card that would work just fine. I know I have seen this done before and as far as I remember it wasn't that complicated. I just for some reason can't seem to find anything through google.
Reply With Quote
  #6  
Old 05-06-2010, 03:44 AM
therealtomlapp therealtomlapp is offline
Freshman
 
Join Date: Jan 2009
Location: New Jersey
Posts: 40
Default

Uggh, this is so frustrating. I know the code is out there because I remember seeing it years ago, and it wasn't even that complicated.

On top of that, there are many programs that allow the user to select what output device to use for audio, so it can be done. Is there anyone who can possible point me in the right direction with this? I'm going to keep the caller id app completely separate from everything else, so all I need is when the program runs to run code to make the audio go out into a specific playback device, I do not need the program to be able to output to multiple devices.

I looked into the WaveOutOpen api, but once again hitting dead ends as far as how to apply it, and i'm not sure if this is even what I need. I think that WaveOutOpen possible opens a "channel" to a specific audio card, then I use that "channel" to output wave files, but I have a feeling that as soon as I execute the speech code (system.speech.speechsynthesizer), that the speech will continue to go out of the main sound card. I need all audio, speech and everything to output to a specific card.
Reply With Quote
  #7  
Old 05-10-2010, 04:23 PM
therealtomlapp therealtomlapp is offline
Freshman
 
Join Date: Jan 2009
Location: New Jersey
Posts: 40
Default

I have an idea, if anyone can fill me in as to what direction to go. I've seen that certain programs are able to represent themselves to Windows as a "communication device". If I go into the "playback devices" control panel, I can individually set the different sound card to the "default communications device" and keep the main one still the default. So if I am able to somehow make my program represent itself as a communications type program, this will work. I've been trying to google some code or an api, I did read a page that talks about new api's in Windows 7 that allow for this functionality, but there were no specifics.
Reply With Quote
  #8  
Old 05-10-2010, 06:37 PM
therealtomlapp therealtomlapp is offline
Freshman
 
Join Date: Jan 2009
Location: New Jersey
Posts: 40
Default

I've got it, but it only works once for some reason.

Code:
   
Public Sub PlayTextToSpeech(ByVal SpeechText As String)

        Dim DsDevice As DirectSound.Device

        DsDevice = New Device(myDevices(2).DriverGuid)
        DsDevice.SetCooperativeLevel(Me, CooperativeLevel.Normal)
        Dim _buffer As SecondaryBuffer

  
        Dim VoiceStream As Stream = New MemoryStream()
        Dim sinfo As New SpeechAudioFormatInfo(128, AudioBitsPerSample.Eight, AudioChannel.Stereo)
        Dim synth As New SpeechSynthesizer()

        synth.SetOutputToWaveStream(VoiceStream)

        synth.Speak(SpeechText)

        VoiceStream.Position = 0

        _buffer = New SecondaryBuffer(VoiceStream, DsDevice)

        _buffer.Play(0, BufferPlayFlags.Default)

End Sub
When I execute that function, it outputs the speech to the other sound card like I wanted. The only problem is, when I do it a second time, it throws an error on the following line:

_buffer = New SecondaryBuffer(VoiceStream, DsDevice)

The error is:
BufferTooSmallException was unhandled
Error in the application

Other than that, I figured out how to output audio to another card, just the code I wrote appears to be slightly off since it throws an error the second time
Reply With Quote
  #9  
Old 05-11-2010, 08:52 AM
Satal Keto's Avatar
Satal Keto Satal Keto is offline
Centurion
 
Join Date: Nov 2005
Location: behind you
Posts: 111
Default

Unfortunately I can't help you with this but I would just like to say thank you as this is something that I have been looking at doing (well something similar), but believed it wasn't possible.
Thank you for keeping this thread active with your updates as they will aid me greatly when I get the free time to work on my project.
__________________
Sam Jenkins' Website
Reply With Quote
  #10  
Old 05-11-2010, 01:10 PM
therealtomlapp therealtomlapp is offline
Freshman
 
Join Date: Jan 2009
Location: New Jersey
Posts: 40
Default

I figured it all out finally, I even figured out how to set the flag so that the sound plays no matter if the application has focus or not. Now when my phone rings, I hear a ring tone, followed by a voice announcing who's calling over my public address system. I even figured out how to modify the frequency so i even added some code to alter the frequency a little bit each time it speaks, as to make it sound less robotic. I will clean up my code and post it on here. The only thing is I had to cheat a small bit, since I am outputting a wave sound, then speech I kind of had to do things twice, but used a timer to delay when the speech would come out (because before the sound and the speech were literally sounding off at the same time). I guess eventually I need to learn how to create a sound buffer, and append to it, then play the entire one once. But whatever, I got the program doing what I want now and that's all that matters to me. This DirectSound stuff is pretty awesome once you get the hang of it, it appears that I can also (but I have to learn how) direct audio to specific speakers (I have a 5.1 sound card), so that if I wanted I could have certain annoucements go to certain rooms of the house.
Reply With Quote
  #11  
Old 05-12-2010, 03:14 AM
Satal Keto's Avatar
Satal Keto Satal Keto is offline
Centurion
 
Join Date: Nov 2005
Location: behind you
Posts: 111
Default

Wow that sounds absolutely awesome
I'm really looking forward to seeing the code that you've used to achieve this. Its greatly appreciated that you would be willing to share your code.

Out of curiosity what application are you using for your telephone system to allow for your computer to know when you're receiving a call, is it something like skype?
__________________
Sam Jenkins' Website
Reply With Quote
  #12  
Old 05-12-2010, 11:52 AM
therealtomlapp therealtomlapp is offline
Freshman
 
Join Date: Jan 2009
Location: New Jersey
Posts: 40
Default

My application is getting the information directly from my modem. You have to get a dial up modem that has Caller Id capabilities in order to do this. It's actually pretty easy, you use the SerialPort control and you send an AT command to the modem to activate caller id. Whenever you receive a call you get the info automatically
Reply With Quote
  #13  
Old 05-12-2010, 03:30 PM
Satal Keto's Avatar
Satal Keto Satal Keto is offline
Centurion
 
Join Date: Nov 2005
Location: behind you
Posts: 111
Default

Shame, that sounds awesome but I have broadband, I might have to see if I can adapt your code to work with Skype or something, if you're still willing to share it
__________________
Sam Jenkins' Website
Reply With Quote
  #14  
Old 05-12-2010, 06:49 PM
therealtomlapp therealtomlapp is offline
Freshman
 
Join Date: Jan 2009
Location: New Jersey
Posts: 40
Default

When you say you have broadband, i'm assuming that you mean you have broadband internet and you have voice over ip? Basically I will give it to you in the simplest possible way. If you have anything that has a telephone cord that plugs into a telephone, and you have caller id, then you can connect that phone cord through a dial up modem and capture the caller id info. This does not matter whether or not you have a traditional phone line, or if you have Comcast digital voice, or vonage where you have a router that has a telephone line coming out of it. Other than that, if you have some strange service that literally the phone call goes through your pc only, meaning if you pc is turned off you cannot make/receive calls them you can't use this code. So the question is, do you have a regular telephone handset, and when the phone rings do you get caller id. If you answered yes to that question, you can use this code.
Reply With Quote
  #15  
Old 05-13-2010, 02:12 AM
Satal Keto's Avatar
Satal Keto Satal Keto is offline
Centurion
 
Join Date: Nov 2005
Location: behind you
Posts: 111
Default

Yeah that sounds like I might be able to use it then, this should be interesting .
I know it sounds like work but if you have a website, blog or something then maybe you should do a write up of this, as this sounds like a really interesting project you have going and I'm sure many people will be interested in knowing how you have done this and what code you've used etc.
__________________
Sam Jenkins' Website
Reply With Quote
  #16  
Old 05-13-2010, 02:23 AM
therealtomlapp therealtomlapp is offline
Freshman
 
Join Date: Jan 2009
Location: New Jersey
Posts: 40
Default

The most important thing is, you need a dialup modem with CallerId capability. Please remember that not just any modem will do this. Of course you can get these off the internet for literally under $10. And i'm definitely not the first person to create a pc caller id. Actually as far as I know, Windows Media Center has it built in. I am making it because I just prefer to write my own software, so instead of Media Center, I use my own proprietary software that works the way I like it to work. Also i'm designing the program to act as a call screener, since no matter how hard I try to get rid of the, telemarketers just seem to keep calling. So I program it to just not respond at all unless it's a call from someone I know. Of course this means I turned off the ringers to all my phones, and the public address system announces the calls instead. I'm a pretty private person so I actually prefer that when the phone rings, that it's only going to be people that I want to talk to, and nobody else.
Reply With Quote
  #17  
Old 05-13-2010, 02:29 AM
Satal Keto's Avatar
Satal Keto Satal Keto is offline
Centurion
 
Join Date: Nov 2005
Location: behind you
Posts: 111
Default

That seems reasonable (as long as no one tries to phone you from any other phone number than the ones that you have programmed in).
To be honest the main thing that I am looking forward to being able to seeing how you managed to do is the selecting different sound cards, the phone bit was just a bonus.
__________________
Sam Jenkins' Website
Reply With Quote
  #18  
Old 05-13-2010, 12:40 PM
therealtomlapp therealtomlapp is offline
Freshman
 
Join Date: Jan 2009
Location: New Jersey
Posts: 40
Default

Ok here it is. You will have to add a reference to DirectX to your application, then at these Imports statements:

Code:
Imports Microsoft.DirectX
Imports Microsoft.DirectX.DirectSound
Then add the following code:

Code:
 Private myDevices As DevicesCollection = Nothing
    Private Structure myDeviceDescription
        Public info As DeviceInformation
        Public Overrides Function ToString() As String
            Return info.Description
        End Function
        Public Sub New(ByVal di As DeviceInformation)
            info = di
        End Sub
    End Structure

Dim DsDevice as Directsound.Device
Dim TheSoundBuffer as MemoryStream
To enumerate your devices, use this code. This example populates a listbox with all your system playback devices:

Code:
Public Sub PopulateDevices()

        ' Retrieve the available DirectSound devices
        myDevices = New DevicesCollection()

        'Clear the list box
        ListBoxAudioDevices.ClearSelected()

        'Step through each device and add it's description to the listbox
        For Each dev As DeviceInformation In myDevices
            ListBoxAudioDevices.Items.Add(dev.Description)
        Next

End Sub
Now this code will select the device, in this example I have selected the 3rd device in my listbox (index 2)

Code:
DsDevice = New Device(myDevices(2).DriverGuid)
DsDevice.SetCooperativeLevel(Me, CooperativeLevel.Priority)

TheSoundBuffer = New MemoryStream
Also, I added the following code because I wanted to enable the ability to control volume, pan, frequency, and also to have the sound play even if the program doesn't have focus (since by default the sound will stop when your app loses focus)

Code:
    Dim bufferDesc As New Microsoft.DirectX.DirectSound.BufferDescription
        With bufferDesc
            .GlobalFocus = True
            .ControlVolume = True
            .ControlPan = True
            .ControlFrequency = True
        End With

'Create the secondary sound buffer
TheSoundBuffer = New SecondaryBuffer("c:\test.wav", bufferDesc, DsDevice)

TheSoundBuffer.Play(0, BufferPlayFlags.Default)
Now also in the TheSoundBuffer.Play function, you can also use BufferPlayFlags.Looping to have the audio loop over and over again until you call TheSoundBuffer.Stop
Reply With Quote
  #19  
Old 05-13-2010, 12:42 PM
therealtomlapp therealtomlapp is offline
Freshman
 
Join Date: Jan 2009
Location: New Jersey
Posts: 40
Default

I'm getting the code cleaned up for the CallerID as well, I will post it when it's done. Trust me the CallerID code is way simpler than the DirectSound code.
Reply With Quote
  #20  
Old 05-14-2010, 02:23 AM
Satal Keto's Avatar
Satal Keto Satal Keto is offline
Centurion
 
Join Date: Nov 2005
Location: behind you
Posts: 111
Default

Greatly appreciated therealtomlapp
__________________
Sam Jenkins' Website
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
Choose between different sound cards for playback in VB.net
Choose between different sound cards for playback in VB.net
Choose between different sound cards for playback in VB.net Choose between different sound cards for playback in VB.net
Choose between different sound cards for playback in VB.net
Choose between different sound cards for playback in VB.net
Choose between different sound cards for playback in VB.net Choose between different sound cards for playback in VB.net Choose between different sound cards for playback in VB.net Choose between different sound cards for playback in VB.net Choose between different sound cards for playback in VB.net Choose between different sound cards for playback in VB.net Choose between different sound cards for playback in VB.net
Choose between different sound cards for playback in VB.net
Choose between different sound cards for playback in VB.net
 
Choose between different sound cards for playback in VB.net
Choose between different sound cards for playback in VB.net
 
-->