AudioDeviceSelector Component and DirectSound


#1

When I select any device other than Primary Sound Driver from juce’s AudioDeviceSelector, I get a crash in the next audioDeviceIOCallback

//from audioDeviceIOCallback

BitArray outputChannels = mDeviceManager->getOutputChannels();
jassert(outputChannels.countNumberOfSetBits() == 2);

int left_idx = outputChannels.findNextSetBit(0); //returns 0
int right_idx = outputChannels.findNextSetBit(left_idx); //returns 1

float * left_output = outputChannelData[left_idx]; // returns 0x0!
float * right_output = outputChannelData[right_idx]; // returns 0x0!

memset(left_output, 0, sizeof(float) * numSamples); //d'oh, bet you stomped some memory!

Obviously I can stop the crash by checking left_output and right_output for NULL values, but that doesn’t solve the mystery of the missing channels. Any idea why the index reported by outputChannels is wrong?

Best,

Art


#2

Sounds like the same thing that we were talking about on another thread - the channels can be null pointers, so you need to check them. I definitely need to refactor the stuff that gets returned in that callback.


#3

Yeah my bad for not checking for null pointers and all, but, um, where are the output channels?

I thought the idea was that the BitArray returned by getOutputChannels would tell me which elements in the outputChannels array had float buffers, i.e., which channels were active–this seems to be the case with all ASIO devices I’ve tested and when the DirectSound driver is set to ‘Primary Output Device’–is this understanding wrong?

Should I be using another method to determine which elements of outputChannels (and InputChannels, I assume) to process?


#4

No, it’s not quite like that - the output bits don’t refer to channels, you need to skip along and use the first two non-zero buffers in the list.

Like I say, I need to sort this out, it’s a bit confusing.


#5

[quote=“jules”]you need to skip along and use the first two non-zero buffers in the list.
[/quote]

Great! Thanks for the speedy help. :slight_smile: