Compare commits

..

No commits in common. "main" and "v0.0.5" have entirely different histories.
main ... v0.0.5

6 changed files with 16 additions and 24 deletions

View file

@ -1,8 +1,6 @@
PYTHON := $(shell which python) PYTHONINCLUDEPATH := $(shell python3.10 -c "import sysconfig; print(sysconfig.get_path('include'))")
PYTHONINCLUDEPATH := $(shell $(PYTHON) -c "import sysconfig; print(sysconfig.get_path('include'))") PYTHONLIBPATH := $(shell python3.10 -c "import sysconfig; print(sysconfig.get_config_var('LIBDIR'))")
PYTHONLIBPATH := $(shell $(PYTHON) -c "import sysconfig; print(sysconfig.get_config_var('LIBDIR'))")
ifndef CONFIG ifndef CONFIG
CONFIG=Release CONFIG=Release
@ -10,7 +8,7 @@ endif
ifndef LIBDIR ifndef LIBDIR
# LIBDIR=/usr/lib/ # LIBDIR=/usr/lib/
LIBDIR=$(shell $(PYTHON) -c "import sysconfig; print(sysconfig.get_config_var('LIBDIR'))") LIBDIR=$(shell python3.10 -c "import sysconfig; print(sysconfig.get_config_var('LIBDIR'))")
endif endif
BUILD_DATE="$(shell date +'%Y %m %d %H %M')" BUILD_DATE="$(shell date +'%Y %m %d %H %M')"

View file

@ -16,7 +16,8 @@ pip install vita
from scipy.io import wavfile from scipy.io import wavfile
import vita import vita
sample_rate = 44100 SAMPLE_RATE = 44_100
bpm = 120.0 bpm = 120.0
note_dur = 1.0 note_dur = 1.0
render_dur = 3.0 render_dur = 3.0
@ -26,7 +27,6 @@ velocity = 0.7 # [0.0 to 1.0]
synth = vita.Synth() synth = vita.Synth()
# The initial preset is loaded by default. # The initial preset is loaded by default.
synth.set_sample_rate(sample_rate)
synth.set_bpm(bpm) synth.set_bpm(bpm)
# Let's make a custom modulation using # Let's make a custom modulation using
@ -57,7 +57,7 @@ print(f"Current: {synth.get_control_text('delay_style')}") # e.g., "Stereo"
# Render audio to numpy array shaped (2, NUM_SAMPLES) # Render audio to numpy array shaped (2, NUM_SAMPLES)
audio = synth.render(pitch, velocity, note_dur, render_dur) audio = synth.render(pitch, velocity, note_dur, render_dur)
wavfile.write("generated_preset.wav", sample_rate, audio.T) wavfile.write("generated_preset.wav", SAMPLE_RATE, audio.T)
# Dump current state to JSON text # Dump current state to JSON text
preset_path = "generated_preset.vital" preset_path = "generated_preset.vital"

View file

@ -448,13 +448,8 @@ void SynthBase::pySetBPM(float bpm) {
engine_->setBpm(bpm); engine_->setBpm(bpm);
}; };
// src/plugin/synth_plugin.cpp Line 129-133 prepareToPlay
void SynthBase::setSampleRate(double sample_rate) {
engine_->setSampleRate(sample_rate);
midi_manager_->setSampleRate(sample_rate);
}
void SynthBase::renderAudioToFile(File file, std::vector<int> notes, float velocity, float note_dur, float render_dur, bool render_images) { void SynthBase::renderAudioToFile(File file, std::vector<int> notes, float velocity, float note_dur, float render_dur, bool render_images) {
static constexpr int kSampleRate = 44100;
static constexpr int kPreProcessSamples = 44100; static constexpr int kPreProcessSamples = 44100;
static constexpr int kFadeSamples = 200; static constexpr int kFadeSamples = 200;
static constexpr int kBufferSize = 64; static constexpr int kBufferSize = 64;
@ -469,11 +464,11 @@ void SynthBase::renderAudioToFile(File file, std::vector<int> notes, float veloc
engine_->allSoundsOff(); // note: dbraun added this engine_->allSoundsOff(); // note: dbraun added this
processModulationChanges(); processModulationChanges();
engine_->setSampleRate(kSampleRate);
// engine_->setBpm(bpm); // engine_->setBpm(bpm);
engine_->updateAllModulationSwitches(); engine_->updateAllModulationSwitches();
int kSampleRate = getSampleRate();
double sample_time = 1.0 / kSampleRate; double sample_time = 1.0 / getSampleRate();
double current_time = -kPreProcessSamples * sample_time; double current_time = -kPreProcessSamples * sample_time;
for (int samples = 0; samples < kPreProcessSamples; samples += kBufferSize) { for (int samples = 0; samples < kPreProcessSamples; samples += kBufferSize) {
@ -580,6 +575,7 @@ void SynthBase::renderAudioToFile(File file, std::vector<int> notes, float veloc
} }
nb::ndarray<float, nb::shape<2, -1>, nb::numpy> SynthBase::renderAudioToNumpy(const int& midi_note, float velocity, float note_dur, float render_dur) { nb::ndarray<float, nb::shape<2, -1>, nb::numpy> SynthBase::renderAudioToNumpy(const int& midi_note, float velocity, float note_dur, float render_dur) {
static constexpr int kSampleRate = 44100;
static constexpr int kFadeSamples = 200; static constexpr int kFadeSamples = 200;
static constexpr int kBufferSize = 64; static constexpr int kBufferSize = 64;
static constexpr int kPreProcessSamples = 256; // note: dbraun decreased this from 44100. static constexpr int kPreProcessSamples = 256; // note: dbraun decreased this from 44100.
@ -592,11 +588,11 @@ nb::ndarray<float, nb::shape<2, -1>, nb::numpy> SynthBase::renderAudioToNumpy(co
engine_->allSoundsOff(); // note: dbraun added this engine_->allSoundsOff(); // note: dbraun added this
processModulationChanges(); processModulationChanges();
engine_->setSampleRate(kSampleRate);
engine_->updateAllModulationSwitches(); engine_->updateAllModulationSwitches();
int kSampleRate = getSampleRate();
// Preprocess modulation // Preprocess modulation
double sample_time = 1.0 / kSampleRate; double sample_time = 1.0 / getSampleRate();
double current_time = -kPreProcessSamples * sample_time; double current_time = -kPreProcessSamples * sample_time;
for (int samples = 0; samples < kPreProcessSamples; samples += kBufferSize) { for (int samples = 0; samples < kPreProcessSamples; samples += kBufferSize) {

View file

@ -139,7 +139,6 @@ class SynthBase : public MidiManager::Listener {
Tuning* getTuning() { return &tuning_; } Tuning* getTuning() { return &tuning_; }
void pySetBPM(float bpm); void pySetBPM(float bpm);
void setSampleRate(double sample_rate);
struct ValueChangedCallback : public CallbackMessage { struct ValueChangedCallback : public CallbackMessage {
ValueChangedCallback(std::shared_ptr<SynthBase*> listener, std::string name, vital::mono_float val) : ValueChangedCallback(std::shared_ptr<SynthBase*> listener, std::string name, vital::mono_float val) :

View file

@ -572,7 +572,6 @@ NB_MODULE(vita, m) {
"Disconnects a modulation source from a destination by name.") "Disconnects a modulation source from a destination by name.")
.def("set_bpm", &HeadlessSynth::pySetBPM, nb::arg("bpm")) .def("set_bpm", &HeadlessSynth::pySetBPM, nb::arg("bpm"))
.def("set_sample_rate", &HeadlessSynth::setSampleRate, nb::arg("sample_rate"))
.def("render_file", &HeadlessSynth::renderAudioToFile2, .def("render_file", &HeadlessSynth::renderAudioToFile2,
nb::arg("output_path"), nb::arg("midi_note"), nb::arg("output_path"), nb::arg("midi_note"),

View file

@ -20,14 +20,15 @@ from vita.constants import (
SyncedFrequency, SyncedFrequency,
) )
SAMPLE_RATE = 44_100
def test_render(bpm=120.0, sample_rate=48000, note_dur=1.0, render_dur=3.0, pitch=36, velocity=0.7):
def test_render(bpm=120.0, note_dur=1.0, render_dur=3.0, pitch=36, velocity=0.7):
synth = vita.Synth() synth = vita.Synth()
# The initial preset is laoded by default. # The initial preset is laoded by default.
synth.set_bpm(bpm) synth.set_bpm(bpm)
synth.set_sample_rate(sample_rate)
assert vita.get_modulation_sources() assert vita.get_modulation_sources()
assert vita.get_modulation_destinations() assert vita.get_modulation_destinations()
@ -42,9 +43,8 @@ def test_render(bpm=120.0, sample_rate=48000, note_dur=1.0, render_dur=3.0, pitc
# Render audio to numpy array shaped (2, NUM_SAMPLES) # Render audio to numpy array shaped (2, NUM_SAMPLES)
audio = synth.render(pitch, velocity, note_dur, render_dur) audio = synth.render(pitch, velocity, note_dur, render_dur)
assert sample_rate == int(audio.shape[1] / render_dur) # assume int
wavfile.write("generated_preset.wav", sample_rate, audio.T) wavfile.write("generated_preset.wav", SAMPLE_RATE, audio.T)
# Dump current state to json text # Dump current state to json text
json_text = synth.to_json() json_text = synth.to_json()