Mercurial > hg > dmlib
annotate src/dmengine.c @ 1263:4e9deb14e67f
Fix audio sync with nosound.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Fri, 22 May 2015 20:41:53 +0300 |
parents | 2bf7cb1e662f |
children | 5e5f75b45f8d |
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 { | |
1049
771e03bf9fcd
Make more error message fall under DM_DEBUG.
Matti Hamalainen <ccr@tnsp.org>
parents:
1043
diff
changeset
|
35 return dmErrorDBG(DMERR_INIT_FAIL, |
1102
e06abfde6c39
Cosmetics pass: Remove excess whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
1049
diff
changeset
|
36 "Could not expand effects structure.\n"); |
368 | 37 } |
38 } | |
39 | |
40 // Copy effects structure | |
41 memcpy(engineEffects + nengineEffects, ef, sizeof(DMEffect)); | |
42 nengineEffects++; | |
1102
e06abfde6c39
Cosmetics pass: Remove excess whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
1049
diff
changeset
|
43 |
368 | 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 { | |
1049
771e03bf9fcd
Make more error message fall under DM_DEBUG.
Matti Hamalainen <ccr@tnsp.org>
parents:
1043
diff
changeset
|
56 return dmErrorDBG(DMERR_INIT_FAIL, |
1102
e06abfde6c39
Cosmetics pass: Remove excess whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
1049
diff
changeset
|
57 "Could not expand effects data structure.\n"); |
368 | 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 { |
1043 | 118 if ((res->resData = dmLoadImage(res)) != NULL) |
342
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
119 return DMERR_OK; |
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
120 else |
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
121 return dmferror(res); |
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
122 } |
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 |
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
125 static void engineResImageFree(DMResource *res) |
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
126 { |
721
bb14d7907eb2
Rename many pack & resource handling functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
642
diff
changeset
|
127 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
|
128 } |
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
129 |
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
130 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
|
131 { |
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
132 (void) res; |
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
133 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
|
134 } |
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 |
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
137 #ifdef JSS_SUP_XM |
779
954b1b392c8b
Restore old note frequency calculation for now.
Matti Hamalainen <ccr@tnsp.org>
parents:
763
diff
changeset
|
138 static int engineResXMModuleLoad(DMResource *res) |
342
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
139 { |
796 | 140 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
|
141 } |
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
142 |
779
954b1b392c8b
Restore old note frequency calculation for now.
Matti Hamalainen <ccr@tnsp.org>
parents:
763
diff
changeset
|
143 static void engineResXMModuleFree(DMResource *res) |
342
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
144 { |
721
bb14d7907eb2
Rename many pack & resource handling functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
642
diff
changeset
|
145 jssFreeModule((JSSModule *) res->resData); |
342
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
146 } |
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
147 |
779
954b1b392c8b
Restore old note frequency calculation for now.
Matti Hamalainen <ccr@tnsp.org>
parents:
763
diff
changeset
|
148 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
|
149 { |
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
150 (void) res; |
779
954b1b392c8b
Restore old note frequency calculation for now.
Matti Hamalainen <ccr@tnsp.org>
parents:
763
diff
changeset
|
151 return fext != NULL && strcasecmp(fext, ".xm") == 0; |
954b1b392c8b
Restore old note frequency calculation for now.
Matti Hamalainen <ccr@tnsp.org>
parents:
763
diff
changeset
|
152 } |
954b1b392c8b
Restore old note frequency calculation for now.
Matti Hamalainen <ccr@tnsp.org>
parents:
763
diff
changeset
|
153 #endif |
954b1b392c8b
Restore old note frequency calculation for now.
Matti Hamalainen <ccr@tnsp.org>
parents:
763
diff
changeset
|
154 |
954b1b392c8b
Restore old note frequency calculation for now.
Matti Hamalainen <ccr@tnsp.org>
parents:
763
diff
changeset
|
155 |
954b1b392c8b
Restore old note frequency calculation for now.
Matti Hamalainen <ccr@tnsp.org>
parents:
763
diff
changeset
|
156 #ifdef JSS_SUP_JSSMOD |
954b1b392c8b
Restore old note frequency calculation for now.
Matti Hamalainen <ccr@tnsp.org>
parents:
763
diff
changeset
|
157 static int engineResJSSModuleLoad(DMResource *res) |
954b1b392c8b
Restore old note frequency calculation for now.
Matti Hamalainen <ccr@tnsp.org>
parents:
763
diff
changeset
|
158 { |
796 | 159 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
|
160 } |
954b1b392c8b
Restore old note frequency calculation for now.
Matti Hamalainen <ccr@tnsp.org>
parents:
763
diff
changeset
|
161 |
954b1b392c8b
Restore old note frequency calculation for now.
Matti Hamalainen <ccr@tnsp.org>
parents:
763
diff
changeset
|
162 static void engineResJSSModuleFree(DMResource *res) |
954b1b392c8b
Restore old note frequency calculation for now.
Matti Hamalainen <ccr@tnsp.org>
parents:
763
diff
changeset
|
163 { |
954b1b392c8b
Restore old note frequency calculation for now.
Matti Hamalainen <ccr@tnsp.org>
parents:
763
diff
changeset
|
164 jssFreeModule((JSSModule *) res->resData); |
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 |
954b1b392c8b
Restore old note frequency calculation for now.
Matti Hamalainen <ccr@tnsp.org>
parents:
763
diff
changeset
|
167 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
|
168 { |
954b1b392c8b
Restore old note frequency calculation for now.
Matti Hamalainen <ccr@tnsp.org>
parents:
763
diff
changeset
|
169 (void) res; |
954b1b392c8b
Restore old note frequency calculation for now.
Matti Hamalainen <ccr@tnsp.org>
parents:
763
diff
changeset
|
170 return fext != NULL && |
954b1b392c8b
Restore old note frequency calculation for now.
Matti Hamalainen <ccr@tnsp.org>
parents:
763
diff
changeset
|
171 (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
|
172 } |
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
173 #endif |
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
174 |
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
175 |
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
176 #ifdef DM_USE_TREMOR |
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
177 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
|
178 { |
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
179 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
|
180 } |
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
181 |
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
182 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
|
183 { |
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
184 return dmfseek((DMResource *) datasource, offset, whence); |
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 |
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
187 static int vorbisFileClose(void *datasource) |
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
188 { |
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
189 (void) datasource; |
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
190 return 0; |
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
191 } |
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 static long vorbisFileTell(void *datasource) |
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
194 { |
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
195 return dmftell((DMResource *) datasource); |
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
196 } |
1102
e06abfde6c39
Cosmetics pass: Remove excess whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
1049
diff
changeset
|
197 |
342
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 static ov_callbacks vorbisFileCBS = |
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 vorbisFileRead, |
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
202 vorbisFileSeek, |
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
203 vorbisFileClose, |
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
204 vorbisFileTell |
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
205 }; |
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
206 |
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
207 static int engineResVorbisLoad(DMResource *res) |
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
208 { |
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
209 OggVorbis_File vf; |
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
210 |
1043 | 211 dmMsg(2, "vorbisfile '%s', %d bytes resource loading\n", |
721
bb14d7907eb2
Rename many pack & resource handling functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
642
diff
changeset
|
212 res->filename, res->rawSize); |
342
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
213 |
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
214 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
|
215 return DMERR_FOPEN; |
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
216 |
721
bb14d7907eb2
Rename many pack & resource handling functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
642
diff
changeset
|
217 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
|
218 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
|
219 { |
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
220 ov_clear(&vf); |
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
221 return DMERR_MALLOC; |
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
222 } |
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
223 |
1043 | 224 dmMsg(2, "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
|
225 |
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
226 BOOL eof = FALSE; |
721
bb14d7907eb2
Rename many pack & resource handling functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
642
diff
changeset
|
227 int left = res->resSize; |
bb14d7907eb2
Rename many pack & resource handling functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
642
diff
changeset
|
228 char *ptr = res->resData; |
342
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
229 int current_section; |
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
230 while (!eof && left > 0) |
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
231 { |
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
232 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
|
233 if (ret == 0) |
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
234 eof = TRUE; |
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
235 else |
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
236 if (ret < 0) |
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
237 { |
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
238 ov_clear(&vf); |
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
239 return DMERR_INVALID_DATA; |
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
240 } |
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
241 else |
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
242 { |
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
243 left -= ret; |
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
244 ptr += ret; |
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
245 } |
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 |
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
248 ov_clear(&vf); |
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
249 return DMERR_OK; |
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 static void engineResVorbisFree(DMResource *res) |
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
253 { |
721
bb14d7907eb2
Rename many pack & resource handling functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
642
diff
changeset
|
254 dmFree(res->resData); |
342
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 |
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
257 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
|
258 { |
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
259 (void) res; |
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
260 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
|
261 } |
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
262 #endif |
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
263 |
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
264 |
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
265 static DMResourceDataOps engineResOps[] = |
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
266 { |
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 engineResImageProbe, |
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
269 engineResImageLoad, |
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
270 engineResImageFree |
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 |
779
954b1b392c8b
Restore old note frequency calculation for now.
Matti Hamalainen <ccr@tnsp.org>
parents:
763
diff
changeset
|
273 #ifdef JSS_SUP_JSSMOD |
954b1b392c8b
Restore old note frequency calculation for now.
Matti Hamalainen <ccr@tnsp.org>
parents:
763
diff
changeset
|
274 { |
954b1b392c8b
Restore old note frequency calculation for now.
Matti Hamalainen <ccr@tnsp.org>
parents:
763
diff
changeset
|
275 engineResJSSModuleProbe, |
954b1b392c8b
Restore old note frequency calculation for now.
Matti Hamalainen <ccr@tnsp.org>
parents:
763
diff
changeset
|
276 engineResJSSModuleLoad, |
954b1b392c8b
Restore old note frequency calculation for now.
Matti Hamalainen <ccr@tnsp.org>
parents:
763
diff
changeset
|
277 engineResJSSModuleFree |
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 #endif |
954b1b392c8b
Restore old note frequency calculation for now.
Matti Hamalainen <ccr@tnsp.org>
parents:
763
diff
changeset
|
280 |
342
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
281 #ifdef JSS_SUP_XM |
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
282 { |
779
954b1b392c8b
Restore old note frequency calculation for now.
Matti Hamalainen <ccr@tnsp.org>
parents:
763
diff
changeset
|
283 engineResXMModuleProbe, |
954b1b392c8b
Restore old note frequency calculation for now.
Matti Hamalainen <ccr@tnsp.org>
parents:
763
diff
changeset
|
284 engineResXMModuleLoad, |
954b1b392c8b
Restore old note frequency calculation for now.
Matti Hamalainen <ccr@tnsp.org>
parents:
763
diff
changeset
|
285 engineResXMModuleFree |
342
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
286 }, |
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
287 #endif |
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
288 |
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
289 #ifdef DM_USE_TREMOR |
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 engineResVorbisProbe, |
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
292 engineResVorbisLoad, |
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
293 engineResVorbisFree |
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 #endif |
779
954b1b392c8b
Restore old note frequency calculation for now.
Matti Hamalainen <ccr@tnsp.org>
parents:
763
diff
changeset
|
296 |
342
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
297 }; |
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 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
|
300 |
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 int engineClassifier(DMResource *res) |
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
303 { |
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
304 int i; |
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
305 char *fext; |
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
306 |
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
307 if (res == NULL) |
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
308 return DMERR_NULLPTR; |
1102
e06abfde6c39
Cosmetics pass: Remove excess whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
1049
diff
changeset
|
309 |
342
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
310 fext = strrchr(res->filename, '.'); |
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
311 for (i = 0; i < nengineResOps; i++) |
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
312 { |
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
313 DMResourceDataOps *rops = &engineResOps[i]; |
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
314 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
|
315 { |
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
316 res->rops = rops; |
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
317 return DMERR_OK; |
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
318 } |
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
319 } |
1102
e06abfde6c39
Cosmetics pass: Remove excess whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
1049
diff
changeset
|
320 |
342
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 |
366
38e10b5f4e09
Work towards base engine re-entrancy.
Matti Hamalainen <ccr@tnsp.org>
parents:
359
diff
changeset
|
325 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
|
326 { |
366
38e10b5f4e09
Work towards base engine re-entrancy.
Matti Hamalainen <ccr@tnsp.org>
parents:
359
diff
changeset
|
327 DMResource *res; |
1043 | 328 if (eng == NULL) |
329 { | |
1049
771e03bf9fcd
Make more error message fall under DM_DEBUG.
Matti Hamalainen <ccr@tnsp.org>
parents:
1043
diff
changeset
|
330 dmErrorDBGMsg( |
1043 | 331 "Engine not initialized but engineGetResource('%s') called.\n", |
332 name); | |
333 return NULL; | |
334 } | |
335 | |
1261
2bf7cb1e662f
Improve error messages for resource not found situations.
Matti Hamalainen <ccr@tnsp.org>
parents:
1167
diff
changeset
|
336 if ((res = dmResourceFind(eng->resources, name)) != NULL) |
2bf7cb1e662f
Improve error messages for resource not found situations.
Matti Hamalainen <ccr@tnsp.org>
parents:
1167
diff
changeset
|
337 { |
2bf7cb1e662f
Improve error messages for resource not found situations.
Matti Hamalainen <ccr@tnsp.org>
parents:
1167
diff
changeset
|
338 if (res->resData != NULL) |
2bf7cb1e662f
Improve error messages for resource not found situations.
Matti Hamalainen <ccr@tnsp.org>
parents:
1167
diff
changeset
|
339 return res->resData; |
2bf7cb1e662f
Improve error messages for resource not found situations.
Matti Hamalainen <ccr@tnsp.org>
parents:
1167
diff
changeset
|
340 |
2bf7cb1e662f
Improve error messages for resource not found situations.
Matti Hamalainen <ccr@tnsp.org>
parents:
1167
diff
changeset
|
341 dmErrorDBGMsg( |
2bf7cb1e662f
Improve error messages for resource not found situations.
Matti Hamalainen <ccr@tnsp.org>
parents:
1167
diff
changeset
|
342 "Could not find resource DATA '%s' (resource was not preloaded).\n", |
2bf7cb1e662f
Improve error messages for resource not found situations.
Matti Hamalainen <ccr@tnsp.org>
parents:
1167
diff
changeset
|
343 name); |
2bf7cb1e662f
Improve error messages for resource not found situations.
Matti Hamalainen <ccr@tnsp.org>
parents:
1167
diff
changeset
|
344 return NULL; |
2bf7cb1e662f
Improve error messages for resource not found situations.
Matti Hamalainen <ccr@tnsp.org>
parents:
1167
diff
changeset
|
345 } |
342
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
346 else |
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
347 { |
1049
771e03bf9fcd
Make more error message fall under DM_DEBUG.
Matti Hamalainen <ccr@tnsp.org>
parents:
1043
diff
changeset
|
348 dmErrorDBGMsg( |
958
985225a93aeb
Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents:
868
diff
changeset
|
349 "Could not find resource '%s'.\n", |
985225a93aeb
Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents:
868
diff
changeset
|
350 name); |
342
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
351 return NULL; |
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
352 } |
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
353 } |
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
354 |
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
355 |
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
356 #ifdef DM_USE_JSS |
366
38e10b5f4e09
Work towards base engine re-entrancy.
Matti Hamalainen <ccr@tnsp.org>
parents:
359
diff
changeset
|
357 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
|
358 { |
763
ad512e54c689
Fix 10L in engine base code.
Matti Hamalainen <ccr@tnsp.org>
parents:
721
diff
changeset
|
359 JSS_LOCK(eng->jssPlr); |
342
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
360 |
787 | 361 *playing = eng->jssPlr->isPlaying; |
362 *row = eng->jssPlr->row; | |
363 *pat = eng->jssPlr->pattern; | |
763
ad512e54c689
Fix 10L in engine base code.
Matti Hamalainen <ccr@tnsp.org>
parents:
721
diff
changeset
|
364 *npattern = eng->jssPlr->npattern; |
787 | 365 *order = eng->jssPlr->order; |
342
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
366 |
763
ad512e54c689
Fix 10L in engine base code.
Matti Hamalainen <ccr@tnsp.org>
parents:
721
diff
changeset
|
367 JSS_UNLOCK(eng->jssPlr); |
342
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
368 } |
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
369 |
785 | 370 |
366
38e10b5f4e09
Work towards base engine re-entrancy.
Matti Hamalainen <ccr@tnsp.org>
parents:
359
diff
changeset
|
371 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
|
372 { |
763
ad512e54c689
Fix 10L in engine base code.
Matti Hamalainen <ccr@tnsp.org>
parents:
721
diff
changeset
|
373 JSS_LOCK(eng->jssPlr); |
787 | 374 |
763
ad512e54c689
Fix 10L in engine base code.
Matti Hamalainen <ccr@tnsp.org>
parents:
721
diff
changeset
|
375 JSSPlayerChannel *chn = &(eng->jssPlr->channels[channel]); |
787 | 376 *ninst = chn->ninstrument; |
342
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
377 *nextInst = chn->nextInstrument; |
787 | 378 *freq = chn->freq; |
379 *note = chn->note; | |
380 | |
763
ad512e54c689
Fix 10L in engine base code.
Matti Hamalainen <ccr@tnsp.org>
parents:
721
diff
changeset
|
381 JSS_UNLOCK(eng->jssPlr); |
342
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
382 } |
c6ec970dc3cf
Separate some demo engine parts to two different modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
383 #endif |
367 | 384 |
385 | |
386 int engineGetTick(DMEngineData *engine) | |
387 { | |
868
2c6b092328be
Possibly improve audio synchronization.
Matti Hamalainen <ccr@tnsp.org>
parents:
867
diff
changeset
|
388 return engine->frameTime - engine->startTime - engine->offsetTime; |
367 | 389 } |
390 | |
391 | |
392 float engineGetTimeDT(DMEngineData *engine) | |
393 { | |
394 return (float) engineGetTick(engine) / 1000.0f; | |
395 } | |
396 | |
397 | |
398 int engineGetTimeDTi(DMEngineData *engine) | |
399 { | |
400 return (float) engineGetTick(engine) / 1000; | |
401 } | |
402 | |
403 | |
404 int engineGetTime(DMEngineData *engine, int t) | |
405 { | |
406 return engineGetTick(engine) - (1000 * t); | |
407 } | |
408 | |
409 | |
410 int engineGetDT(DMEngineData *engine, int t) | |
411 { | |
412 return engineGetTime(engine, t) / 1000; | |
413 } | |
784
35b881454ea2
Move a function implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
779
diff
changeset
|
414 |
35b881454ea2
Move a function implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
779
diff
changeset
|
415 |
846 | 416 int engineGetVideoAspect(int width, int height) |
417 { | |
418 if (width > 0 && height > 0) | |
419 return (width * 1000) / height; | |
420 else | |
421 return 1; | |
422 } | |
423 | |
424 | |
1263
4e9deb14e67f
Fix audio sync with nosound.
Matti Hamalainen <ccr@tnsp.org>
parents:
1261
diff
changeset
|
425 void enginePauseAudio(DMEngineData *engine, int status) |
846 | 426 { |
427 if (status) | |
1263
4e9deb14e67f
Fix audio sync with nosound.
Matti Hamalainen <ccr@tnsp.org>
parents:
1261
diff
changeset
|
428 engine->audioStatus = SDL_AUDIO_PAUSED; |
846 | 429 else |
1263
4e9deb14e67f
Fix audio sync with nosound.
Matti Hamalainen <ccr@tnsp.org>
parents:
1261
diff
changeset
|
430 engine->audioStatus = SDL_AUDIO_PLAYING; |
846 | 431 |
432 SDL_PauseAudio(status); | |
433 } | |
434 | |
435 | |
791
7ea8775b265a
Move audio callback code to dmengine.
Matti Hamalainen <ccr@tnsp.org>
parents:
787
diff
changeset
|
436 void engineAudioCallback(void *userdata, Uint8 *stream, int len) |
7ea8775b265a
Move audio callback code to dmengine.
Matti Hamalainen <ccr@tnsp.org>
parents:
787
diff
changeset
|
437 { |
845 | 438 DMEngineData *engine = (DMEngineData *) userdata; |
439 | |
440 if (engine == NULL) | |
441 return; | |
791
7ea8775b265a
Move audio callback code to dmengine.
Matti Hamalainen <ccr@tnsp.org>
parents:
787
diff
changeset
|
442 |
845 | 443 dmMutexLock(engine->audioStreamMutex); |
1102
e06abfde6c39
Cosmetics pass: Remove excess whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
1049
diff
changeset
|
444 |
868
2c6b092328be
Possibly improve audio synchronization.
Matti Hamalainen <ccr@tnsp.org>
parents:
867
diff
changeset
|
445 // Update variables for analysis buffer (FFT, etc.) |
845 | 446 engine->audioStreamBuf = stream; |
447 engine->audioStreamLen = len / engine->audioSampleSize; | |
868
2c6b092328be
Possibly improve audio synchronization.
Matti Hamalainen <ccr@tnsp.org>
parents:
867
diff
changeset
|
448 |
2c6b092328be
Possibly improve audio synchronization.
Matti Hamalainen <ccr@tnsp.org>
parents:
867
diff
changeset
|
449 // Update audio stream time position |
845 | 450 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
|
451 |
868
2c6b092328be
Possibly improve audio synchronization.
Matti Hamalainen <ccr@tnsp.org>
parents:
867
diff
changeset
|
452 // If paused, just render nothing |
845 | 453 if (engine->paused) |
791
7ea8775b265a
Move audio callback code to dmengine.
Matti Hamalainen <ccr@tnsp.org>
parents:
787
diff
changeset
|
454 { |
1167 | 455 dmMemset(stream, 0, len); |
791
7ea8775b265a
Move audio callback code to dmengine.
Matti Hamalainen <ccr@tnsp.org>
parents:
787
diff
changeset
|
456 } |
7ea8775b265a
Move audio callback code to dmengine.
Matti Hamalainen <ccr@tnsp.org>
parents:
787
diff
changeset
|
457 else |
868
2c6b092328be
Possibly improve audio synchronization.
Matti Hamalainen <ccr@tnsp.org>
parents:
867
diff
changeset
|
458 // Otherwise, render audio |
845 | 459 switch (engine->optAudioSetup) |
791
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 #ifdef DM_USE_JSS |
7ea8775b265a
Move audio callback code to dmengine.
Matti Hamalainen <ccr@tnsp.org>
parents:
787
diff
changeset
|
462 case DM_ASETUP_JSS: |
845 | 463 if (engine->jssDev != NULL) |
464 jvmRenderAudio(engine->jssDev, stream, len / engine->audioSampleSize); | |
791
7ea8775b265a
Move audio callback code to dmengine.
Matti Hamalainen <ccr@tnsp.org>
parents:
787
diff
changeset
|
465 break; |
7ea8775b265a
Move audio callback code to dmengine.
Matti Hamalainen <ccr@tnsp.org>
parents:
787
diff
changeset
|
466 #endif |
7ea8775b265a
Move audio callback code to dmengine.
Matti Hamalainen <ccr@tnsp.org>
parents:
787
diff
changeset
|
467 #ifdef DM_USE_TREMOR |
7ea8775b265a
Move audio callback code to dmengine.
Matti Hamalainen <ccr@tnsp.org>
parents:
787
diff
changeset
|
468 case DM_ASETUP_TREMOR: |
845 | 469 if (engine->audioPos + len >= engine->audioRes->resSize) |
470 engine->exitFlag = TRUE; | |
791
7ea8775b265a
Move audio callback code to dmengine.
Matti Hamalainen <ccr@tnsp.org>
parents:
787
diff
changeset
|
471 else |
7ea8775b265a
Move audio callback code to dmengine.
Matti Hamalainen <ccr@tnsp.org>
parents:
787
diff
changeset
|
472 { |
867 | 473 memcpy(stream, (Uint8 *) engine->audioRes->resData + engine->audioPos, len); |
845 | 474 engine->audioPos += len; |
791
7ea8775b265a
Move audio callback code to dmengine.
Matti Hamalainen <ccr@tnsp.org>
parents:
787
diff
changeset
|
475 } |
7ea8775b265a
Move audio callback code to dmengine.
Matti Hamalainen <ccr@tnsp.org>
parents:
787
diff
changeset
|
476 break; |
7ea8775b265a
Move audio callback code to dmengine.
Matti Hamalainen <ccr@tnsp.org>
parents:
787
diff
changeset
|
477 #endif |
7ea8775b265a
Move audio callback code to dmengine.
Matti Hamalainen <ccr@tnsp.org>
parents:
787
diff
changeset
|
478 |
7ea8775b265a
Move audio callback code to dmengine.
Matti Hamalainen <ccr@tnsp.org>
parents:
787
diff
changeset
|
479 default: |
7ea8775b265a
Move audio callback code to dmengine.
Matti Hamalainen <ccr@tnsp.org>
parents:
787
diff
changeset
|
480 break; |
7ea8775b265a
Move audio callback code to dmengine.
Matti Hamalainen <ccr@tnsp.org>
parents:
787
diff
changeset
|
481 } |
7ea8775b265a
Move audio callback code to dmengine.
Matti Hamalainen <ccr@tnsp.org>
parents:
787
diff
changeset
|
482 |
868
2c6b092328be
Possibly improve audio synchronization.
Matti Hamalainen <ccr@tnsp.org>
parents:
867
diff
changeset
|
483 // First round of audio callback sets up the |
2c6b092328be
Possibly improve audio synchronization.
Matti Hamalainen <ccr@tnsp.org>
parents:
867
diff
changeset
|
484 // necessary variables for audio synchro |
2c6b092328be
Possibly improve audio synchronization.
Matti Hamalainen <ccr@tnsp.org>
parents:
867
diff
changeset
|
485 if (engine->startTimeAudio == -1 && engine->startTime != -1) |
2c6b092328be
Possibly improve audio synchronization.
Matti Hamalainen <ccr@tnsp.org>
parents:
867
diff
changeset
|
486 { |
2c6b092328be
Possibly improve audio synchronization.
Matti Hamalainen <ccr@tnsp.org>
parents:
867
diff
changeset
|
487 engine->startTimeAudio = SDL_GetTicks(); |
2c6b092328be
Possibly improve audio synchronization.
Matti Hamalainen <ccr@tnsp.org>
parents:
867
diff
changeset
|
488 engine->offsetTime = engine->startTimeAudio - engine->startTime; |
2c6b092328be
Possibly improve audio synchronization.
Matti Hamalainen <ccr@tnsp.org>
parents:
867
diff
changeset
|
489 } |
2c6b092328be
Possibly improve audio synchronization.
Matti Hamalainen <ccr@tnsp.org>
parents:
867
diff
changeset
|
490 |
845 | 491 dmMutexUnlock(engine->audioStreamMutex); |
791
7ea8775b265a
Move audio callback code to dmengine.
Matti Hamalainen <ccr@tnsp.org>
parents:
787
diff
changeset
|
492 } |
7ea8775b265a
Move audio callback code to dmengine.
Matti Hamalainen <ccr@tnsp.org>
parents:
787
diff
changeset
|
493 |
7ea8775b265a
Move audio callback code to dmengine.
Matti Hamalainen <ccr@tnsp.org>
parents:
787
diff
changeset
|
494 |
846 | 495 static int engineAudioThreadFunc(void *userdata) |
785 | 496 { |
846 | 497 DMEngineData *engine = (DMEngineData *) userdata; |
498 if (engine == NULL) | |
499 return 0; | |
500 do | |
501 { | |
502 dmMutexLock(engine->audioStreamMutex); | |
503 if (engine->audioStatus == SDL_AUDIO_PLAYING) | |
504 { | |
505 engineAudioCallback(userdata, engine->audioSimBuf, engine->audioSimBufSize); | |
506 } | |
507 dmMutexUnlock(engine->audioStreamMutex); | |
508 | |
509 SDL_Delay(engine->audioSimDelay); | |
510 } while (!engine->audioSimDone); | |
511 | |
512 return 0; | |
785 | 513 } |
514 | |
515 | |
846 | 516 int engineInitAudioParts(DMEngineData *engine) |
784
35b881454ea2
Move a function implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
779
diff
changeset
|
517 { |
846 | 518 if (engine == NULL) |
519 return DMERR_NULLPTR; | |
520 | |
521 engine->audioStreamMutex = dmCreateMutex(); | |
522 engine->audioStatus = SDL_AUDIO_STOPPED; | |
523 engine->optAfmt.callback = engineAudioCallback; | |
524 engine->optAfmt.userdata = (void *) engine; | |
525 | |
526 engine->audioSampleSize = engine->optAfmt.channels; | |
527 switch (engine->optAfmt.format) | |
528 { | |
529 case AUDIO_S16SYS: | |
530 case AUDIO_U16SYS: engine->audioSampleSize *= 2; break; | |
531 } | |
1102
e06abfde6c39
Cosmetics pass: Remove excess whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
1049
diff
changeset
|
532 |
846 | 533 if (SDL_OpenAudio(&engine->optAfmt, NULL) < 0) |
534 { | |
535 // We'll let this pass, as we want to support no-sound. | |
958
985225a93aeb
Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents:
868
diff
changeset
|
536 dmMsg(0, |
985225a93aeb
Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents:
868
diff
changeset
|
537 "Couldn't open SDL audio, falling back to no sound: %s\n", |
985225a93aeb
Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents:
868
diff
changeset
|
538 SDL_GetError()); |
846 | 539 |
540 // Set up simulated audio thread | |
541 engine->audioSimDelay = 1000 / 45; | |
542 engine->audioSimBufSize = (engine->optAfmt.freq / 45) * engine->audioSampleSize; | |
543 engine->audioSimBuf = dmMalloc(engine->audioSimBufSize); | |
544 engine->audioSimDone = FALSE; | |
1263
4e9deb14e67f
Fix audio sync with nosound.
Matti Hamalainen <ccr@tnsp.org>
parents:
1261
diff
changeset
|
545 engine->audioSimThread = SDL_CreateThread(engineAudioThreadFunc, engine); |
846 | 546 if (engine->audioSimThread == NULL) |
547 return DMERR_INIT_FAIL; | |
548 } | |
549 | |
550 return DMERR_OK; | |
784
35b881454ea2
Move a function implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
779
diff
changeset
|
551 } |