annotate decoders/mod.c @ 94:230f75fac1d1

Changed comment regarding "the mikmod directory".
author Ryan C. Gordon <icculus@icculus.org>
date Tue, 02 Oct 2001 17:22:07 +0000
parents 6252979e2453
children 6d9fdec2f708
rev   line source
43
e5082972f9bc Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1 /*
e5082972f9bc Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
2 * SDL_sound -- An abstract sound format decoding API.
e5082972f9bc Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
3 * Copyright (C) 2001 Ryan C. Gordon.
e5082972f9bc Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
4 *
e5082972f9bc Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
5 * This library is free software; you can redistribute it and/or
e5082972f9bc Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
6 * modify it under the terms of the GNU Lesser General Public
e5082972f9bc Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
7 * License as published by the Free Software Foundation; either
e5082972f9bc Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
8 * version 2.1 of the License, or (at your option) any later version.
e5082972f9bc Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
9 *
e5082972f9bc Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
10 * This library is distributed in the hope that it will be useful,
e5082972f9bc Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
e5082972f9bc Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
e5082972f9bc Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
13 * Lesser General Public License for more details.
e5082972f9bc Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
14 *
e5082972f9bc Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
15 * You should have received a copy of the GNU Lesser General Public
e5082972f9bc Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
16 * License along with this library; if not, write to the Free Software
e5082972f9bc Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
e5082972f9bc Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
18 */
e5082972f9bc Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
19
e5082972f9bc Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
20 /*
e5082972f9bc Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
21 * Module player - through MikMod - for SDL_sound.
e5082972f9bc Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
22 *
e5082972f9bc Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
23 * This driver handles anything our subset of MikMod handles. It is based on
e5082972f9bc Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
24 * SDL_mixer's MikMod music player.
e5082972f9bc Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
25 *
94
230f75fac1d1 Changed comment regarding "the mikmod directory".
Ryan C. Gordon <icculus@icculus.org>
parents: 92
diff changeset
26 * Please see the file LICENSE in the source's root directory.
43
e5082972f9bc Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
27 *
e5082972f9bc Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
28 * This file written by Torbjörn Andersson (d91tan@Update.UU.SE)
e5082972f9bc Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
29 */
e5082972f9bc Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
30
64
40006625142a Changes in preparation of autoconf support.
Ryan C. Gordon <icculus@icculus.org>
parents: 62
diff changeset
31 #ifdef SOUND_SUPPORTS_MOD
40006625142a Changes in preparation of autoconf support.
Ryan C. Gordon <icculus@icculus.org>
parents: 62
diff changeset
32
43
e5082972f9bc Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
33 #include <stdio.h>
e5082972f9bc Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
34 #include <stdlib.h>
e5082972f9bc Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
35 #include <string.h>
e5082972f9bc Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
36 #include <assert.h>
e5082972f9bc Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
37 #include "SDL_sound.h"
e5082972f9bc Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
38 #include "mikmod.h"
e5082972f9bc Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
39
e5082972f9bc Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
40 #define __SDL_SOUND_INTERNAL__
e5082972f9bc Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
41 #include "SDL_sound_internal.h"
e5082972f9bc Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
42
e5082972f9bc Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
43 static int MOD_init(void);
e5082972f9bc Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
44 static void MOD_quit(void);
e5082972f9bc Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
45 static int MOD_open(Sound_Sample *sample, const char *ext);
e5082972f9bc Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
46 static void MOD_close(Sound_Sample *sample);
e5082972f9bc Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
47 static Uint32 MOD_read(Sound_Sample *sample);
e5082972f9bc Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
48
e5082972f9bc Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
49 const Sound_DecoderFunctions __Sound_DecoderFunctions_MOD =
e5082972f9bc Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
50 {
e5082972f9bc Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
51 {
e5082972f9bc Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
52 "MOD",
e5082972f9bc Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
53 "Play modules through MikMod",
e5082972f9bc Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
54 "Torbjörn Andersson <d91tan@Update.UU.SE>",
e5082972f9bc Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
55 "http://www.mikmod.org/"
e5082972f9bc Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
56 },
e5082972f9bc Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
57
e5082972f9bc Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
58 MOD_init, /* init() method */
e5082972f9bc Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
59 MOD_quit, /* quit() method */
e5082972f9bc Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
60 MOD_open, /* open() method */
e5082972f9bc Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
61 MOD_close, /* close() method */
e5082972f9bc Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
62 MOD_read /* read() method */
e5082972f9bc Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
63 };
e5082972f9bc Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
64
e5082972f9bc Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
65 /* this is what we store in our internal->decoder_private field... */
e5082972f9bc Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
66 typedef struct {
e5082972f9bc Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
67 MODULE *module;
e5082972f9bc Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
68 } mod_t;
e5082972f9bc Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
69
e5082972f9bc Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
70
e5082972f9bc Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
71 /* Make MikMod read from a RWops... */
e5082972f9bc Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
72
e5082972f9bc Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
73 typedef struct MRWOPSREADER {
e5082972f9bc Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
74 MREADER core;
e5082972f9bc Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
75 Sound_Sample *sample;
e5082972f9bc Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
76 int end;
e5082972f9bc Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
77 } MRWOPSREADER;
e5082972f9bc Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
78
e5082972f9bc Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
79 static BOOL _mm_RWopsReader_eof(MREADER *reader)
e5082972f9bc Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
80 {
e5082972f9bc Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
81 MRWOPSREADER *rwops_reader = (MRWOPSREADER *) reader;
e5082972f9bc Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
82 Sound_Sample *sample = rwops_reader->sample;
e5082972f9bc Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
83 Sound_SampleInternal *internal = (Sound_SampleInternal *) sample->opaque;
e5082972f9bc Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
84 int pos = SDL_RWtell(internal->rw);
e5082972f9bc Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
85
e5082972f9bc Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
86 if (rwops_reader->end == pos)
e5082972f9bc Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
87 return(1);
e5082972f9bc Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
88
e5082972f9bc Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
89 return(0);
e5082972f9bc Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
90 } /* _mm_RWopsReader_eof */
e5082972f9bc Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
91
e5082972f9bc Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
92
e5082972f9bc Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
93 static BOOL _mm_RWopsReader_read(MREADER *reader, void *ptr, size_t size)
e5082972f9bc Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
94 {
e5082972f9bc Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
95 MRWOPSREADER *rwops_reader = (MRWOPSREADER *) reader;
e5082972f9bc Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
96 Sound_Sample *sample = rwops_reader->sample;
e5082972f9bc Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
97 Sound_SampleInternal *internal = (Sound_SampleInternal *) sample->opaque;
e5082972f9bc Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
98 return(SDL_RWread(internal->rw, ptr, size, 1));
e5082972f9bc Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
99 } /* _mm_RWopsReader_Read */
e5082972f9bc Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
100
e5082972f9bc Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
101
e5082972f9bc Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
102 static int _mm_RWopsReader_get(MREADER *reader)
e5082972f9bc Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
103 {
e5082972f9bc Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
104 char buf;
e5082972f9bc Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
105 MRWOPSREADER *rwops_reader = (MRWOPSREADER *) reader;
e5082972f9bc Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
106 Sound_Sample *sample = rwops_reader->sample;
e5082972f9bc Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
107 Sound_SampleInternal *internal = (Sound_SampleInternal *) sample->opaque;
e5082972f9bc Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
108
e5082972f9bc Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
109 if (SDL_RWread(internal->rw, &buf, 1, 1) != 1)
e5082972f9bc Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
110 return(EOF);
e5082972f9bc Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
111
e5082972f9bc Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
112 return((int) buf);
e5082972f9bc Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
113 } /* _mm_RWopsReader_get */
e5082972f9bc Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
114
e5082972f9bc Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
115
e5082972f9bc Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
116 static BOOL _mm_RWopsReader_seek(MREADER *reader, long offset, int whence)
e5082972f9bc Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
117 {
e5082972f9bc Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
118 MRWOPSREADER *rwops_reader = (MRWOPSREADER *) reader;
e5082972f9bc Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
119 Sound_Sample *sample = rwops_reader->sample;
e5082972f9bc Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
120 Sound_SampleInternal *internal = (Sound_SampleInternal *) sample->opaque;
e5082972f9bc Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
121
e5082972f9bc Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
122 return(SDL_RWseek(internal->rw, offset, whence));
e5082972f9bc Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
123 } /* _mm_RWopsReader_seek */
e5082972f9bc Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
124
e5082972f9bc Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
125
e5082972f9bc Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
126 static long _mm_RWopsReader_tell(MREADER *reader)
e5082972f9bc Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
127 {
e5082972f9bc Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
128 MRWOPSREADER *rwops_reader = (MRWOPSREADER *) reader;
e5082972f9bc Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
129 Sound_Sample *sample = rwops_reader->sample;
e5082972f9bc Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
130 Sound_SampleInternal *internal = (Sound_SampleInternal *) sample->opaque;
e5082972f9bc Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
131
e5082972f9bc Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
132 return(SDL_RWtell(internal->rw));
e5082972f9bc Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
133 } /* _mm_RWopsReader_tell */
e5082972f9bc Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
134
e5082972f9bc Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
135
e5082972f9bc Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
136 static MREADER *_mm_new_rwops_reader(Sound_Sample *sample)
e5082972f9bc Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
137 {
e5082972f9bc Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
138 Sound_SampleInternal *internal = (Sound_SampleInternal *) sample->opaque;
e5082972f9bc Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
139
e5082972f9bc Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
140 MRWOPSREADER *reader = (MRWOPSREADER *) malloc(sizeof (MRWOPSREADER));
e5082972f9bc Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
141 if (reader != NULL)
e5082972f9bc Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
142 {
e5082972f9bc Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
143 int here;
e5082972f9bc Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
144 reader->core.Eof = _mm_RWopsReader_eof;
e5082972f9bc Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
145 reader->core.Read = _mm_RWopsReader_read;
e5082972f9bc Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
146 reader->core.Get = _mm_RWopsReader_get;
e5082972f9bc Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
147 reader->core.Seek = _mm_RWopsReader_seek;
e5082972f9bc Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
148 reader->core.Tell = _mm_RWopsReader_tell;
e5082972f9bc Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
149 reader->sample = sample;
e5082972f9bc Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
150
e5082972f9bc Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
151 /* RWops does not explicitly support an eof check, so we shall find
e5082972f9bc Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
152 the end manually - this requires seek support for the RWop */
e5082972f9bc Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
153 here = SDL_RWtell(internal->rw);
e5082972f9bc Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
154 reader->end = SDL_RWseek(internal->rw, 0, SEEK_END);
e5082972f9bc Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
155 SDL_RWseek(internal->rw, here, SEEK_SET); /* Move back */
e5082972f9bc Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
156 /* !!! FIXME: What happens if the seek fails? */
e5082972f9bc Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
157 } /* if */
e5082972f9bc Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
158
e5082972f9bc Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
159 return((MREADER *) reader);
e5082972f9bc Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
160 } /* _mm_new_rwops_reader */
e5082972f9bc Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
161
e5082972f9bc Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
162
e5082972f9bc Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
163 static void _mm_delete_rwops_reader(MREADER *reader)
e5082972f9bc Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
164 {
e5082972f9bc Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
165 /* SDL_sound will delete the RWops and sample at a higher level... */
e5082972f9bc Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
166 if (reader != NULL)
e5082972f9bc Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
167 free(reader);
e5082972f9bc Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
168 } /* _mm_delete_rwops_reader */
e5082972f9bc Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
169
e5082972f9bc Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
170
e5082972f9bc Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
171
e5082972f9bc Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
172 static int MOD_init(void)
e5082972f9bc Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
173 {
52
69d56e196de7 going with MikMod defaults (adds more reverb) and only register the "no
Ryan C. Gordon <icculus@icculus.org>
parents: 43
diff changeset
174 MikMod_RegisterDriver(&drv_nos);
43
e5082972f9bc Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
175 MikMod_RegisterAllLoaders();
e5082972f9bc Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
176
e5082972f9bc Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
177 /*
e5082972f9bc Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
178 * Both DMODE_SOFT_MUSIC and DMODE_16BITS should be set by default,
e5082972f9bc Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
179 * so this is just for clarity. I haven't experimented with any of
e5082972f9bc Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
180 * the other flags. There are a few which are said to give better
e5082972f9bc Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
181 * sound quality.
e5082972f9bc Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
182 */
e5082972f9bc Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
183 md_mode |= (DMODE_SOFT_MUSIC | DMODE_16BITS);
52
69d56e196de7 going with MikMod defaults (adds more reverb) and only register the "no
Ryan C. Gordon <icculus@icculus.org>
parents: 43
diff changeset
184
69d56e196de7 going with MikMod defaults (adds more reverb) and only register the "no
Ryan C. Gordon <icculus@icculus.org>
parents: 43
diff changeset
185 #if 0
43
e5082972f9bc Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
186 /*
e5082972f9bc Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
187 * SDL_mixer used to set these, but I don't know... is there
e5082972f9bc Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
188 * something wrong with the defaults? Actually, the only difference
e5082972f9bc Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
189 * from the defaults is md_reverb, which is usually 6.
e5082972f9bc Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
190 */
e5082972f9bc Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
191 md_device = 0; /* Selects sound driver. 0 = autodetect */
e5082972f9bc Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
192 md_volume = 96; /* Overall sound volume, 0 - 128 */
e5082972f9bc Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
193 md_musicvolume = 128; /* Module volume, 0 - 128 */
e5082972f9bc Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
194 md_sndfxvolume = 128; /* Sound effect volume, 0 - 128 */
e5082972f9bc Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
195 md_pansep = 128; /* Stereo channels separation, 0 - 128 */
e5082972f9bc Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
196 md_reverb = 0; /* Sound reverbation, 0 - 15 */
e5082972f9bc Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
197 #endif
e5082972f9bc Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
198
e5082972f9bc Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
199 BAIL_IF_MACRO(MikMod_Init(""), MikMod_strerror(MikMod_errno), 0);
e5082972f9bc Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
200
e5082972f9bc Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
201 return(1); /* success. */
e5082972f9bc Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
202 } /* MOD_init */
e5082972f9bc Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
203
e5082972f9bc Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
204
e5082972f9bc Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
205 static void MOD_quit(void)
e5082972f9bc Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
206 {
e5082972f9bc Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
207 MikMod_Exit();
e5082972f9bc Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
208 } /* MOD_quit */
e5082972f9bc Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
209
e5082972f9bc Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
210
e5082972f9bc Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
211 static int MOD_open(Sound_Sample *sample, const char *ext)
e5082972f9bc Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
212 {
e5082972f9bc Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
213 Sound_SampleInternal *internal = (Sound_SampleInternal *) sample->opaque;
e5082972f9bc Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
214 MREADER *reader;
e5082972f9bc Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
215 mod_t *m;
e5082972f9bc Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
216
e5082972f9bc Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
217 m = (mod_t *) malloc(sizeof(mod_t));
e5082972f9bc Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
218 BAIL_IF_MACRO(m == NULL, ERR_OUT_OF_MEMORY, 0);
e5082972f9bc Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
219 reader = _mm_new_rwops_reader(sample);
e5082972f9bc Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
220 BAIL_IF_MACRO(reader == NULL, ERR_OUT_OF_MEMORY, 0);
e5082972f9bc Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
221 m->module = Player_LoadGeneric(reader, 64, 0);
e5082972f9bc Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
222 _mm_delete_rwops_reader(reader);
e5082972f9bc Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
223 BAIL_IF_MACRO(m->module == NULL, "MOD: Not a module file.", 0);
e5082972f9bc Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
224
e5082972f9bc Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
225 md_mixfreq = sample->desired.rate;
e5082972f9bc Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
226 sample->actual.channels = 2;
e5082972f9bc Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
227 sample->actual.rate = md_mixfreq;
e5082972f9bc Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
228 sample->actual.format = AUDIO_S16SYS;
e5082972f9bc Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
229 internal->decoder_private = (void *) m;
e5082972f9bc Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
230
e5082972f9bc Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
231 Player_Start(m->module);
e5082972f9bc Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
232 Player_SetPosition(0);
e5082972f9bc Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
233
e5082972f9bc Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
234 /* !!! FIXME: A little late to be giving this information... */
e5082972f9bc Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
235 sample->flags = SOUND_SAMPLEFLAG_NEEDSEEK;
e5082972f9bc Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
236
62
b13fafb976be Changed _D macro to DBGSND.
Ryan C. Gordon <icculus@icculus.org>
parents: 52
diff changeset
237 SNDDBG(("MOD: Accepting data stream\n"));
43
e5082972f9bc Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
238 return(1); /* we'll handle this data. */
e5082972f9bc Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
239 } /* MOD_open */
e5082972f9bc Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
240
e5082972f9bc Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
241
e5082972f9bc Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
242 static void MOD_close(Sound_Sample *sample)
e5082972f9bc Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
243 {
e5082972f9bc Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
244 Sound_SampleInternal *internal = (Sound_SampleInternal *) sample->opaque;
e5082972f9bc Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
245 mod_t *m = (mod_t *) internal->decoder_private;
e5082972f9bc Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
246
e5082972f9bc Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
247 Player_Free(m->module);
92
6252979e2453 Fixed a memory leak in the close() method.
Ryan C. Gordon <icculus@icculus.org>
parents: 64
diff changeset
248 free(m);
43
e5082972f9bc Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
249 } /* MOD_close */
e5082972f9bc Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
250
e5082972f9bc Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
251
e5082972f9bc Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
252 static Uint32 MOD_read(Sound_Sample *sample)
e5082972f9bc Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
253 {
e5082972f9bc Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
254 Sound_SampleInternal *internal = (Sound_SampleInternal *) sample->opaque;
e5082972f9bc Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
255 mod_t *m = (mod_t *) internal->decoder_private;
e5082972f9bc Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
256
e5082972f9bc Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
257 /* Switch to the current module, stopping any previous one. */
e5082972f9bc Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
258 Player_Start(m->module);
e5082972f9bc Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
259 if (!Player_Active())
e5082972f9bc Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
260 {
e5082972f9bc Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
261 sample->flags |= SOUND_SAMPLEFLAG_EOF;
e5082972f9bc Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
262 return(0);
e5082972f9bc Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
263 } /* if */
e5082972f9bc Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
264 return((Uint32) VC_WriteBytes(internal->buffer, internal->buffer_size));
e5082972f9bc Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
265 } /* MOD_read */
e5082972f9bc Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
266
64
40006625142a Changes in preparation of autoconf support.
Ryan C. Gordon <icculus@icculus.org>
parents: 62
diff changeset
267 #endif /* SOUND_SUPPORTS_MOD */
40006625142a Changes in preparation of autoconf support.
Ryan C. Gordon <icculus@icculus.org>
parents: 62
diff changeset
268
43
e5082972f9bc Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
269
e5082972f9bc Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
270 /* end of mod.c ... */
e5082972f9bc Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
271