Re: Once again multi channel sound...

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



From: "Gottfried Lesigang"

My problem is that I'm not very experienced with sound
programming. this feature is a key-feature for my
application, but it's just about 2% of my code ;-)

At the moment I'm dveloping with C# in VS. For the sound
I'm using DirectShow.Net. My free time is very limited...
Learning advanced sound programming is quite a challenge!

Splitting or mixing uncompressed PCM audio channels is not
very advanced. Each channel is a sequence of fixed size
samples (e.g. the sample of 16-bit PCM are short ints). The
samples of each channel are interleaved in the buffer in a
fixed pattern (e.g. if you have 4 channels, the pattern in
the buffer is 123412341234, where the numbers represent
channels 1 to 4).

So, if you for example want to mix 2 x 16-bit stereo buffers
into 1 x 16-bit 4-channel buffer, you just read 2 shorts
from buffer #1 and write them to the target buffer, than 2
short from buffer #2, them buffer #1 again and so on...

The only care you need to take is about filling the
WAVEFORMATEX structure: if you have more than 2 channels,
you need to use WAVEFORMATEXTENSIBLE (which is a special
form of WAVEFORMATEX) instead of a plain WAVEFORMATEX. Some
audio components may accept a plain WAVEFORMATEX with
nChannels > 2, but it is not standard.


--
// Alessandro Angeli
// MVP :: DirectShow / MediaFoundation
// mvpnews at riseoftheants dot com
// http://www.riseoftheants.com/mmx/faq.htm


.



Relevant Pages

  • Re: Advice on PC Based Logic Analyzer
    ... article in that I will rather buy 8 'good channels' with sufficient ... buffer depth than 32 channels and anyway not be able to use them all. ... busses are contained within the processor core, so the analyzer is ... needed is to delay the trigger based on an edge count or time. ...
    (sci.electronics.equipment)
  • Re: [PATCH 3/3] relay: Add buffer-only channels; useful for early logging.
    ... 20d8b67c06fa5e74f44e80b0a0fd68c8327f7c6a) broke LTTng. ... buffer file creation callback to be called when it calls relay_open. ... Therefore, such channels can be ...
    (Linux-Kernel)
  • Re: Sound and mixing channels question
    ... >buffer, the code i've seen just adds the two channels, but what happens ... Rather than overflowing and ... if you lower the amplitudes of the waveforms ...
    (comp.programming)
  • Re: Audio output to multiple Channels on multiple sound cards
    ... > 3) Play MP3 files to all the channels. ... > I have also used MediaPlayer to play MP3 files but these again only come out ... struct instead of the standard WAVEFORMATEX. ... In the case of DirectSound ...
    (microsoft.public.win32.programmer.directx.audio)
  • TIP #287: Add a Commands for Determining Size of Buffered Data
    ... and ways to plug the hole. ... the incoming buffer, and if it appears to be accumulating too much data ... prevention that doesn't require polling the channels periodically. ... or upper limit on the line length ...
    (comp.lang.tcl)