Selecting an input device and getting the device manager to use it

I’m attempting to write a simple app merging two of the demos… the recording app and the device settings app. I’m on a PC with multiple microphones, one is a headset and the other is the embedded mic and want the user to be able to switch microphones.

When you select a new input device in the audioSetupComp, how do you get your app to read from the new input device vs the old one. Do you need to reinitialize something in your devicemanager to switch the buffers out?

In my app, the user selects the new microphone in the setting component, but the app still reads input from the default microphone.

I found the work around, but I’m not C plus plussy enough to know why it works one way and not the other. I should have mentioned, I grabbed some of the code from the juce tutorial area on the website and some from the projucer examples.

If you are a newbie and build onto the AudioDeviceManager tutorial from the tutorial website the code to create the selector appears to create and initialize the selector as part of the constructor for the maincomponent.

MainContentComponent()
    : audioSetupComp (deviceManager,
                      0,     // minimum input channels
                      256,   // maximum input channels
                      0,     // minimum output channels
                      256,   // maximum output channels
                      false, // ability to select midi inputs
                      false, // ability to select midi output device
                      false, // treat channels as stereo pairs
                      false) // hide advanced options

{
This works, but if you start dropping audio recording code (from the recording demo in the demo runner) in there, the device selected is not the device your recorded audio will come from. It just keeps reading from your default audio device no matter what you have selected.

BUT- I played around more with the demorunner code examples and found that if you just use a pointer and allocate a selector “new (audioSetupComp)” in the maincomponent constructor, the respective selector will work.

Not sure why the device tutorial code doesn’t work when you build out on it, but it doesn’t.

I notice the example code in the demo runner doesn’t delete this at the end. I’m a bit of a rusty dinosaur … but in the old days there ought to have been a delete for that new.