[Stk] RtAudio multiple channel input/output

dimoni@dimoni.demon.nl dimoni@dimoni.demon.nl
Sun, 17 Oct 2004 21:48:16 +0200


--Apple-Mail-6--523788030
Content-Transfer-Encoding: 7bit
Content-Type: text/plain;
	charset=US-ASCII;
	format=flowed

Hi Gary et al.,

I am trying to get multiple input/output channels with a Digi002r from 
Digidesign but I am running into problems.
I have tested if I can get multiple input from other sound cards and I 
get the same errors  although when running probe.cpp from the tutorial 
I obtain the correct information for each device.

Output from probe.cpp:

device = 1
: maximum output channels = 8
: maximum input channels = 2
duplex = 2
device = 2
: maximum output channels = 2
: maximum input channels = 2
duplex = 2
device = 3
: maximum output channels = 18
: maximum input channels = 18
duplex = 18

I have split your code in order to have an audio class where I define 
the process and stop member functions.

AudioClass.cpp code:

#include <iostream>
#include <stk/RtAudio.h>

class AudioClass
{
	int SR;
	int nBuffers;
	int bufferSize;
	int inputChannels, outputChannels;
	int inputDevice, outputDevice;
	RtAudio *audio;
	
public:
	AudioClass( int inputDevice,int inputChannels, int outputDevice, int 
outputChannels, int SR, int bufferSize, int nBuffers)
	{
		this -> SR = SR;
		this -> nBuffers = nBuffers;
		this -> bufferSize = bufferSize;
		this -> inputChannels = inputChannels;
		this -> outputChannels = outputChannels;

		this -> inputDevice = inputDevice;
		this -> outputDevice = outputDevice;
		this -> SR = SR;
		
		try
		{
			audio = new RtAudio(inputDevice, inputChannels, outputDevice, 
outputChannels,
								RTAUDIO_FLOAT64, SR, &bufferSize, nBuffers);
		}
		
		catch (RtError &error)
		{
			error.printMessage();
			exit(EXIT_FAILURE);
		}
	}
	
	~AudioClass()
	{
		delete audio;
	}
	
	void ProcessAudio(int Callback)
	{
		try
		{
			audio->setStreamCallback(/*&AudioClass::*/Callback, NULL); // Set 
the stream callback function
			audio->startStream(); // Start the stream
		}
		catch (RtError &error)
		{
			error.printMessage();
			exit(1);
		}
	}
		
	void StopAudio()
	{
		try
		{
			// Stop and close the stream
			audio->stopStream();
			audio->closeStream();
		}
		catch (RtError &error)
		{
			error.printMessage();
			exit(1);
		}
	}
}; //end of AudioClass


******* Main code: *******


#include <iostream>
#include "AudioClass.cpp"

int Callback( char *buffer, int bufferSize, void *userData)
         {
                 // Note: do nothing here for pass through.
                 double *my_buffer = (double *) buffer;

                 // Scale input data for output.
                 for (int i=0; i<bufferSize; i++) {
                         // Do for two channels.
                        *my_buffer++ *= 0.9;
                         *my_buffer++ *= 0.9;
                 }

                 return 0;
         }

int main()
{
	char input;
	AudioClass audio(3, 0, 3, 4, 44100, 256, 4);
	
	audio.ProcessAudio(&Callback);
	std::cout << "\nRunning duplex ... press <enter> to quit.\n";
	std::cin.get(input);
	audio.StopAudio();
	
	return 0;
}

After running it, I get the following error:

"
RtApi: unable to open specified device(s) with given stream parameters:
     RtApiCore: OS-X error getting stream format for device (Digidesign: 
Digidesign HW ( 002 )).

rtAudioInOut has exited with status 1.
"
I have run the same code by providing 2 inputs and 2 outputs and it 
works fine.
In order to test if there was a hardware problem, I have tried to get 
multiple outputs by using PortAudio and had no problems.
Is there anything I am missing in my code?


--Apple-Mail-6--523788030
Content-Transfer-Encoding: 7bit
Content-Type: text/enriched;
	charset=US-ASCII

Hi Gary et al.,


I am trying to get multiple input/output channels with a Digi002r from
Digidesign but I am running into problems.

I have tested if I can get multiple input from other sound cards and I
get the same errors  although when running probe.cpp from the tutorial
I obtain the correct information for each device.


Output from probe.cpp:


device = 1

: maximum output channels = 8

: maximum input channels = 2

duplex = 2

device = 2

: maximum output channels = 2

: maximum input channels = 2

duplex = 2

device = 3

: maximum output channels = 18

: maximum input channels = 18

duplex = 18


I have split your code in order to have an audio class where I define
the process and stop member functions. 


AudioClass.cpp code:


<fixed><color><param>6868,3838,2121</param>#include <<iostream></color>

<color><param>6868,3838,2121</param>#include <<stk/RtAudio.h></color>


<color><param>7676,0F0F,5050</param>class</color> AudioClass

{

	<color><param>7676,0F0F,5050</param>int</color> SR;

	<color><param>7676,0F0F,5050</param>int</color> nBuffers;

	<color><param>7676,0F0F,5050</param>int</color> bufferSize;

	<color><param>7676,0F0F,5050</param>int</color> inputChannels,
outputChannels;

	<color><param>7676,0F0F,5050</param>int</color> inputDevice,
outputDevice;

	RtAudio *audio;

	

<color><param>7676,0F0F,5050</param>public</color>:

	AudioClass( <color><param>7676,0F0F,5050</param>int</color>
inputDevice,<color><param>7676,0F0F,5050</param>int</color>
inputChannels, <color><param>7676,0F0F,5050</param>int</color>
outputDevice, <color><param>7676,0F0F,5050</param>int</color>
outputChannels, <color><param>7676,0F0F,5050</param>int</color> SR,
<color><param>7676,0F0F,5050</param>int</color> bufferSize,
<color><param>7676,0F0F,5050</param>int</color> nBuffers)

	{

		<color><param>7676,0F0F,5050</param>this</color> -> SR = SR;

		<color><param>7676,0F0F,5050</param>this</color> -> nBuffers =
nBuffers;

		<color><param>7676,0F0F,5050</param>this</color> -> bufferSize =
bufferSize;

		<color><param>7676,0F0F,5050</param>this</color> -> inputChannels =
inputChannels;

		<color><param>7676,0F0F,5050</param>this</color> -> outputChannels =
outputChannels;


		<color><param>7676,0F0F,5050</param>this</color> -> inputDevice =
inputDevice;

		<color><param>7676,0F0F,5050</param>this</color> -> outputDevice =
outputDevice;

		<color><param>7676,0F0F,5050</param>this</color> -> SR = SR;

		

		<color><param>7676,0F0F,5050</param>try</color>

		{

			audio = <color><param>7676,0F0F,5050</param>new</color>
RtAudio(inputDevice, inputChannels, outputDevice, outputChannels, 

								RTAUDIO_FLOAT64, SR, &bufferSize, nBuffers);

		}

		

		<color><param>7676,0F0F,5050</param>catch</color> (RtError &error) 

		{

			error.printMessage();

			exit(EXIT_FAILURE);

		}

	}

	

	~AudioClass()

	{

		<color><param>7676,0F0F,5050</param>delete</color> audio;

	}

	

	<color><param>7676,0F0F,5050</param>void</color>
ProcessAudio(<color><param>7676,0F0F,5050</param>int</color> Callback)

	{

		<color><param>7676,0F0F,5050</param>try</color>

		{

			audio->setStreamCallback(<color><param>0000,6464,0404</param>/*&AudioClass::*/</color>Callback,
<color><param>7676,0F0F,5050</param>NULL</color>);
<color><param>0000,6464,0404</param>// Set the stream callback function</color>

			audio->startStream(); <color><param>0000,6464,0404</param>// Start
the stream</color>

		}

		<color><param>7676,0F0F,5050</param>catch</color> (RtError &error)

		{

			error.printMessage();

			exit(<color><param>0000,0000,FFFF</param>1</color>);

		}

	}

		

	<color><param>7676,0F0F,5050</param>void</color> StopAudio()

	{

		<color><param>7676,0F0F,5050</param>try</color>

		{

			<color><param>0000,6464,0404</param>// Stop and close the stream</color>

			audio->stopStream();

			audio->closeStream();

		}

		<color><param>7676,0F0F,5050</param>catch</color> (RtError &error) 

		{

			error.printMessage();

			exit(<color><param>0000,0000,FFFF</param>1</color>);

		}

	}

}; //end of AudioClass



******* Main code: *******


</fixed>

<fixed><color><param>6868,3838,2121</param>#include <<iostream></color>

<color><param>6868,3838,2121</param>#include "AudioClass.cpp"</color>


<color><param>7676,0F0F,5050</param>int</color> Callback(
<color><param>7676,0F0F,5050</param>char</color> *buffer,
<color><param>7676,0F0F,5050</param>int</color> bufferSize,
<color><param>7676,0F0F,5050</param>void</color> *userData)

        {

                <color><param>0000,6464,0404</param>// Note: do
nothing here for pass through.</color>

                <color><param>7676,0F0F,5050</param>double</color>
*my_buffer = (<color><param>7676,0F0F,5050</param>double</color> *)
buffer;


                <color><param>0000,6464,0404</param>// Scale input
data for output.</color>

                <color><param>7676,0F0F,5050</param>for</color>
(<color><param>7676,0F0F,5050</param>int</color>
i=<color><param>0000,0000,FFFF</param>0</color>; i<<bufferSize; i++) {

                        <color><param>0000,6464,0404</param>// Do for
two channels.</color>

                       *my_buffer++ *=
<color><param>0000,0000,FFFF</param>0.9</color>;

                        *my_buffer++ *=
<color><param>0000,0000,FFFF</param>0.9</color>;

                }


                <color><param>7676,0F0F,5050</param>return</color>
<color><param>0000,0000,FFFF</param>0</color>;

        }


<color><param>7676,0F0F,5050</param>int</color> main()

{

	<color><param>7676,0F0F,5050</param>char</color> input;

	AudioClass audio(<color><param>0000,0000,FFFF</param>3</color>,
<color><param>0000,0000,FFFF</param>0</color>,
<color><param>0000,0000,FFFF</param>3</color>,
<color><param>0000,0000,FFFF</param>4</color>,
<color><param>0000,0000,FFFF</param>44100</color>,
<color><param>0000,0000,FFFF</param>256</color>,
<color><param>0000,0000,FFFF</param>4</color>);

	

	audio.ProcessAudio(&Callback);

	std::cout <<<< <color><param>8989,1313,1515</param>"\nRunning duplex
... press <<enter> to quit.\n"</color>;

	std::cin.get(input);

	audio.StopAudio();

	

	<color><param>7676,0F0F,5050</param>return</color>
<color><param>0000,0000,FFFF</param>0</color>;

}


</fixed>After running it, I get the following error:


"

RtApi: unable to open specified device(s) with given stream
parameters: 

    RtApiCore: OS-X error getting stream format for device
(Digidesign: Digidesign HW ( 002 )).


rtAudioInOut has exited with status 1.

"

I have run the same code by providing 2 inputs and 2 outputs and it
works fine.

In order to test if there was a hardware problem, I have tried to get
multiple outputs by using PortAudio and had no problems.

Is there anything I am missing in my code?



--Apple-Mail-6--523788030--