looper/backends/playback/fluidsynth/fluidsynth_backend.cpp

68 lines
2 KiB
C++
Raw Normal View History

2024-10-24 11:33:08 -07:00
#include "fluidsynth_backend.hpp"
#include <algorithm>
#include <ipc/common.pb.h>
#include <exception>
#include <filesystem>
#include "file_backend.hpp"
#include <stddef.h>
#include <string.h>
#include <file_backend.hpp>
#include <util.hpp>
2024-10-26 09:01:06 -07:00
void FluidSynthBackend::fluidsynth_get_property_list_wrapper(void *udata, const char *name, int type) {
2024-10-24 11:33:08 -07:00
((FluidSynthBackend*)udata)->fluidsynth_get_property_list(name, type);
}
2024-10-26 09:01:06 -07:00
void FluidSynthBackend::fluidsynth_get_property_list(const char *name, int type) {
Property property;
property.set_path(fmt::format("fluidsynth/{0}", name));
property.set_name(name);
switch (type) {
case FLUID_NUM_TYPE: {
property.set_type(PropertyType::Double);
} break;
case FLUID_INT_TYPE: {
property.set_type(PropertyType::Int);
} break;
case FLUID_STR_TYPE: {
property.set_type(PropertyType::String);
} break;
}
property.set_id(PropertyId::BackendSpecific);
fluidsynth_properties.push_back(property);
}
2024-10-24 11:33:08 -07:00
std::vector<Property> FluidSynthBackend::get_property_list() {
2024-10-26 09:01:06 -07:00
return fluidsynth_properties;
2024-10-24 11:33:08 -07:00
}
void FluidSynthBackend::load(const char *filename) {
memset(&spec, 0, sizeof(spec));
current_file = filename;
2024-10-26 09:01:06 -07:00
spec.format = AUDIO_F32SYS;
2024-10-24 11:33:08 -07:00
spec.samples = 100;
spec.channels = 2;
2024-10-26 09:01:06 -07:00
spec.freq = 48000;
2024-10-24 11:33:08 -07:00
spec.size = 100 * 2 * sizeof(int16_t);
file = open_file(filename);
2024-10-26 09:01:06 -07:00
this->settings = new_fluid_settings();
fluid_settings_foreach(settings, (void*)this, &fluidsynth_get_property_list_wrapper);
2024-10-24 11:33:08 -07:00
}
extern SDL_AudioSpec obtained;
2024-10-26 09:01:06 -07:00
void FluidSynthBackend::switch_stream(int idx) {
2024-10-24 11:33:08 -07:00
}
2024-10-26 09:01:06 -07:00
void FluidSynthBackend::cleanup() {
2024-10-24 11:33:08 -07:00
delete file;
file = nullptr;
}
2024-10-26 09:01:06 -07:00
size_t FluidSynthBackend::render(void *buf, size_t maxlen) {
2024-10-24 11:33:08 -07:00
size_t sample_type_len = 2;
maxlen /= sample_type_len;
maxlen *= sample_type_len;
return copied;
}
2024-10-26 09:01:06 -07:00
void FluidSynthBackend::seek(double position) {
2024-10-24 11:33:08 -07:00
}
2024-10-26 09:01:06 -07:00
double FluidSynthBackend::get_position() {
2024-10-24 11:33:08 -07:00
return position;
}
2024-10-26 09:01:06 -07:00
int FluidSynthBackend::get_stream_idx() {
2024-10-24 11:33:08 -07:00
return 0;
2024-10-26 09:01:06 -07:00
}