Merge branch 'wav-file-input' of github.com:jameshball/osci-render into wav-file-input

pull/251/head
James H Ball 2024-08-23 11:07:15 +01:00
commit 479319b11c
7 zmienionych plików z 85 dodań i 4 usunięć

Wyświetl plik

@ -10,7 +10,7 @@ MainComponent::MainComponent(OscirenderAudioProcessor& p, OscirenderAudioProcess
fileButton.setButtonText("Choose File(s)");
fileButton.onClick = [this] {
chooser = std::make_unique<juce::FileChooser>("Open", audioProcessor.lastOpenedDirectory, "*.obj;*.svg;*.lua;*.txt;*.gpla;*.gif;*.png;*.jpg;*.jpeg");
chooser = std::make_unique<juce::FileChooser>("Open", audioProcessor.lastOpenedDirectory, "*.obj;*.svg;*.lua;*.txt;*.gpla;*.gif;*.png;*.jpg;*.jpeg;*.wav;*.aiff");
auto flags = juce::FileBrowserComponent::openMode | juce::FileBrowserComponent::canSelectMultipleItems |
juce::FileBrowserComponent::canSelectFiles;

Wyświetl plik

@ -137,7 +137,7 @@ OscirenderAudioProcessorEditor::~OscirenderAudioProcessorEditor() {
}
bool OscirenderAudioProcessorEditor::isBinaryFile(juce::String name) {
return name.endsWith(".gpla") || name.endsWith(".gif") || name.endsWith(".png") || name.endsWith(".jpg") || name.endsWith(".jpeg");
return name.endsWith(".gpla") || name.endsWith(".gif") || name.endsWith(".png") || name.endsWith(".jpg") || name.endsWith(".jpeg") || name.endsWith(".wav") || name.endsWith(".aiff");
}
// parsersLock must be held

Wyświetl plik

@ -18,6 +18,7 @@ void FileParser::parse(juce::String fileId, juce::String extension, std::unique_
gpla = nullptr;
lua = nullptr;
img = nullptr;
wav = nullptr;
if (extension == ".obj") {
object = std::make_shared<WorldObject>(stream->readEntireStreamAsString().toStdString());
@ -33,10 +34,12 @@ void FileParser::parse(juce::String fileId, juce::String extension, std::unique_
juce::MemoryBlock buffer{};
int bytesRead = stream->readIntoMemoryBlock(buffer);
img = std::make_shared<ImageParser>(audioProcessor, extension, buffer);
} else if (extension == ".wav" || extension == ".aiff") {
wav = std::make_shared<WavParser>(audioProcessor, std::move(stream));
}
isAnimatable = gpla != nullptr || (img != nullptr && extension == ".gif");
sampleSource = lua != nullptr || img != nullptr;
sampleSource = lua != nullptr || img != nullptr || wav != nullptr;
}
std::vector<std::unique_ptr<Shape>> FileParser::nextFrame() {
@ -72,7 +75,9 @@ Point FileParser::nextSample(lua_State*& L, LuaVariables& vars) {
}
} else if (img != nullptr) {
return img->getSample();
}
} else if (wav != nullptr) {
return wav->getSample();
}
return Point();
}
@ -122,3 +127,7 @@ std::shared_ptr<LuaParser> FileParser::getLua() {
std::shared_ptr<ImageParser> FileParser::getImg() {
return img;
}
std::shared_ptr<WavParser> FileParser::getWav() {
return wav;
}

Wyświetl plik

@ -8,6 +8,7 @@
#include "../gpla/LineArtParser.h"
#include "../lua/LuaParser.h"
#include "../img/ImageParser.h"
#include "../wav/WavParser.h"
class OscirenderAudioProcessor;
class FileParser {
@ -29,6 +30,7 @@ public:
std::shared_ptr<LineArtParser> getLineArt();
std::shared_ptr<LuaParser> getLua();
std::shared_ptr<ImageParser> getImg();
std::shared_ptr<WavParser> getWav();
bool isAnimatable = false;
@ -46,6 +48,7 @@ private:
std::shared_ptr<LineArtParser> gpla;
std::shared_ptr<LuaParser> lua;
std::shared_ptr<ImageParser> img;
std::shared_ptr<WavParser> wav;
juce::String fallbackLuaScript = "return { 0.0, 0.0 }";

Wyświetl plik

@ -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));
}
}

Wyświetl plik

@ -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;
};

Wyświetl plik

@ -584,6 +584,10 @@
<FILE id="mC1tUv" name="ugen_JuceUtility.h" compile="0" resource="0"
file="Source/UGen/ugen_JuceUtility.h"/>
</GROUP>
<GROUP id="{DC345620-B6F6-F3B9-D359-C265590B0F00}" name="wav">
<FILE id="vYzJlF" name="WavParser.cpp" compile="1" resource="0" file="Source/wav/WavParser.cpp"/>
<FILE id="ZRT5Xk" name="WavParser.h" compile="0" resource="0" file="Source/wav/WavParser.h"/>
</GROUP>
<FILE id="I44EdJ" name="EffectsComponent.cpp" compile="1" resource="0"
file="Source/EffectsComponent.cpp"/>
<FILE id="qxxNX3" name="EffectsComponent.h" compile="0" resource="0"