[Stk] RtAudio multiple channel input/output

Gary Scavone gary@ccrma.Stanford.EDU
Mon, 18 Oct 2004 10:35:10 -0400


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

Hi Dimoni,

I suggest defining __RTAUDIO_DEBUG__ if you haven't already done so.  I 
don't have any personal experience with this hardware.  Are you sure 
you are using the correct device identifier?  Compile and run the 
"info.cpp" program in the tests directory to see what number you should 
use.

--gary

On Sunday, October 17, 2004, at 03:48  PM, dimoni@dimoni.demon.nl wrote:

> 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-28--456173617
Content-Transfer-Encoding: 7bit
Content-Type: text/enriched;
	charset=US-ASCII

Hi Dimoni,


I suggest defining __RTAUDIO_DEBUG__ if you haven't already done so. 
I don't have any personal experience with this hardware.  Are you sure
you are using the correct device identifier?  Compile and run the
"info.cpp" program in the tests directory to see what number you
should use.


--gary


On Sunday, October 17, 2004, at 03:48  PM, dimoni@dimoni.demon.nl
wrote:


<excerpt>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>6866,3836,211F</param>#include <<iostream></color>

<color><param>6866,3836,211F</param>#include <<stk/RtAudio.h></color>


<color><param>7674,0F0D,504E</param>class</color> AudioClass

{

	<color><param>7674,0F0D,504E</param>int</color> SR;

	<color><param>7674,0F0D,504E</param>int</color> nBuffers;

	<color><param>7674,0F0D,504E</param>int</color> bufferSize;

	<color><param>7674,0F0D,504E</param>int</color> inputChannels,
outputChannels;

	<color><param>7674,0F0D,504E</param>int</color> inputDevice,
outputDevice;

	RtAudio *audio;

	

<color><param>7674,0F0D,504E</param>public</color>:

	AudioClass( <color><param>7674,0F0D,504E</param>int</color>
inputDevice,<color><param>7674,0F0D,504E</param>int</color>
inputChannels, <color><param>7674,0F0D,504E</param>int</color>
outputDevice, <color><param>7674,0F0D,504E</param>int</color>
outputChannels, <color><param>7674,0F0D,504E</param>int</color> SR,
<color><param>7674,0F0D,504E</param>int</color> bufferSize,
<color><param>7674,0F0D,504E</param>int</color> nBuffers)

	{

		<color><param>7674,0F0D,504E</param>this</color> -> SR = SR;

		<color><param>7674,0F0D,504E</param>this</color> -> nBuffers =
nBuffers;

		<color><param>7674,0F0D,504E</param>this</color> -> bufferSize =
bufferSize;

		<color><param>7674,0F0D,504E</param>this</color> -> inputChannels =
inputChannels;

		<color><param>7674,0F0D,504E</param>this</color> -> outputChannels =
outputChannels;


		<color><param>7674,0F0D,504E</param>this</color> -> inputDevice =
inputDevice;

		<color><param>7674,0F0D,504E</param>this</color> -> outputDevice =
outputDevice;

		<color><param>7674,0F0D,504E</param>this</color> -> SR = SR;

		

		<color><param>7674,0F0D,504E</param>try</color>

		{

			audio = <color><param>7674,0F0D,504E</param>new</color>
RtAudio(inputDevice, inputChannels, outputDevice, outputChannels, 

								RTAUDIO_FLOAT64, SR, &bufferSize, nBuffers);

		}

		

		<color><param>7674,0F0D,504E</param>catch</color> (RtError &error) 

		{

			error.printMessage();

			exit(EXIT_FAILURE);

		}

	}

	

	~AudioClass()

	{

		<color><param>7674,0F0D,504E</param>delete</color> audio;

	}

	

	<color><param>7674,0F0D,504E</param>void</color>
ProcessAudio(<color><param>7674,0F0D,504E</param>int</color> Callback)

	{

		<color><param>7674,0F0D,504E</param>try</color>

		{

			audio->setStreamCallback(<color><param>0000,6462,0402</param>/*&AudioClass::*/</color>Callback,
<color><param>7674,0F0D,504E</param>NULL</color>);
<color><param>0000,6462,0402</param>// Set the stream callback function</color>

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

		}

		<color><param>7674,0F0D,504E</param>catch</color> (RtError &error)

		{

			error.printMessage();

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

		}

	}

		

	<color><param>7674,0F0D,504E</param>void</color> StopAudio()

	{

		<color><param>7674,0F0D,504E</param>try</color>

		{

			<color><param>0000,6462,0402</param>// Stop and close the stream</color>

			audio->stopStream();

			audio->closeStream();

		}

		<color><param>7674,0F0D,504E</param>catch</color> (RtError &error) 

		{

			error.printMessage();

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

		}

	}

}; //end of AudioClass



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


</fixed>

<fixed><color><param>6866,3836,211F</param>#include <<iostream></color>

<color><param>6866,3836,211F</param>#include "AudioClass.cpp"</color>


<color><param>7674,0F0D,504E</param>int</color> Callback(
<color><param>7674,0F0D,504E</param>char</color> *buffer,
<color><param>7674,0F0D,504E</param>int</color> bufferSize,
<color><param>7674,0F0D,504E</param>void</color> *userData)

        {

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

                <color><param>7674,0F0D,504E</param>double</color>
*my_buffer = (<color><param>7674,0F0D,504E</param>double</color> *)
buffer;


                <color><param>0000,6462,0402</param>// Scale input
data for output.</color>

                <color><param>7674,0F0D,504E</param>for</color>
(<color><param>7674,0F0D,504E</param>int</color>
i=<color><param>0000,0000,FFFD</param>0</color>; i<<bufferSize; i++) {

                        <color><param>0000,6462,0402</param>// Do for
two channels.</color>

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

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

                }


                <color><param>7674,0F0D,504E</param>return</color>
<color><param>0000,0000,FFFD</param>0</color>;

        }


<color><param>7674,0F0D,504E</param>int</color> main()

{

	<color><param>7674,0F0D,504E</param>char</color> input;

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

	

	audio.ProcessAudio(&Callback);

	std::cout <<<< <color><param>8987,1311,1513</param>"\nRunning duplex
... press <<enter> to quit.\n"</color>;

	std::cin.get(input);

	audio.StopAudio();

	

	<color><param>7674,0F0D,504E</param>return</color>
<color><param>0000,0000,FFFD</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?


</excerpt>
--Apple-Mail-28--456173617--