1

I am trying to make my own basic mixer and wanted to know how I could take multiple channels of input audio and outputting all of the channels as one mixed audio source with controllable levels for each input channel. Right now I am trying to use pyo but I am unable to mix the channels in real-time.

Derick Mathews
  • 347
  • 2
  • 3
  • 12
  • [Mixer?](http://ajaxsoundstudio.com/pyodoc/api/classes/pan.html#pyo.Mixer) – fdcpp Apr 08 '20 at 20:28
  • As I am understanding mixer can't stream a live sound. Unless there is some workaround that I am unaware of. – Derick Mathews Apr 09 '20 at 04:48
  • I don't see why not. Best thing to do is start with a single input stream example and post what you have so far. That should make it easier for others to offer advice. – fdcpp Apr 09 '20 at 10:11

1 Answers1

0

here is some pseudo code to combine multiple input channels into a single output channel where each input channel has its own volume control in array mix_volume

max_index = length(all_chan[0])  // identify audio buffer size

all_chan   // assume all channels live in a two dimensional array where 
           // dimension 0 is which channel and dim 1 is index into each audio sample

mix_volume  // array holding multiplication factor to control volume per channel
            // each element a floating point value between 0.0 and 1.0

output_chan  //  define and/or allocate your output channel buffer

for index := 0; index < max_index; index++ {

    curr_sample := 0  // output audio curve height for current audio sample

    for curr_chan := 0; curr_chan < num_channels; curr_chan++ {

        curr_sample += (all_chan[curr_chan][index] * mix_volume[curr_chan])
    }

    output_chan[index] = curr_sample / num_channels  // output audio buffer
}

the trick to perform above on a live stream is to populate the above all_chan audio buffers inside an event loop where you copy into these buffers the audio sample values for each channel then execute above code from inside that event loop ... typically you will want your audio buffers to have about 2^12 ( 4096 ) audio samples ... experiment using larger or smaller buffer size ... too small and this event loop will become very cpu intensive yet too large and you will incur an audible delay ... have fun

you may want to use a compiled language like golang YMMV

Scott Stensland
  • 26,870
  • 12
  • 93
  • 104