Add audio input support

pull/170/head
James Ball 2023-12-14 21:26:40 +00:00
rodzic ea67f99a94
commit b2d37dacb1
7 zmienionych plików z 51 dodań i 8 usunięć

Wyświetl plik

@ -0,0 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M12,2A3,3 0 0,1 15,5V11A3,3 0 0,1 12,14A3,3 0 0,1 9,11V5A3,3 0 0,1 12,2M19,11C19,14.53 16.39,17.44 13,17.93V21H11V17.93C7.61,17.44 5,14.53 5,11H7A5,5 0 0,0 12,16A5,5 0 0,0 17,11H19Z" /></svg>

Po

Szerokość:  |  Wysokość:  |  Rozmiar: 260 B

Wyświetl plik

@ -45,6 +45,10 @@ MainComponent::MainComponent(OscirenderAudioProcessor& p, OscirenderAudioProcess
pluginEditor.fileUpdated(audioProcessor.getCurrentFileName());
};
addAndMakeVisible(inputEnabled);
inputEnabled.onClick = [this] {
audioProcessor.inputEnabled->setBoolValueNotifyingHost(!audioProcessor.inputEnabled->getBoolValue());
};
addAndMakeVisible(fileLabel);
updateFileLabel();
@ -125,6 +129,8 @@ void MainComponent::resized() {
auto row = bounds.removeFromTop(buttonHeight);
fileButton.setBounds(row.removeFromLeft(buttonWidth));
row.removeFromLeft(rowPadding);
inputEnabled.setBounds(row.removeFromLeft(20));
row.removeFromLeft(rowPadding);
fileLabel.setBounds(row);
bounds.removeFromTop(padding);

Wyświetl plik

@ -7,6 +7,7 @@
#include "components/VisualiserComponent.h"
#include "audio/PitchDetector.h"
#include "UGen/ugen_JuceEnvelopeComponent.h"
#include "components/SvgButton.h"
class OscirenderAudioProcessorEditor;
class MainComponent : public juce::GroupComponent {
@ -24,6 +25,7 @@ private:
std::unique_ptr<juce::FileChooser> chooser;
juce::TextButton fileButton;
juce::TextButton closeFileButton;
SvgButton inputEnabled{"inputEnabled", juce::String(BinaryData::microphone_svg), "white", "red", audioProcessor.inputEnabled};
juce::Label fileLabel;
juce::TextEditor fileName;

Wyświetl plik

@ -147,6 +147,7 @@ OscirenderAudioProcessor::OscirenderAudioProcessor()
booleanParameters.push_back(perspectiveEffect->fixedRotateY);
booleanParameters.push_back(perspectiveEffect->fixedRotateZ);
booleanParameters.push_back(midiEnabled);
booleanParameters.push_back(inputEnabled);
for (auto parameter : booleanParameters) {
addParameter(parameter);
@ -474,7 +475,13 @@ void OscirenderAudioProcessor::processBlock(juce::AudioBuffer<float>& buffer, ju
auto totalNumInputChannels = getTotalNumInputChannels();
auto totalNumOutputChannels = getTotalNumOutputChannels();
buffer.clear();
// clear output channels
for (auto i = totalNumInputChannels; i < totalNumOutputChannels; ++i) {
buffer.clear(i, 0, buffer.getNumSamples());
}
bool usingInput = inputEnabled->getBoolValue();
bool usingMidi = midiEnabled->getBoolValue();
if (!usingMidi) {
midiMessages.clear();
@ -496,12 +503,25 @@ void OscirenderAudioProcessor::processBlock(juce::AudioBuffer<float>& buffer, ju
const double EPSILON = 0.00001;
if (usingInput && totalNumInputChannels >= 2) {
// handle all midi messages
auto midiIterator = midiMessages.cbegin();
std::for_each(midiIterator,
midiMessages.cend(),
[&] (const juce::MidiMessageMetadata& meta) { synth.publicHandleMidiEvent(meta.getMessage()); }
);
} else {
for (auto i = 0; i < totalNumInputChannels; ++i) {
buffer.clear(i, 0, buffer.getNumSamples());
}
if (volume > EPSILON) {
juce::SpinLock::ScopedLockType lock1(parsersLock);
juce::SpinLock::ScopedLockType lock2(effectsLock);
synth.renderNextBlock(buffer, midiMessages, 0, buffer.getNumSamples());
}
}
midiMessages.clear();
auto* channelData = buffer.getArrayOfWritePointers();

Wyświetl plik

@ -14,6 +14,7 @@
#include "audio/Effect.h"
#include "audio/ShapeSound.h"
#include "audio/ShapeVoice.h"
#include "audio/PublicSynthesiser.h"
#include <numbers>
#include "audio/AudioWebSocketServer.h"
#include "audio/DelayEffect.h"
@ -192,6 +193,7 @@ public:
std::shared_ptr<PerspectiveEffect> perspectiveEffect = std::make_shared<PerspectiveEffect>(VERSION_HINT);
BooleanParameter* midiEnabled = new BooleanParameter("MIDI Enabled", "midiEnabled", VERSION_HINT, !juce::JUCEApplicationBase::isStandaloneApp());
BooleanParameter* inputEnabled = new BooleanParameter("Audio Input Enabled", "inputEnabled", VERSION_HINT, false);
std::atomic<float> frequency = 440.0f;
juce::SpinLock parsersLock;
@ -268,7 +270,7 @@ private:
std::vector<std::shared_ptr<Effect>> permanentEffects;
ShapeSound::Ptr defaultSound = new ShapeSound(std::make_shared<FileParser>());
juce::Synthesiser synth;
PublicSynthesiser synth;
AudioWebSocketServer softwareOscilloscopeServer{*this};
ObjectServer objectServer{*this};

Wyświetl plik

@ -0,0 +1,9 @@
#pragma once
#include <JuceHeader.h>
class PublicSynthesiser : public juce::Synthesiser {
public:
void publicHandleMidiEvent(const juce::MidiMessage& m) {
handleMidiEvent(m);
}
};

Wyświetl plik

@ -18,6 +18,7 @@
<FILE id="IqXIZW" name="demo.svg" compile="0" resource="1" file="Resources/svg/demo.svg"/>
<FILE id="YwkQpy" name="fixed_rotate.svg" compile="0" resource="1"
file="Resources/svg/fixed_rotate.svg"/>
<FILE id="PxYKbt" name="microphone.svg" compile="0" resource="1" file="Resources/svg/microphone.svg"/>
<FILE id="pSc1mq" name="osci.svg" compile="0" resource="1" file="Resources/svg/osci.svg"/>
<FILE id="D2AI1b" name="pencil.svg" compile="0" resource="1" file="Resources/svg/pencil.svg"/>
<FILE id="rXjNlx" name="threshold.svg" compile="0" resource="1" file="Resources/svg/threshold.svg"/>
@ -64,6 +65,8 @@
<FILE id="t2bsR8" name="PitchDetector.cpp" compile="1" resource="0"
file="Source/audio/PitchDetector.cpp"/>
<FILE id="rQC2gX" name="PitchDetector.h" compile="0" resource="0" file="Source/audio/PitchDetector.h"/>
<FILE id="t5g8pf" name="PublicSynthesiser.h" compile="0" resource="0"
file="Source/audio/PublicSynthesiser.h"/>
<FILE id="PbbNqz" name="RotateEffect.cpp" compile="1" resource="0"
file="Source/audio/RotateEffect.cpp"/>
<FILE id="tUwNZV" name="RotateEffect.h" compile="0" resource="0" file="Source/audio/RotateEffect.h"/>