aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordakkar <dakkar@thenautilus.net>2020-08-23 12:30:36 +0100
committerdakkar <dakkar@thenautilus.net>2020-08-23 12:30:36 +0100
commited2e5f90bb2273e4444aed9bb73411b9f8752d1e (patch)
treec25752f22adc7891c26bbf8a590d07c8ca80c231
parentsoundfont works! (diff)
downloadlego-piano-ed2e5f90bb2273e4444aed9bb73411b9f8752d1e.tar.gz
lego-piano-ed2e5f90bb2273e4444aed9bb73411b9f8752d1e.tar.bz2
lego-piano-ed2e5f90bb2273e4444aed9bb73411b9f8752d1e.zip
vague attempt at dumping a tsf object statically
I don't think it can be done, the `fontSamples` are a float array but we can't see how big
-rw-r--r--sf-compile/Makefile6
-rwxr-xr-xsf-compile/sf-compilebin0 -> 55144 bytes
-rw-r--r--sf-compile/sf-compile.cpp56
-rw-r--r--sf-compile/static-tsf.h24
4 files changed, 86 insertions, 0 deletions
diff --git a/sf-compile/Makefile b/sf-compile/Makefile
new file mode 100644
index 0000000..8c36db8
--- /dev/null
+++ b/sf-compile/Makefile
@@ -0,0 +1,6 @@
+all: sf-compile static-tsf.h
+
+sf-compile: sf-compile.cpp
+
+static-tsf.h: sf-compile
+ ./sf-compile > static-tsf.h
diff --git a/sf-compile/sf-compile b/sf-compile/sf-compile
new file mode 100755
index 0000000..4ba3087
--- /dev/null
+++ b/sf-compile/sf-compile
Binary files differ
diff --git a/sf-compile/sf-compile.cpp b/sf-compile/sf-compile.cpp
new file mode 100644
index 0000000..aab971b
--- /dev/null
+++ b/sf-compile/sf-compile.cpp
@@ -0,0 +1,56 @@
+#include <iostream>
+#include <string>
+
+#define TSF_IMPLEMENTATION
+#include "../tsf/tsf.h"
+
+void dumpChars(std::ostream& os, const char *ptr,size_t size) {
+ os << "{" << std::hex;
+ for (size_t i=0;i<size;++i) {
+ os << "0x" << (int)ptr[i] << ",";
+ if (i%16 == 15) os << "\n";
+ }
+ os << std::dec << "}";
+}
+
+int main() {
+ tsf* f = tsf_load_filename("../tsf/examples/florestan-subset.sf2");
+ tsf_set_output(f, TSF_MONO, 20000, 0);
+
+ struct tsf_preset *preset, *presetEnd;
+
+ std::cout << "tsf_preset g_presets[] = PROGMEM {\n";
+ for (preset = f->presets, presetEnd = preset + f->presetNum; preset != presetEnd; preset++) {
+ std::cout << " {\n"
+ << " .presetName= ";
+ dumpChars(std::cout,preset->presetName,20);
+ std::cout << ",\n"
+ << " .preset= " << preset->preset << ",\n"
+ << " .bank= " << preset->bank << ",\n"
+ << " .regionNum= " << preset->regionNum << ",\n"
+ << " },\n"
+ ;
+ }
+ std::cout << "};\n";
+
+ std::cout << "tsf theSoundFont PROGMEM = {\n"
+ << " .presets= g_presets,\n"
+ << " .fontSamples = " << f->fontSamples << ",\n"
+ << " .voices= 0,\n"
+ << " .channels= 0,\n"
+ << " .outputSamples= 0,\n"
+ << " .presetNum= " << f->presetNum << ",\n"
+ << " .voiceNum= " << f->voiceNum << ",\n"
+ << " .maxVoiceNum= " << f->maxVoiceNum << ",\n"
+ << " .outputSampleSize= " << f->outputSampleSize << ",\n"
+ << " .voicePlayIndex= " << f->voicePlayIndex << ",\n"
+ << " .outputmode= TSF_MONO,\n" // cheat
+ << " .outSampleRate= " << f->outSampleRate << ",\n"
+ << " .globalGainDB= " << f->globalGainDB << ",\n"
+ ;
+
+
+ std::cout << "};\n";
+
+ TSF_FREE(f->fontSamples);
+}
diff --git a/sf-compile/static-tsf.h b/sf-compile/static-tsf.h
new file mode 100644
index 0000000..bb45da1
--- /dev/null
+++ b/sf-compile/static-tsf.h
@@ -0,0 +1,24 @@
+tsf_preset g_presets[] = PROGMEM {
+ {
+ .presetName= {0x50,0x69,0x61,0x6e,0x6f,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,
+0x0,0x0,0x0,0x0,},
+ .preset= 2,
+ .bank= 0,
+ .regionNum= 4,
+ },
+};
+tsf theSoundFont PROGMEM = {
+ .presets= g_presets,
+ .fontSamples = 0x7fed29afd010,
+ .voices= 0,
+ .channels= 0,
+ .outputSamples= 0,
+ .presetNum= 1,
+ .voiceNum= 0,
+ .maxVoiceNum= 0,
+ .outputSampleSize= 0,
+ .voicePlayIndex= 0,
+ .outputmode= TSF_MONO,
+ .outSampleRate= 20000,
+ .globalGainDB= 0,
+};