soundflower in, speakers out?

Hi OF,

Another beginner question that I have not been able to figure out (sorry) … I’m trying to get simple playback from the soundstream that has a Soundflower channel routed in. The Soundflower part works, its the playing back from another (output) soundstream that does not. I’ve looked through threads like this:

http://forum.openframeworks.cc/t/managing-buffersrecording-audio/3240/0

but quite honestly am not entirely sure what I need to do.

I do an input soundstream and output soundstream in setup:


int bufferSize = 512;
left.assign(bufferSize, 0.0);
right.assign(bufferSize, 0.0);

leftOut.assign (bufferSize, 0.0);
rightOut.assign (bufferSize, 0.0);

sfDeviceID = 2;
outputDeviceID = 1;

soundStream.listDevices();

inputSoundStream.setDeviceID(sfDeviceID); //this now uses the soundflower input rather than mic input for mac
inputSoundStream.setup(this, 0, 2, 44100, bufferSize, 4);

outputSoundStream.setDeviceID(outputDeviceID); //standard mac output
outputSoundStream.setup(this, 2, 0, 44100, bufferSize, 4);


in audio in:

for (int i = 0; i < bufferSize; i++) {
left[i] = input[i\*2]*0.5;
right[i] = input[i\*2+1]*0.5;
//numCounted+=2;

bufferCounter ++;
}
}


in audio requested:

for (int i = 0; i < bufferSize; i++){
leftOut[i] = output[i\*nChannels ] ;
rightOut[i] = output[i\*nChannels + 1] ;
}


would appreciate any guidance… thank you in advance!

Is this right?

  
leftOut = output[i*nChannels    ]  ;  
         rightOut = output[i*nChannels + 1] ;  
  

Unless you’re doing something tricky, shouldn’t that be an array:

  
leftOut[i] = output[i*nChannels    ]  ;  
         rightOut[i] = output[i*nChannels + 1] ;  
  

Also, as an FYI, audioRequested is still around, but it’s going away in favor of audioOut.

thank you joshua!

You are right, they are both arrays, I dont know why it didn’t copy over. Let me try again:

  
  
void testApp::setup(){	   
	  
	ofSetVerticalSync(true);  
	ofSetCircleResolution(80);  
	ofBackground(54, 54, 54);	  
	  
      
    setupFinished = false;   
      
    int bufferSize = 512;  
    left.assign(bufferSize, 0.0);  
	right.assign(bufferSize, 0.0);  
      
    leftOut.assign (bufferSize, 0.0);   
    rightOut.assign (bufferSize, 0.0);   
      
    sfDeviceID = 2;  
    outputDeviceID = 1;   
      
    soundStream.listDevices();  
      
    inputSoundStream.setDeviceID(sfDeviceID);   //this now uses the soundflower input rather than mic input for mac      
    inputSoundStream.setup(this, 0, 2, 44100, bufferSize, 4);  
  
      
    outputSoundStream.setDeviceID(outputDeviceID);  
    outputSoundStream.setup(this, 2, 0, 44100, bufferSize, 4);  
  
      
    setupFinished = true;  
      
  
  
}  
  
  

  
void testApp::audioIn(float * input, int bufferSize, int nChannels){	  
      
    //start here  
    if (setupFinished) {  
  
            for (int i = 0; i < bufferSize; i++) {  
                left[i]		= input[i*2]*0.5;  
                right[i]	= input[i*2+1]*0.5;  
            bufferCounter ++;  
        }  
    }  
}  

  
void testApp::audioRequested(float * output, int bufferSize, int nChannels){  
      
    if (setupFinished) {  
  
		for (int i = 0; i < bufferSize; i++){  
			leftOut[i] = output[i*nChannels    ]  ;  
			rightOut[i] = output[i*nChannels + 1] ;  
		}  
	}  
      
}  

I know audioIn is working because I am drawing a waveform, but can’t hear anything from audioRequested.

:-/

I could be totally wrong, so take this with a grain of salt, but I wonder if you might need to have a single ofSoundStream instance like so:

  
ofSoundStreamSetup(2,2,this, 44100, 512, 4);  

But looking at the internals of that method it looks like it’s not set up right now to handle different devices right now, so you might need to modify that, maybe like:

  
inputParameters.deviceId = inputDeviceID;  
....  
outputParameters.deviceId = outputDeviceID;  

I’m away from my computer but I can code something up in a little bit if you don’t get it first :slight_smile:

Hi josh, Do you mean to go into rtOfAudioSoundStream and create something like a “set output deviceID” method?

I tried creating a setoutputDeviceID method in ofRtAudioSoundStream.cpp,

altering this:

  
	  
if(nOutputChannels>0){  
		if( deviceID >= 0 ){  
			outputParameters.deviceId = outDeviceID;  
		}else{  
			outputParameters.deviceId = audio->getDefaultOutputDevice();  
		}  
		outputParameters.nChannels = nOutputChannels;  
	}  

and this:

  
//------------------------------------------------------------------------------  
void ofRtAudioSoundStream::setOutputDeviceID(int _deviceoutID){  
	outDeviceID = _deviceoutID;  
}  

so that in my main app I could do this:

  
 soundStream.setOutputDeviceID(2);  

but alas, nothing (so far… will keep trying)

(in case anyone noticed, i fixed the discrepancies between audio in/ audio out variables)

I also found this thread … it looks like I need portAudio?
http://forum.openframeworks.cc/t/[solved]-problem-outputing-microphone-in-real-time-using-ofsoundstream/6129/0

Has anyone had success with this? the instructions on how to use it:
http://ofxaddons.com/repos/409

are not too clear …

thanks again!

Are you just using PD or Max with SoundFlower? I submitted a patch to allow set up of separate input and output devices that I can test with your particular setup if you’d like.

Hiya would love a patch or anything that helps. unfortunately, just soundflower for now as introducing Max might make things even more complicated… :slight_smile: Setup is basically:

OF -> terminal -> VLC -> soundflower -> OF -> speakers.

I finally got something playing with the help of this thread (whew): http://forum.openframeworks.cc/t/audio-using-soundstream/7533/0

but the audio is quite scratchy, so it is probably a buffer issue that I will now look into …

Ah, great. I think that’ll be going into core soon, I’ll test this evening when I get back home and make sure it works with that flow. Scratchy/weird sound is usually sampling rate issues, but if it’s not definitely post back for other people who might have the same problem.

I can’t seem to switch deviceIDs on OSX. I get no sound when I try setDeviceID (even when it’s set to the default). Did you guys ever work this out?