Howto use ofSoundStream.setDeviceID()?

I am trying to get oF to listen to streaming sound output of my system. But the only thing working is listening to the microphone. So, the easiest way:

  
ofSoundStreamSetup(0,2,this, 44100, BUFFER_SIZE, 4);  

works for the microphone, but I have no idea how to switch the input.
I tried this for the line out:

  
  
ofSoundStream soundStream;  
soundStream.setDeviceID(2);  
soundStream.setup(this, 0, 2, 44100, BUFFER_SIZE, 4);  
  

But it doesn’t work. If I use only this: (so leave out soundStream.soundStream.setDeviceID(2))

  
  
ofSoundStream soundStream;  
soundStream.setup(this, 0, 2, 44100, BUFFER_SIZE, 4);  
  

It does work, but with the microphone again.

I also tried the example “audioInputExample”. If I use soundStream.setDeviceID(1) the microphone works, but if I change it to 2 than there is no audio input anymore.

What is the right way to use setDeviceID()?

(oF 0.8.0, OSX 10.8)

1 Like

Did you make sure, that the ID is the proper ID of your preferred input device, by calling

  
 ofSoundStreamListDevices();  

In my case it usually starts with 3, after internal mic, internal audio-out and internal audio-in.

Also, you said you wanted audio-out?
then instead of

  
soundStream.setup(this, 0, 2, 44100, BUFFER_SIZE, 4);    

You need:

  
soundStream.setup(this, 2, 0, 44100, BUFFER_SIZE, 4);    

It is stated in the documentation, that the 2nd argument is outChannels, the 3rd argument is inChannels. (http://www.openframeworks.cc/documentation/sound/ofSoundStream.html#show-setup)

  
bool ofSoundStream::setup(ofBaseApp *app, int outChannels, int inChannels, int sampleRate, int bufferSize, int nBuffers)  

I tried all devices listed, I switched in and outchannels. There is an error message if you use the wrong channels. that’s helpful.
I use this:

  
  
  ofSoundStream soundStream;   
  
  soundStream.setDeviceID(1);  
  soundStream.setInput(this);  
  soundStream.setup(this, 0, 2, 44100, BUFFER_SIZE, 4);  
  soundStream.listDevices();  
  

It works for the built in microphone. What I want is to directly “listen” to sound played on the mac. What is going to the speakers.
I guess I was wrong in my post with using ID 2, but I also tried 3 and switched channels, still nothing.

If understand, you want access to sound to directed to your speakers. for example sound from youtube or itunes.

You need to download and install soundflower http://cycling74.com/soundflower-landing-page/
then go to system preferences->sound and set the sound output to soundflower. Then go to openframeworks and set the audio device to soundflower out.

Thanks M_Drive! With soundflower I got it to work. This works

  
  
  ofSoundStream soundStream;  
  soundStream.setDeviceID(4);  
  soundStream.setup(this, 2, 2, 44100, BUFFER_SIZE, 4);  
  soundStream.listDevices();  
  

One odd thing though: I used audio from youtube. The app didn’t work if there was already sound. So, first the application needs to start, only then you can switch the audio on.

It works on mine. I just tested a simple pass through:

  
  
void testApp::setup(){  
    soundStream.listDevices();  
    soundStream.setInDeviceID(3); // soundFlower 2ch out  
    soundStream.setOutDeviceID(2); // default mac speakers  
    samplesLeft.reserve(512);  
    samplesRight.reserve(512);  
    soundStream.setup(this, 2, 2, 44100, 512, 4);  
      
}  
  
void testApp::audioIn(float *input, int bufferSize, int nChannels){  
    for (int i = 0; i < bufferSize; i++) {  
        samplesLeft[i] = input[2*i];  
        samplesRight[i] = input[2*i+1];  
          
    }  
}  
  
  
void testApp::audioOut(float *output, int bufferSize, int nChannels){  
    for (int i = 0; i < bufferSize; i++) {  
        output[2*i] = samplesLeft[i];  
        output[2*i+1] = samplesRight[i];  
    }  
}  
  
  

all this does is take the input from soundflower and then outputs it with openframeworks

1 Like

There is no [more] setInDeviceID and setOutDeviceID() int the documentation. Can this be a replacement ? But it doesn’t work :frowning:

ofSoundStream soundStreamIn;
ofSoundStream soundStreamOut;

void ofApp::setup(){

//-----------------------------------------------
soundStreamIn.printDeviceList();
soundStreamIn.setDeviceID(4); // soundFlower
soundStreamOut.setDeviceID(2); // SoundCard

int bufferSize = 256;

soundStreamIn.setup(this, 0, 2, 44100, bufferSize, 4);
soundStreamOut.setup(this, 2, 0, 44100, bufferSize, 4);

soundStreamOut.setSoundStream(soundStreamIn.getSoundStream());
}

I’m trying to use Rogue Amoeba’s Loopback and I cannot get it to work. something is very strange… Can’t seem to be able to change soundcard either. Yes, in and out are not decoupled anymore. This is not good.

I’m also getting a bunch of nan, not sure why. Does not happen all the time :frowning:

1 Like