annotate decoders/modplug.c @ 208:32376317eedb

Initial adds.
author Ryan C. Gordon <icculus@icculus.org>
date Thu, 10 Jan 2002 01:16:24 +0000
parents
children b35c04e4691e
rev   line source
208
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1 /*
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
2 * SDL_sound -- An abstract sound format decoding API.
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
3 * Copyright (C) 2001 Ryan C. Gordon.
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
4 *
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
5 * This library is free software; you can redistribute it and/or
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
6 * modify it under the terms of the GNU Lesser General Public
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
7 * License as published by the Free Software Foundation; either
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
8 * version 2.1 of the License, or (at your option) any later version.
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
9 *
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
10 * This library is distributed in the hope that it will be useful,
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
13 * Lesser General Public License for more details.
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
14 *
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
15 * You should have received a copy of the GNU Lesser General Public
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
16 * License along with this library; if not, write to the Free Software
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
18 */
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
19
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
20 /*
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
21 * Module player for SDL_sound. This driver handles anything that ModPlug does.
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
22 *
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
23 * Please see the file COPYING in the source's root directory.
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
24 *
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
25 * This file written by Torbjörn Andersson (d91tan@Update.UU.SE)
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
26 */
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
27
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
28 #if HAVE_CONFIG_H
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
29 # include <config.h>
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
30 #endif
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
31
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
32 #ifdef SOUND_SUPPORTS_MODPLUG
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
33
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
34 #include <stdio.h>
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
35 #include <stdlib.h>
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
36 #include <string.h>
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
37 #include <assert.h>
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
38
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
39 #include "SDL_sound.h"
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
40
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
41 #define __SDL_SOUND_INTERNAL__
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
42 #include "SDL_sound_internal.h"
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
43
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
44 #include "modplug.h"
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
45
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
46
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
47 static int MODPLUG_init(void);
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
48 static void MODPLUG_quit(void);
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
49 static int MODPLUG_open(Sound_Sample *sample, const char *ext);
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
50 static void MODPLUG_close(Sound_Sample *sample);
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
51 static Uint32 MODPLUG_read(Sound_Sample *sample);
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
52
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
53 static const char *extensions_modplug[] =
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
54 {
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
55 /* Plays 22 different mod formats (there are two kinds of AMF), including:
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
56 */
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
57 "MOD", "S3M", "XM", "IT", "669", "AMF", "AMS", "DMB",
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
58 "DMF", "DSM", "FAR", "MDL", "MED", "MHM", "OKT", "PTM",
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
59 "STM", "ULT", "UMX", "MT2", "PSM",
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
60
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
61 /* Plays zip, rar, gzip, and bzip2 compressed mods. The following
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
62 * extensions are recognized:
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
63 */
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
64 "MDZ", "S3Z", "XMZ", "ITZ", /* zip */
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
65 "MDR", "S3R", "XMR", "ITR", /* rar */
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
66 "MDGZ", "S3GZ", "XMGZ", "ITGZ", /* gzip */
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
67
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
68 /* You can also load plain old ZIP, RAR, and GZ files. If ModPlug finds
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
69 * a mod in them, it will play it.
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
70 */
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
71 #if 0
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
72 "ZIP", "RAR", "GZ",
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
73 #endif
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
74
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
75 NULL
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
76 };
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
77
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
78 const Sound_DecoderFunctions __Sound_DecoderFunctions_MODPLUG =
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
79 {
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
80 {
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
81 extensions_modplug,
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
82 "Play modules through ModPlug",
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
83 "Torbjörn Andersson <d91tan@Update.UU.SE>",
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
84 "http://modplug-xmms.sourceforge.net/"
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
85 },
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
86
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
87 MODPLUG_init, /* init() method */
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
88 MODPLUG_quit, /* quit() method */
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
89 MODPLUG_open, /* open() method */
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
90 MODPLUG_close, /* close() method */
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
91 MODPLUG_read /* read() method */
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
92 };
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
93
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
94
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
95 static int MODPLUG_init(void)
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
96 {
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
97 ModPlug_Settings settings;
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
98
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
99 /* The settings will require some experimenting. I've borrowed some
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
100 * of them from the XMMS ModPlug plugin.
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
101 */
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
102 settings.mFlags =
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
103 MODPLUG_ENABLE_OVERSAMPLING
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
104 | MODPLUG_ENABLE_NOISE_REDUCTION
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
105 | MODPLUG_ENABLE_REVERB
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
106 | MODPLUG_ENABLE_MEGABASS
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
107 | MODPLUG_ENABLE_SURROUND;
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
108 settings.mChannels = 2;
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
109 settings.mBits = 16;
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
110 settings.mFrequency = 44100;
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
111 settings.mResamplingMode = MODPLUG_RESAMPLE_FIR;
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
112 settings.mReverbDepth = 30;
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
113 settings.mReverbDelay = 100;
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
114 settings.mBassAmount = 40;
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
115 settings.mBassRange = 30;
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
116 settings.mSurroundDepth = 20;
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
117 settings.mSurroundDelay = 20;
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
118 settings.mLoopCount = 0;
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
119
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
120 ModPlug_SetSettings(&settings);
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
121 return(1); /* success. */
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
122 } /* MODPLUG_init */
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
123
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
124
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
125 static void MODPLUG_quit(void)
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
126 {
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
127 } /* MODPLUG_quit */
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
128
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
129
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
130 /* Most MOD files I've seen have tended to be a few hundred KB, even if some
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
131 * of them were much smaller than that.
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
132 */
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
133 #define CHUNK_SIZE 65536
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
134
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
135 static int MODPLUG_open(Sound_Sample *sample, const char *ext)
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
136 {
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
137 Sound_SampleInternal *internal = (Sound_SampleInternal *) sample->opaque;
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
138 ModPlugFile *module;
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
139 Uint8 *data;
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
140 size_t size;
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
141 Uint32 retval;
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
142
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
143 /* ModPlug needs the entire stream in one big chunk. I don't like it,
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
144 * but I don't think there's any way around it.
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
145 */
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
146 data = (Uint8 *) malloc(CHUNK_SIZE);
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
147 BAIL_IF_MACRO(data == NULL, ERR_OUT_OF_MEMORY, 0);
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
148 size = 0;
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
149
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
150 do
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
151 {
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
152 retval = SDL_RWread(internal->rw, &data[size], 1, CHUNK_SIZE);
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
153 size += retval;
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
154 if (retval == CHUNK_SIZE)
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
155 {
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
156 data = (Uint8 *) realloc(data, size + CHUNK_SIZE);
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
157 BAIL_IF_MACRO(data == NULL, ERR_OUT_OF_MEMORY, 0);
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
158 } /* if */
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
159 } while (retval > 0);
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
160
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
161 /* The buffer may be a bit too large, but that doesn't matter. I think
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
162 * it's safe to free it as soon as ModPlug_Load() is finished anyway.
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
163 */
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
164 module = ModPlug_Load((void *) data, size);
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
165 free(data);
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
166 BAIL_IF_MACRO(module == NULL, "MODPLUG: Not a module file.", 0);
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
167
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
168 SNDDBG(("MODPLUG: [%d ms] %s\n",
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
169 ModPlug_GetLength(module), ModPlug_GetName(module)));
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
170
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
171 sample->actual.channels = 2;
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
172 sample->actual.rate = 44100;
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
173 sample->actual.format = AUDIO_S16SYS;
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
174
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
175 internal->decoder_private = (void *) module;
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
176 sample->flags = SOUND_SAMPLEFLAG_NONE;
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
177
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
178 SNDDBG(("MODPLUG: Accepting data stream\n"));
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
179 return(1); /* we'll handle this data. */
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
180 } /* MODPLUG_open */
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
181
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
182
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
183 static void MODPLUG_close(Sound_Sample *sample)
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
184 {
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
185 Sound_SampleInternal *internal = (Sound_SampleInternal *) sample->opaque;
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
186 ModPlugFile *module = (ModPlugFile *) internal->decoder_private;
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
187
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
188 ModPlug_Unload(module);
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
189 } /* MODPLUG_close */
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
190
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
191
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
192 static Uint32 MODPLUG_read(Sound_Sample *sample)
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
193 {
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
194 Sound_SampleInternal *internal = (Sound_SampleInternal *) sample->opaque;
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
195 ModPlugFile *module = (ModPlugFile *) internal->decoder_private;
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
196 int retval;
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
197
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
198 retval = ModPlug_Read(module, internal->buffer, internal->buffer_size);
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
199 if (retval == 0)
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
200 sample->flags |= SOUND_SAMPLEFLAG_EOF;
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
201 return(retval);
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
202 } /* MODPLUG_read */
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
203
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
204 #endif /* SOUND_SUPPORTS_MODPLUG */
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
205
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
206
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
207 /* end of modplug.c ... */