Skip to content

Commit 81ee9a3

Browse files
committed
fix reading conditional chunks in the articulation data
1 parent 4be47d6 commit 81ee9a3

5 files changed

Lines changed: 19 additions & 23 deletions

File tree

src/soundbank/downloadable_sounds/articulation.ts

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -106,23 +106,21 @@ export class DownloadableSoundsArticulation extends DLSVerifier {
106106
* @param chunks
107107
*/
108108
public read(chunks: RIFFChunk[]) {
109-
const lart = RIFFChunk.findType(chunks, "lart");
110-
const lar2 = RIFFChunk.findType(chunks, "lar2");
109+
const lart = RIFFChunk.findListType(chunks, "lart");
110+
const lar2 = RIFFChunk.findListType(chunks, "lar2");
111111

112112
if (lart) {
113113
this.mode = "dls1";
114114
while (lart.data.currentIndex < lart.data.length) {
115-
const art1 = RIFFChunk.read(lart.data);
115+
const chunk = RIFFChunk.read(lart.data);
116116
// Note:
117117
// DLS Specification says that lar2 should only have art2, but a DirectMusic Producer example
118118
// "FarmGame.dls" has 'art1' in there.
119119
// Hence, we allow art2 in lart and art1 in lar2.
120-
DownloadableSoundsArticulation.verifyHeader(
121-
art1,
122-
"art1",
123-
"art2"
124-
);
125-
const artData = art1.data;
120+
if (chunk.header !== "art1" && chunk.header !== "art2")
121+
// There may be a cdl chunk, testcase romania_main.dls
122+
continue;
123+
const artData = chunk.data;
126124
const cbSize = readLittleEndianIndexed(artData, 4);
127125
if (cbSize !== 8) {
128126
SpessaSynthWarn(
@@ -137,17 +135,15 @@ export class DownloadableSoundsArticulation extends DLSVerifier {
137135
} else if (lar2) {
138136
this.mode = "dls2";
139137
while (lar2.data.currentIndex < lar2.data.length) {
140-
const art2 = RIFFChunk.read(lar2.data);
138+
const chunk = RIFFChunk.read(lar2.data);
141139
// Note:
142140
// DLS Specification says that lar2 should only have art2, but a DirectMusic Producer example
143141
// "FarmGame.dls" has 'art1' in there.
144142
// Hence, we allow art2 in lart and art1 in lar2.
145-
DownloadableSoundsArticulation.verifyHeader(
146-
art2,
147-
"art2",
148-
"art1"
149-
);
150-
const artData = art2.data;
143+
if (chunk.header !== "art1" && chunk.header !== "art2")
144+
// There may be a cdl chunk, testcase romania_main.dls
145+
continue;
146+
const artData = chunk.data;
151147
const cbSize = readLittleEndianIndexed(artData, 4);
152148
if (cbSize !== 8) {
153149
SpessaSynthWarn(

src/soundbank/downloadable_sounds/downloadable_sounds.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ export class DownloadableSounds extends DLSVerifier {
8080
dls.soundBankInfo.comment = "(no description)";
8181

8282
// Read info
83-
const infoChunk = RIFFChunk.findType(chunks, "INFO");
83+
const infoChunk = RIFFChunk.findListType(chunks, "INFO");
8484
if (infoChunk) {
8585
while (infoChunk.data.currentIndex < infoChunk.data.length) {
8686
const infoPart = RIFFChunk.read(infoChunk.data);
@@ -148,7 +148,7 @@ export class DownloadableSounds extends DLSVerifier {
148148
);
149149

150150
// Read the wave list
151-
const waveListChunk = RIFFChunk.findType(chunks, "wvpl");
151+
const waveListChunk = RIFFChunk.findListType(chunks, "wvpl");
152152
if (!waveListChunk) {
153153
this.parsingError("No wvpl chunk!");
154154
return 5 as never;
@@ -159,7 +159,7 @@ export class DownloadableSounds extends DLSVerifier {
159159
}
160160

161161
// Read the instrument list
162-
const instrumentListChunk = RIFFChunk.findType(chunks, "lins");
162+
const instrumentListChunk = RIFFChunk.findListType(chunks, "lins");
163163
if (!instrumentListChunk) {
164164
this.parsingError("No lins chunk!");
165165
return 5 as never;

src/soundbank/downloadable_sounds/instrument.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ export class DownloadableSoundsInstrument
7777

7878
// Read the instrument name in INFO
7979
let instrumentName = ``;
80-
const infoChunk = RIFFChunk.findType(chunks, "INFO");
80+
const infoChunk = RIFFChunk.findListType(chunks, "INFO");
8181
if (infoChunk) {
8282
let info = RIFFChunk.read(infoChunk.data);
8383
while (info.header !== "INAM") {
@@ -122,7 +122,7 @@ export class DownloadableSoundsInstrument
122122
);
123123

124124
// List of regions
125-
const regionListChunk = RIFFChunk.findType(chunks, "lrgn");
125+
const regionListChunk = RIFFChunk.findListType(chunks, "lrgn");
126126
if (!regionListChunk) {
127127
SpessaSynthGroupEnd();
128128
throw new Error("No region list!");

src/soundbank/downloadable_sounds/sample.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ export class DownloadableSoundsSample extends DLSVerifier {
7474
);
7575

7676
// Read sample name
77-
const waveInfo = RIFFChunk.findType(chunks, "INFO");
77+
const waveInfo = RIFFChunk.findListType(chunks, "INFO");
7878
if (waveInfo) {
7979
let infoChunk = RIFFChunk.read(waveInfo.data);
8080
while (

src/utils/riff_chunk.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ export class RIFFChunk {
195195
* @remarks
196196
* Also skips the current index to after the list FourCC.
197197
*/
198-
public static findType(
198+
public static findListType(
199199
collection: RIFFChunk[],
200200
type: FourCC
201201
): RIFFChunk | undefined {

0 commit comments

Comments
 (0)