fix empty samples eating memory

when DPCM is requested, Furnace would waste 500MB of memory per empty sample

that's why it had to be signed!
This commit is contained in:
tildearrow 2025-10-09 03:53:44 -05:00
parent 2739b5af54
commit 6b83f399f0
2 changed files with 12 additions and 5 deletions

View file

@ -543,7 +543,11 @@ bool DivSample::saveRaw(const char* path) {
}
// 16-bit memory is padded to 512, to make things easier for ADPCM-A/B.
bool DivSample::initInternal(DivSampleDepth d, unsigned int count) {
bool DivSample::initInternal(DivSampleDepth d, int count) {
if (count<0) {
logE("initInternal(%d,%d) - NEGATIVE!",(int)d,count);
return false;
}
logV("initInternal(%d,%d)",(int)d,count);
switch (d) {
case DIV_SAMPLE_DEPTH_1BIT: // 1-bit
@ -650,8 +654,11 @@ bool DivSample::initInternal(DivSampleDepth d, unsigned int count) {
return true;
}
bool DivSample::init(unsigned int count) {
if (count>16777215) return false;
bool DivSample::init(int count) {
if (count<0 || count>16777215) {
logE("tried to init sample with length %d!",count);
return false;
}
if (!initInternal(depth,count)) return false;
setSampleCount(count);
return true;

View file

@ -236,14 +236,14 @@ struct DivSample {
* @param count number of samples.
* @return whether it was successful.
*/
bool initInternal(DivSampleDepth d, unsigned int count);
bool initInternal(DivSampleDepth d, int count);
/**
* initialize sample data. make sure you have set `depth` before doing so.
* @param count number of samples.
* @return whether it was successful.
*/
bool init(unsigned int count);
bool init(int count);
/**
* resize sample data. make sure the sample has been initialized before doing so.