Multiple sound inputs to one output

This is a discussion on Multiple sound inputs to one output within the C++ Programming forums, part of the General Programming Boards category; Hey guys, I'm new here Anyways, what is the best way to retrieve any number of sound inputs from the ...

  1. #1
    Registered User
    Join Date
    Jun 2004
    Posts
    5

    Multiple sound inputs to one output

    Hey guys, I'm new here

    Anyways, what is the best way to retrieve any number of sound inputs from the sound card, and combine them into one output?

    Sorry if this is a really noobish question

    Thanks,
    Don

  2. #2
    Hardware Engineer
    Join Date
    Sep 2001
    Posts
    1,398
    This is going to depend on your hardware, drivers, operating system, and related applications.

    With Windows 98, you can use the built-in mixer: Programs->Accessories->Intertainment->Volume Control. By default, all of the inputs are turned-on, and all of the sounds will be mixed.

    Are you trying to do something with a C++ program? There is no sound in standard C++. Anything to do with sound will be platform specific.

  3. #3
    Registered User
    Join Date
    Jun 2004
    Posts
    5
    Thanks for you help

    Now that you bring that to my attention, is there a way through a C++ program to modify those? However, I'd rather the program have full control. Is this possible?

    The platform will either be Windows 98 or Windows XP - more likely 98 than XP. Is there a generic way to do this for all soundcards with multiple inputs (all of the inputs will be through RCA jacks or MIDI; all located on one or two soundcards)? If not, the soundcard is located here: http://m-audio.com/index.php?do=prod...3fa8b83343bfb8

    Is there a library to handle all differenent audio inputs? Does DirectX have the proper capabilities to merge differenent audio inputs and combine them for one output?

  4. #4
    Hardware Engineer
    Join Date
    Sep 2001
    Posts
    1,398
    The WinAPI (Application Programming Interface) probably has most, if not all of the functions that you need. You can look-up mmsystem (Multi Media System). Windows has a file named MMSYSTEM.DLL, that has lots of multimedia functions. Direct-X has additional sound functions. I think most of the Direct-X stuff is geared toward real-time processing.

    Most sound cards have only one auxiliary input. You'll need a special (professional) sound card if you need multiple line-level inputs. A special purpose multi-input sound card could be a problem, because the driver may not work with the standard Windows API... it might only work with the manufacturer's software... I really don't know... All of the consumer cards are "soundblaster compatable".

    Now, everything above is related to mixing the analog signals in the sound card's hardware. I'm pretty sure that there are no standard WinAPI functions for mixing sounds digitally. But, I assume that Direct-X does have such a function. If you are not concerned about real-time processing, it would be easy to mix two (or more) wave files, and save the result to another file. All you have to do is sum the samples. All of the files would need to have the same sample rate, and you'd have to scale the levels, so that the summed result doesn't attempt to go over "zero dB". (A sample in a 16 bit wave file will have a value between -32768 and 32767.)

    [EDIT] - I took a quick look at your M-AUDIO link. From the compatability info, I'd guess their driver works seamlessly with Windows and the WinAPI. This is probably the best solution. The standard application for this type of card is as a 4-track digital recorder. You "capture" the analog sound (either as 4 wave files, or as one 4-channel wave file), and digitally manipulate/mix it later. If you use 2 standard sound cards, you will have to mix digitally. Capturing the input from 2 sound cards simultaniously would most likely be much trickier than capturing 4 channels from one card (fewer multi-threading issues to deal with).

    REAL-TIME ISSUES - Digital processing in real-time is "interesting" with a multitasking operating system. Your program NEVER has uninterruptable control of the CPU... unless you write a kernel-mode driver, which I've never done, but I know it's not easy! The trick is to use buffers effectively. For example, make sure that the sound card's input buffers never overflow, and that the output buffers never get empty.

    If you're not working in real-time, things get much easier. I have a standard sound card with one stereo input, and I've mixed wave files recorded at different times with Goldwave.
    Last edited by DougDbug; 06-16-2004 at 07:21 PM.

  5. #5
    Registered User
    Join Date
    Jun 2004
    Posts
    5
    Thanks a lot for your help

    Yes, it will definately need to be real-time. Essentially, I want the inputs, which are analog, to be mixed together. At this point all I am concerned with is their relative volumes, i.e., I can increase one of the input's volume while decreasing the other, and have them playing simultaneously through the same output. I'm sure now that I will be using one profressional grade soundcard with more than one input/outputs. Later on, I'd like to add equalizing to each channel/input and perhaps some effects, as well as a second, unique output. This is not an issue at the moment; I am just concerned with the basic functionality. Should I start looking at the DirectX/DirectSound API right from the start?

    About the digital real-time processing, I plan on having a decent enough processor (running only this application and whatever overhead the OS gives), that not having an uninterruptable control of the processor shouldn't be too big of a deal. My brother has used the computer to record music and this has never been an issue. Is it possible the M-Audio cards come with a kernel-mode driver?

    Thanks again!

  6. #6
    Hardware Engineer
    Join Date
    Sep 2001
    Posts
    1,398
    I'm getting a little concerned that we're off-topic... No C++ here. But this is one of my favorite subjects.
    Should I start looking at the DirectX/DirectSound API right from the start?
    Stuff like program control of the Windows mixer, where all of the mixing is done in the sound card, requires insignificant CPU time, so anything that works will be OK. I've never used DirectX, but for any signal processing I'd say probably yes.

    My brother has used the computer to record music and this has never been an issue.
    Right. Recording audio requires some CPU bus-time, but, all of the analog-to-digital conversion is done in the sound card. I've recorded stereo with a 100MHz Pentium without problems. So, 4 channels on any modern computer won't be a problem. (I wouldn't try scanning-in an image while recording!)

    However, once you start doing processor-intensive stuff, like digital EQ, you will most-likely have to use some tricks and techniques to minimize delay, and keep the audio stream flowing. I don't believe that professional studios use Windows (or MAC) systems for real-time processing, although they may use a PC to control their hardware... Or, to control DSP cards in their computers.

    I wouldn't recommend using a PC's CPU for anything critical, like live performance, or broadcast. I want to be guaranteed all of the CPU cycles that I need, when I need them. No cooperative multitasking (AKA non pre-mptive multitasking) system can do that!!! Sound cards only work because they have their own A/D, D/A, clocks, MIDI sound generators, sometimes DSP, etc. All of the "work" is done by the card.

    Is it possible the M-Audio cards come with a kernel-mode driver?
    Yes. All drivers run in kernel mode. However, they don't (or shouldn't) take-over CPU control for long periods of time. If they did, nothing else would work... not even the mouse. The problem is, once they relinquish control, you can't tell when you're getting it back.

    When you're ready to do some processing (EQ/filters, reverb, etc.) I recommend a book called Digital Signal Processing, by Doug Coulter.

    BTW - I wouldn't consider any of this "newbish". I would consider almost anything that is system-specific an "advanced topic". It may be simple to control the Windows mixer, but it's going to require some research. Assuming you want a GUI interface, that's an advanced topic. DSP is an advanced topic... real-time DSP even more advanced!
    Last edited by DougDbug; 06-17-2004 at 02:15 PM.

  7. #7
    Registered User
    Join Date
    Jun 2004
    Posts
    5
    My brother told me about ASIO (Audio Streaming Input Output) Drivers, which significantly improve realtime audio work. Are you familiar with them? I have to do some research, but I think that they may (hopefully) guarantee good real-time performance. What I am designing is a dj mixer, so it will need to be able to perform solidly in live situations. Things like effects and eq come secondary, but taking the audio input from two live turntables, and being able to control the volume of each shouldn't be too processor intensive, should it? I mean how much of the processor should that tax? The card does the A/D conversion for sure.

    I don't even need to record, just simply output the sound (although recording would be a good feature, I consider it an extra at this point in time). Come to think of it though, performance-wise, recording probably wouldn't add too much more strain because the computer is already producing the digital audio, so all that would need to be done is write it to disk in real-time.

    In terms of professional studios, I think that the trend is definitely going towards entirely computer-based systems. The big studios use software/hardware systems like Pro Tools (it is a dsp system), but a lot of smaller studios do just fine with their beefy pc's, professional sound cards, and their software sequencers. An increasing number of artists, especially those that I listen to, are moving to entirely software based synthesis and sound design.

    I guess that the biggest question right now for me is how to control the sound card and get it to do what I need to do. I'm pretty sure that the card can do the internal volume-mixing that I require, but I really don't know where to start. Right now, all I'm looking to do is take the two live inputs, have the sound card (hopefully) mix them together, and output this resultant sound live. The next step would be to create a functional user interface that can show me the levels from each input and, (getting ambitious here), use a touchscreen LCD to control the sound level of each input. Then things like crossfading, recording, eq, effects would come. I don't want to get too ahead of myself at this point in time though

    What exactly does Coulter's book cover? DSP algorithms? I am very interested in them, but first I would like to figure out how to write code to get the soundcard to take the analogue audio input that it is receiving and mix it internally and output it. Would this definitely be a directx thing? Or does this fall under the realm of some other Windows API? Do you know if this would be covered in Coulter's book?

    Sorry for being so repetitive, but I'm just trying to make sure that you understand exactly what I am trying to do.

    Thanks again

  8. #8
    Registered User
    Join Date
    Jun 2004
    Posts
    5
    Any ideas?

  9. #9
    Hardware Engineer
    Join Date
    Sep 2001
    Posts
    1,398

    I'll send you a private message....

    ... 'cause we're off-topic.

    And, please don't "bump your threads". See the Forum Guidelines.
    Last edited by DougDbug; 06-23-2004 at 05:43 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Sound lags in multi-thread version
    By VirtualAce in forum Game Programming
    Replies: 23
    Last Post: 08-27-2008, 12:54 PM
  2. Monitors Supporting Multiple Inputs
    By SlyMaelstrom in forum Tech Board
    Replies: 3
    Last Post: 08-22-2006, 05:15 PM
  3. Retrieving Multiple inputs with fgets?
    By Axel in forum C Programming
    Replies: 25
    Last Post: 09-13-2005, 05:04 PM
  4. Need help fixing bugs in data parsing program
    By daluu in forum C Programming
    Replies: 8
    Last Post: 03-27-2003, 06:02 PM
  5. Getting multiple inputs using cin
    By edk in forum C++ Programming
    Replies: 2
    Last Post: 09-13-2001, 03:34 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21