soundStream requests

  1. Could we possibly add deviceID selection to the function, instead of it being default 0

ofSoundStreamSetup(int nOutputChannels, int nInputChannels, int device, ofBaseApp * OFSA, int sampleRate, int bufferSize, int nBuffers)

  1. Could we also add a bool if the soundstream was opened ok?

SO my code now looks like:

  
  
bool ofSoundStreamSetup(int nOutputs, int nInputs, int device, ofBaseApp * OFSA, int sampleRate, int bufferSize, int nBuffers){  
  
	nInputChannels 		=  nInputs;  
	nOutputChannels 	=  nOutputs;  
	OFSAptr 			=  OFSA;  
  
	bufferSize = ofNextPow2(bufferSize);	// must be pow2  
  
	bool ok = false;  
  
	try {  
		audio = new RtAudio();  
		audio->openStream(	device, nOutputs, device, nInputs, RTAUDIO_FLOAT32, sampleRate, &bufferSize, nBuffers);  
  
        ok = true;  
  
	} catch (RtError &error) {  
		error.printMessage();  
		ok = false;  
		//std::exit(EXIT_FAILURE); // need case here  
	}  
  
	try {  
		audio->setStreamCallback(&receiveAudioBufferAndCallSimpleApp, (void *)NULL);  
		audio->startStream();  
		ok = true;  
	} catch (RtError &error) {  
		error.printMessage();  
		ok = false;  
	}  
	return ok;  
}  
  

Can I ask why ofSoundStream isn’t in a class? Is it because of limitations of only one instance of RtAudio being able to run?

Ideally I’d like to get a list of devices which I can show in software, not just in the console.

I’m wondering if it would be nicer to have all of this in a class.

Thanks

hey chris

while preparing 006, i tried to move soundStream to a class, so you can open several devices at the same time. to not break the current api there can be a default instance of that class and then the current functions will call the methods of that default instance.

in the end it seemed to me that wont fit in the core as it needs some kind of extern declaration or singleton for the default instance so just made an addon, then totally forgot about it :slight_smile:

haven’t tried it, but it should work with 006 without problem. it has a setDeviceID that you need to call before setup.

ofxSoundStream.zip

Thanks, will take a look.

I’m confused as to why in ofSoundStreamListDevices() it says:
(int i=1; i<=devices; i++)

when on the rt-audio-api it says “The device ID is an index value between 0 and getDeviceCount() - 1.”

So shouldn’t the list be?
(int i0; i<devices; i++)

**[edit]
Strange enough, 0 gives an invalid device ID from RT Audio. **


Also, in ofSoundStreamSetup if you want only input for example you say ofSoundStreamSetup(0,1 …

And then it passes to rtaudio:
audio->openStream( device, nOutputs, device, nInputs

On the rt audio site it says:
“For input-only streams, this argument should be NULL.”

So shouldn’t we check and if nOutputs = 0 do something like:
audio->openStream( NULL, NULL, device, nInputs

?

the reference in the rtAudio web page are for version 4. not completely sure but we are using 3 right now, so perhaps the differences in the api are because of that?

I have updated this library to support RtAudio 4 and an extended ofxAudioEventArgs including device id and name. Check my latest post in this thread: http://forum.openframeworks.cc/t/controlling-two-microphones-in-of/3444/11

Cheers,
Edu