mirror of
https://github.com/tildearrow/furnace.git
synced 2024-11-06 21:05:04 +00:00
7ba8607270
as of now we store and use the actual sample rate as opposed to an index fo a fixed rate table. this allows for more flexibility in a future file format...
47 lines
948 B
C++
47 lines
948 B
C++
#include "sample.h"
|
|
#include "../ta-log.h"
|
|
#include <string.h>
|
|
#include <sndfile.h>
|
|
|
|
bool DivSample::save(const char* path) {
|
|
SNDFILE* f;
|
|
SF_INFO si;
|
|
memset(&si,0,sizeof(SF_INFO));
|
|
|
|
if (length<1) return false;
|
|
|
|
si.channels=1;
|
|
si.samplerate=rate;
|
|
if (depth==16) {
|
|
si.format=SF_FORMAT_PCM_16|SF_FORMAT_WAV;
|
|
} else {
|
|
si.format=SF_FORMAT_PCM_U8|SF_FORMAT_WAV;
|
|
}
|
|
|
|
f=sf_open(path,SFM_WRITE,&si);
|
|
|
|
if (f==NULL) {
|
|
logE("could not open wave file for saving! %s\n",sf_error_number(sf_error(f)));
|
|
return false;
|
|
}
|
|
|
|
if (depth==16) {
|
|
sf_writef_short(f,data,length);
|
|
} else {
|
|
short* cbuf=new short[length];
|
|
for (int i=0; i<length; i++) {
|
|
cbuf[i]=(data[i]<<8)^0x8000;
|
|
}
|
|
sf_writef_short(f,cbuf,length);
|
|
delete[] cbuf;
|
|
}
|
|
sf_close(f);
|
|
|
|
return true;
|
|
}
|
|
|
|
DivSample::~DivSample() {
|
|
if (data) delete[] data;
|
|
if (rendData) delete[] rendData;
|
|
if (adpcmRendData) delete[] adpcmRendData;
|
|
}
|