add wavetable saving
This commit is contained in:
parent
7c40948680
commit
62a499644f
4 changed files with 62 additions and 22 deletions
|
|
@ -1719,16 +1719,7 @@ SafeWriter* DivEngine::saveFur() {
|
|||
for (int i=0; i<song.waveLen; i++) {
|
||||
DivWavetable* wave=song.wave[i];
|
||||
wavePtr[i]=w->tell();
|
||||
w->write("WAVE",4);
|
||||
w->writeI(0);
|
||||
|
||||
w->writeC(0); // name
|
||||
w->writeI(wave->len);
|
||||
w->writeI(wave->min);
|
||||
w->writeI(wave->max);
|
||||
for (int j=0; j<wave->len; j++) {
|
||||
w->writeI(wave->data[j]);
|
||||
}
|
||||
wave->putWaveData(w);
|
||||
}
|
||||
|
||||
/// SAMPLE
|
||||
|
|
|
|||
|
|
@ -1,3 +1,45 @@
|
|||
#include "engine.h"
|
||||
#include "wavetable.h"
|
||||
#include "../ta-log.h"
|
||||
|
||||
// ???
|
||||
void DivWavetable::putWaveData(SafeWriter* w) {
|
||||
w->write("WAVE",4);
|
||||
w->writeI(0);
|
||||
|
||||
w->writeC(0); // name
|
||||
w->writeI(len);
|
||||
w->writeI(min);
|
||||
w->writeI(max);
|
||||
for (int j=0; j<len; j++) {
|
||||
w->writeI(data[j]);
|
||||
}
|
||||
}
|
||||
|
||||
bool DivWavetable::save(const char* path) {
|
||||
SafeWriter* w=new SafeWriter();
|
||||
w->init();
|
||||
|
||||
// write magic
|
||||
w->write("-Furnace waveta-",16);
|
||||
|
||||
// write version
|
||||
w->writeS(DIV_ENGINE_VERSION);
|
||||
|
||||
// reserved
|
||||
w->writeS(0);
|
||||
|
||||
putWaveData(w);
|
||||
|
||||
FILE* outFile=fopen(path,"wb");
|
||||
if (outFile==NULL) {
|
||||
logE("could not save wavetable: %s!\n",strerror(errno));
|
||||
w->finish();
|
||||
return false;
|
||||
}
|
||||
if (fwrite(w->getFinalBuf(),1,w->size(),outFile)!=w->size()) {
|
||||
logW("did not write entire wavetable!\n");
|
||||
}
|
||||
fclose(outFile);
|
||||
w->finish();
|
||||
return true;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue