1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267
|
--- /dev/null Thu Nov 4 09:07:25 1999
+++ src/readsmp.c Mon Jul 22 22:27:48 2002
@@ -0,0 +1,192 @@
+/* ______ ___ ___
+ * /\ _ \ /\_ \ /\_ \
+ * \ \ \L\ \\//\ \ \//\ \ __ __ _ __ ___
+ * \ \ __ \ \ \ \ \ \ \ /'__`\ /'_ `\/\`'__\/ __`\
+ * \ \ \/\ \ \_\ \_ \_\ \_/\ __//\ \L\ \ \ \//\ \L\ \
+ * \ \_\ \_\/\____\/\____\ \____\ \____ \ \_\\ \____/
+ * \/_/\/_/\/____/\/____/\/____/\/___L\ \/_/ \/___/
+ * /\____/
+ * \_/__/
+ *
+ * Top level sample reading routines.
+ *
+ * By Shawn Hargreaves.
+ *
+ * See readme.txt for copyright information.
+ */
+
+
+#include <string.h>
+
+#include "allegro.h"
+#include "allegro/internal/aintern.h"
+
+
+
+typedef struct SAMPLE_TYPE_INFO
+{
+ char *ext;
+ SAMPLE *(*load)(AL_CONST char *filename);
+ int (*save)(AL_CONST char *filename, SAMPLE *smp);
+ struct SAMPLE_TYPE_INFO *next;
+} SAMPLE_TYPE_INFO;
+
+static SAMPLE_TYPE_INFO *sample_type_list = NULL;
+
+
+
+/* register_sample_file_type:
+ * Informs Allegro of a new sample file type, telling it how to load and
+ * save files of this format (either function may be NULL).
+ */
+void register_sample_file_type(AL_CONST char *ext, SAMPLE *(*load)(AL_CONST char *filename), int (*save)(AL_CONST char *filename, SAMPLE *smp))
+{
+ char tmp[32], *aext;
+ SAMPLE_TYPE_INFO *iter = sample_type_list;
+
+ aext = uconvert_toascii(ext, tmp);
+ if (strlen(aext) == 0) return;
+
+ if (!iter)
+ iter = sample_type_list = malloc(sizeof(struct SAMPLE_TYPE_INFO));
+ else {
+ for (iter = sample_type_list; iter->next; iter = iter->next);
+ iter = iter->next = malloc(sizeof(struct SAMPLE_TYPE_INFO));
+ }
+
+ if (iter) {
+ iter->load = load;
+ iter->save = save;
+ iter->ext = strdup(aext);
+ iter->next = NULL;
+ }
+}
+
+
+
+/* load_sample:
+ * Loads a sample from disk.
+ */
+SAMPLE *load_sample(AL_CONST char *filename)
+{
+ char tmp[32], *aext;
+ SAMPLE_TYPE_INFO *iter;
+
+ aext = uconvert_toascii(get_extension(filename), tmp);
+
+ for (iter = sample_type_list; iter; iter = iter->next) {
+ if (stricmp(iter->ext, aext) == 0) {
+ if (iter->load)
+ return iter->load(filename);
+ return NULL;
+ }
+ }
+
+ return NULL;
+}
+
+
+
+/* save_sample:
+ * Writes a sample to disk.
+ */
+int save_sample(AL_CONST char *filename, SAMPLE *smp)
+{
+ char tmp[32], *aext;
+ SAMPLE_TYPE_INFO *iter;
+
+ aext = uconvert_toascii(get_extension(filename), tmp);
+
+ for (iter = sample_type_list; iter; iter = iter->next) {
+ if (stricmp(iter->ext, aext) == 0) {
+ if (iter->load)
+ return iter->save(filename, smp);
+ return 1;
+ }
+ }
+
+ return 1;
+}
+
+
+
+/* register_sample_file_type_exit:
+ * Free list of registered sample file types.
+ */
+static void register_sample_file_type_exit(void)
+{
+ SAMPLE_TYPE_INFO *iter = sample_type_list, *next;
+
+ while (iter) {
+ next = iter->next;
+ free(iter->ext);
+ free(iter);
+ iter = next;
+ }
+
+ sample_type_list = NULL;
+
+ /* If we are using a destructor, then we only want to prune the list
+ * down to valid modules. So we clean up as usual, but then reinstall
+ * the internal modules.
+ */
+ #if defined(CONSTRUCTOR_FUNCTION) && defined(DESTRUCTOR_FUNCTION)
+ _register_sample_file_type_init();
+ #endif
+
+ _remove_exit_func(register_sample_file_type_exit);
+}
+
+
+
+/* _register_sample_file_type_init:
+ * Register built-in sample file types.
+ */
+void _register_sample_file_type_init(void)
+{
+ char buf[32];
+
+ _add_exit_func(register_sample_file_type_exit);
+
+ register_sample_file_type(uconvert_ascii("wav", buf), load_wav, NULL);
+ register_sample_file_type(uconvert_ascii("voc", buf), load_voc, NULL);
+}
+
+
+
+#if (defined CONSTRUCTOR_FUNCTION) && (defined DESTRUCTOR_FUNCTION)
+ CONSTRUCTOR_FUNCTION(static void sample_filetype_constructor());
+ DESTRUCTOR_FUNCTION(static void sample_filetype_destructor());
+
+ /* sample_filetype_constructor:
+ * Register sample filetype functions if this object file is linked
+ * in. This isn't called if the load_sample() and save_sample()
+ * functions aren't used in a program, thus saving a little space
+ * in statically linked programs.
+ */
+ static void sample_filetype_constructor()
+ {
+ _register_sample_file_type_init();
+ }
+
+ /* sample_filetype_destructor:
+ * Since we only want to destroy the whole list when we *actually*
+ * quit, not just when allegro_exit() is called, we need to use a
+ * destructor to accomplish this.
+ */
+ static void sample_filetype_destructor()
+ {
+ SAMPLE_TYPE_INFO *iter = sample_type_list, *next;
+
+ while (iter) {
+ next = iter->next;
+ free(iter->ext);
+ free(iter);
+ iter = next;
+ }
+
+ sample_type_list = NULL;
+
+ _remove_exit_func(register_sample_file_type_exit);
+ }
+#endif
--- ./include/allegro/internal/aintern.h.sample Mon Jul 22 22:27:00 2002
+++ ./include/allegro/internal/aintern.h Mon Jul 22 22:27:18 2002
@@ -1123,6 +1123,9 @@
/* for readbmp.c */
AL_FUNC(void, _register_bitmap_file_type_init, (void));
+/* for readsmp.c */
+AL_FUNC(void, _register_sample_file_type_init, (void));
+
/* for module linking system; see comment in allegro.c */
struct _AL_LINKER_MIDI
--- ./include/allegro/digi.h.sample Mon Jul 22 22:05:29 2002
+++ ./include/allegro/digi.h Mon Jul 22 22:05:31 2002
@@ -201,6 +201,8 @@
AL_FUNC(void, lock_sample, (struct SAMPLE *spl));
+AL_FUNC(void, register_sample_file_type, (AL_CONST char *ext, AL_METHOD(struct SAMPLE *, load, (AL_CONST char *filename)), AL_METHOD(int, save, (AL_CONST char *filename, struct SAMPLE *smp))));
+
#ifdef __cplusplus
}
#endif
--- ./src/allegro.c.sample Mon Jul 22 22:08:27 2002
+++ ./src/allegro.c Mon Jul 22 22:08:46 2002
@@ -282,8 +282,10 @@
_midi_constructor();
_mouse_constructor();
_register_bitmap_file_type_init();
+ _register_sample_file_type_init();
#else
#ifndef DESTRUCTOR_FUNCTION
+ _register_sample_file_type_init();
_register_bitmap_file_type_init();
#endif
#endif
--- ./src/sound.c.sample Mon Jul 22 22:22:33 2002
+++ ./src/sound.c Mon Jul 22 22:22:51 2002
@@ -772,23 +772,6 @@
-/* load_sample:
- * Loads a sample from disk.
- */
-SAMPLE *load_sample(AL_CONST char *filename)
-{
- char tmp[32];
-
- if (ustricmp(get_extension(filename), uconvert_ascii("wav", tmp)) == 0)
- return load_wav(filename);
- else if (ustricmp(get_extension(filename), uconvert_ascii("voc", tmp)) == 0)
- return load_voc(filename);
- else
- return NULL;
-}
-
-
-
/* load_voc:
* Reads a mono VOC format sample file, returning a SAMPLE structure,
* or NULL on error.
--- ./makefile.lst.sample Mon Jul 22 22:23:05 2002
+++ ./makefile.lst Mon Jul 22 22:23:12 2002
@@ -44,6 +44,7 @@
src/quantize.c \
src/quat.c \
src/readbmp.c \
+ src/readsmp.c \
src/rgblp15.c \
src/rgblp16.c \
src/rgblp24.c \
|