Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions examples/audiograph/source/AudioGraphApp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -202,8 +202,10 @@ void AudioGraphApp::audioDeviceAboutToStart (yup::AudioIODevice* device)
nodeRegistry.setPluginScanner (scanner.get(), ctx);
#endif

graph->prepareToPlay (static_cast<float> (device->getCurrentSampleRate()),
device->getCurrentBufferSizeSamples());
const auto spec = yup::AudioSpec (
static_cast<float> (device->getCurrentSampleRate()),
device->getCurrentBufferSizeSamples());
graph->prepareToPlay (spec);
}

void AudioGraphApp::audioDeviceStopped()
Expand Down
4 changes: 2 additions & 2 deletions examples/audiograph/source/nodes/AnalyzerNodes.h
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ class OscilloscopeProcessor final : public yup::AudioProcessor
analyzerState.setOverlapFactor (0.0f);
}

void prepareToPlay (float, int) override
void prepareToPlay (const yup::AudioSpec&) override
{
analyzerState.reset();
peakLevel.store (0.0f, std::memory_order_relaxed);
Expand Down Expand Up @@ -379,7 +379,7 @@ class SpectrumAnalyzerProcessor final : public yup::AudioProcessor
analyzerState.setOverlapFactor (0.5f);
}

void prepareToPlay (float, int) override
void prepareToPlay (const yup::AudioSpec&) override
{
analyzerState.reset();
peakLevel.store (0.0f, std::memory_order_relaxed);
Expand Down
24 changes: 12 additions & 12 deletions examples/audiograph/source/nodes/DistortionNodes.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,17 +46,17 @@ class TanhDistortionProcessor final : public yup::AudioProcessor
updateLatency();
}

void prepareToPlay (float newSampleRate, int maxBlockSize) override
void prepareToPlay (const yup::AudioSpec& spec) override
{
const auto sampleRate = yup::jmax (1.0f, newSampleRate);
const auto blockSize = yup::jmax (1, maxBlockSize);
const auto sampleRate = yup::jmax (1.0f, spec.sampleRate);
const auto blockSize = yup::jmax (1, spec.maxBlockSize);

oversampler2x.prepare (sampleRate, maximumOversampledChannels, blockSize);
oversampler4x.prepare (sampleRate, maximumOversampledChannels, blockSize);
oversampler8x.prepare (sampleRate, maximumOversampledChannels, blockSize);
oversamplersPrepared = true;

smoothedDrive.reset (newSampleRate, 0.02);
smoothedDrive.reset (sampleRate, 0.02);
smoothedDrive.setCurrentAndTargetValue (getDrive());

updateLatency();
Expand Down Expand Up @@ -279,14 +279,14 @@ class BlunterSoftClipperProcessor final : public yup::AudioProcessor
addParameter (output);
}

void prepareToPlay (float newSampleRate, int maxBlockSize) override
void prepareToPlay (const yup::AudioSpec& spec) override
{
for (auto& clipper : clippers)
clipper.prepare (newSampleRate, maxBlockSize);
clipper.prepare (spec.sampleRate, spec.maxBlockSize);

smoothedDrive.reset (newSampleRate, 0.02);
smoothedDrive.reset (spec.sampleRate, 0.02);
smoothedDrive.setCurrentAndTargetValue (getDrive());
smoothedOutput.reset (newSampleRate, 0.02);
smoothedOutput.reset (spec.sampleRate, 0.02);
smoothedOutput.setCurrentAndTargetValue (getOutput());
}

Expand Down Expand Up @@ -592,14 +592,14 @@ class AaIirHardClipperProcessor final : public yup::AudioProcessor
addParameter (output);
}

void prepareToPlay (float newSampleRate, int maxBlockSize) override
void prepareToPlay (const yup::AudioSpec& spec) override
{
for (auto& clipper : clippers)
clipper.prepare (static_cast<double> (newSampleRate), maxBlockSize);
clipper.prepare (static_cast<double> (spec.sampleRate), spec.maxBlockSize);

smoothedDrive.reset (newSampleRate, 0.02);
smoothedDrive.reset (spec.sampleRate, 0.02);
smoothedDrive.setCurrentAndTargetValue (getDrive());
smoothedOutput.reset (newSampleRate, 0.02);
smoothedOutput.reset (spec.sampleRate, 0.02);
smoothedOutput.setCurrentAndTargetValue (getOutput());
}

Expand Down
4 changes: 2 additions & 2 deletions examples/audiograph/source/nodes/FractionalDelayNode.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ class FractionalDelayProcessor final : public yup::AudioProcessor
addParameter (dryWet);
}

void prepareToPlay (float newSampleRate, int) override
void prepareToPlay (const yup::AudioSpec& spec) override
{
sampleRate.store (yup::jmax (1.0f, newSampleRate), std::memory_order_relaxed);
sampleRate.store (yup::jmax (1.0f, spec.sampleRate), std::memory_order_relaxed);

const int maxDelaySamples = yup::roundToInt (delayMillisecondsToSamples (maximumDelayMilliseconds));
for (auto& delayLine : delayLines)
Expand Down
4 changes: 2 additions & 2 deletions examples/audiograph/source/nodes/GainNode.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ class GainProcessor final : public yup::AudioProcessor
addParameter (gain);
}

void prepareToPlay (float newSampleRate, int) override
void prepareToPlay (const yup::AudioSpec& spec) override
{
smoothedGain.reset (newSampleRate, 0.02);
smoothedGain.reset (spec.sampleRate, 0.02);
smoothedGain.setCurrentAndTargetValue (getGain());
}

Expand Down
6 changes: 3 additions & 3 deletions examples/audiograph/source/nodes/LatencyNode.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,12 @@ class LatencyProcessor final : public yup::AudioProcessor
reportUpdatedLatency();
}

void prepareToPlay (float newSampleRate, int maxBlockSize) override
void prepareToPlay (const yup::AudioSpec& spec) override
{
sampleRate.store (yup::jmax (1.0f, newSampleRate), std::memory_order_relaxed);
sampleRate.store (yup::jmax (1.0f, spec.sampleRate), std::memory_order_relaxed);

const int maxDelaySamples = delayMillisecondsToSamples (maximumDelayMilliseconds);
history.setSize (2, maxDelaySamples + yup::jmax (1, maxBlockSize) + 1);
history.setSize (2, maxDelaySamples + yup::jmax (1, spec.maxBlockSize) + 1);
history.clear();

writePosition = 0;
Expand Down
23 changes: 23 additions & 0 deletions examples/audiograph/source/nodes/NodeRegistry.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
#include "PluginNodeView.h"
#include "RecorderNode.h"
#include "SamplePlayerNode.h"
#include "SpectralPassthroughNode.h"
#include "SubgraphNode.h"

//==============================================================================
Expand Down Expand Up @@ -87,6 +88,9 @@ class NodeRegistry
/** Stable factory key for the built-in recorder node. */
static constexpr const char* recorderIdentifier = "internal.recorder";

/** Stable factory key for the built-in spectral passthrough node. */
static constexpr const char* spectralPassthroughIdentifier = "internal.spectralPassthrough";

/** Stable factory key for the built-in recursive subgraph node. */
static constexpr const char* subgraphIdentifier = "internal.subgraph";

Expand Down Expand Up @@ -305,6 +309,21 @@ class NodeRegistry
}
};

entries[spectralPassthroughIdentifier] = {
[] (const yup::AudioGraphNodeProperties&) -> yup::ResultValue<std::unique_ptr<yup::AudioProcessor>>
{
return yup::makeResultValueOk (std::make_unique<SpectralPassthroughProcessor>());
},
[] (yup::AudioGraphNodeID nodeID, yup::AudioProcessor* proc, yup::AudioGraphProcessor*) -> std::unique_ptr<yup::AudioGraphNodeView>
{
auto* spectral = dynamic_cast<SpectralPassthroughProcessor*> (proc);
if (spectral == nullptr)
return nullptr;

return std::make_unique<SpectralPassthroughNodeView> (nodeID, *spectral);
}
};

entries[subgraphIdentifier] = {
[this] (const yup::AudioGraphNodeProperties& props) -> yup::ResultValue<std::unique_ptr<yup::AudioProcessor>>
{
Expand Down Expand Up @@ -528,6 +547,7 @@ class NodeRegistry
oscilloscopeIdentifier,
recorderIdentifier,
samplePlayerIdentifier,
spectralPassthroughIdentifier,
spectrumAnalyzerIdentifier,
subgraphIdentifier,
svfIdentifier,
Expand Down Expand Up @@ -581,6 +601,9 @@ class NodeRegistry
if (id == recorderIdentifier)
return "Recorder";

if (id == spectralPassthroughIdentifier)
return "Spectral Passthrough";

if (id == subgraphIdentifier)
return "Subgraph";

Expand Down
4 changes: 2 additions & 2 deletions examples/audiograph/source/nodes/OscillatorNode.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ class OscillatorProcessor final : public yup::AudioProcessor
addParameter (sweepEnabled);
}

void prepareToPlay (float newSampleRate, int) override
void prepareToPlay (const yup::AudioSpec& spec) override
{
sampleRate = newSampleRate;
sampleRate = spec.sampleRate;
phase = 0.0;
sweepPositionSeconds = 0.0;
wasSweepActive = false;
Expand Down
4 changes: 2 additions & 2 deletions examples/audiograph/source/nodes/RecorderNode.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,9 @@ class RecorderProcessor final : public yup::AudioProcessor
fifoBuffer.resize (fifoCapacity);
}

void prepareToPlay (float sampleRate, int) override
void prepareToPlay (const yup::AudioSpec& spec) override
{
currentSampleRate.store (sampleRate > 0.0f ? sampleRate : 44100.0f, std::memory_order_relaxed);
currentSampleRate.store (spec.sampleRate > 0.0f ? spec.sampleRate : 44100.0f, std::memory_order_relaxed);
}

void releaseResources() override {}
Expand Down
4 changes: 2 additions & 2 deletions examples/audiograph/source/nodes/SamplePlayerNode.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ class SamplePlayerProcessor final : public yup::AudioProcessor
{
}

void prepareToPlay (float newSampleRate, int) override
void prepareToPlay (const yup::AudioSpec& spec) override
{
playbackSampleRate.store (newSampleRate > 0.0f ? newSampleRate : 44100.0f, std::memory_order_relaxed);
playbackSampleRate.store (spec.sampleRate > 0.0f ? spec.sampleRate : 44100.0f, std::memory_order_relaxed);
}

void releaseResources() override {}
Expand Down
150 changes: 150 additions & 0 deletions examples/audiograph/source/nodes/SpectralPassthroughNode.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
/*
==============================================================================

This file is part of the YUP library.
Copyright (c) 2026 - kunitoki@gmail.com

YUP is an open source library subject to open-source licensing.

The code included in this file is provided under the terms of the ISC license
http://www.isc.org/downloads/software-support-policy/isc-license. Permission
to use, copy, modify, and/or distribute this software for any purpose with or
without fee is hereby granted provided that the above copyright notice and
this permission notice appear in all copies.

YUP IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
DISCLAIMED.

==============================================================================
*/

#pragma once

#include "NodeViewHelpers.h"

//==============================================================================
class SpectralPassthroughProcessor final : public yup::SpectralBridge
{
public:
SpectralPassthroughProcessor()
: SpectralBridge ("Spectral Passthrough",
yup::AudioBusLayout ({ yup::AudioBus ("Main", yup::AudioBus::Audio, yup::AudioBus::Input, 2) },
{ yup::AudioBus ("Main", yup::AudioBus::Audio, yup::AudioBus::Output, 2) }))
{
fftSizeIndex = NodeViewHelpers::createParameter ("fftSizeIndex", "FFT Size", 0.0f, 6.0f, 3.0f, 1.0f);
overlapFactorIndex = NodeViewHelpers::createParameter ("overlapFactorIndex", "Overlap", 0.0f, 2.0f, 1.0f, 1.0f);

addParameter (fftSizeIndex);
addParameter (overlapFactorIndex);

applySettings();
}

float getFFTSizeIndex() const noexcept { return fftSizeIndex->getValue(); }

float getOverlapFactorIndex() const noexcept { return overlapFactorIndex->getValue(); }

void setFFTSizeIndex (float v) noexcept
{
fftSizeIndex->setValue (v);
applySettings();
}

void setOverlapFactorIndex (float v) noexcept
{
overlapFactorIndex->setValue (v);
applySettings();
}

int getCurrentFFTSize() const noexcept { return getFFTSize(); }

private:
static constexpr const char* stateType = "SpectralPassthroughState";
static constexpr int kFftSizeOptions[7] = { 128, 256, 512, 1024, 2048, 4096, 8192 };
static constexpr int kOverlapOptions[3] = { 2, 4, 8 };

void applySettings()
{
const int fftSizeIdx = yup::jlimit (0, 6, yup::roundToInt (getFFTSizeIndex()));
const int overlapIdx = yup::jlimit (0, 2, yup::roundToInt (getOverlapFactorIndex()));

setFFTSize (kFftSizeOptions[fftSizeIdx]);
setOverlapFactor (kOverlapOptions[overlapIdx]);
}

yup::AudioParameter::Ptr fftSizeIndex;
yup::AudioParameter::Ptr overlapFactorIndex;
};

//==============================================================================
class SpectralPassthroughNodeView final : public yup::AudioGraphNodeView
{
public:
SpectralPassthroughNodeView (yup::AudioGraphNodeID nodeID, SpectralPassthroughProcessor& processorIn)
: AudioGraphNodeView (nodeID)
, processor (processorIn)
, fftSizeSlider (yup::Slider::LinearBarHorizontal)
, overlapSlider (yup::Slider::LinearBarHorizontal)
{
NodeViewHelpers::configureParameterSlider (fftSizeSlider, getPortKindColor (PortKind::parameter));
fftSizeSlider.setRange (0.0, 6.0, 1.0);
fftSizeSlider.setValue (processor.getFFTSizeIndex(), yup::dontSendNotification);
fftSizeSlider.onValueChanged = [this] (double value)
{
processor.setFFTSizeIndex (static_cast<float> (value));
repaint();
};
addAndMakeVisible (fftSizeSlider);

NodeViewHelpers::configureParameterSlider (overlapSlider, getPortKindColor (PortKind::parameter));
overlapSlider.setRange (0.0, 2.0, 1.0);
overlapSlider.setValue (processor.getOverlapFactorIndex(), yup::dontSendNotification);
overlapSlider.onValueChanged = [this] (double value)
{
processor.setOverlapFactorIndex (static_cast<float> (value));
repaint();
};
addAndMakeVisible (overlapSlider);
}

yup::String getNodeTitle() const override { return "SPECTRAL"; }

int getNumInputPorts() const override { return 1; }

int getNumOutputPorts() const override { return 1; }

int getPreferredWidth() const override { return 240; }

yup::Color getNodeColor() const override { return yup::Color (0xff8b5cf6); }

yup::String getNodeSubtitle() const override
{
return yup::String (processor.getCurrentFFTSize()) + " / " + yup::String (processor.getFFTSize() / processor.getOverlapFactor()) + " hop";
}

PortInfo getInputPortInfo (int) const override { return { "audio", getPortKindColor (PortKind::audio), PortKind::audio }; }

PortInfo getOutputPortInfo (int) const override { return { "audio", getPortKindColor (PortKind::audio), PortKind::audio }; }

int getNumParameterRows() const override { return 2; }

ParameterInfo getParameterInfo (int row) const override
{
if (row == 0)
return { "FFT", yup::String (processor.getCurrentFFTSize()), getPortKindColor (PortKind::parameter), -1.0f, PortKind::parameter };

return { "Overlap", yup::String (1.0f / static_cast<float> (processor.getOverlapFactor()), 2), getPortKindColor (PortKind::parameter), -1.0f, PortKind::parameter };
}

void resized() override
{
fftSizeSlider.setBounds (NodeViewHelpers::getInlineSliderBounds (*this, getPreferredWidth(), 0));
overlapSlider.setBounds (NodeViewHelpers::getInlineSliderBounds (*this, getPreferredWidth(), 1));
}

private:
SpectralPassthroughProcessor& processor;
yup::Slider fftSizeSlider;
yup::Slider overlapSlider;
};
Loading
Loading