8 audio of channels input

I have a sound card that allows for 24 audio inputs. I can get 2 channels working but am having difficulty getting 8 can anyone help me, I will post the appropriate parts of the code below. I have tried various code for audioReceived and audioRequested methods in the cpp but never get anywhere.

Thanks in advance if anyone can help me.

  
testApp.h  
public:  
  
		//Audio  
		void audioReceived 	(float * input, int bufferSize, int nChannels);  
		void audioRequested (float * input, int bufferSize, int nChannels);  
private:  
		  
	float   * ch1In;  
	float   * ch2In;  
	float   * ch3In;  
	float   * ch4In;  
	float   * ch5In;  
	float   * ch6In;  
	float   * ch7In;  
	float   * ch8In;  
  
  

  
testApp.cpp  
	ofSoundStreamListDevices();  
	  
	/**************************************  
	 2 output channels, 2 input cxxhannels  
	 SAMPLE_RATE samples per second  
	 BUFFER_SIZE samples per buffer  
	 4 num buffers (latency)  
	 ***************************************/  
	ofSoundStreamSetup(2,8,this, SAMPLE_RATE, BUFFER_SIZE, 4);  
	ch1In = new float[BUFFER_SIZE];  
	ch2In = new float[BUFFER_SIZE];  
	ch3In = new float[BUFFER_SIZE];  
	ch4In = new float[BUFFER_SIZE];  
	ch5In = new float[BUFFER_SIZE];  
	ch6In = new float[BUFFER_SIZE];  
	ch7In = new float[BUFFER_SIZE];  
	ch8In = new float[BUFFER_SIZE];  
  
	  
	volume = 0.8f;  
	leftpan = 0.5f;  
	rightpan = 0.5f;  
  
void testApp::audioReceived 	(float * input, int bufferSize, int nChannels){  
	  
		//here is the interleaving	  
	for (int i = 0; i < bufferSize; i++){  
		ch1In[i] = input[i*2];  
		ch2In[i] = input[i*2+1];  
	}  
}  
  
  
void testApp::audioRequested 	(float * output, int bufferSize, int nChannels){  
			  
	for(int i=0; i<BUFFER_SIZE;i++) {  
		output[i*nChannels    ]   = ch1In[i] * volume * leftpan;  
		output[i*nChannels + 1]   = ch2In[i] * volume * rightpan;  
		  
		  
	}  
	  
}  
  

did you check your soundcard selection in you system preference ?
loic

Yes I set it as default and tested it with 2 channels It works easily, (I am on OSX and using a firewire soundcard from Maudio- profire 2626) I get 2 channels in and out fine but when I go to get more I can’t make it work.

I am truly a beginner though and mostly was just guessing on how to get more channels to play out. I dont want to do anything with them except to change the volume and pan (I want them to come back into stereo).

Thanks for you response!

There’s some info on this here:
http://forum.openframeworks.cc/t/multichannel-output-using-the-rtaudio-library/1766/0

The audio output and input in ofSoundStream is “interleaved”. This means that samples are played back one channel at a time.

e.g. for an 8 channel sound stream (each number represents both a sample value and the current output channel):

1 2 3 4 5 6 7 8 1 2 3 4 5 6 7 8 1 2 3 4 5 6 7 8

for stereo (2 channel sound):

1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2

and quad (4 channel sound):

1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4

That’s the whole point of the for loop in the audioReceived and audioRequested…to interleave the samples. In the OF example, it’s only using stereo and therefore 2 channels. To extend this to multichannel, you need to add more channels, something like:

output[i\*nChannels ] = ch1In[i] * volume;
output[i\*nChannels + 1] = ch2In[i] * volume;
output[i\*nChannels + 2] = ch3In[i] * volume;
output[i\*nChannels + 3] = ch4In[i] * volume;
output[i\*nChannels + 4] = ch5In[i] * volume;
output[i\*nChannels + 5] = ch6In[i] * volume;
output[i\*nChannels +6] = ch7In[i] * volume;
output[i\*nChannels + 7] = ch8In[i] * volume;

To do what you want, which is route 8 inputs to 2 outputs, I think you will need to do something like this:

output[i\*nChannels ] = (ch1In[i] + ch1In[i] + ch5In[i] + ch7In[i] ) / 4.0f * volume;
output[i\*nChannels+ 1] = (ch2In[i] + ch4In[i] + ch6In[i] + ch8In[i] ) / 4.0f * volume;

In this last example, you divide by 4.0f because you want 4 channels to merge into 1 on each output. I use “4.0f” and not “4” because we are using floats for our audio output.

Thanks so much, your examples and posts on this forum have been an invaluable resource for me, and I have this one solved.

Cheers

would this interleaving also apply when using to mic inputs?

  
  
//setup()  
        soundStream0.setDeviceID(3);  
	soundStream0.setup(this, 0, channels, sampleRate, mainBufferSize, 4);  
	  
	soundStream1.setDeviceID(4);  
	soundStream1.setup(this, 0, channels, sampleRate, mainBufferSize, 4);  
  
//audioIn()  
for (int i = 0; i < bufferSize; i++){  
			mic0[i]	= input[i*nChannels];  
			mic1[i]	= input[i*nChannels+1];  
}  
  

Hi Stephan,

yes, mic inputs are interleaved.

we have a lot of plans for sound in the next 12 months, like implementing an ofSoundBuffer that will simplify sound data the way ofPixels simplifies pixel data, it will take care of interleaving/non interleaving.

cheers
Damian