Struct-ize sample map variable

This commit is contained in:
cam900 2022-07-20 23:01:06 +09:00
parent dff7c61b79
commit a5959ae7b9
4 changed files with 40 additions and 24 deletions

View file

@ -2445,8 +2445,8 @@ bool DivEngine::loadFTM(unsigned char* file, size_t len) {
const int dpcmNotes=(blockVersion>=2)?96:72;
for (int j=0; j<dpcmNotes; j++) {
ins->amiga.noteMap[j]=(short)((unsigned char)reader.readC())-1;
ins->amiga.noteFreq[j]=(unsigned char)reader.readC();
ins->amiga.noteMap[j].map=(short)((unsigned char)reader.readC())-1;
ins->amiga.noteMap[j].freq=(unsigned char)reader.readC();
if (blockVersion>=6) {
reader.readC(); // DMC value
}

View file

@ -387,8 +387,12 @@ void DivInstrument::putInsData(SafeWriter* w) {
// sample map
w->writeC(amiga.useNoteMap);
if (amiga.useNoteMap) {
w->write(amiga.noteFreq,120*sizeof(unsigned int));
w->write(amiga.noteMap,120*sizeof(short));
for (int note=0; note<120; note++) {
w->writeI(amiga.noteMap[note].freq);
}
for (int note=0; note<120; note++) {
w->writeS(amiga.noteMap[note].map);
}
}
// N163
@ -932,8 +936,12 @@ DivDataErrors DivInstrument::readInsData(SafeReader& reader, short version) {
if (version>=67) {
amiga.useNoteMap=reader.readC();
if (amiga.useNoteMap) {
reader.read(amiga.noteFreq,120*sizeof(unsigned int));
reader.read(amiga.noteMap,120*sizeof(short));
for (int note=0; note<120; note++) {
amiga.noteMap[note].freq=reader.readI();
}
for (int note=0; note<120; note++) {
amiga.noteMap[note].map=reader.readS();
}
}
}

View file

@ -306,12 +306,18 @@ struct DivInstrumentC64 {
};
struct DivInstrumentAmiga {
struct SampleMap {
int freq;
short map;
SampleMap(int f=0, short m=-1):
freq(f),
map(m) {}
};
short initSample;
bool useNoteMap;
bool useWave;
unsigned char waveLen;
int noteFreq[120];
short noteMap[120];
SampleMap noteMap[120];
/**
* get the sample at specified note.
@ -321,7 +327,7 @@ struct DivInstrumentAmiga {
if (useNoteMap) {
if (note<0) note=0;
if (note>119) note=119;
return noteMap[note];
return noteMap[note].map;
}
return initSample;
}
@ -334,7 +340,7 @@ struct DivInstrumentAmiga {
if (useNoteMap) {
if (note<0) note=0;
if (note>119) note=119;
return noteFreq[note];
return noteMap[note].freq;
}
return -1;
}
@ -344,8 +350,9 @@ struct DivInstrumentAmiga {
useNoteMap(false),
useWave(false),
waveLen(31) {
memset(noteMap,-1,120*sizeof(short));
memset(noteFreq,0,120*sizeof(int));
for (SampleMap& elem: noteMap) {
elem=SampleMap();
}
}
};