No audio after migration to modularized juce

Everything works since I switched to modularized juce except of audio. During debugging I found that everything appears to be working, device gets openend, callbacks are called just fine, except there is just no audio. As if the volume were on 0 or muted. This is true for both the iOS simulator and the actual hardware.

Has someone else observed this? Pointers to where to look would be very appreciated.

Patrick

Are you getting NaNs in your audio output buffer?

FWIW, it does not appear to be a generic iOS problem. I just tried JuceDemo on an iPad and record, playback, etc. all worked correctly (though I had to leave the demo end re-enter for the documents folder tree to properly populate with recorded wav files for playback).

I created a test project with the Introjucer. Added an ios and a mac exporter. On ios silence. On the mac working sound.

If anyone wants to double check, I used the Introjucer to generate a project with a main window. Then I created this simple class:

http://codepad.org/NpCns5wZ

Finally I added

to MainWindow.h and

to MainWindow.cpp as the last line of the MainWindow constructor.

Patrick

From codepad

[code]
#ifndef JuceTest_AudioTest_h
#define JuceTest_AudioTest_h

class AudioMixerImpl
: public AudioIODeviceCallback
{
ScopedPointer m_deviceManager;
ToneGeneratorAudioSource m_audioSource;

public:
AudioMixerImpl()
{
m_deviceManager = new AudioDeviceManager;
m_deviceManager->initialise(0, 2, NULL, true);
m_deviceManager->addAudioCallback(this);

    //m_deviceManager->playTestSound();
}

virtual void audioDeviceIOCallback (const float** inputChannelData,
                                    int numInputChannels,
                                    float** outputChannelData,
                                    int numOutputChannels,
                                    int numSamples)
{

	AudioSampleBuffer buffer(outputChannelData, numOutputChannels, numSamples);
    
    AudioSourceChannelInfo info;
    info.buffer = &buffer;
    info.startSample = 0;
    info.numSamples = numSamples;
    
    m_audioSource.getNextAudioBlock(info);
}

virtual void audioDeviceAboutToStart (AudioIODevice* device)
{
    m_audioSource.prepareToPlay(device->getCurrentBufferSizeSamples(), device->getCurrentSampleRate());
}

virtual void audioDeviceStopped() {}
virtual void audioDeviceError (const String& errorMessage) {}

};

#endif[/code]

If I change the number of input channels in deviceManager.initialize from 2 to 0, JuceDemo demonstrates the same behavior. I suspect that if you add two input channels to your initialization:

m_deviceManager->initialise(2, 2, NULL, true);

Your audio will start to play. I haven’t traced down into JUCE’s createDevice yet to see why.

UGH I should have remembered…I came across this a long time ago. I posted something about it, and Jules responded.

[quote=“TheVinn”]
UGH I should have remembered…I came across this a long time ago. I posted something about it, and Jules responded.[/quote]

I’d bet you $20 that the next time this pops up I will have forgotten, but I’d also never remember to collect… :wink:

You guys rock! Setting input channels to 2 worked, my audio is back, but…

When my app is running and I switch to the springboard or other apps the status bar now shows in red. I remember Jules fixed that problem a while ago: http://www.rawmaterialsoftware.com/viewtopic.php?f=4&t=8080&p=45720&hilit=red#p45720

But if I have to set input channels to 2 to get audio playback the fix no longer works.

I really would love to have audio and no red recording status bar. I wonder what the underlying problem of no audio with 0 input channels is. Can you point me to the thread were Jules replied?

Patrick

Hmm maybe I was thinking of a different issue with AudioDeviceManager, I can’t find it

[quote=“P4tr3ck”]I really would love to have audio and no red recording status bar. I wonder what the underlying problem of no audio with 0 input channels is. Can you point me to the thread were Jules replied?
[/quote]

I think that to get rid of the bar the underlying bug needs to get fixed. If you simply comment out:

        if (numInputChannels > 0)
        {
            const UInt32 one = 1;
            AudioUnitSetProperty (audioUnit, kAudioOutputUnitProperty_EnableIO, kAudioUnitScope_Input, 1, &one, sizeof (one));
        }

In juce_ios_Audio.cpp, then you get the same bad audio behavior your reported originally. This doesn’t completely surprise me, since Juce is registering for input callbacks, but input is disabled in hardware. The whole not playing with input 0 might be something similar. I’d a little swamped at work today, but if I can get a few minutes later I’ll dig a little deeper.

OK, the original bug appears to be in the process method of IPhoneAudioIODevice (juce_ios_Audio.cpp):

    OSStatus process (AudioUnitRenderActionFlags* flags, const AudioTimeStamp* time,
                      const UInt32 numFrames, AudioBufferList* data)
    {
        OSStatus err = noErr;

        if (audioInputIsAvailable)
            err = AudioUnitRender (audioUnit, flags, time, 1, numFrames, data);

        .
        .
        .
        return err;
    }

Audio Input IS available, so AudioUnitRender is called. But with 0 inputs set, the input hardware is not enabled (see the code snip I posted before). So the call returns an error. That error is returned at the bottom of the function, so the OS ignores the populated output buffers and plays silence.

Changing the function to:

    OSStatus process (AudioUnitRenderActionFlags* flags, const AudioTimeStamp* time,
                      const UInt32 numFrames, AudioBufferList* data)
    {
        OSStatus err = noErr;

        if (audioInputIsAvailable && numInputChannels > 0)
            err = AudioUnitRender (audioUnit, flags, time, 1, numFrames, data);

        .
        .
        .
        return err;
    }

Allows audio to play even if the DeviceManager is initialized with 0 inputs. Since 0 inputs means that the input hardware is not enabled, this should remove the blinking red bar. However, the simulator does not handle background audio and I don’t have time to setup a provision profile, etc. to run this on a device right now.

I hope that helps. Assuming that resolves your problem (it seemed to here), we should bring it to Jule’s attention.

I tested your fix on the device and it worked! Audio and no red status bar!

Just noticed this thread… Thanks for the heads-up on that, chaps!