2222#pragma once
2323
2424#include < yup_dsp/yup_dsp.h>
25+ #include < yup_audio_formats/yup_audio_formats.h>
2526
2627#include < memory>
2728#include < random>
@@ -58,8 +59,10 @@ class CrossoverFrequencyResponseDisplay : public yup::Component
5859
5960 // Reserve space for labels
6061 auto titleBounds = bounds.removeFromTop (25 );
62+ titleBounds.removeFromLeft (5 );
6163 auto bottomLabelSpace = bounds.removeFromBottom (20 );
6264 auto leftLabelSpace = bounds.removeFromLeft (50 );
65+ leftLabelSpace.removeFromRight (5 );
6366
6467 // Grid
6568 g.setStrokeColor (yup::Color (0xFF333333 ));
@@ -247,6 +250,9 @@ class CrossoverDemo : public yup::Component,
247250 , lowGainSlider (yup::Slider::LinearVertical)
248251 , highGainSlider (yup::Slider::LinearVertical)
249252 {
253+ // Load the audio file
254+ loadAudioFile ();
255+
250256 // Audio device manager
251257 audioDeviceManager.initialiseWithDefaultDevices (0 , 2 );
252258
@@ -346,7 +352,7 @@ class CrossoverDemo : public yup::Component,
346352 yup::FloatVectorOperations::clear (outputChannelData[ch], numSamples);
347353 }
348354
349- if (numOutputChannels < 2 )
355+ if (numOutputChannels < 2 || audioBuffer. getNumSamples () == 0 )
350356 return ;
351357
352358 // Get the active filter
@@ -375,6 +381,9 @@ class CrossoverDemo : public yup::Component,
375381 }
376382
377383 // Process samples
384+ const int totalSamples = audioBuffer.getNumSamples ();
385+ const int numChannels = audioBuffer.getNumChannels ();
386+
378387 for (int i = 0 ; i < numSamples; ++i)
379388 {
380389 // Update crossover frequency smoothly
@@ -386,12 +395,30 @@ class CrossoverDemo : public yup::Component,
386395 filter8.setFrequency (freq);
387396 }
388397
389- // Generate white noise
390- float noise = noiseGenerator.getNextSample () * 0 .2f ;
398+ // Get the audio sample from the loaded file (mono to stereo if needed)
399+ float audioSample = 0 .0f ;
400+
401+ if (numChannels == 1 )
402+ {
403+ // Mono file
404+ audioSample = audioBuffer.getSample (0 , readPosition) * 0 .3f ;
405+ }
406+ else
407+ {
408+ // Stereo or multichannel - mix to mono
409+ for (int ch = 0 ; ch < yup::jmin (2 , numChannels); ++ch)
410+ audioSample += audioBuffer.getSample (ch, readPosition) * 0 .3f ;
411+ audioSample /= yup::jmin (2 , numChannels);
412+ }
413+
414+ // Increment read position and wrap around for looping
415+ readPosition++;
416+ if (readPosition >= totalSamples)
417+ readPosition = 0 ;
391418
392419 // Process through crossover
393420 float lowLeft, lowRight, highLeft, highRight;
394- filterProcess (noise, noise , lowLeft, lowRight, highLeft, highRight);
421+ filterProcess (audioSample, audioSample , lowLeft, lowRight, highLeft, highRight);
395422
396423 // Apply gains
397424 float lowGainValue = lowGain.getNextValue ();
@@ -409,12 +436,52 @@ class CrossoverDemo : public yup::Component,
409436 }
410437
411438private:
439+ void loadAudioFile ()
440+ {
441+ // Create the path to the audio file
442+ auto dataDir = yup::File (__FILE__)
443+ .getParentDirectory ()
444+ .getParentDirectory ()
445+ .getParentDirectory ()
446+ .getChildFile (" data" );
447+
448+ yup::File audioFile = dataDir.getChildFile (" break_boomblastic_92bpm.wav" );
449+ if (! audioFile.existsAsFile ())
450+ {
451+ std::cerr << " Could not find break_boomblastic_92bpm.wav" << std::endl;
452+ return ;
453+ }
454+
455+ // Load the audio file
456+ yup::AudioFormatManager formatManager;
457+ formatManager.registerDefaultFormats ();
458+
459+ if (auto reader = formatManager.createReaderFor (audioFile))
460+ {
461+ audioBuffer.setSize ((int ) reader->numChannels , (int ) reader->lengthInSamples );
462+ reader->read (&audioBuffer, 0 , (int ) reader->lengthInSamples , 0 , true , true );
463+
464+ std::cout << " Loaded audio file: " << audioFile.getFileName () << std::endl;
465+ std::cout << " Sample rate: " << reader->sampleRate << " Hz" << std::endl;
466+ std::cout << " Channels: " << reader->numChannels << std::endl;
467+ std::cout << " Length: " << reader->lengthInSamples << " samples" << std::endl;
468+ }
469+ else
470+ {
471+ std::cerr << " Failed to create reader for audio file" << std::endl;
472+ }
473+ }
474+
412475 void createUI ()
413476 {
414477 setOpaque (false );
415478
479+ // Get a 12pt font
480+ auto labelFont = yup::ApplicationTheme::getGlobalTheme ()->getDefaultFont ().withHeight (12 .0f );
481+
416482 // Order selection
417483 orderLabel.setText (" Filter Order" , yup::NotificationType::dontSendNotification);
484+ orderLabel.setFont (labelFont);
418485 addAndMakeVisible (orderLabel);
419486
420487 orderComboBox.addItem (" 2nd Order" , 1 );
@@ -435,6 +502,7 @@ class CrossoverDemo : public yup::Component,
435502
436503 // Crossover frequency slider
437504 freqLabel.setText (" Crossover Frequency" , yup::NotificationType::dontSendNotification);
505+ freqLabel.setFont (labelFont);
438506 addAndMakeVisible (freqLabel);
439507
440508 freqSlider.setRange (20.0 , 20000.0 );
@@ -450,7 +518,8 @@ class CrossoverDemo : public yup::Component,
450518
451519 // Low gain slider
452520 lowGainLabel.setText (" Low" , yup::NotificationType::dontSendNotification);
453- // lowGainLabel.setJustification (yup::Justification::center);
521+ lowGainLabel.setFont (labelFont);
522+ lowGainLabel.setJustification (yup::Justification::center);
454523 // lowGainLabel.setColour (yup::Label::textColourId, yup::Color (0xFF4488FF));
455524 addAndMakeVisible (lowGainLabel);
456525
@@ -465,7 +534,8 @@ class CrossoverDemo : public yup::Component,
465534
466535 // High gain slider
467536 highGainLabel.setText (" High" , yup::NotificationType::dontSendNotification);
468- // highGainLabel.setJustification (yup::Justification::center);
537+ highGainLabel.setFont (labelFont);
538+ highGainLabel.setJustification (yup::Justification::center);
469539 // highGainLabel.setColour (yup::Label::textColourId, yup::Color (0xFFFF8844));
470540 addAndMakeVisible (highGainLabel);
471541
@@ -546,7 +616,8 @@ class CrossoverDemo : public yup::Component,
546616
547617 // Audio
548618 yup::AudioDeviceManager audioDeviceManager;
549- yup::WhiteNoise noiseGenerator;
619+ yup::AudioBuffer<float > audioBuffer;
620+ int readPosition = 0 ;
550621
551622 // Filters
552623 yup::LinkwitzRiley2Filter<float > filter2;
0 commit comments