OpenDSPX is a C++20 library for working with the DSPX format. It provides four layers:
model: the core DSPX data model and headersinterpolator: DSPX parameter curve interpolation utilities for evaluating parameter valuesserializer: serialization and deserialization for DSPX filesconverter: DSPX format conversion utilities built on top of the model layer; MIDI is the first supported backend today
Build-time dependencies:
- CMake 3.17 or newer
- A C++20-capable compiler
nlohmann-jsonstdcorelibzstdfor the serializer modulewolf-midifor the converter module
The project is currently configured for Windows and other CMake-supported platforms.
Configure and build with CMake:
cmake -S . -B build
cmake --build buildUseful options:
OPENDSPX_BUILD_STATIC: build static libraries instead of shared librariesOPENDSPX_BUILD_TESTS: build the test executableOPENDSPX_BUILD_INTERPOLATOR: build the interpolator interface libraryOPENDSPX_BUILD_SERIALIZER: build the serializer libraryOPENDSPX_BUILD_CONVERTER: build the converter libraryOPENDSPX_INSTALL: generate install rules and CMake package files
The core data type is opendspx::Model. It currently exposes version V1 and the associated DSPX content tree.
The interpolator module is a header-only utility for building and evaluating cubic curves. It is useful for DSPX parameter evaluation.
The public API provides helpers for:
- creating a curve from two key points plus reference points
- creating a curve from only one side of reference data
- creating a linear interpolator
- evaluating the resulting curve at any x position
Example:
#include <opendspxinterpolator/interpolator.h>
using opendspx::Interpolator;
int main() {
auto curve = Interpolator<double>::createLinear(0.0, 0.0, 1.0, 1.0);
double value = curve.evaluate(0.5);
(void)value;
}Use opendspx::Serializer to convert between Model and DSPX data streams.
#include <fstream>
#include <opendspx/model.h>
#include <opendspxserializer/serializer.h>
using namespace opendspx;
int main() {
std::ifstream input("song.dspx", std::ios::binary);
SerializationErrorList errors;
Model model = Serializer::deserialize(input, errors);
std::ofstream output("song-out.dspx", std::ios::binary);
Serializer::serialize(output, model, errors);
}Serializer::serialize can also write compressed output when the compress flag is set to true.
Use opendspx::Converter to convert between DSPX data and other formats.
#include <fstream>
#include <opendspxconverter/midi/midiconverter.h>
using namespace opendspx;
int main() {
Model model;
auto intermediate = MidiConverter::convertDspxToIntermediate(model);
std::ofstream midiOutput("output.mid", std::ios::binary);
MidiConverter::convertIntermediateToMidi(midiOutput, intermediate);
MidiConverter::Error error;
std::ifstream midiInput("input.mid", std::ios::binary);
auto imported = MidiConverter::convertMidiToIntermediate(midiInput, error);
if (error != MidiConverter::Error::NoError) {
return 1;
}
bool ok = false;
Model roundTrip = MidiConverter::convertIntermediateToDspx(imported, &ok);
if (!ok) {
return 1;
}
(void)roundTrip;
}include/opendspx/: public model headersinclude/opendspxinterpolator/: interpolator APIinclude/opendspxserializer/: serializer APIinclude/opendspxconverter/: converter APIsrc/serializer/: serializer implementationsrc/converter/: converter implementation, currently focused on MIDItests/: usage tests
This project is distributed under the Apache License, Version 2.0, as described in LICENSE.