kopia lustrzana https://github.com/jameshball/osci-render
Add support for .wav and .aiff files
rodzic
997de907bc
commit
557b9f3371
|
@ -10,7 +10,7 @@ MainComponent::MainComponent(OscirenderAudioProcessor& p, OscirenderAudioProcess
|
||||||
fileButton.setButtonText("Choose File(s)");
|
fileButton.setButtonText("Choose File(s)");
|
||||||
|
|
||||||
fileButton.onClick = [this] {
|
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 |
|
auto flags = juce::FileBrowserComponent::openMode | juce::FileBrowserComponent::canSelectMultipleItems |
|
||||||
juce::FileBrowserComponent::canSelectFiles;
|
juce::FileBrowserComponent::canSelectFiles;
|
||||||
|
|
||||||
|
|
|
@ -121,7 +121,7 @@ OscirenderAudioProcessorEditor::~OscirenderAudioProcessorEditor() {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool OscirenderAudioProcessorEditor::isBinaryFile(juce::String name) {
|
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
|
// parsersLock must be held
|
||||||
|
|
|
@ -18,6 +18,7 @@ void FileParser::parse(juce::String fileId, juce::String extension, std::unique_
|
||||||
gpla = nullptr;
|
gpla = nullptr;
|
||||||
lua = nullptr;
|
lua = nullptr;
|
||||||
img = nullptr;
|
img = nullptr;
|
||||||
|
wav = nullptr;
|
||||||
|
|
||||||
if (extension == ".obj") {
|
if (extension == ".obj") {
|
||||||
object = std::make_shared<WorldObject>(stream->readEntireStreamAsString().toStdString());
|
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{};
|
juce::MemoryBlock buffer{};
|
||||||
int bytesRead = stream->readIntoMemoryBlock(buffer);
|
int bytesRead = stream->readIntoMemoryBlock(buffer);
|
||||||
img = std::make_shared<ImageParser>(audioProcessor, extension, 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");
|
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() {
|
std::vector<std::unique_ptr<Shape>> FileParser::nextFrame() {
|
||||||
|
@ -72,7 +75,9 @@ Point FileParser::nextSample(lua_State*& L, LuaVariables& vars) {
|
||||||
}
|
}
|
||||||
} else if (img != nullptr) {
|
} else if (img != nullptr) {
|
||||||
return img->getSample();
|
return img->getSample();
|
||||||
}
|
} else if (wav != nullptr) {
|
||||||
|
return wav->getSample();
|
||||||
|
}
|
||||||
|
|
||||||
return Point();
|
return Point();
|
||||||
}
|
}
|
||||||
|
@ -122,3 +127,7 @@ std::shared_ptr<LuaParser> FileParser::getLua() {
|
||||||
std::shared_ptr<ImageParser> FileParser::getImg() {
|
std::shared_ptr<ImageParser> FileParser::getImg() {
|
||||||
return img;
|
return img;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::shared_ptr<WavParser> FileParser::getWav() {
|
||||||
|
return wav;
|
||||||
|
}
|
||||||
|
|
|
@ -8,6 +8,7 @@
|
||||||
#include "../gpla/LineArtParser.h"
|
#include "../gpla/LineArtParser.h"
|
||||||
#include "../lua/LuaParser.h"
|
#include "../lua/LuaParser.h"
|
||||||
#include "../img/ImageParser.h"
|
#include "../img/ImageParser.h"
|
||||||
|
#include "../wav/WavParser.h"
|
||||||
|
|
||||||
class OscirenderAudioProcessor;
|
class OscirenderAudioProcessor;
|
||||||
class FileParser {
|
class FileParser {
|
||||||
|
@ -29,6 +30,7 @@ public:
|
||||||
std::shared_ptr<LineArtParser> getLineArt();
|
std::shared_ptr<LineArtParser> getLineArt();
|
||||||
std::shared_ptr<LuaParser> getLua();
|
std::shared_ptr<LuaParser> getLua();
|
||||||
std::shared_ptr<ImageParser> getImg();
|
std::shared_ptr<ImageParser> getImg();
|
||||||
|
std::shared_ptr<WavParser> getWav();
|
||||||
|
|
||||||
bool isAnimatable = false;
|
bool isAnimatable = false;
|
||||||
|
|
||||||
|
@ -46,6 +48,7 @@ private:
|
||||||
std::shared_ptr<LineArtParser> gpla;
|
std::shared_ptr<LineArtParser> gpla;
|
||||||
std::shared_ptr<LuaParser> lua;
|
std::shared_ptr<LuaParser> lua;
|
||||||
std::shared_ptr<ImageParser> img;
|
std::shared_ptr<ImageParser> img;
|
||||||
|
std::shared_ptr<WavParser> wav;
|
||||||
|
|
||||||
juce::String fallbackLuaScript = "return { 0.0, 0.0 }";
|
juce::String fallbackLuaScript = "return { 0.0, 0.0 }";
|
||||||
|
|
||||||
|
|
|
@ -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));
|
||||||
|
}
|
||||||
|
}
|
|
@ -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;
|
||||||
|
};
|
|
@ -584,6 +584,10 @@
|
||||||
<FILE id="mC1tUv" name="ugen_JuceUtility.h" compile="0" resource="0"
|
<FILE id="mC1tUv" name="ugen_JuceUtility.h" compile="0" resource="0"
|
||||||
file="Source/UGen/ugen_JuceUtility.h"/>
|
file="Source/UGen/ugen_JuceUtility.h"/>
|
||||||
</GROUP>
|
</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 id="I44EdJ" name="EffectsComponent.cpp" compile="1" resource="0"
|
||||||
file="Source/EffectsComponent.cpp"/>
|
file="Source/EffectsComponent.cpp"/>
|
||||||
<FILE id="qxxNX3" name="EffectsComponent.h" compile="0" resource="0"
|
<FILE id="qxxNX3" name="EffectsComponent.h" compile="0" resource="0"
|
||||||
|
|
Ładowanie…
Reference in New Issue