[SOLVED] Projucer Live Build audio input issue

I’m trying to process audio input in a Component running in the Projucer Live Build engine. It seems that audio input is not working. I made a simple PIP to demonstrate this.

It works as an app, but not in the live build engine. Does Projucer need to be built with audio input enabled?

AudioInputTest.h (3.5 KB)

/*******************************************************************************
 The block below describes the properties of this PIP. A PIP is a short snippet
 of code that can be read by the Projucer and used to generate a JUCE project.

 BEGIN_JUCE_PIP_METADATA

  name:             AudioInputTest
  version:          1.0
  description:      Basic audio input test

  dependencies:     juce_core, juce_data_structures, juce_events, juce_graphics, juce_gui_basics, juce_audio_devices, juce_audio_utils, juce_audio_basics, juce_audio_processors, juce_gui_extra, juce_audio_formats
  exporters:        vs2017, xcode_mac

  moduleFlags:      JUCE_STRICT_REFCOUNTEDPOINTER=1

  type:             Component
  mainClass:        MainComponent

 END_JUCE_PIP_METADATA

*******************************************************************************/

#pragma once


//==============================================================================
class MainComponent   : public AudioAppComponent, private Timer
{
public:
    //==============================================================================
    MainComponent()
    {
        // Some platforms require permissions to open input channels so request that here
        if (RuntimePermissions::isRequired (RuntimePermissions::recordAudio)
            && ! RuntimePermissions::isGranted (RuntimePermissions::recordAudio))
        {
            RuntimePermissions::request (RuntimePermissions::recordAudio,
                                         [&] (bool granted) { if (granted)  setAudioChannels (2, 2); });
        }
        else
        {
            // Specify the number of input and output channels that we want to open
            setAudioChannels (2, 2);
        }
        magnitude = -23.4;
        startTimerHz(60);
        
        setSize (200, 200);
    }

    ~MainComponent()
    {
        shutdownAudio();
    }
    
    //==============================================================================
    void prepareToPlay (int samplesPerBlockExpected, double sampleRate) override {}
    void getNextAudioBlock (const AudioSourceChannelInfo& bufferToFill) override
    {
        magnitude = bufferToFill.buffer->getMagnitude (0, bufferToFill.numSamples);
        
        // Right now we are not producing any data, in which case we need to clear the buffer
        // (to prevent the output of random noise)
        bufferToFill.clearActiveBufferRegion();
    }
    void releaseResources() override {}

    //==============================================================================
    void paint (Graphics& g) override
    {
        g.fillAll (getLookAndFeel().findColour (ResizableWindow::backgroundColourId));
        g.setColour(Colours::white);
        g.drawText(String(magnitude, 7, false), 50, 50, 200, 100, Justification::centredLeft);
    }

    void resized() override
    {
        // This is called when the MainComponent is resized.
        // If you add any child components, this is where you should
        // update their positions.
    }


private:
    //==============================================================================
    void timerCallback() override
    {
        repaint();
    }
    //==============================================================================
    // Your private member variables go here...
    std::atomic<float> magnitude;


    JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (MainComponent)
};

Well, to answer my own question: Yes it does! It works now :slight_smile: