Mercurial > hg > dmlib
annotate src/dmengine.c @ 863:27949209238b
Update copyrights.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Thu, 01 Jan 2015 09:23:03 +0200 |
parents | 00729394df6a |
children | 56e12109b936 |
rev | line source |
---|---|
642
0888971cbff8
Add comment headers to several files.
Matti Hamalainen <ccr@tnsp.org>
parents:
573
diff
changeset
|
1 /* |
0888971cbff8
Add comment headers to several files.
Matti Hamalainen <ccr@tnsp.org>
parents:
573
diff
changeset
|
2 * dmlib |
0888971cbff8
Add comment headers to several files.
Matti Hamalainen <ccr@tnsp.org>
parents:
573
diff
changeset
|
3 * -- Demo engine / editor common code and definitions |
0888971cbff8
Add comment headers to several files.
Matti Hamalainen <ccr@tnsp.org>
parents:
573
diff
changeset
|
4 * Programmed and designed by Matti 'ccr' Hamalainen |
863 | 5 * (C) Copyright 2012-2015 Tecnic Software productions (TNSP) |
642
0888971cbff8
Add comment headers to several files.
Matti Hamalainen <ccr@tnsp.org>
parents:
573
diff
changeset
|
6 */ |
342
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
7 #include "dmengine.h" |
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
8 #include "dmimage.h" |
846 | 9 #include <SDL_timer.h> |
342
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
10 |
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
11 |
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
12 #ifdef DM_USE_TREMOR |
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
13 #include <tremor/ivorbiscodec.h> |
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
14 #include <tremor/ivorbisfile.h> |
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
15 #endif |
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
16 |
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
17 |
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
18 DMEngineData engine; |
368 | 19 DMEffect *engineEffects = NULL; |
20 int nengineEffects = 0, nengineEffectsAlloc = 0; | |
21 | |
22 | |
23 int engineRegisterEffect(const DMEffect *ef) | |
24 { | |
25 if (ef == NULL) | |
26 return DMERR_NULLPTR; | |
27 | |
28 // Allocate more space for effects | |
29 if (nengineEffects + 1 >= nengineEffectsAlloc) | |
30 { | |
31 nengineEffectsAlloc += 16; | |
32 engineEffects = dmRealloc(engineEffects, sizeof(DMEffect) * nengineEffectsAlloc); | |
33 if (engineEffects == NULL) | |
34 { | |
35 dmError("Could not expand effects structure.\n"); | |
36 return DMERR_INIT_FAIL; | |
37 } | |
38 } | |
39 | |
40 // Copy effects structure | |
41 memcpy(engineEffects + nengineEffects, ef, sizeof(DMEffect)); | |
42 nengineEffects++; | |
43 | |
44 return DMERR_OK; | |
45 } | |
46 | |
47 | |
48 int engineInitializeEffects(DMEngineData *engine) | |
49 { | |
50 int i, res; | |
51 | |
52 dmFree(engine->effectData); | |
53 engine->effectData = dmCalloc(nengineEffectsAlloc, sizeof(void *)); | |
54 if (engine->effectData == NULL) | |
55 { | |
56 dmError("Could not expand effects data structure.\n"); | |
57 return DMERR_INIT_FAIL; | |
58 } | |
59 | |
60 for (i = 0; i < nengineEffects; i++) | |
61 { | |
849 | 62 DMEffect *eff = &engineEffects[i]; |
63 if (eff->init != NULL && | |
64 (res = eff->init(engine, eff, &engine->effectData[i])) != DMERR_OK) | |
368 | 65 return res; |
66 } | |
67 | |
68 return DMERR_OK; | |
69 } | |
70 | |
71 | |
72 void engineShutdownEffects(DMEngineData *engine) | |
73 { | |
369 | 74 if (engine != NULL && engine->effectData != NULL) |
368 | 75 { |
369 | 76 int i; |
77 for (i = 0; i < nengineEffects; i++) | |
78 { | |
849 | 79 DMEffect *eff = &engineEffects[i]; |
80 if (eff->shutdown != NULL) | |
81 eff->shutdown(engine, eff, engine->effectData[i]); | |
369 | 82 } |
83 dmFree(engine->effectData); | |
84 engine->effectData = NULL; | |
368 | 85 } |
86 } | |
87 | |
88 | |
89 DMEffect *engineFindEffect(const char *name, const int nparams) | |
90 { | |
91 int i; | |
92 for (i = 0; i < nengineEffects; i++) | |
93 { | |
849 | 94 DMEffect *eff = &engineEffects[i]; |
95 if (strcmp(eff->name, name) == 0 && | |
96 eff->nparams == nparams) | |
97 return eff; | |
368 | 98 } |
99 return NULL; | |
100 } | |
101 | |
102 | |
103 DMEffect *engineFindEffectByName(const char *name) | |
104 { | |
105 int i; | |
106 for (i = 0; i < nengineEffects; i++) | |
107 { | |
849 | 108 DMEffect *eff = &engineEffects[i]; |
109 if (strcmp(eff->name, name) == 0) | |
110 return eff; | |
368 | 111 } |
112 return NULL; | |
113 } | |
342
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
114 |
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
115 |
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
116 static int engineResImageLoad(DMResource *res) |
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
117 { |
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
118 SDL_Surface *img = dmLoadImage(res); |
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
119 if (res != NULL) |
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
120 { |
721
bb14d7907eb2
Rename many pack & resource handling functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
642
diff
changeset
|
121 res->resData = img; |
342
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
122 return DMERR_OK; |
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
123 } |
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
124 else |
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
125 return dmferror(res); |
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
126 } |
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
127 |
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
128 |
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
129 static void engineResImageFree(DMResource *res) |
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
130 { |
721
bb14d7907eb2
Rename many pack & resource handling functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
642
diff
changeset
|
131 SDL_FreeSurface((SDL_Surface *)res->resData); |
342
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
132 } |
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
133 |
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
134 static BOOL engineResImageProbe(DMResource *res, const char *fext) |
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
135 { |
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
136 (void) res; |
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
137 return fext != NULL && (strcasecmp(fext, ".jpg") == 0 || strcasecmp(fext, ".png") == 0); |
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
138 } |
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
139 |
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
140 |
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
141 #ifdef JSS_SUP_XM |
779
954b1b392c8b
Restore old note frequency calculation for now.
Matti Hamalainen <ccr@tnsp.org>
parents:
763
diff
changeset
|
142 static int engineResXMModuleLoad(DMResource *res) |
342
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
143 { |
796 | 144 return jssLoadXM(res, (JSSModule **) &(res->resData), FALSE); |
342
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
145 } |
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
146 |
779
954b1b392c8b
Restore old note frequency calculation for now.
Matti Hamalainen <ccr@tnsp.org>
parents:
763
diff
changeset
|
147 static void engineResXMModuleFree(DMResource *res) |
342
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
148 { |
721
bb14d7907eb2
Rename many pack & resource handling functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
642
diff
changeset
|
149 jssFreeModule((JSSModule *) res->resData); |
342
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
150 } |
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
151 |
779
954b1b392c8b
Restore old note frequency calculation for now.
Matti Hamalainen <ccr@tnsp.org>
parents:
763
diff
changeset
|
152 static BOOL engineResXMModuleProbe(DMResource *res, const char *fext) |
342
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
153 { |
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
154 (void) res; |
779
954b1b392c8b
Restore old note frequency calculation for now.
Matti Hamalainen <ccr@tnsp.org>
parents:
763
diff
changeset
|
155 return fext != NULL && strcasecmp(fext, ".xm") == 0; |
954b1b392c8b
Restore old note frequency calculation for now.
Matti Hamalainen <ccr@tnsp.org>
parents:
763
diff
changeset
|
156 } |
954b1b392c8b
Restore old note frequency calculation for now.
Matti Hamalainen <ccr@tnsp.org>
parents:
763
diff
changeset
|
157 #endif |
954b1b392c8b
Restore old note frequency calculation for now.
Matti Hamalainen <ccr@tnsp.org>
parents:
763
diff
changeset
|
158 |
954b1b392c8b
Restore old note frequency calculation for now.
Matti Hamalainen <ccr@tnsp.org>
parents:
763
diff
changeset
|
159 |
954b1b392c8b
Restore old note frequency calculation for now.
Matti Hamalainen <ccr@tnsp.org>
parents:
763
diff
changeset
|
160 #ifdef JSS_SUP_JSSMOD |
954b1b392c8b
Restore old note frequency calculation for now.
Matti Hamalainen <ccr@tnsp.org>
parents:
763
diff
changeset
|
161 static int engineResJSSModuleLoad(DMResource *res) |
954b1b392c8b
Restore old note frequency calculation for now.
Matti Hamalainen <ccr@tnsp.org>
parents:
763
diff
changeset
|
162 { |
796 | 163 return jssLoadJSSMOD(res, (JSSModule **) &(res->resData), FALSE); |
779
954b1b392c8b
Restore old note frequency calculation for now.
Matti Hamalainen <ccr@tnsp.org>
parents:
763
diff
changeset
|
164 } |
954b1b392c8b
Restore old note frequency calculation for now.
Matti Hamalainen <ccr@tnsp.org>
parents:
763
diff
changeset
|
165 |
954b1b392c8b
Restore old note frequency calculation for now.
Matti Hamalainen <ccr@tnsp.org>
parents:
763
diff
changeset
|
166 static void engineResJSSModuleFree(DMResource *res) |
954b1b392c8b
Restore old note frequency calculation for now.
Matti Hamalainen <ccr@tnsp.org>
parents:
763
diff
changeset
|
167 { |
954b1b392c8b
Restore old note frequency calculation for now.
Matti Hamalainen <ccr@tnsp.org>
parents:
763
diff
changeset
|
168 jssFreeModule((JSSModule *) res->resData); |
954b1b392c8b
Restore old note frequency calculation for now.
Matti Hamalainen <ccr@tnsp.org>
parents:
763
diff
changeset
|
169 } |
954b1b392c8b
Restore old note frequency calculation for now.
Matti Hamalainen <ccr@tnsp.org>
parents:
763
diff
changeset
|
170 |
954b1b392c8b
Restore old note frequency calculation for now.
Matti Hamalainen <ccr@tnsp.org>
parents:
763
diff
changeset
|
171 static BOOL engineResJSSModuleProbe(DMResource *res, const char *fext) |
954b1b392c8b
Restore old note frequency calculation for now.
Matti Hamalainen <ccr@tnsp.org>
parents:
763
diff
changeset
|
172 { |
954b1b392c8b
Restore old note frequency calculation for now.
Matti Hamalainen <ccr@tnsp.org>
parents:
763
diff
changeset
|
173 (void) res; |
954b1b392c8b
Restore old note frequency calculation for now.
Matti Hamalainen <ccr@tnsp.org>
parents:
763
diff
changeset
|
174 return fext != NULL && |
954b1b392c8b
Restore old note frequency calculation for now.
Matti Hamalainen <ccr@tnsp.org>
parents:
763
diff
changeset
|
175 (strcasecmp(fext, ".jss") == 0 || strcasecmp(fext, ".jmod") == 0); |
342
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
176 } |
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
177 #endif |
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
178 |
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
179 |
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
180 #ifdef DM_USE_TREMOR |
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
181 static size_t vorbisFileRead(void *ptr, size_t size, size_t nmemb, void *datasource) |
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
182 { |
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
183 return dmfread(ptr, size, nmemb, (DMResource *) datasource); |
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
184 } |
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
185 |
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
186 static int vorbisFileSeek(void *datasource, ogg_int64_t offset, int whence) |
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
187 { |
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
188 return dmfseek((DMResource *) datasource, offset, whence); |
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
189 } |
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
190 |
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
191 static int vorbisFileClose(void *datasource) |
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
192 { |
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
193 (void) datasource; |
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
194 return 0; |
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
195 } |
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
196 |
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
197 static long vorbisFileTell(void *datasource) |
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
198 { |
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
199 return dmftell((DMResource *) datasource); |
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
200 } |
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
201 |
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
202 |
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
203 static ov_callbacks vorbisFileCBS = |
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
204 { |
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
205 vorbisFileRead, |
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
206 vorbisFileSeek, |
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
207 vorbisFileClose, |
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
208 vorbisFileTell |
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
209 }; |
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
210 |
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
211 static int engineResVorbisLoad(DMResource *res) |
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
212 { |
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
213 OggVorbis_File vf; |
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
214 |
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
215 dmMsg(1, "vorbisfile '%s', %d bytes resource loading\n", |
721
bb14d7907eb2
Rename many pack & resource handling functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
642
diff
changeset
|
216 res->filename, res->rawSize); |
342
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
217 |
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
218 if (ov_open_callbacks(res, &vf, NULL, 0, vorbisFileCBS) < 0) |
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
219 return DMERR_FOPEN; |
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
220 |
721
bb14d7907eb2
Rename many pack & resource handling functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
642
diff
changeset
|
221 res->resSize = ov_pcm_total(&vf, -1) * 2 * 2; |
bb14d7907eb2
Rename many pack & resource handling functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
642
diff
changeset
|
222 if ((res->resData = dmMalloc(res->resSize + 16)) == NULL) |
342
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
223 { |
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
224 ov_clear(&vf); |
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
225 return DMERR_MALLOC; |
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
226 } |
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
227 |
721
bb14d7907eb2
Rename many pack & resource handling functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
642
diff
changeset
|
228 dmMsg(1, "rdataSize=%d bytes?\n", res->resSize); |
342
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
229 |
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
230 BOOL eof = FALSE; |
721
bb14d7907eb2
Rename many pack & resource handling functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
642
diff
changeset
|
231 int left = res->resSize; |
bb14d7907eb2
Rename many pack & resource handling functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
642
diff
changeset
|
232 char *ptr = res->resData; |
342
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
233 int current_section; |
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
234 while (!eof && left > 0) |
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
235 { |
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
236 int ret = ov_read(&vf, ptr, left > 4096 ? 4096 : left, ¤t_section); |
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
237 if (ret == 0) |
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
238 eof = TRUE; |
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
239 else |
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
240 if (ret < 0) |
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
241 { |
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
242 ov_clear(&vf); |
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
243 return DMERR_INVALID_DATA; |
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
244 } |
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
245 else |
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
246 { |
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
247 left -= ret; |
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
248 ptr += ret; |
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
249 } |
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
250 } |
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
251 |
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
252 ov_clear(&vf); |
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
253 return DMERR_OK; |
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
254 } |
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
255 |
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
256 static void engineResVorbisFree(DMResource *res) |
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
257 { |
721
bb14d7907eb2
Rename many pack & resource handling functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
642
diff
changeset
|
258 dmFree(res->resData); |
342
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
259 } |
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
260 |
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
261 static BOOL engineResVorbisProbe(DMResource *res, const char *fext) |
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
262 { |
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
263 (void) res; |
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
264 return fext != NULL && (strcasecmp(fext, ".ogg") == 0); |
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
265 } |
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
266 #endif |
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
267 |
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
268 |
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
269 static DMResourceDataOps engineResOps[] = |
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
270 { |
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
271 { |
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
272 engineResImageProbe, |
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
273 engineResImageLoad, |
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
274 engineResImageFree |
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
275 }, |
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
276 |
779
954b1b392c8b
Restore old note frequency calculation for now.
Matti Hamalainen <ccr@tnsp.org>
parents:
763
diff
changeset
|
277 #ifdef JSS_SUP_JSSMOD |
954b1b392c8b
Restore old note frequency calculation for now.
Matti Hamalainen <ccr@tnsp.org>
parents:
763
diff
changeset
|
278 { |
954b1b392c8b
Restore old note frequency calculation for now.
Matti Hamalainen <ccr@tnsp.org>
parents:
763
diff
changeset
|
279 engineResJSSModuleProbe, |
954b1b392c8b
Restore old note frequency calculation for now.
Matti Hamalainen <ccr@tnsp.org>
parents:
763
diff
changeset
|
280 engineResJSSModuleLoad, |
954b1b392c8b
Restore old note frequency calculation for now.
Matti Hamalainen <ccr@tnsp.org>
parents:
763
diff
changeset
|
281 engineResJSSModuleFree |
954b1b392c8b
Restore old note frequency calculation for now.
Matti Hamalainen <ccr@tnsp.org>
parents:
763
diff
changeset
|
282 }, |
954b1b392c8b
Restore old note frequency calculation for now.
Matti Hamalainen <ccr@tnsp.org>
parents:
763
diff
changeset
|
283 #endif |
954b1b392c8b
Restore old note frequency calculation for now.
Matti Hamalainen <ccr@tnsp.org>
parents:
763
diff
changeset
|
284 |
342
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
285 #ifdef JSS_SUP_XM |
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
286 { |
779
954b1b392c8b
Restore old note frequency calculation for now.
Matti Hamalainen <ccr@tnsp.org>
parents:
763
diff
changeset
|
287 engineResXMModuleProbe, |
954b1b392c8b
Restore old note frequency calculation for now.
Matti Hamalainen <ccr@tnsp.org>
parents:
763
diff
changeset
|
288 engineResXMModuleLoad, |
954b1b392c8b
Restore old note frequency calculation for now.
Matti Hamalainen <ccr@tnsp.org>
parents:
763
diff
changeset
|
289 engineResXMModuleFree |
342
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
290 }, |
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
291 #endif |
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
292 |
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
293 #ifdef DM_USE_TREMOR |
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
294 { |
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
295 engineResVorbisProbe, |
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
296 engineResVorbisLoad, |
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
297 engineResVorbisFree |
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
298 }, |
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
299 #endif |
779
954b1b392c8b
Restore old note frequency calculation for now.
Matti Hamalainen <ccr@tnsp.org>
parents:
763
diff
changeset
|
300 |
342
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
301 }; |
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
302 |
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
303 static const int nengineResOps = sizeof(engineResOps) / sizeof(engineResOps[0]); |
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
304 |
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
305 |
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
306 int engineClassifier(DMResource *res) |
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
307 { |
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
308 int i; |
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
309 char *fext; |
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
310 |
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
311 if (res == NULL) |
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
312 return DMERR_NULLPTR; |
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
313 |
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
314 fext = strrchr(res->filename, '.'); |
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
315 for (i = 0; i < nengineResOps; i++) |
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
316 { |
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
317 DMResourceDataOps *rops = &engineResOps[i]; |
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
318 if (rops->probe != NULL && rops->probe(res, fext)) |
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
319 { |
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
320 res->rops = rops; |
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
321 return DMERR_OK; |
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
322 } |
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
323 } |
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
324 |
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
325 return DMERR_OK; |
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
326 } |
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
327 |
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
328 |
366
38e10b5f4e09
Work towards base engine re-entrancy.
Matti Hamalainen <ccr@tnsp.org>
parents:
359
diff
changeset
|
329 void *engineGetResource(DMEngineData *eng, const char *name) |
342
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
330 { |
366
38e10b5f4e09
Work towards base engine re-entrancy.
Matti Hamalainen <ccr@tnsp.org>
parents:
359
diff
changeset
|
331 DMResource *res; |
38e10b5f4e09
Work towards base engine re-entrancy.
Matti Hamalainen <ccr@tnsp.org>
parents:
359
diff
changeset
|
332 if (eng != NULL && |
721
bb14d7907eb2
Rename many pack & resource handling functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
642
diff
changeset
|
333 (res = dmResourceFind(eng->resources, name)) != NULL && |
bb14d7907eb2
Rename many pack & resource handling functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
642
diff
changeset
|
334 res->resData != NULL) |
bb14d7907eb2
Rename many pack & resource handling functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
642
diff
changeset
|
335 return res->resData; |
342
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
336 else |
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
337 { |
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
338 dmError("Could not find resource '%s'.\n", name); |
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
339 return NULL; |
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
340 } |
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
341 } |
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
342 |
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
343 |
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
344 #ifdef DM_USE_JSS |
366
38e10b5f4e09
Work towards base engine re-entrancy.
Matti Hamalainen <ccr@tnsp.org>
parents:
359
diff
changeset
|
345 void engineGetJSSInfo(DMEngineData *eng, BOOL *playing, int *order, JSSPattern **pat, int *npattern, int *row) |
342
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
346 { |
763
ad512e54c689
Fix 10L in engine base code.
Matti Hamalainen <ccr@tnsp.org>
parents:
721
diff
changeset
|
347 JSS_LOCK(eng->jssPlr); |
342
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
348 |
787 | 349 *playing = eng->jssPlr->isPlaying; |
350 *row = eng->jssPlr->row; | |
351 *pat = eng->jssPlr->pattern; | |
763
ad512e54c689
Fix 10L in engine base code.
Matti Hamalainen <ccr@tnsp.org>
parents:
721
diff
changeset
|
352 *npattern = eng->jssPlr->npattern; |
787 | 353 *order = eng->jssPlr->order; |
342
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
354 |
763
ad512e54c689
Fix 10L in engine base code.
Matti Hamalainen <ccr@tnsp.org>
parents:
721
diff
changeset
|
355 JSS_UNLOCK(eng->jssPlr); |
342
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
356 } |
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
357 |
785 | 358 |
366
38e10b5f4e09
Work towards base engine re-entrancy.
Matti Hamalainen <ccr@tnsp.org>
parents:
359
diff
changeset
|
359 void engineGetJSSChannelInfo(DMEngineData *eng, const int channel, int *ninst, int *nextInst, int *freq, int *note) |
342
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
360 { |
763
ad512e54c689
Fix 10L in engine base code.
Matti Hamalainen <ccr@tnsp.org>
parents:
721
diff
changeset
|
361 JSS_LOCK(eng->jssPlr); |
787 | 362 |
763
ad512e54c689
Fix 10L in engine base code.
Matti Hamalainen <ccr@tnsp.org>
parents:
721
diff
changeset
|
363 JSSPlayerChannel *chn = &(eng->jssPlr->channels[channel]); |
787 | 364 *ninst = chn->ninstrument; |
342
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
365 *nextInst = chn->nextInstrument; |
787 | 366 *freq = chn->freq; |
367 *note = chn->note; | |
368 | |
763
ad512e54c689
Fix 10L in engine base code.
Matti Hamalainen <ccr@tnsp.org>
parents:
721
diff
changeset
|
369 JSS_UNLOCK(eng->jssPlr); |
342
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
370 } |
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
371 #endif |
367 | 372 |
373 | |
374 int engineGetTick(DMEngineData *engine) | |
375 { | |
390
a7ee3567f718
Remove adjustTime variable, it is not needed anymore.
Matti Hamalainen <ccr@tnsp.org>
parents:
369
diff
changeset
|
376 return engine->frameTime - engine->startTime; |
367 | 377 } |
378 | |
379 | |
380 float engineGetTimeDT(DMEngineData *engine) | |
381 { | |
382 return (float) engineGetTick(engine) / 1000.0f; | |
383 } | |
384 | |
385 | |
386 int engineGetTimeDTi(DMEngineData *engine) | |
387 { | |
388 return (float) engineGetTick(engine) / 1000; | |
389 } | |
390 | |
391 | |
392 int engineGetTime(DMEngineData *engine, int t) | |
393 { | |
394 return engineGetTick(engine) - (1000 * t); | |
395 } | |
396 | |
397 | |
398 int engineGetDT(DMEngineData *engine, int t) | |
399 { | |
400 return engineGetTime(engine, t) / 1000; | |
401 } | |
784
35b881454ea2
Move a function implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
779
diff
changeset
|
402 |
35b881454ea2
Move a function implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
779
diff
changeset
|
403 |
846 | 404 int engineGetVideoAspect(int width, int height) |
405 { | |
406 if (width > 0 && height > 0) | |
407 return (width * 1000) / height; | |
408 else | |
409 return 1; | |
410 } | |
411 | |
412 | |
413 void enginePauseAudio(int status) | |
414 { | |
415 if (status) | |
416 engine.audioStatus = SDL_AUDIO_PAUSED; | |
417 else | |
418 engine.audioStatus = SDL_AUDIO_PLAYING; | |
419 | |
420 SDL_PauseAudio(status); | |
421 } | |
422 | |
423 | |
791
7ea8775b265a
Move audio callback code to dmengine.
Matti Hamalainen <ccr@tnsp.org>
parents:
787
diff
changeset
|
424 void engineAudioCallback(void *userdata, Uint8 *stream, int len) |
7ea8775b265a
Move audio callback code to dmengine.
Matti Hamalainen <ccr@tnsp.org>
parents:
787
diff
changeset
|
425 { |
845 | 426 DMEngineData *engine = (DMEngineData *) userdata; |
427 | |
428 if (engine == NULL) | |
429 return; | |
791
7ea8775b265a
Move audio callback code to dmengine.
Matti Hamalainen <ccr@tnsp.org>
parents:
787
diff
changeset
|
430 |
845 | 431 dmMutexLock(engine->audioStreamMutex); |
432 engine->audioStreamBuf = stream; | |
433 engine->audioStreamLen = len / engine->audioSampleSize; | |
434 engine->audioTimePos += (1000 * engine->audioStreamLen) / engine->optAfmt.freq; | |
791
7ea8775b265a
Move audio callback code to dmengine.
Matti Hamalainen <ccr@tnsp.org>
parents:
787
diff
changeset
|
435 |
845 | 436 if (engine->paused) |
791
7ea8775b265a
Move audio callback code to dmengine.
Matti Hamalainen <ccr@tnsp.org>
parents:
787
diff
changeset
|
437 { |
7ea8775b265a
Move audio callback code to dmengine.
Matti Hamalainen <ccr@tnsp.org>
parents:
787
diff
changeset
|
438 memset(stream, 0, len); |
7ea8775b265a
Move audio callback code to dmengine.
Matti Hamalainen <ccr@tnsp.org>
parents:
787
diff
changeset
|
439 } |
7ea8775b265a
Move audio callback code to dmengine.
Matti Hamalainen <ccr@tnsp.org>
parents:
787
diff
changeset
|
440 else |
845 | 441 switch (engine->optAudioSetup) |
791
7ea8775b265a
Move audio callback code to dmengine.
Matti Hamalainen <ccr@tnsp.org>
parents:
787
diff
changeset
|
442 { |
7ea8775b265a
Move audio callback code to dmengine.
Matti Hamalainen <ccr@tnsp.org>
parents:
787
diff
changeset
|
443 #ifdef DM_USE_JSS |
7ea8775b265a
Move audio callback code to dmengine.
Matti Hamalainen <ccr@tnsp.org>
parents:
787
diff
changeset
|
444 case DM_ASETUP_JSS: |
845 | 445 if (engine->jssDev != NULL) |
446 jvmRenderAudio(engine->jssDev, stream, len / engine->audioSampleSize); | |
791
7ea8775b265a
Move audio callback code to dmengine.
Matti Hamalainen <ccr@tnsp.org>
parents:
787
diff
changeset
|
447 break; |
7ea8775b265a
Move audio callback code to dmengine.
Matti Hamalainen <ccr@tnsp.org>
parents:
787
diff
changeset
|
448 #endif |
7ea8775b265a
Move audio callback code to dmengine.
Matti Hamalainen <ccr@tnsp.org>
parents:
787
diff
changeset
|
449 #ifdef DM_USE_TREMOR |
7ea8775b265a
Move audio callback code to dmengine.
Matti Hamalainen <ccr@tnsp.org>
parents:
787
diff
changeset
|
450 case DM_ASETUP_TREMOR: |
845 | 451 if (engine->audioPos + len >= engine->audioRes->resSize) |
452 engine->exitFlag = TRUE; | |
791
7ea8775b265a
Move audio callback code to dmengine.
Matti Hamalainen <ccr@tnsp.org>
parents:
787
diff
changeset
|
453 else |
7ea8775b265a
Move audio callback code to dmengine.
Matti Hamalainen <ccr@tnsp.org>
parents:
787
diff
changeset
|
454 { |
845 | 455 memcpy(stream, engine->audioRes->resData + engine->audioPos, len); |
456 engine->audioPos += len; | |
791
7ea8775b265a
Move audio callback code to dmengine.
Matti Hamalainen <ccr@tnsp.org>
parents:
787
diff
changeset
|
457 } |
7ea8775b265a
Move audio callback code to dmengine.
Matti Hamalainen <ccr@tnsp.org>
parents:
787
diff
changeset
|
458 break; |
7ea8775b265a
Move audio callback code to dmengine.
Matti Hamalainen <ccr@tnsp.org>
parents:
787
diff
changeset
|
459 #endif |
7ea8775b265a
Move audio callback code to dmengine.
Matti Hamalainen <ccr@tnsp.org>
parents:
787
diff
changeset
|
460 |
7ea8775b265a
Move audio callback code to dmengine.
Matti Hamalainen <ccr@tnsp.org>
parents:
787
diff
changeset
|
461 default: |
7ea8775b265a
Move audio callback code to dmengine.
Matti Hamalainen <ccr@tnsp.org>
parents:
787
diff
changeset
|
462 break; |
7ea8775b265a
Move audio callback code to dmengine.
Matti Hamalainen <ccr@tnsp.org>
parents:
787
diff
changeset
|
463 } |
7ea8775b265a
Move audio callback code to dmengine.
Matti Hamalainen <ccr@tnsp.org>
parents:
787
diff
changeset
|
464 |
845 | 465 dmMutexUnlock(engine->audioStreamMutex); |
791
7ea8775b265a
Move audio callback code to dmengine.
Matti Hamalainen <ccr@tnsp.org>
parents:
787
diff
changeset
|
466 } |
7ea8775b265a
Move audio callback code to dmengine.
Matti Hamalainen <ccr@tnsp.org>
parents:
787
diff
changeset
|
467 |
7ea8775b265a
Move audio callback code to dmengine.
Matti Hamalainen <ccr@tnsp.org>
parents:
787
diff
changeset
|
468 |
846 | 469 static int engineAudioThreadFunc(void *userdata) |
785 | 470 { |
846 | 471 DMEngineData *engine = (DMEngineData *) userdata; |
472 if (engine == NULL) | |
473 return 0; | |
785 | 474 |
846 | 475 do |
476 { | |
477 dmMutexLock(engine->audioStreamMutex); | |
478 if (engine->audioStatus == SDL_AUDIO_PLAYING) | |
479 { | |
480 engineAudioCallback(userdata, engine->audioSimBuf, engine->audioSimBufSize); | |
481 } | |
482 dmMutexUnlock(engine->audioStreamMutex); | |
483 | |
484 SDL_Delay(engine->audioSimDelay); | |
485 } while (!engine->audioSimDone); | |
486 | |
487 return 0; | |
785 | 488 } |
489 | |
490 | |
846 | 491 int engineInitAudioParts(DMEngineData *engine) |
784
35b881454ea2
Move a function implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
779
diff
changeset
|
492 { |
846 | 493 if (engine == NULL) |
494 return DMERR_NULLPTR; | |
495 | |
496 engine->audioStreamMutex = dmCreateMutex(); | |
497 engine->audioStatus = SDL_AUDIO_STOPPED; | |
498 engine->optAfmt.callback = engineAudioCallback; | |
499 engine->optAfmt.userdata = (void *) engine; | |
500 | |
501 engine->audioSampleSize = engine->optAfmt.channels; | |
502 switch (engine->optAfmt.format) | |
503 { | |
504 case AUDIO_S16SYS: | |
505 case AUDIO_U16SYS: engine->audioSampleSize *= 2; break; | |
506 } | |
507 | |
508 if (SDL_OpenAudio(&engine->optAfmt, NULL) < 0) | |
509 { | |
510 // We'll let this pass, as we want to support no-sound. | |
511 dmError("Couldn't open SDL audio, falling back to no sound: %s\n", SDL_GetError()); | |
512 | |
513 // Set up simulated audio thread | |
514 engine->audioSimDelay = 1000 / 45; | |
515 engine->audioSimBufSize = (engine->optAfmt.freq / 45) * engine->audioSampleSize; | |
516 engine->audioSimBuf = dmMalloc(engine->audioSimBufSize); | |
517 engine->audioSimDone = FALSE; | |
518 engine->audioSimThread = SDL_CreateThread(engineAudioThreadFunc, NULL); | |
519 if (engine->audioSimThread == NULL) | |
520 return DMERR_INIT_FAIL; | |
521 } | |
522 | |
523 return DMERR_OK; | |
784
35b881454ea2
Move a function implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
779
diff
changeset
|
524 } |