-
-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #251 from jameshball/wav-file-input
Fix visualiser bugs, add support for .wav and .aiff files, and add brightness slider to visualiser
- Loading branch information
Showing
16 changed files
with
145 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
#include "WavParser.h" | ||
#include "../PluginProcessor.h" | ||
|
||
|
||
WavParser::WavParser(OscirenderAudioProcessor& p, std::unique_ptr<juce::InputStream> stream) : audioProcessor(p) { | ||
juce::AudioFormatManager formatManager; | ||
formatManager.registerBasicFormats(); | ||
juce::AudioFormatReader* reader = formatManager.createReaderFor(std::move(stream)); | ||
auto* afSource = new juce::AudioFormatReaderSource(reader, true); | ||
afSource->setLooping(true); | ||
source = std::make_unique<juce::ResamplingAudioSource>(afSource, true); | ||
fileSampleRate = reader->sampleRate; | ||
audioBuffer.setSize(reader->numChannels, 1); | ||
setSampleRate(audioProcessor.currentSampleRate); | ||
source->prepareToPlay(1, audioProcessor.currentSampleRate); | ||
} | ||
|
||
WavParser::~WavParser() { | ||
} | ||
|
||
void WavParser::setSampleRate(double sampleRate) { | ||
double ratio = fileSampleRate / sampleRate; | ||
source->setResamplingRatio(ratio); | ||
source->prepareToPlay(1, sampleRate); | ||
currentSampleRate = sampleRate; | ||
} | ||
|
||
Point WavParser::getSample() { | ||
if (currentSampleRate != audioProcessor.currentSampleRate) { | ||
setSampleRate(audioProcessor.currentSampleRate); | ||
} | ||
if (source == nullptr) { | ||
return Point(); | ||
} | ||
|
||
source->getNextAudioBlock(juce::AudioSourceChannelInfo(audioBuffer)); | ||
|
||
if (audioBuffer.getNumChannels() == 1) { | ||
return Point(audioBuffer.getSample(0, 0), audioBuffer.getSample(0, 0)); | ||
} else { | ||
return Point(audioBuffer.getSample(0, 0), audioBuffer.getSample(1, 0)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
#pragma once | ||
#include "../shape/Point.h" | ||
#include <JuceHeader.h> | ||
|
||
class OscirenderAudioProcessor; | ||
class WavParser { | ||
public: | ||
WavParser(OscirenderAudioProcessor& p, std::unique_ptr<juce::InputStream> stream); | ||
~WavParser(); | ||
|
||
Point getSample(); | ||
|
||
private: | ||
void setSampleRate(double sampleRate); | ||
|
||
std::unique_ptr<juce::ResamplingAudioSource> source; | ||
juce::AudioBuffer<float> audioBuffer; | ||
int currentSample = 0; | ||
int fileSampleRate; | ||
int currentSampleRate; | ||
OscirenderAudioProcessor& audioProcessor; | ||
}; |
Oops, something went wrong.