annotate decoders/timidity/instrum_dls.c @ 474:c66080364dff

Most decoders now report total sample play time, now. Technically, this breaks binary compatibility with the 1.0 branch, since it extends the Sound_Sample struct, but most (all?) programs are just passing pointers allocated by SDL_sound around, and might be okay. Source-level compatibility is not broken...yet! :) --ryan. -------- Original Message -------- Subject: SDL_sound patch: Finding total length of time of sound file. Date: Sun, 26 Jan 2003 09:31:17 -0800 (PST) Hi Ryan, I am working with Eric Wing and helping him modify SDL_sound. AS part of our efforts in improving and enhancing SDL_sound, we like to submit this patch. We modified the codecs to find the total time of a sound file. Below is the explanation of the patch. The patch is appended as an attachment to this email. * MOTIVATION: We needed the ability to get the total play time of a sample (And we noticed that we're not the only ones). Since SDL_sound blocks direct access to the specific decoders, there is no way for a user to know this information short of decoding the whole thing. Because of this, we believe this will be a useful addition, even though the accuracy may not be perfect (subject to each decoder) or the information may not always be available. * CONTRIBUTORS: Wesley Leong (modified the majority of the codecs and verified the results) Eric Wing (showed everyone how to do modify codec, modified mikmod) Wang Lam (modified a handful of codecs, researched into specs and int overflow) Ahilan Anantha (modified a few codecs and helped with integer math) * GENERAL ISSUES: We chose the value to be milliseconds as an Sint32. Milliseconds because that's what Sound_Seek takes as a parameter and -1 to allow for instances/codecs where the value could not be determined. We are not sure if this is the final convention you want, so we are willing to work with you on this. We also expect the total_time field to be set on open and never again modified by SDL_sound. Users may access it directly much like the sample buffer and buffer_size. We thought about recomputing the time on DecodeAll, but since users may seek or decode small chunks first, not all the data may be there. So this is better done by the user. This may be good information to document. Currently, all the main codecs are implemented except for QuickTime.
author Ryan C. Gordon <icculus@icculus.org>
date Sat, 08 May 2004 08:19:50 +0000
parents 4d2febf33dc7
children d02c00ce16d9
rev   line source
455
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1 /*
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
2
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
3 TiMidity -- Experimental MIDI to WAVE converter
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
4 Copyright (C) 1995 Tuukka Toivonen <toivonen@clinet.fi>
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
5
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
6 This program is free software; you can redistribute it and/or modify
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
7 it under the terms of the GNU General Public License as published by
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
8 the Free Software Foundation; either version 2 of the License, or
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
9 (at your option) any later version.
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
10
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
11 This program is distributed in the hope that it will be useful,
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
14 GNU General Public License for more details.
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
15
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
16 You should have received a copy of the GNU General Public License
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
17 along with this program; if not, write to the Free Software
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
19
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
20 instrum.h
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
21
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
22 */
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
23
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
24 #include <stdlib.h>
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
25 #include <string.h>
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
26
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
27 #include "SDL.h"
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
28 #include "SDL_endian.h"
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
29 #include "SDL_rwops.h"
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
30
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
31 #include "SDL_sound.h"
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
32
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
33 #define __SDL_SOUND_INTERNAL__
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
34 #include "SDL_sound_internal.h"
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
35
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
36 #include "timidity.h"
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
37 #include "options.h"
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
38 #include "instrum.h"
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
39 #include "tables.h"
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
40 #include "common.h"
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
41
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
42 /*-------------------------------------------------------------------------*/
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
43 /* * * * * * * * * * * * * * * * * load_riff.h * * * * * * * * * * * * * * */
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
44 /*-------------------------------------------------------------------------*/
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
45 typedef struct _RIFF_Chunk {
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
46 Uint32 magic;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
47 Uint32 length;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
48 Uint32 subtype;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
49 Uint8 *data;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
50 struct _RIFF_Chunk *child;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
51 struct _RIFF_Chunk *next;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
52 } RIFF_Chunk;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
53
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
54 extern DECLSPEC RIFF_Chunk* SDLCALL LoadRIFF(SDL_RWops *src);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
55 extern DECLSPEC void SDLCALL FreeRIFF(RIFF_Chunk *chunk);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
56 extern DECLSPEC void SDLCALL PrintRIFF(RIFF_Chunk *chunk, int level);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
57 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
58
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
59 /*-------------------------------------------------------------------------*/
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
60 /* * * * * * * * * * * * * * * * * load_riff.c * * * * * * * * * * * * * * */
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
61 /*-------------------------------------------------------------------------*/
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
62 #define RIFF 0x46464952 /* "RIFF" */
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
63 #define LIST 0x5453494c /* "LIST" */
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
64
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
65 static RIFF_Chunk *AllocRIFFChunk()
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
66 {
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
67 RIFF_Chunk *chunk = (RIFF_Chunk *)malloc(sizeof(*chunk));
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
68 if ( !chunk ) {
459
4d2febf33dc7 Changed some SDL_Error()s to __Sound_SetError() to fix linking issues.
Ryan C. Gordon <icculus@icculus.org>
parents: 458
diff changeset
69 __Sound_SetError(ERR_OUT_OF_MEMORY);
455
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
70 return NULL;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
71 }
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
72 memset(chunk, 0, sizeof(*chunk));
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
73 return chunk;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
74 }
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
75
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
76 static void FreeRIFFChunk(RIFF_Chunk *chunk)
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
77 {
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
78 if ( chunk->child ) {
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
79 FreeRIFFChunk(chunk->child);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
80 }
458
69c8ba97f4bd Fixed memory corruption when freeing DLS instruments
hercules
parents: 455
diff changeset
81 if ( chunk->next ) {
69c8ba97f4bd Fixed memory corruption when freeing DLS instruments
hercules
parents: 455
diff changeset
82 FreeRIFFChunk(chunk->next);
455
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
83 }
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
84 free(chunk);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
85 }
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
86
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
87 static int ChunkHasSubType(Uint32 magic)
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
88 {
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
89 static Uint32 chunk_list[] = {
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
90 RIFF, LIST
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
91 };
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
92 int i;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
93 for ( i = 0; i < SDL_TABLESIZE(chunk_list); ++i ) {
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
94 if ( magic == chunk_list[i] ) {
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
95 return 1;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
96 }
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
97 }
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
98 return 0;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
99 }
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
100
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
101 static int ChunkHasSubChunks(Uint32 magic)
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
102 {
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
103 static Uint32 chunk_list[] = {
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
104 RIFF, LIST
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
105 };
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
106 int i;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
107 for ( i = 0; i < SDL_TABLESIZE(chunk_list); ++i ) {
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
108 if ( magic == chunk_list[i] ) {
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
109 return 1;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
110 }
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
111 }
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
112 return 0;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
113 }
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
114
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
115 static void LoadSubChunks(RIFF_Chunk *chunk, Uint8 *data, Uint32 left)
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
116 {
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
117 Uint8 *subchunkData;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
118 Uint32 subchunkDataLen;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
119
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
120 while ( left > 8 ) {
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
121 RIFF_Chunk *child = AllocRIFFChunk();
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
122 RIFF_Chunk *next, *prev = NULL;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
123 for ( next = chunk->child; next; next = next->next ) {
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
124 prev = next;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
125 }
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
126 if ( prev ) {
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
127 prev->next = child;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
128 } else {
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
129 chunk->child = child;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
130 }
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
131
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
132 child->magic = (data[0] << 0) |
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
133 (data[1] << 8) |
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
134 (data[2] << 16) |
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
135 (data[3] << 24);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
136 data += 4;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
137 left -= 4;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
138 child->length = (data[0] << 0) |
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
139 (data[1] << 8) |
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
140 (data[2] << 16) |
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
141 (data[3] << 24);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
142 data += 4;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
143 left -= 4;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
144 child->data = data;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
145
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
146 if ( child->length > left ) {
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
147 child->length = left;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
148 }
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
149
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
150 subchunkData = child->data;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
151 subchunkDataLen = child->length;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
152 if ( ChunkHasSubType(child->magic) && subchunkDataLen >= 4 ) {
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
153 child->subtype = (subchunkData[0] << 0) |
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
154 (subchunkData[1] << 8) |
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
155 (subchunkData[2] << 16) |
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
156 (subchunkData[3] << 24);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
157 subchunkData += 4;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
158 subchunkDataLen -= 4;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
159 }
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
160 if ( ChunkHasSubChunks(child->magic) ) {
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
161 LoadSubChunks(child, subchunkData, subchunkDataLen);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
162 }
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
163
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
164 data += child->length;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
165 left -= child->length;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
166 }
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
167 }
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
168
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
169 RIFF_Chunk *LoadRIFF(SDL_RWops *src)
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
170 {
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
171 RIFF_Chunk *chunk;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
172 Uint8 *subchunkData;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
173 Uint32 subchunkDataLen;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
174
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
175 /* Allocate the chunk structure */
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
176 chunk = AllocRIFFChunk();
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
177
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
178 /* Make sure the file is in RIFF format */
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
179 chunk->magic = SDL_ReadLE32(src);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
180 chunk->length = SDL_ReadLE32(src);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
181 if ( chunk->magic != RIFF ) {
459
4d2febf33dc7 Changed some SDL_Error()s to __Sound_SetError() to fix linking issues.
Ryan C. Gordon <icculus@icculus.org>
parents: 458
diff changeset
182 __Sound_SetError("Not a RIFF file");
455
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
183 FreeRIFFChunk(chunk);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
184 return NULL;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
185 }
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
186 chunk->data = (Uint8 *)malloc(chunk->length);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
187 if ( chunk->data == NULL ) {
459
4d2febf33dc7 Changed some SDL_Error()s to __Sound_SetError() to fix linking issues.
Ryan C. Gordon <icculus@icculus.org>
parents: 458
diff changeset
188 __Sound_SetError(ERR_OUT_OF_MEMORY);
455
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
189 FreeRIFFChunk(chunk);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
190 return NULL;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
191 }
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
192 if ( SDL_RWread(src, chunk->data, chunk->length, 1) != 1 ) {
459
4d2febf33dc7 Changed some SDL_Error()s to __Sound_SetError() to fix linking issues.
Ryan C. Gordon <icculus@icculus.org>
parents: 458
diff changeset
193 __Sound_SetError(ERR_IO_ERROR);
455
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
194 FreeRIFF(chunk);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
195 return NULL;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
196 }
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
197 subchunkData = chunk->data;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
198 subchunkDataLen = chunk->length;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
199 if ( ChunkHasSubType(chunk->magic) && subchunkDataLen >= 4 ) {
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
200 chunk->subtype = (subchunkData[0] << 0) |
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
201 (subchunkData[1] << 8) |
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
202 (subchunkData[2] << 16) |
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
203 (subchunkData[3] << 24);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
204 subchunkData += 4;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
205 subchunkDataLen -= 4;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
206 }
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
207 if ( ChunkHasSubChunks(chunk->magic) ) {
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
208 LoadSubChunks(chunk, subchunkData, subchunkDataLen);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
209 }
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
210 return chunk;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
211 }
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
212
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
213 void FreeRIFF(RIFF_Chunk *chunk)
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
214 {
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
215 free(chunk->data);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
216 FreeRIFFChunk(chunk);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
217 }
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
218
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
219 void PrintRIFF(RIFF_Chunk *chunk, int level)
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
220 {
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
221 static char prefix[128];
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
222
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
223 if ( level == sizeof(prefix)-1 ) {
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
224 return;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
225 }
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
226 if ( level > 0 ) {
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
227 prefix[(level-1)*2] = ' ';
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
228 prefix[(level-1)*2+1] = ' ';
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
229 }
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
230 prefix[level*2] = '\0';
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
231 printf("%sChunk: %c%c%c%c (%d bytes)", prefix,
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
232 ((chunk->magic >> 0) & 0xFF),
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
233 ((chunk->magic >> 8) & 0xFF),
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
234 ((chunk->magic >> 16) & 0xFF),
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
235 ((chunk->magic >> 24) & 0xFF), chunk->length);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
236 if ( chunk->subtype ) {
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
237 printf(" subtype: %c%c%c%c",
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
238 ((chunk->subtype >> 0) & 0xFF),
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
239 ((chunk->subtype >> 8) & 0xFF),
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
240 ((chunk->subtype >> 16) & 0xFF),
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
241 ((chunk->subtype >> 24) & 0xFF));
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
242 }
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
243 printf("\n");
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
244 if ( chunk->child ) {
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
245 printf("%s{\n", prefix);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
246 PrintRIFF(chunk->child, level + 1);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
247 printf("%s}\n", prefix);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
248 }
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
249 if ( chunk->next ) {
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
250 PrintRIFF(chunk->next, level);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
251 }
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
252 if ( level > 0 ) {
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
253 prefix[(level-1)*2] = '\0';
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
254 }
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
255 }
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
256
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
257 #ifdef TEST_MAIN_RIFF
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
258
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
259 main(int argc, char *argv[])
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
260 {
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
261 int i;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
262 for ( i = 1; i < argc; ++i ) {
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
263 RIFF_Chunk *chunk;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
264 SDL_RWops *src = SDL_RWFromFile(argv[i], "rb");
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
265 if ( !src ) {
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
266 fprintf(stderr, "Couldn't open %s: %s", argv[i], SDL_GetError());
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
267 continue;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
268 }
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
269 chunk = LoadRIFF(src);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
270 if ( chunk ) {
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
271 PrintRIFF(chunk, 0);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
272 FreeRIFF(chunk);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
273 } else {
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
274 fprintf(stderr, "Couldn't load %s: %s\n", argv[i], SDL_GetError());
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
275 }
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
276 SDL_RWclose(src);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
277 }
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
278 }
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
279
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
280 #endif // TEST_MAIN
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
281 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
282
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
283 /*-------------------------------------------------------------------------*/
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
284 /* * * * * * * * * * * * * * * * * load_dls.h * * * * * * * * * * * * * * */
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
285 /*-------------------------------------------------------------------------*/
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
286 /* This code is based on the DLS spec version 1.1, available at:
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
287 http://www.midi.org/about-midi/dls/dlsspec.shtml
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
288 */
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
289
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
290 /* Some typedefs so the public dls headers don't need to be modified */
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
291 #define FAR
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
292 typedef Uint8 BYTE;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
293 typedef Sint16 SHORT;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
294 typedef Uint16 USHORT;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
295 typedef Uint16 WORD;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
296 typedef Sint32 LONG;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
297 typedef Uint32 ULONG;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
298 typedef Uint32 DWORD;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
299 #define mmioFOURCC(A, B, C, D) \
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
300 (((A) << 0) | ((B) << 8) | ((C) << 16) | ((D) << 24))
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
301 #define DEFINE_GUID(A, B, C, E, F, G, H, I, J, K, L, M)
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
302
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
303 #include "dls1.h"
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
304 #include "dls2.h"
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
305
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
306 typedef struct _WaveFMT {
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
307 WORD wFormatTag;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
308 WORD wChannels;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
309 DWORD dwSamplesPerSec;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
310 DWORD dwAvgBytesPerSec;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
311 WORD wBlockAlign;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
312 WORD wBitsPerSample;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
313 } WaveFMT;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
314
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
315 typedef struct _DLS_Wave {
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
316 WaveFMT *format;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
317 Uint8 *data;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
318 Uint32 length;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
319 WSMPL *wsmp;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
320 WLOOP *wsmp_loop;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
321 } DLS_Wave;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
322
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
323 typedef struct _DLS_Region {
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
324 RGNHEADER *header;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
325 WAVELINK *wlnk;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
326 WSMPL *wsmp;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
327 WLOOP *wsmp_loop;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
328 CONNECTIONLIST *art;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
329 CONNECTION *artList;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
330 } DLS_Region;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
331
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
332 typedef struct _DLS_Instrument {
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
333 const char *name;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
334 INSTHEADER *header;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
335 DLS_Region *regions;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
336 CONNECTIONLIST *art;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
337 CONNECTION *artList;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
338 } DLS_Instrument;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
339
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
340 typedef struct _DLS_Data {
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
341 struct _RIFF_Chunk *chunk;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
342
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
343 Uint32 cInstruments;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
344 DLS_Instrument *instruments;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
345
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
346 POOLTABLE *ptbl;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
347 POOLCUE *ptblList;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
348 DLS_Wave *waveList;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
349
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
350 const char *name;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
351 const char *artist;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
352 const char *copyright;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
353 const char *comments;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
354 } DLS_Data;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
355
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
356 extern DECLSPEC DLS_Data* SDLCALL LoadDLS(SDL_RWops *src);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
357 extern DECLSPEC void SDLCALL FreeDLS(DLS_Data *chunk);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
358 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
359
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
360 /*-------------------------------------------------------------------------*/
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
361 /* * * * * * * * * * * * * * * * * load_dls.c * * * * * * * * * * * * * * */
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
362 /*-------------------------------------------------------------------------*/
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
363
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
364 #define FOURCC_LIST 0x5453494c /* "LIST" */
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
365 #define FOURCC_FMT 0x20746D66 /* "fmt " */
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
366 #define FOURCC_DATA 0x61746164 /* "data" */
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
367 #define FOURCC_INFO mmioFOURCC('I','N','F','O')
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
368 #define FOURCC_IARL mmioFOURCC('I','A','R','L')
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
369 #define FOURCC_IART mmioFOURCC('I','A','R','T')
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
370 #define FOURCC_ICMS mmioFOURCC('I','C','M','S')
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
371 #define FOURCC_ICMT mmioFOURCC('I','C','M','T')
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
372 #define FOURCC_ICOP mmioFOURCC('I','C','O','P')
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
373 #define FOURCC_ICRD mmioFOURCC('I','C','R','D')
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
374 #define FOURCC_IENG mmioFOURCC('I','E','N','G')
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
375 #define FOURCC_IGNR mmioFOURCC('I','G','N','R')
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
376 #define FOURCC_IKEY mmioFOURCC('I','K','E','Y')
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
377 #define FOURCC_IMED mmioFOURCC('I','M','E','D')
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
378 #define FOURCC_INAM mmioFOURCC('I','N','A','M')
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
379 #define FOURCC_IPRD mmioFOURCC('I','P','R','D')
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
380 #define FOURCC_ISBJ mmioFOURCC('I','S','B','J')
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
381 #define FOURCC_ISFT mmioFOURCC('I','S','F','T')
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
382 #define FOURCC_ISRC mmioFOURCC('I','S','R','C')
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
383 #define FOURCC_ISRF mmioFOURCC('I','S','R','F')
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
384 #define FOURCC_ITCH mmioFOURCC('I','T','C','H')
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
385
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
386
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
387 static void FreeRegions(DLS_Instrument *instrument)
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
388 {
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
389 if ( instrument->regions ) {
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
390 free(instrument->regions);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
391 }
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
392 }
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
393
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
394 static void AllocRegions(DLS_Instrument *instrument)
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
395 {
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
396 int datalen = (instrument->header->cRegions * sizeof(DLS_Region));
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
397 FreeRegions(instrument);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
398 instrument->regions = (DLS_Region *)malloc(datalen);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
399 if ( instrument->regions ) {
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
400 memset(instrument->regions, 0, datalen);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
401 }
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
402 }
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
403
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
404 static void FreeInstruments(DLS_Data *data)
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
405 {
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
406 if ( data->instruments ) {
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
407 Uint32 i;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
408 for ( i = 0; i < data->cInstruments; ++i ) {
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
409 FreeRegions(&data->instruments[i]);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
410 }
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
411 free(data->instruments);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
412 }
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
413 }
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
414
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
415 static void AllocInstruments(DLS_Data *data)
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
416 {
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
417 int datalen = (data->cInstruments * sizeof(DLS_Instrument));
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
418 FreeInstruments(data);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
419 data->instruments = (DLS_Instrument *)malloc(datalen);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
420 if ( data->instruments ) {
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
421 memset(data->instruments, 0, datalen);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
422 }
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
423 }
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
424
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
425 static void FreeWaveList(DLS_Data *data)
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
426 {
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
427 if ( data->waveList ) {
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
428 free(data->waveList);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
429 }
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
430 }
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
431
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
432 static void AllocWaveList(DLS_Data *data)
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
433 {
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
434 int datalen = (data->ptbl->cCues * sizeof(DLS_Wave));
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
435 FreeWaveList(data);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
436 data->waveList = (DLS_Wave *)malloc(datalen);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
437 if ( data->waveList ) {
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
438 memset(data->waveList, 0, datalen);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
439 }
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
440 }
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
441
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
442 static void Parse_colh(DLS_Data *data, RIFF_Chunk *chunk)
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
443 {
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
444 data->cInstruments = SDL_SwapLE32(*(Uint32 *)chunk->data);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
445 AllocInstruments(data);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
446 }
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
447
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
448 static void Parse_insh(DLS_Data *data, RIFF_Chunk *chunk, DLS_Instrument *instrument)
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
449 {
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
450 INSTHEADER *header = (INSTHEADER *)chunk->data;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
451 header->cRegions = SDL_SwapLE32(header->cRegions);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
452 header->Locale.ulBank = SDL_SwapLE32(header->Locale.ulBank);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
453 header->Locale.ulInstrument = SDL_SwapLE32(header->Locale.ulInstrument);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
454 instrument->header = header;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
455 AllocRegions(instrument);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
456 }
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
457
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
458 static void Parse_rgnh(DLS_Data *data, RIFF_Chunk *chunk, DLS_Region *region)
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
459 {
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
460 RGNHEADER *header = (RGNHEADER *)chunk->data;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
461 header->RangeKey.usLow = SDL_SwapLE16(header->RangeKey.usLow);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
462 header->RangeKey.usHigh = SDL_SwapLE16(header->RangeKey.usHigh);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
463 header->RangeVelocity.usLow = SDL_SwapLE16(header->RangeVelocity.usLow);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
464 header->RangeVelocity.usHigh = SDL_SwapLE16(header->RangeVelocity.usHigh);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
465 header->fusOptions = SDL_SwapLE16(header->fusOptions);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
466 header->usKeyGroup = SDL_SwapLE16(header->usKeyGroup);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
467 region->header = header;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
468 }
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
469
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
470 static void Parse_wlnk(DLS_Data *data, RIFF_Chunk *chunk, DLS_Region *region)
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
471 {
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
472 WAVELINK *wlnk = (WAVELINK *)chunk->data;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
473 wlnk->fusOptions = SDL_SwapLE16(wlnk->fusOptions);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
474 wlnk->usPhaseGroup = SDL_SwapLE16(wlnk->usPhaseGroup);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
475 wlnk->ulChannel = SDL_SwapLE16(wlnk->ulChannel);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
476 wlnk->ulTableIndex = SDL_SwapLE16(wlnk->ulTableIndex);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
477 region->wlnk = wlnk;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
478 }
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
479
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
480 static void Parse_wsmp(DLS_Data *data, RIFF_Chunk *chunk, WSMPL **wsmp_ptr, WLOOP **wsmp_loop_ptr)
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
481 {
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
482 Uint32 i;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
483 WSMPL *wsmp = (WSMPL *)chunk->data;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
484 WLOOP *loop;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
485 wsmp->cbSize = SDL_SwapLE32(wsmp->cbSize);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
486 wsmp->usUnityNote = SDL_SwapLE16(wsmp->usUnityNote);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
487 wsmp->sFineTune = SDL_SwapLE16(wsmp->sFineTune);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
488 wsmp->lAttenuation = SDL_SwapLE32(wsmp->lAttenuation);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
489 wsmp->fulOptions = SDL_SwapLE32(wsmp->fulOptions);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
490 wsmp->cSampleLoops = SDL_SwapLE32(wsmp->cSampleLoops);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
491 loop = (WLOOP *)((Uint8 *)chunk->data + wsmp->cbSize);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
492 *wsmp_ptr = wsmp;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
493 *wsmp_loop_ptr = loop;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
494 for ( i = 0; i < wsmp->cSampleLoops; ++i ) {
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
495 loop->cbSize = SDL_SwapLE32(loop->cbSize);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
496 loop->ulType = SDL_SwapLE32(loop->ulType);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
497 loop->ulStart = SDL_SwapLE32(loop->ulStart);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
498 loop->ulLength = SDL_SwapLE32(loop->ulLength);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
499 ++loop;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
500 }
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
501 }
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
502
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
503 static void Parse_art(DLS_Data *data, RIFF_Chunk *chunk, CONNECTIONLIST **art_ptr, CONNECTION **artList_ptr)
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
504 {
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
505 Uint32 i;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
506 CONNECTIONLIST *art = (CONNECTIONLIST *)chunk->data;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
507 CONNECTION *artList;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
508 art->cbSize = SDL_SwapLE32(art->cbSize);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
509 art->cConnections = SDL_SwapLE32(art->cConnections);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
510 artList = (CONNECTION *)((Uint8 *)chunk->data + art->cbSize);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
511 *art_ptr = art;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
512 *artList_ptr = artList;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
513 for ( i = 0; i < art->cConnections; ++i ) {
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
514 artList->usSource = SDL_SwapLE16(artList->usSource);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
515 artList->usControl = SDL_SwapLE16(artList->usControl);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
516 artList->usDestination = SDL_SwapLE16(artList->usDestination);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
517 artList->usTransform = SDL_SwapLE16(artList->usTransform);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
518 artList->lScale = SDL_SwapLE32(artList->lScale);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
519 ++artList;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
520 }
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
521 }
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
522
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
523 static void Parse_lart(DLS_Data *data, RIFF_Chunk *chunk, CONNECTIONLIST **conn_ptr, CONNECTION **connList_ptr)
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
524 {
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
525 /* FIXME: This only supports one set of connections */
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
526 for ( chunk = chunk->child; chunk; chunk = chunk->next ) {
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
527 Uint32 magic = (chunk->magic == FOURCC_LIST) ? chunk->subtype : chunk->magic;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
528 switch(magic) {
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
529 case FOURCC_ART1:
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
530 case FOURCC_ART2:
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
531 Parse_art(data, chunk, conn_ptr, connList_ptr);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
532 return;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
533 }
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
534 }
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
535 }
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
536
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
537 static void Parse_rgn(DLS_Data *data, RIFF_Chunk *chunk, DLS_Region *region)
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
538 {
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
539 for ( chunk = chunk->child; chunk; chunk = chunk->next ) {
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
540 Uint32 magic = (chunk->magic == FOURCC_LIST) ? chunk->subtype : chunk->magic;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
541 switch(magic) {
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
542 case FOURCC_RGNH:
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
543 Parse_rgnh(data, chunk, region);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
544 break;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
545 case FOURCC_WLNK:
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
546 Parse_wlnk(data, chunk, region);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
547 break;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
548 case FOURCC_WSMP:
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
549 Parse_wsmp(data, chunk, &region->wsmp, &region->wsmp_loop);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
550 break;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
551 case FOURCC_LART:
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
552 case FOURCC_LAR2:
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
553 Parse_lart(data, chunk, &region->art, &region->artList);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
554 break;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
555 }
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
556 }
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
557 }
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
558
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
559 static void Parse_lrgn(DLS_Data *data, RIFF_Chunk *chunk, DLS_Instrument *instrument)
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
560 {
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
561 Uint32 region = 0;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
562 for ( chunk = chunk->child; chunk; chunk = chunk->next ) {
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
563 Uint32 magic = (chunk->magic == FOURCC_LIST) ? chunk->subtype : chunk->magic;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
564 switch(magic) {
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
565 case FOURCC_RGN:
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
566 case FOURCC_RGN2:
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
567 if ( region < instrument->header->cRegions ) {
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
568 Parse_rgn(data, chunk, &instrument->regions[region++]);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
569 }
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
570 break;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
571 }
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
572 }
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
573 }
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
574
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
575 static void Parse_INFO_INS(DLS_Data *data, RIFF_Chunk *chunk, DLS_Instrument *instrument)
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
576 {
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
577 for ( chunk = chunk->child; chunk; chunk = chunk->next ) {
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
578 Uint32 magic = (chunk->magic == FOURCC_LIST) ? chunk->subtype : chunk->magic;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
579 switch(magic) {
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
580 case FOURCC_INAM: /* Name */
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
581 instrument->name = chunk->data;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
582 break;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
583 }
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
584 }
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
585 }
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
586
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
587 static void Parse_ins(DLS_Data *data, RIFF_Chunk *chunk, DLS_Instrument *instrument)
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
588 {
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
589 for ( chunk = chunk->child; chunk; chunk = chunk->next ) {
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
590 Uint32 magic = (chunk->magic == FOURCC_LIST) ? chunk->subtype : chunk->magic;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
591 switch(magic) {
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
592 case FOURCC_INSH:
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
593 Parse_insh(data, chunk, instrument);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
594 break;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
595 case FOURCC_LRGN:
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
596 Parse_lrgn(data, chunk, instrument);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
597 break;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
598 case FOURCC_LART:
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
599 case FOURCC_LAR2:
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
600 Parse_lart(data, chunk, &instrument->art, &instrument->artList);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
601 break;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
602 case FOURCC_INFO:
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
603 Parse_INFO_INS(data, chunk, instrument);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
604 break;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
605 }
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
606 }
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
607 }
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
608
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
609 static void Parse_lins(DLS_Data *data, RIFF_Chunk *chunk)
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
610 {
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
611 Uint32 instrument = 0;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
612 for ( chunk = chunk->child; chunk; chunk = chunk->next ) {
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
613 Uint32 magic = (chunk->magic == FOURCC_LIST) ? chunk->subtype : chunk->magic;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
614 switch(magic) {
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
615 case FOURCC_INS:
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
616 if ( instrument < data->cInstruments ) {
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
617 Parse_ins(data, chunk, &data->instruments[instrument++]);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
618 }
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
619 break;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
620 }
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
621 }
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
622 }
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
623
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
624 static void Parse_ptbl(DLS_Data *data, RIFF_Chunk *chunk)
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
625 {
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
626 Uint32 i;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
627 POOLTABLE *ptbl = (POOLTABLE *)chunk->data;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
628 ptbl->cbSize = SDL_SwapLE32(ptbl->cbSize);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
629 ptbl->cCues = SDL_SwapLE32(ptbl->cCues);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
630 data->ptbl = ptbl;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
631 data->ptblList = (POOLCUE *)((Uint8 *)chunk->data + ptbl->cbSize);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
632 for ( i = 0; i < ptbl->cCues; ++i ) {
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
633 data->ptblList[i].ulOffset = SDL_SwapLE32(data->ptblList[i].ulOffset);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
634 }
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
635 AllocWaveList(data);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
636 }
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
637
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
638 static void Parse_fmt(DLS_Data *data, RIFF_Chunk *chunk, DLS_Wave *wave)
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
639 {
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
640 WaveFMT *fmt = (WaveFMT *)chunk->data;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
641 fmt->wFormatTag = SDL_SwapLE16(fmt->wFormatTag);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
642 fmt->wChannels = SDL_SwapLE16(fmt->wChannels);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
643 fmt->dwSamplesPerSec = SDL_SwapLE32(fmt->dwSamplesPerSec);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
644 fmt->dwAvgBytesPerSec = SDL_SwapLE32(fmt->dwAvgBytesPerSec);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
645 fmt->wBlockAlign = SDL_SwapLE16(fmt->wBlockAlign);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
646 fmt->wBitsPerSample = SDL_SwapLE16(fmt->wBitsPerSample);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
647 wave->format = fmt;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
648 }
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
649
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
650 static void Parse_data(DLS_Data *data, RIFF_Chunk *chunk, DLS_Wave *wave)
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
651 {
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
652 wave->data = chunk->data;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
653 wave->length = chunk->length;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
654 }
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
655
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
656 static void Parse_wave(DLS_Data *data, RIFF_Chunk *chunk, DLS_Wave *wave)
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
657 {
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
658 for ( chunk = chunk->child; chunk; chunk = chunk->next ) {
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
659 Uint32 magic = (chunk->magic == FOURCC_LIST) ? chunk->subtype : chunk->magic;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
660 switch(magic) {
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
661 case FOURCC_FMT:
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
662 Parse_fmt(data, chunk, wave);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
663 break;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
664 case FOURCC_DATA:
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
665 Parse_data(data, chunk, wave);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
666 break;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
667 case FOURCC_WSMP:
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
668 Parse_wsmp(data, chunk, &wave->wsmp, &wave->wsmp_loop);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
669 break;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
670 }
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
671 }
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
672 }
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
673
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
674 static void Parse_wvpl(DLS_Data *data, RIFF_Chunk *chunk)
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
675 {
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
676 Uint32 wave = 0;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
677 for ( chunk = chunk->child; chunk; chunk = chunk->next ) {
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
678 Uint32 magic = (chunk->magic == FOURCC_LIST) ? chunk->subtype : chunk->magic;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
679 switch(magic) {
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
680 case FOURCC_wave:
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
681 if ( wave < data->ptbl->cCues ) {
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
682 Parse_wave(data, chunk, &data->waveList[wave++]);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
683 }
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
684 break;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
685 }
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
686 }
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
687 }
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
688
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
689 static void Parse_INFO_DLS(DLS_Data *data, RIFF_Chunk *chunk)
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
690 {
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
691 for ( chunk = chunk->child; chunk; chunk = chunk->next ) {
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
692 Uint32 magic = (chunk->magic == FOURCC_LIST) ? chunk->subtype : chunk->magic;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
693 switch(magic) {
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
694 case FOURCC_IARL: /* Archival Location */
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
695 break;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
696 case FOURCC_IART: /* Artist */
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
697 data->artist = chunk->data;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
698 break;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
699 case FOURCC_ICMS: /* Commisioned */
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
700 break;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
701 case FOURCC_ICMT: /* Comments */
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
702 data->comments = chunk->data;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
703 break;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
704 case FOURCC_ICOP: /* Copyright */
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
705 data->copyright = chunk->data;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
706 break;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
707 case FOURCC_ICRD: /* Creation Date */
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
708 break;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
709 case FOURCC_IENG: /* Engineer */
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
710 break;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
711 case FOURCC_IGNR: /* Genre */
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
712 break;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
713 case FOURCC_IKEY: /* Keywords */
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
714 break;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
715 case FOURCC_IMED: /* Medium */
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
716 break;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
717 case FOURCC_INAM: /* Name */
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
718 data->name = chunk->data;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
719 break;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
720 case FOURCC_IPRD: /* Product */
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
721 break;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
722 case FOURCC_ISBJ: /* Subject */
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
723 break;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
724 case FOURCC_ISFT: /* Software */
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
725 break;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
726 case FOURCC_ISRC: /* Source */
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
727 break;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
728 case FOURCC_ISRF: /* Source Form */
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
729 break;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
730 case FOURCC_ITCH: /* Technician */
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
731 break;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
732 }
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
733 }
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
734 }
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
735
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
736 DLS_Data *LoadDLS(SDL_RWops *src)
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
737 {
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
738 RIFF_Chunk *chunk;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
739 DLS_Data *data = (DLS_Data *)malloc(sizeof(*data));
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
740 if ( !data ) {
459
4d2febf33dc7 Changed some SDL_Error()s to __Sound_SetError() to fix linking issues.
Ryan C. Gordon <icculus@icculus.org>
parents: 458
diff changeset
741 __Sound_SetError(ERR_OUT_OF_MEMORY);
455
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
742 return NULL;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
743 }
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
744 memset(data, 0, sizeof(*data));
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
745
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
746 data->chunk = LoadRIFF(src);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
747 if ( !data->chunk ) {
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
748 FreeDLS(data);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
749 return NULL;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
750 }
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
751
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
752 for ( chunk = data->chunk->child; chunk; chunk = chunk->next ) {
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
753 Uint32 magic = (chunk->magic == FOURCC_LIST) ? chunk->subtype : chunk->magic;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
754 switch(magic) {
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
755 case FOURCC_COLH:
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
756 Parse_colh(data, chunk);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
757 break;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
758 case FOURCC_LINS:
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
759 Parse_lins(data, chunk);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
760 break;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
761 case FOURCC_PTBL:
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
762 Parse_ptbl(data, chunk);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
763 break;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
764 case FOURCC_WVPL:
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
765 Parse_wvpl(data, chunk);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
766 break;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
767 case FOURCC_INFO:
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
768 Parse_INFO_DLS(data, chunk);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
769 break;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
770 }
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
771 }
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
772 return data;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
773 }
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
774
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
775 void FreeDLS(DLS_Data *data)
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
776 {
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
777 if ( data->chunk ) {
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
778 FreeRIFF(data->chunk);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
779 }
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
780 FreeInstruments(data);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
781 FreeWaveList(data);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
782 free(data);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
783 }
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
784
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
785 static const char *SourceToString(USHORT usSource)
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
786 {
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
787 switch(usSource) {
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
788 case CONN_SRC_NONE:
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
789 return "NONE";
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
790 case CONN_SRC_LFO:
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
791 return "LFO";
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
792 case CONN_SRC_KEYONVELOCITY:
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
793 return "KEYONVELOCITY";
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
794 case CONN_SRC_KEYNUMBER:
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
795 return "KEYNUMBER";
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
796 case CONN_SRC_EG1:
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
797 return "EG1";
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
798 case CONN_SRC_EG2:
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
799 return "EG2";
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
800 case CONN_SRC_PITCHWHEEL:
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
801 return "PITCHWHEEL";
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
802 case CONN_SRC_CC1:
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
803 return "CC1";
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
804 case CONN_SRC_CC7:
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
805 return "CC7";
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
806 case CONN_SRC_CC10:
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
807 return "CC10";
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
808 case CONN_SRC_CC11:
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
809 return "CC11";
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
810 case CONN_SRC_POLYPRESSURE:
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
811 return "POLYPRESSURE";
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
812 case CONN_SRC_CHANNELPRESSURE:
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
813 return "CHANNELPRESSURE";
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
814 case CONN_SRC_VIBRATO:
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
815 return "VIBRATO";
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
816 case CONN_SRC_MONOPRESSURE:
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
817 return "MONOPRESSURE";
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
818 case CONN_SRC_CC91:
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
819 return "CC91";
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
820 case CONN_SRC_CC93:
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
821 return "CC93";
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
822 default:
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
823 return "UNKNOWN";
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
824 }
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
825 }
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
826
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
827 static const char *TransformToString(USHORT usTransform)
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
828 {
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
829 switch (usTransform) {
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
830 case CONN_TRN_NONE:
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
831 return "NONE";
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
832 case CONN_TRN_CONCAVE:
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
833 return "CONCAVE";
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
834 case CONN_TRN_CONVEX:
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
835 return "CONVEX";
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
836 case CONN_TRN_SWITCH:
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
837 return "SWITCH";
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
838 default:
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
839 return "UNKNOWN";
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
840 }
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
841 }
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
842
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
843 static const char *DestinationToString(USHORT usDestination)
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
844 {
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
845 switch (usDestination) {
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
846 case CONN_DST_NONE:
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
847 return "NONE";
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
848 case CONN_DST_ATTENUATION:
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
849 return "ATTENUATION";
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
850 case CONN_DST_PITCH:
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
851 return "PITCH";
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
852 case CONN_DST_PAN:
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
853 return "PAN";
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
854 case CONN_DST_LFO_FREQUENCY:
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
855 return "LFO_FREQUENCY";
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
856 case CONN_DST_LFO_STARTDELAY:
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
857 return "LFO_STARTDELAY";
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
858 case CONN_DST_EG1_ATTACKTIME:
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
859 return "EG1_ATTACKTIME";
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
860 case CONN_DST_EG1_DECAYTIME:
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
861 return "EG1_DECAYTIME";
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
862 case CONN_DST_EG1_RELEASETIME:
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
863 return "EG1_RELEASETIME";
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
864 case CONN_DST_EG1_SUSTAINLEVEL:
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
865 return "EG1_SUSTAINLEVEL";
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
866 case CONN_DST_EG2_ATTACKTIME:
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
867 return "EG2_ATTACKTIME";
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
868 case CONN_DST_EG2_DECAYTIME:
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
869 return "EG2_DECAYTIME";
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
870 case CONN_DST_EG2_RELEASETIME:
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
871 return "EG2_RELEASETIME";
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
872 case CONN_DST_EG2_SUSTAINLEVEL:
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
873 return "EG2_SUSTAINLEVEL";
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
874 case CONN_DST_KEYNUMBER:
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
875 return "KEYNUMBER";
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
876 case CONN_DST_LEFT:
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
877 return "LEFT";
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
878 case CONN_DST_RIGHT:
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
879 return "RIGHT";
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
880 case CONN_DST_CENTER:
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
881 return "CENTER";
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
882 case CONN_DST_LEFTREAR:
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
883 return "LEFTREAR";
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
884 case CONN_DST_RIGHTREAR:
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
885 return "RIGHTREAR";
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
886 case CONN_DST_LFE_CHANNEL:
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
887 return "LFE_CHANNEL";
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
888 case CONN_DST_CHORUS:
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
889 return "CHORUS";
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
890 case CONN_DST_REVERB:
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
891 return "REVERB";
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
892 case CONN_DST_VIB_FREQUENCY:
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
893 return "VIB_FREQUENCY";
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
894 case CONN_DST_VIB_STARTDELAY:
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
895 return "VIB_STARTDELAY";
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
896 case CONN_DST_EG1_DELAYTIME:
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
897 return "EG1_DELAYTIME";
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
898 case CONN_DST_EG1_HOLDTIME:
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
899 return "EG1_HOLDTIME";
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
900 case CONN_DST_EG1_SHUTDOWNTIME:
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
901 return "EG1_SHUTDOWNTIME";
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
902 case CONN_DST_EG2_DELAYTIME:
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
903 return "EG2_DELAYTIME";
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
904 case CONN_DST_EG2_HOLDTIME:
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
905 return "EG2_HOLDTIME";
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
906 case CONN_DST_FILTER_CUTOFF:
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
907 return "FILTER_CUTOFF";
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
908 case CONN_DST_FILTER_Q:
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
909 return "FILTER_Q";
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
910 default:
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
911 return "UNKOWN";
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
912 }
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
913 }
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
914
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
915 static void PrintArt(const char *type, CONNECTIONLIST *art, CONNECTION *artList)
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
916 {
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
917 Uint32 i;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
918 printf("%s Connections:\n", type);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
919 for ( i = 0; i < art->cConnections; ++i ) {
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
920 printf(" Source: %s, Control: %s, Destination: %s, Transform: %s, Scale: %d\n",
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
921 SourceToString(artList[i].usSource),
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
922 SourceToString(artList[i].usControl),
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
923 DestinationToString(artList[i].usDestination),
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
924 TransformToString(artList[i].usTransform),
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
925 artList[i].lScale);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
926 }
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
927 }
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
928
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
929 static void PrintWave(DLS_Wave *wave, Uint32 index)
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
930 {
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
931 WaveFMT *format = wave->format;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
932 if ( format ) {
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
933 printf(" Wave %u: Format: %hu, %hu channels, %u Hz, %hu bits (length = %u)\n", index, format->wFormatTag, format->wChannels, format->dwSamplesPerSec, format->wBitsPerSample, wave->length);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
934 }
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
935 if ( wave->wsmp ) {
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
936 Uint32 i;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
937 printf(" wsmp->usUnityNote = %hu\n", wave->wsmp->usUnityNote);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
938 printf(" wsmp->sFineTune = %hd\n", wave->wsmp->sFineTune);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
939 printf(" wsmp->lAttenuation = %d\n", wave->wsmp->lAttenuation);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
940 printf(" wsmp->fulOptions = 0x%8.8x\n", wave->wsmp->fulOptions);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
941 printf(" wsmp->cSampleLoops = %u\n", wave->wsmp->cSampleLoops);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
942 for ( i = 0; i < wave->wsmp->cSampleLoops; ++i ) {
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
943 WLOOP *loop = &wave->wsmp_loop[i];
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
944 printf(" Loop %u:\n", i);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
945 printf(" ulStart = %u\n", loop->ulStart);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
946 printf(" ulLength = %u\n", loop->ulLength);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
947 }
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
948 }
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
949 }
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
950
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
951 static void PrintRegion(DLS_Region *region, Uint32 index)
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
952 {
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
953 printf(" Region %u:\n", index);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
954 if ( region->header ) {
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
955 printf(" RangeKey = { %hu - %hu }\n", region->header->RangeKey.usLow, region->header->RangeKey.usHigh);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
956 printf(" RangeVelocity = { %hu - %hu }\n", region->header->RangeVelocity.usLow, region->header->RangeVelocity.usHigh);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
957 printf(" fusOptions = 0x%4.4hx\n", region->header->fusOptions);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
958 printf(" usKeyGroup = %hu\n", region->header->usKeyGroup);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
959 }
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
960 if ( region->wlnk ) {
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
961 printf(" wlnk->fusOptions = 0x%4.4hx\n", region->wlnk->fusOptions);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
962 printf(" wlnk->usPhaseGroup = %hu\n", region->wlnk->usPhaseGroup);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
963 printf(" wlnk->ulChannel = %u\n", region->wlnk->ulChannel);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
964 printf(" wlnk->ulTableIndex = %u\n", region->wlnk->ulTableIndex);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
965 }
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
966 if ( region->wsmp ) {
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
967 Uint32 i;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
968 printf(" wsmp->usUnityNote = %hu\n", region->wsmp->usUnityNote);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
969 printf(" wsmp->sFineTune = %hd\n", region->wsmp->sFineTune);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
970 printf(" wsmp->lAttenuation = %d\n", region->wsmp->lAttenuation);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
971 printf(" wsmp->fulOptions = 0x%8.8x\n", region->wsmp->fulOptions);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
972 printf(" wsmp->cSampleLoops = %u\n", region->wsmp->cSampleLoops);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
973 for ( i = 0; i < region->wsmp->cSampleLoops; ++i ) {
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
974 WLOOP *loop = &region->wsmp_loop[i];
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
975 printf(" Loop %u:\n", i);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
976 printf(" ulStart = %u\n", loop->ulStart);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
977 printf(" ulLength = %u\n", loop->ulLength);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
978 }
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
979 }
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
980 if ( region->art && region->art->cConnections > 0 ) {
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
981 PrintArt("Region", region->art, region->artList);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
982 }
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
983 }
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
984
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
985 static void PrintInstrument(DLS_Instrument *instrument, Uint32 index)
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
986 {
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
987 printf("Instrument %u:\n", index);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
988 if ( instrument->name ) {
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
989 printf(" Name: %s\n", instrument->name);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
990 }
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
991 if ( instrument->header ) {
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
992 Uint32 i;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
993 printf(" ulBank = 0x%8.8x\n", instrument->header->Locale.ulBank);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
994 printf(" ulInstrument = %u\n", instrument->header->Locale.ulInstrument);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
995 printf(" Regions: %u\n", instrument->header->cRegions);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
996 for ( i = 0; i < instrument->header->cRegions; ++i ) {
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
997 PrintRegion(&instrument->regions[i], i);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
998 }
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
999 }
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1000 if ( instrument->art && instrument->art->cConnections > 0 ) {
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1001 PrintArt("Instrument", instrument->art, instrument->artList);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1002 }
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1003 };
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1004
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1005 void PrintDLS(DLS_Data *data)
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1006 {
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1007 printf("DLS Data:\n");
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1008 printf("cInstruments = %u\n", data->cInstruments);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1009 if ( data->instruments ) {
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1010 Uint32 i;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1011 for ( i = 0; i < data->cInstruments; ++i ) {
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1012 PrintInstrument(&data->instruments[i], i);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1013 }
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1014 }
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1015 if ( data->ptbl && data->ptbl->cCues > 0 ) {
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1016 Uint32 i;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1017 printf("Cues: ");
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1018 for ( i = 0; i < data->ptbl->cCues; ++i ) {
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1019 if ( i > 0 ) {
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1020 printf(", ");
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1021 }
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1022 printf("%u", data->ptblList[i].ulOffset);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1023 }
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1024 printf("\n");
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1025 }
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1026 if ( data->waveList ) {
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1027 Uint32 i;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1028 printf("Waves:\n");
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1029 for ( i = 0; i < data->ptbl->cCues; ++i ) {
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1030 PrintWave(&data->waveList[i], i);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1031 }
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1032 }
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1033 if ( data->name ) {
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1034 printf("Name: %s\n", data->name);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1035 }
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1036 if ( data->artist ) {
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1037 printf("Artist: %s\n", data->artist);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1038 }
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1039 if ( data->copyright ) {
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1040 printf("Copyright: %s\n", data->copyright);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1041 }
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1042 if ( data->comments ) {
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1043 printf("Comments: %s\n", data->comments);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1044 }
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1045 }
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1046
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1047 #ifdef TEST_MAIN_DLS
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1048
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1049 main(int argc, char *argv[])
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1050 {
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1051 int i;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1052 for ( i = 1; i < argc; ++i ) {
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1053 DLS_Data *data;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1054 SDL_RWops *src = SDL_RWFromFile(argv[i], "rb");
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1055 if ( !src ) {
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1056 fprintf(stderr, "Couldn't open %s: %s", argv[i], SDL_GetError());
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1057 continue;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1058 }
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1059 data = LoadDLS(src);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1060 if ( data ) {
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1061 PrintRIFF(data->chunk, 0);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1062 PrintDLS(data);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1063 FreeDLS(data);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1064 } else {
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1065 fprintf(stderr, "Couldn't load %s: %s\n", argv[i], SDL_GetError());
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1066 }
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1067 SDL_RWclose(src);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1068 }
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1069 }
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1070
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1071 #endif // TEST_MAIN
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1072 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1073
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1074 /*-------------------------------------------------------------------------*/
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1075 /* * * * * * * * * * * * * * * * * instrum_dls.c * * * * * * * * * * * * * */
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1076 /*-------------------------------------------------------------------------*/
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1077
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1078 DLS_Data *Timidity_LoadDLS(SDL_RWops *src)
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1079 {
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1080 DLS_Data *patches = LoadDLS(src);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1081 if (!patches) {
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1082 SNDDBG(("%s", SDL_GetError()));
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1083 }
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1084 return patches;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1085 }
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1086
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1087 void Timidity_FreeDLS(DLS_Data *patches)
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1088 {
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1089 FreeDLS(patches);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1090 }
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1091
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1092 /* convert timecents to sec */
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1093 static double to_msec(int timecent)
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1094 {
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1095 if (timecent == 0x80000000 || timecent == 0)
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1096 return 0.0;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1097 return 1000.0 * pow(2.0, (double)(timecent / 65536) / 1200.0);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1098 }
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1099
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1100 /* convert decipercent to {0..1} */
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1101 static double to_normalized_percent(int decipercent)
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1102 {
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1103 return ((double)(decipercent / 65536)) / 1000.0;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1104 }
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1105
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1106 /* convert from 8bit value to fractional offset (15.15) */
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1107 static Sint32 to_offset(int offset)
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1108 {
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1109 return (Sint32)offset << (7+15);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1110 }
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1111
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1112 /* calculate ramp rate in fractional unit;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1113 * diff = 8bit, time = msec
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1114 */
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1115 static Sint32 calc_rate(MidiSong *song, int diff, int sample_rate, double msec)
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1116 {
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1117 double rate;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1118
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1119 if(msec < 6)
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1120 msec = 6;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1121 if(diff == 0)
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1122 diff = 255;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1123 diff <<= (7+15);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1124 rate = ((double)diff / song->rate) * song->control_ratio * 1000.0 / msec;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1125 return (Sint32)rate;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1126 }
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1127
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1128 static int load_connection(ULONG cConnections, CONNECTION *artList, USHORT destination)
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1129 {
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1130 ULONG i;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1131 int value = 0;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1132 for (i = 0; i < cConnections; ++i) {
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1133 CONNECTION *conn = &artList[i];
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1134 if(conn->usDestination == destination) {
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1135 // The formula for the destination is:
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1136 // usDestination = usDestination + usTransform(usSource * (usControl * lScale))
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1137 // Since we are only handling source/control of NONE and identity
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1138 // transform, this simplifies to: usDestination = usDestination + lScale
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1139 if (conn->usSource == CONN_SRC_NONE &&
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1140 conn->usControl == CONN_SRC_NONE &&
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1141 conn->usTransform == CONN_TRN_NONE)
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1142 value += conn->lScale;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1143 }
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1144 }
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1145 return value;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1146 }
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1147
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1148 static void load_region_dls(MidiSong *song, Sample *sample, DLS_Instrument *ins, Uint32 index)
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1149 {
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1150 DLS_Region *rgn = &ins->regions[index];
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1151 DLS_Wave *wave = &song->patches->waveList[rgn->wlnk->ulTableIndex];
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1152
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1153 sample->low_freq = freq_table[rgn->header->RangeKey.usLow];
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1154 sample->high_freq = freq_table[rgn->header->RangeKey.usHigh];
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1155 sample->root_freq = freq_table[rgn->wsmp->usUnityNote];
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1156 sample->low_vel = rgn->header->RangeVelocity.usLow;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1157 sample->high_vel = rgn->header->RangeVelocity.usHigh;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1158
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1159 sample->modes = MODES_16BIT;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1160 sample->sample_rate = wave->format->dwSamplesPerSec;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1161 sample->data_length = wave->length / 2;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1162 sample->data = (sample_t *)safe_malloc(wave->length);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1163 memcpy(sample->data, wave->data, wave->length);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1164 if (rgn->wsmp->cSampleLoops) {
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1165 sample->modes |= (MODES_LOOPING|MODES_SUSTAIN);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1166 sample->loop_start = rgn->wsmp_loop->ulStart / 2;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1167 sample->loop_end = sample->loop_start + (rgn->wsmp_loop->ulLength / 2);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1168 }
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1169 sample->volume = 1.0f;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1170
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1171 if (sample->modes & MODES_SUSTAIN) {
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1172 int value;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1173 double attack, hold, decay, release; int sustain;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1174 CONNECTIONLIST *art = NULL;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1175 CONNECTION *artList = NULL;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1176
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1177 if (ins->art && ins->art->cConnections > 0 && ins->artList) {
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1178 art = ins->art;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1179 artList = ins->artList;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1180 } else {
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1181 art = rgn->art;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1182 artList = rgn->artList;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1183 }
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1184
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1185 value = load_connection(art->cConnections, artList, CONN_DST_EG1_ATTACKTIME);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1186 attack = to_msec(value);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1187 value = load_connection(art->cConnections, artList, CONN_DST_EG1_HOLDTIME);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1188 hold = to_msec(value);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1189 value = load_connection(art->cConnections, artList, CONN_DST_EG1_DECAYTIME);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1190 decay = to_msec(value);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1191 value = load_connection(art->cConnections, artList, CONN_DST_EG1_RELEASETIME);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1192 release = to_msec(value);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1193 value = load_connection(art->cConnections, artList, CONN_DST_EG1_SUSTAINLEVEL);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1194 sustain = (int)((1.0 - to_normalized_percent(value)) * 250.0);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1195 value = load_connection(art->cConnections, artList, CONN_DST_PAN);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1196 sample->panning = (int)((0.5 + to_normalized_percent(value)) * 127.0);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1197
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1198 /*
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1199 printf("%d, Rate=%d LV=%d HV=%d Low=%d Hi=%d Root=%d Pan=%d Attack=%f Hold=%f Sustain=%d Decay=%f Release=%f\n", index, sample->sample_rate, rgn->header->RangeVelocity.usLow, rgn->header->RangeVelocity.usHigh, sample->low_freq, sample->high_freq, sample->root_freq, sample->panning, attack, hold, sustain, decay, release);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1200 */
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1201
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1202 sample->envelope_offset[0] = to_offset(255);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1203 sample->envelope_rate[0] = calc_rate(song, 255, sample->sample_rate, attack);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1204
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1205 sample->envelope_offset[1] = to_offset(250);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1206 sample->envelope_rate[1] = calc_rate(song, 5, sample->sample_rate, hold);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1207
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1208 sample->envelope_offset[2] = to_offset(sustain);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1209 sample->envelope_rate[2] = calc_rate(song, 255 - sustain, sample->sample_rate, decay);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1210
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1211 sample->envelope_offset[3] = to_offset(0);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1212 sample->envelope_rate[3] = calc_rate(song, 5 + sustain, sample->sample_rate, release);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1213
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1214 sample->envelope_offset[4] = to_offset(0);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1215 sample->envelope_rate[4] = to_offset(1);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1216
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1217 sample->envelope_offset[5] = to_offset(0);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1218 sample->envelope_rate[5] = to_offset(1);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1219
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1220 sample->modes |= MODES_ENVELOPE;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1221 }
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1222
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1223 sample->data_length <<= FRACTION_BITS;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1224 sample->loop_start <<= FRACTION_BITS;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1225 sample->loop_end <<= FRACTION_BITS;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1226 }
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1227
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1228 Instrument *load_instrument_dls(MidiSong *song, int drum, int bank, int instrument)
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1229 {
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1230 Instrument *inst;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1231 Uint32 i;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1232 DLS_Instrument *dls_ins;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1233
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1234 if (!song->patches)
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1235 return(NULL);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1236
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1237 drum = drum ? 0x80000000 : 0;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1238 for (i = 0; i < song->patches->cInstruments; ++i) {
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1239 dls_ins = &song->patches->instruments[i];
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1240 if ((dls_ins->header->Locale.ulBank & 0x80000000) == drum &&
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1241 ((dls_ins->header->Locale.ulBank >> 8) & 0xFF) == bank &&
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1242 dls_ins->header->Locale.ulInstrument == instrument)
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1243 break;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1244 }
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1245 if (i == song->patches->cInstruments && !bank) {
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1246 for (i = 0; i < song->patches->cInstruments; ++i) {
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1247 dls_ins = &song->patches->instruments[i];
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1248 if ((dls_ins->header->Locale.ulBank & 0x80000000) == drum &&
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1249 dls_ins->header->Locale.ulInstrument == instrument)
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1250 break;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1251 }
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1252 }
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1253 if (i == song->patches->cInstruments) {
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1254 SNDDBG(("Couldn't find %s instrument %d in bank %d\n", drum ? "drum" : "melodic", instrument, bank));
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1255 return(NULL);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1256 }
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1257
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1258 inst = (Instrument *)safe_malloc(sizeof(*inst));
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1259 inst->samples = dls_ins->header->cRegions;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1260 inst->sample = (Sample *)safe_malloc(inst->samples * sizeof(*inst->sample));
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1261 memset(inst->sample, 0, inst->samples * sizeof(*inst->sample));
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1262 /*
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1263 printf("Found %s instrument %d in bank %d named %s with %d regions\n", drum ? "drum" : "melodic", instrument, bank, dls_ins->name, inst->samples);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1264 */
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1265 for (i = 0; i < dls_ins->header->cRegions; ++i) {
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1266 load_region_dls(song, &inst->sample[i], dls_ins, i);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1267 }
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1268 return(inst);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1269 }