gosu 0.15.2 → 1.1.0.pre2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/dependencies/SDL/include/SDL.h +138 -0
- data/dependencies/SDL/include/SDL_assert.h +293 -0
- data/dependencies/SDL/include/SDL_atomic.h +295 -0
- data/dependencies/SDL/include/SDL_audio.h +859 -0
- data/dependencies/SDL/include/SDL_bits.h +121 -0
- data/dependencies/SDL/include/SDL_blendmode.h +123 -0
- data/dependencies/SDL/include/SDL_clipboard.h +71 -0
- data/dependencies/SDL/include/SDL_config.h +55 -0
- data/dependencies/SDL/include/SDL_config_android.h +182 -0
- data/dependencies/SDL/include/SDL_config_iphoneos.h +207 -0
- data/dependencies/SDL/include/SDL_config_macosx.h +266 -0
- data/dependencies/SDL/include/SDL_config_minimal.h +85 -0
- data/dependencies/SDL/include/SDL_config_os2.h +188 -0
- data/dependencies/SDL/include/SDL_config_pandora.h +135 -0
- data/dependencies/SDL/include/SDL_config_psp.h +165 -0
- data/dependencies/SDL/include/SDL_config_windows.h +288 -0
- data/dependencies/SDL/include/SDL_config_winrt.h +243 -0
- data/dependencies/SDL/include/SDL_config_wiz.h +149 -0
- data/dependencies/SDL/include/SDL_copying.h +20 -0
- data/dependencies/SDL/include/SDL_cpuinfo.h +299 -0
- data/dependencies/SDL/include/SDL_egl.h +1676 -0
- data/dependencies/SDL/include/SDL_endian.h +263 -0
- data/dependencies/SDL/include/SDL_error.h +112 -0
- data/dependencies/SDL/include/SDL_events.h +827 -0
- data/dependencies/SDL/include/SDL_filesystem.h +136 -0
- data/dependencies/SDL/include/SDL_gamecontroller.h +541 -0
- data/dependencies/SDL/include/SDL_gesture.h +87 -0
- data/dependencies/SDL/include/SDL_haptic.h +1247 -0
- data/dependencies/SDL/include/SDL_hints.h +1578 -0
- data/dependencies/SDL/include/SDL_joystick.h +499 -0
- data/dependencies/SDL/include/SDL_keyboard.h +217 -0
- data/dependencies/SDL/include/SDL_keycode.h +351 -0
- data/dependencies/SDL/include/SDL_loadso.h +81 -0
- data/dependencies/SDL/include/SDL_locale.h +101 -0
- data/dependencies/SDL/include/SDL_log.h +211 -0
- data/dependencies/SDL/include/SDL_main.h +180 -0
- data/dependencies/SDL/include/SDL_messagebox.h +146 -0
- data/dependencies/SDL/include/SDL_metal.h +117 -0
- data/dependencies/SDL/include/SDL_misc.h +75 -0
- data/dependencies/SDL/include/SDL_mouse.h +302 -0
- data/dependencies/SDL/include/SDL_mutex.h +251 -0
- data/dependencies/SDL/include/SDL_name.h +33 -0
- data/dependencies/SDL/include/SDL_opengl.h +2183 -0
- data/dependencies/SDL/include/SDL_opengl_glext.h +11180 -0
- data/dependencies/SDL/include/SDL_opengles.h +39 -0
- data/dependencies/SDL/include/SDL_opengles2.h +52 -0
- data/dependencies/SDL/include/SDL_opengles2_gl2.h +621 -0
- data/dependencies/SDL/include/SDL_opengles2_gl2ext.h +2050 -0
- data/dependencies/SDL/include/SDL_opengles2_gl2platform.h +30 -0
- data/dependencies/SDL/include/SDL_opengles2_khrplatform.h +282 -0
- data/dependencies/SDL/include/SDL_pixels.h +479 -0
- data/dependencies/SDL/include/SDL_platform.h +198 -0
- data/dependencies/SDL/include/SDL_power.h +75 -0
- data/dependencies/SDL/include/SDL_quit.h +58 -0
- data/dependencies/SDL/include/SDL_rect.h +174 -0
- data/dependencies/SDL/include/SDL_render.h +1158 -0
- data/dependencies/SDL/include/SDL_revision.h +2 -0
- data/dependencies/SDL/include/SDL_rwops.h +283 -0
- data/dependencies/SDL/include/SDL_scancode.h +413 -0
- data/dependencies/SDL/include/SDL_sensor.h +267 -0
- data/dependencies/SDL/include/SDL_shape.h +144 -0
- data/dependencies/SDL/include/SDL_stdinc.h +647 -0
- data/dependencies/SDL/include/SDL_surface.h +563 -0
- data/dependencies/SDL/include/SDL_system.h +325 -0
- data/dependencies/SDL/include/SDL_syswm.h +354 -0
- data/dependencies/SDL/include/SDL_test.h +69 -0
- data/dependencies/SDL/include/SDL_test_assert.h +105 -0
- data/dependencies/SDL/include/SDL_test_common.h +218 -0
- data/dependencies/SDL/include/SDL_test_compare.h +69 -0
- data/dependencies/SDL/include/SDL_test_crc32.h +124 -0
- data/dependencies/SDL/include/SDL_test_font.h +81 -0
- data/dependencies/SDL/include/SDL_test_fuzzer.h +384 -0
- data/dependencies/SDL/include/SDL_test_harness.h +134 -0
- data/dependencies/SDL/include/SDL_test_images.h +78 -0
- data/dependencies/SDL/include/SDL_test_log.h +67 -0
- data/dependencies/SDL/include/SDL_test_md5.h +129 -0
- data/dependencies/SDL/include/SDL_test_memory.h +63 -0
- data/dependencies/SDL/include/SDL_test_random.h +115 -0
- data/dependencies/SDL/include/SDL_thread.h +366 -0
- data/dependencies/SDL/include/SDL_timer.h +115 -0
- data/dependencies/SDL/include/SDL_touch.h +102 -0
- data/dependencies/SDL/include/SDL_types.h +29 -0
- data/dependencies/SDL/include/SDL_version.h +162 -0
- data/dependencies/SDL/include/SDL_video.h +1282 -0
- data/dependencies/SDL/include/SDL_vulkan.h +276 -0
- data/dependencies/SDL/include/begin_code.h +166 -0
- data/dependencies/SDL/include/close_code.h +40 -0
- data/dependencies/SDL/lib/x64/libSDL2.dll.a +0 -0
- data/dependencies/SDL/lib/x86/libSDL2.dll.a +0 -0
- data/dependencies/SDL_sound/SDL_sound.c +795 -0
- data/dependencies/SDL_sound/SDL_sound.h +725 -0
- data/dependencies/SDL_sound/SDL_sound_aiff.c +537 -0
- data/dependencies/SDL_sound/SDL_sound_au.c +352 -0
- data/dependencies/SDL_sound/SDL_sound_coreaudio.c +747 -0
- data/dependencies/SDL_sound/SDL_sound_flac.c +182 -0
- data/dependencies/SDL_sound/SDL_sound_internal.h +304 -0
- data/dependencies/SDL_sound/SDL_sound_modplug.c +228 -0
- data/dependencies/SDL_sound/SDL_sound_mp3.c +184 -0
- data/dependencies/SDL_sound/SDL_sound_raw.c +164 -0
- data/dependencies/SDL_sound/SDL_sound_shn.c +1309 -0
- data/dependencies/SDL_sound/SDL_sound_voc.c +550 -0
- data/dependencies/SDL_sound/SDL_sound_vorbis.c +223 -0
- data/dependencies/SDL_sound/SDL_sound_wav.c +783 -0
- data/dependencies/SDL_sound/dr_flac.h +5906 -0
- data/dependencies/SDL_sound/dr_mp3.h +2832 -0
- data/dependencies/SDL_sound/libmodplug/fastmix.c +1748 -0
- data/dependencies/SDL_sound/libmodplug/libmodplug.h +1001 -0
- data/dependencies/SDL_sound/libmodplug/load_669.c +188 -0
- data/dependencies/SDL_sound/libmodplug/load_abc.c +4725 -0
- data/dependencies/SDL_sound/libmodplug/load_amf.c +403 -0
- data/dependencies/SDL_sound/libmodplug/load_ams.c +587 -0
- data/dependencies/SDL_sound/libmodplug/load_dbm.c +357 -0
- data/dependencies/SDL_sound/libmodplug/load_dmf.c +531 -0
- data/dependencies/SDL_sound/libmodplug/load_dsm.c +232 -0
- data/dependencies/SDL_sound/libmodplug/load_far.c +253 -0
- data/dependencies/SDL_sound/libmodplug/load_it.c +796 -0
- data/dependencies/SDL_sound/libmodplug/load_mdl.c +488 -0
- data/dependencies/SDL_sound/libmodplug/load_med.c +757 -0
- data/dependencies/SDL_sound/libmodplug/load_mid.c +1405 -0
- data/dependencies/SDL_sound/libmodplug/load_mod.c +269 -0
- data/dependencies/SDL_sound/libmodplug/load_mt2.c +546 -0
- data/dependencies/SDL_sound/libmodplug/load_mtm.c +142 -0
- data/dependencies/SDL_sound/libmodplug/load_okt.c +192 -0
- data/dependencies/SDL_sound/libmodplug/load_pat.c +1143 -0
- data/dependencies/SDL_sound/libmodplug/load_pat.h +25 -0
- data/dependencies/SDL_sound/libmodplug/load_psm.c +350 -0
- data/dependencies/SDL_sound/libmodplug/load_ptm.c +204 -0
- data/dependencies/SDL_sound/libmodplug/load_s3m.c +325 -0
- data/dependencies/SDL_sound/libmodplug/load_stm.c +180 -0
- data/dependencies/SDL_sound/libmodplug/load_ult.c +206 -0
- data/dependencies/SDL_sound/libmodplug/load_umx.c +51 -0
- data/dependencies/SDL_sound/libmodplug/load_xm.c +554 -0
- data/dependencies/SDL_sound/libmodplug/mmcmp.c +382 -0
- data/dependencies/SDL_sound/libmodplug/modplug.c +170 -0
- data/dependencies/SDL_sound/libmodplug/modplug.h +90 -0
- data/dependencies/SDL_sound/libmodplug/snd_dsp.c +301 -0
- data/dependencies/SDL_sound/libmodplug/snd_flt.c +63 -0
- data/dependencies/SDL_sound/libmodplug/snd_fx.c +2350 -0
- data/dependencies/SDL_sound/libmodplug/sndfile.c +1169 -0
- data/dependencies/SDL_sound/libmodplug/sndmix.c +1034 -0
- data/dependencies/SDL_sound/libmodplug/tables.h +371 -0
- data/{src/stb_vorbis.c → dependencies/SDL_sound/stb_vorbis.h} +143 -78
- data/dependencies/al_soft/AL/al.h +655 -0
- data/dependencies/al_soft/AL/alc.h +270 -0
- data/dependencies/al_soft/AL/alext.h +585 -0
- data/dependencies/al_soft/AL/efx-creative.h +3 -0
- data/dependencies/al_soft/AL/efx-presets.h +402 -0
- data/dependencies/al_soft/AL/efx.h +762 -0
- data/dependencies/al_soft/x64/libOpenAL32.dll.a +0 -0
- data/dependencies/al_soft/x86/libOpenAL32.dll.a +0 -0
- data/{src → dependencies/stb}/stb_image.h +330 -127
- data/{src → dependencies/stb}/stb_image_write.h +156 -85
- data/{src → dependencies/stb}/stb_truetype.h +192 -69
- data/{src → dependencies/utf8proc}/utf8proc.c +0 -0
- data/{src → dependencies/utf8proc}/utf8proc.h +0 -0
- data/{src → dependencies/utf8proc}/utf8proc_data.h +0 -0
- data/ext/gosu/extconf.rb +53 -39
- data/{Gosu → include/Gosu}/Audio.hpp +6 -8
- data/include/Gosu/Bitmap.hpp +100 -0
- data/{Gosu → include/Gosu}/Buttons.hpp +104 -44
- data/{Gosu → include/Gosu}/Color.hpp +0 -0
- data/{Gosu → include/Gosu}/Directories.hpp +0 -0
- data/{Gosu → include/Gosu}/Font.hpp +1 -1
- data/{Gosu → include/Gosu}/Fwd.hpp +0 -5
- data/{Gosu → include/Gosu}/Gosu.hpp +0 -0
- data/{Gosu → include/Gosu}/Graphics.hpp +0 -0
- data/{Gosu → include/Gosu}/GraphicsBase.hpp +0 -0
- data/{Gosu → include/Gosu}/IO.hpp +0 -0
- data/{Gosu → include/Gosu}/Image.hpp +7 -6
- data/{Gosu → include/Gosu}/ImageData.hpp +0 -0
- data/{Gosu → include/Gosu}/Input.hpp +39 -51
- data/{Gosu → include/Gosu}/Inspection.hpp +0 -0
- data/{Gosu → include/Gosu}/Math.hpp +0 -0
- data/{Gosu → include/Gosu}/Platform.hpp +0 -0
- data/{Gosu → include/Gosu}/Text.hpp +0 -0
- data/{Gosu → include/Gosu}/TextInput.hpp +0 -0
- data/{Gosu → include/Gosu}/Timing.hpp +0 -0
- data/{Gosu → include/Gosu}/Utility.hpp +15 -4
- data/{Gosu → include/Gosu}/Version.hpp +3 -3
- data/{Gosu → include/Gosu}/Window.hpp +46 -34
- data/lib/OpenAL32.dll +0 -0
- data/lib/SDL2.dll +0 -0
- data/lib/gosu.rb +0 -3
- data/lib/gosu/patches.rb +0 -23
- data/lib/gosu/preview.rb +1 -3
- data/lib/gosu/swig_patches.rb +14 -12
- data/lib64/OpenAL32.dll +0 -0
- data/lib64/SDL2.dll +0 -0
- data/rdoc/gosu.rb +112 -23
- data/src/Audio.cpp +50 -224
- data/src/AudioFile.hpp +20 -37
- data/src/AudioFileAudioToolbox.cpp +237 -0
- data/src/AudioFileSDLSound.cpp +147 -0
- data/src/AudioImpl.cpp +3 -12
- data/src/AudioImpl.hpp +3 -1
- data/src/Bitmap.cpp +85 -83
- data/src/BitmapIO.cpp +52 -58
- data/src/Font.cpp +3 -1
- data/src/Graphics.cpp +7 -4
- data/src/Image.cpp +13 -16
- data/src/Input.cpp +412 -164
- data/src/LargeImageData.cpp +1 -1
- data/src/MarkupParser.cpp +2 -1
- data/src/Resolution.cpp +8 -8
- data/src/RubyGosu.cxx +1017 -196
- data/src/RubyGosu.h +4 -2
- data/src/TexChunk.cpp +1 -1
- data/src/TextBuilder.cpp +3 -1
- data/src/Texture.cpp +1 -1
- data/src/TrueTypeFont.cpp +1 -1
- data/src/TrueTypeFontWin.cpp +3 -3
- data/src/Utility.cpp +11 -7
- data/src/Window.cpp +90 -62
- data/src/WindowUIKit.cpp +21 -9
- metadata +194 -65
- data/Gosu/AutoLink.hpp +0 -14
- data/Gosu/Bitmap.hpp +0 -113
- data/Gosu/Channel.h +0 -25
- data/Gosu/Color.h +0 -38
- data/Gosu/Font.h +0 -36
- data/Gosu/Gosu.h +0 -79
- data/Gosu/Image.h +0 -54
- data/Gosu/Sample.h +0 -19
- data/Gosu/Song.h +0 -24
- data/Gosu/TextInput.h +0 -30
- data/Gosu/Window.h +0 -61
- data/lib/gosu/zen.rb +0 -89
- data/src/AudioToolboxFile.hpp +0 -210
- data/src/ChannelWrapper.cpp +0 -50
- data/src/ColorWrapper.cpp +0 -126
- data/src/Constants.cpp +0 -287
- data/src/FontWrapper.cpp +0 -74
- data/src/GosuWrapper.cpp +0 -232
- data/src/ImageWrapper.cpp +0 -168
- data/src/MPEGFile.hpp +0 -90
- data/src/OggFile.hpp +0 -92
- data/src/SampleWrapper.cpp +0 -30
- data/src/SndFile.hpp +0 -174
- data/src/SongWrapper.cpp +0 -52
- data/src/TextInputWrapper.cpp +0 -101
- data/src/WinMain.cpp +0 -64
- data/src/WindowWrapper.cpp +0 -289
@@ -0,0 +1,228 @@
|
|
1
|
+
/**
|
2
|
+
* SDL_sound; An abstract sound format decoding API.
|
3
|
+
*
|
4
|
+
* Please see the file LICENSE.txt in the source's root directory.
|
5
|
+
*
|
6
|
+
* This file written by Torbjörn Andersson.
|
7
|
+
*/
|
8
|
+
|
9
|
+
/*
|
10
|
+
* Module player for SDL_sound. This driver handles anything that ModPlug does.
|
11
|
+
*
|
12
|
+
* ModPlug can be found at https://sourceforge.net/projects/modplug-xmms
|
13
|
+
*
|
14
|
+
* An unofficial version of modplug with all C++ dependencies removed is also
|
15
|
+
* available: http://freecraft.net/snapshots/
|
16
|
+
* (Look for something like "libmodplug-johns-*.tar.gz")
|
17
|
+
* (update: this domain is gone. --ryan.)
|
18
|
+
*/
|
19
|
+
|
20
|
+
#define __SDL_SOUND_INTERNAL__
|
21
|
+
#include "SDL_sound_internal.h"
|
22
|
+
|
23
|
+
#if SOUND_SUPPORTS_MODPLUG
|
24
|
+
|
25
|
+
#include "libmodplug/modplug.h"
|
26
|
+
|
27
|
+
static const char *extensions_modplug[] =
|
28
|
+
{
|
29
|
+
/* The XMMS plugin is apparently able to load compressed modules as
|
30
|
+
* well, but libmodplug does not handle this.
|
31
|
+
*/
|
32
|
+
"669", /* Composer 669 / UNIS 669 module */
|
33
|
+
"AMF", /* ASYLUM Music Format / Advanced Music Format(DSM) */
|
34
|
+
"AMS", /* AMS module */
|
35
|
+
"DBM", /* DigiBooster Pro Module */
|
36
|
+
"DMF", /* DMF DELUSION DIGITAL MUSIC FILEFORMAT (X-Tracker) */
|
37
|
+
"DSM", /* DSIK Internal Format module */
|
38
|
+
"FAR", /* Farandole module */
|
39
|
+
"IT", /* Impulse Tracker IT file */
|
40
|
+
"MDL", /* DigiTracker module */
|
41
|
+
"MED", /* OctaMed MED file */
|
42
|
+
"MOD", /* ProTracker / NoiseTracker MOD/NST file */
|
43
|
+
"MT2", /* MadTracker 2.0 */
|
44
|
+
"MTM", /* MTM file */
|
45
|
+
"OKT", /* Oktalyzer module */
|
46
|
+
"PTM", /* PTM PolyTracker module */
|
47
|
+
"PSM", /* PSM module */
|
48
|
+
"S3M", /* ScreamTracker file */
|
49
|
+
"STM", /* ST 2.xx */
|
50
|
+
"ULT",
|
51
|
+
"UMX",
|
52
|
+
"XM", /* FastTracker II */
|
53
|
+
"ABC",
|
54
|
+
"MID",
|
55
|
+
"MIDI",
|
56
|
+
NULL
|
57
|
+
};
|
58
|
+
|
59
|
+
|
60
|
+
|
61
|
+
static int MODPLUG_init(void)
|
62
|
+
{
|
63
|
+
return ModPlug_Init(); /* success. */
|
64
|
+
} /* MODPLUG_init */
|
65
|
+
|
66
|
+
|
67
|
+
static void MODPLUG_quit(void)
|
68
|
+
{
|
69
|
+
/* it's a no-op. */
|
70
|
+
} /* MODPLUG_quit */
|
71
|
+
|
72
|
+
|
73
|
+
/*
|
74
|
+
* Most MOD files I've seen have tended to be a few hundred KB, even if some
|
75
|
+
* of them were much smaller than that.
|
76
|
+
*/
|
77
|
+
#define CHUNK_SIZE 65536
|
78
|
+
|
79
|
+
static int MODPLUG_open(Sound_Sample *sample, const char *ext)
|
80
|
+
{
|
81
|
+
ModPlug_Settings settings;
|
82
|
+
Sound_SampleInternal *internal = (Sound_SampleInternal *) sample->opaque;
|
83
|
+
ModPlugFile *module;
|
84
|
+
Uint8 *data;
|
85
|
+
size_t size;
|
86
|
+
Uint32 retval;
|
87
|
+
int has_extension = 0;
|
88
|
+
int i;
|
89
|
+
|
90
|
+
/*
|
91
|
+
* Apparently ModPlug's loaders are too forgiving. They gladly accept
|
92
|
+
* streams that they shouldn't. For now, rely on file extension instead.
|
93
|
+
*/
|
94
|
+
for (i = 0; extensions_modplug[i] != NULL; i++)
|
95
|
+
{
|
96
|
+
if (SDL_strcasecmp(ext, extensions_modplug[i]) == 0)
|
97
|
+
{
|
98
|
+
has_extension = 1;
|
99
|
+
break;
|
100
|
+
} /* if */
|
101
|
+
} /* for */
|
102
|
+
|
103
|
+
if (!has_extension)
|
104
|
+
{
|
105
|
+
SNDDBG(("MODPLUG: Unrecognized file type: %s\n", ext));
|
106
|
+
BAIL_MACRO("MODPLUG: Not a module file.", 0);
|
107
|
+
} /* if */
|
108
|
+
|
109
|
+
/* ModPlug needs the entire stream in one big chunk. I don't like it,
|
110
|
+
but I don't think there's any way around it. !!! FIXME: rework modplug? */
|
111
|
+
data = (Uint8 *) SDL_malloc(CHUNK_SIZE);
|
112
|
+
BAIL_IF_MACRO(data == NULL, ERR_OUT_OF_MEMORY, 0);
|
113
|
+
size = 0;
|
114
|
+
|
115
|
+
do
|
116
|
+
{
|
117
|
+
retval = SDL_RWread(internal->rw, &data[size], 1, CHUNK_SIZE);
|
118
|
+
size += retval;
|
119
|
+
if (retval == CHUNK_SIZE)
|
120
|
+
{
|
121
|
+
data = (Uint8 *) SDL_realloc(data, size + CHUNK_SIZE);
|
122
|
+
BAIL_IF_MACRO(data == NULL, ERR_OUT_OF_MEMORY, 0);
|
123
|
+
} /* if */
|
124
|
+
} while (retval > 0);
|
125
|
+
|
126
|
+
SDL_memcpy(&sample->actual, &sample->desired, sizeof (Sound_AudioInfo));
|
127
|
+
if (sample->actual.rate == 0) sample->actual.rate = 44100;
|
128
|
+
if (sample->actual.channels == 0) sample->actual.channels = 2;
|
129
|
+
if (sample->actual.format == 0) sample->actual.format = AUDIO_S16SYS;
|
130
|
+
|
131
|
+
settings.mChannels=sample->actual.channels;
|
132
|
+
settings.mFrequency=sample->actual.rate;
|
133
|
+
settings.mBits = sample->actual.format & 0xFF;
|
134
|
+
|
135
|
+
/* The settings will require some experimenting. I've borrowed some
|
136
|
+
of them from the XMMS ModPlug plugin. */
|
137
|
+
settings.mFlags = MODPLUG_ENABLE_OVERSAMPLING;
|
138
|
+
settings.mFlags |= MODPLUG_ENABLE_NOISE_REDUCTION |
|
139
|
+
MODPLUG_ENABLE_MEGABASS |
|
140
|
+
MODPLUG_ENABLE_SURROUND;
|
141
|
+
|
142
|
+
settings.mReverbDepth = 30;
|
143
|
+
settings.mReverbDelay = 100;
|
144
|
+
settings.mBassAmount = 40;
|
145
|
+
settings.mBassRange = 30;
|
146
|
+
settings.mSurroundDepth = 20;
|
147
|
+
settings.mSurroundDelay = 20;
|
148
|
+
settings.mChannels = 2;
|
149
|
+
settings.mBits = 16;
|
150
|
+
settings.mFrequency = 44100;
|
151
|
+
settings.mResamplingMode = MODPLUG_RESAMPLE_FIR;
|
152
|
+
settings.mLoopCount = 0;
|
153
|
+
|
154
|
+
/* The buffer may be a bit too large, but that doesn't matter. I think
|
155
|
+
it's safe to free it as soon as ModPlug_Load() is finished anyway. */
|
156
|
+
module = ModPlug_Load((void *) data, size, &settings);
|
157
|
+
SDL_free(data);
|
158
|
+
BAIL_IF_MACRO(module == NULL, "MODPLUG: Not a module file.", 0);
|
159
|
+
|
160
|
+
internal->total_time = ModPlug_GetLength(module);
|
161
|
+
internal->decoder_private = (void *) module;
|
162
|
+
sample->flags = SOUND_SAMPLEFLAG_CANSEEK;
|
163
|
+
|
164
|
+
SNDDBG(("MODPLUG: Accepting data stream\n"));
|
165
|
+
return 1; /* we'll handle this data. */
|
166
|
+
} /* MODPLUG_open */
|
167
|
+
|
168
|
+
|
169
|
+
static void MODPLUG_close(Sound_Sample *sample)
|
170
|
+
{
|
171
|
+
Sound_SampleInternal *internal = (Sound_SampleInternal *) sample->opaque;
|
172
|
+
ModPlugFile *module = (ModPlugFile *) internal->decoder_private;
|
173
|
+
ModPlug_Unload(module);
|
174
|
+
} /* MODPLUG_close */
|
175
|
+
|
176
|
+
|
177
|
+
static Uint32 MODPLUG_read(Sound_Sample *sample)
|
178
|
+
{
|
179
|
+
Sound_SampleInternal *internal = (Sound_SampleInternal *) sample->opaque;
|
180
|
+
ModPlugFile *module = (ModPlugFile *) internal->decoder_private;
|
181
|
+
int retval;
|
182
|
+
retval = ModPlug_Read(module, internal->buffer, internal->buffer_size);
|
183
|
+
if (retval == 0)
|
184
|
+
sample->flags |= SOUND_SAMPLEFLAG_EOF;
|
185
|
+
return retval;
|
186
|
+
} /* MODPLUG_read */
|
187
|
+
|
188
|
+
|
189
|
+
static int MODPLUG_rewind(Sound_Sample *sample)
|
190
|
+
{
|
191
|
+
Sound_SampleInternal *internal = (Sound_SampleInternal *) sample->opaque;
|
192
|
+
ModPlugFile *module = (ModPlugFile *) internal->decoder_private;
|
193
|
+
ModPlug_Seek(module, 0);
|
194
|
+
return 1;
|
195
|
+
} /* MODPLUG_rewind */
|
196
|
+
|
197
|
+
|
198
|
+
static int MODPLUG_seek(Sound_Sample *sample, Uint32 ms)
|
199
|
+
{
|
200
|
+
Sound_SampleInternal *internal = (Sound_SampleInternal *) sample->opaque;
|
201
|
+
ModPlugFile *module = (ModPlugFile *) internal->decoder_private;
|
202
|
+
ModPlug_Seek(module, ms);
|
203
|
+
return 1;
|
204
|
+
} /* MODPLUG_seek */
|
205
|
+
|
206
|
+
|
207
|
+
const Sound_DecoderFunctions __Sound_DecoderFunctions_MODPLUG =
|
208
|
+
{
|
209
|
+
{
|
210
|
+
extensions_modplug,
|
211
|
+
"Play modules through ModPlug",
|
212
|
+
"Torbjörn Andersson <d91tan@Update.UU.SE>",
|
213
|
+
"http://modplug-xmms.sourceforge.net/"
|
214
|
+
},
|
215
|
+
|
216
|
+
MODPLUG_init, /* init() method */
|
217
|
+
MODPLUG_quit, /* quit() method */
|
218
|
+
MODPLUG_open, /* open() method */
|
219
|
+
MODPLUG_close, /* close() method */
|
220
|
+
MODPLUG_read, /* read() method */
|
221
|
+
MODPLUG_rewind, /* rewind() method */
|
222
|
+
MODPLUG_seek /* seek() method */
|
223
|
+
};
|
224
|
+
|
225
|
+
#endif /* SOUND_SUPPORTS_MODPLUG */
|
226
|
+
|
227
|
+
/* end of SDL_sound_modplug.c ... */
|
228
|
+
|
@@ -0,0 +1,184 @@
|
|
1
|
+
/**
|
2
|
+
* SDL_sound; An abstract sound format decoding API.
|
3
|
+
*
|
4
|
+
* Please see the file LICENSE.txt in the source's root directory.
|
5
|
+
*
|
6
|
+
* This file written by Ryan C. Gordon.
|
7
|
+
*/
|
8
|
+
|
9
|
+
/*
|
10
|
+
* MP3 decoder for SDL_sound.
|
11
|
+
*
|
12
|
+
* !!! FIXME: write something here.
|
13
|
+
*
|
14
|
+
* dr_mp3 is here: https://github.com/mackron/dr_libs/
|
15
|
+
*/
|
16
|
+
|
17
|
+
#define __SDL_SOUND_INTERNAL__
|
18
|
+
#include "SDL_sound_internal.h"
|
19
|
+
|
20
|
+
#if SOUND_SUPPORTS_MP3
|
21
|
+
|
22
|
+
#define DR_MP3_IMPLEMENTATION
|
23
|
+
#define DR_MP3_NO_STDIO 1
|
24
|
+
#define DRMP3_ASSERT(x) SDL_assert((x))
|
25
|
+
#define DRMP3_MALLOC(sz) SDL_malloc((sz))
|
26
|
+
#define DRMP3_REALLOC(p, sz) SDL_realloc((p), (sz))
|
27
|
+
#define DRMP3_FREE(p) SDL_free((p))
|
28
|
+
#define DRMP3_COPY_MEMORY(dst, src, sz) SDL_memcpy((dst), (src), (sz))
|
29
|
+
#define DRMP3_ZERO_MEMORY(p, sz) SDL_memset((p), 0, (sz))
|
30
|
+
|
31
|
+
#if !defined(__clang_analyzer__)
|
32
|
+
#ifdef memset
|
33
|
+
#undef memset
|
34
|
+
#endif
|
35
|
+
#ifdef memcpy
|
36
|
+
#undef memcpy
|
37
|
+
#endif
|
38
|
+
#ifdef memmove
|
39
|
+
#undef memmove
|
40
|
+
#endif
|
41
|
+
#define memset SDL_memset
|
42
|
+
#define memcpy SDL_memcpy
|
43
|
+
#define memmove SDL_memmove
|
44
|
+
#endif
|
45
|
+
|
46
|
+
#include "dr_mp3.h"
|
47
|
+
|
48
|
+
static size_t mp3_read(void* pUserData, void* pBufferOut, size_t bytesToRead)
|
49
|
+
{
|
50
|
+
Uint8 *ptr = (Uint8 *) pBufferOut;
|
51
|
+
Sound_Sample *sample = (Sound_Sample *) pUserData;
|
52
|
+
Sound_SampleInternal *internal = (Sound_SampleInternal *) sample->opaque;
|
53
|
+
SDL_RWops *rwops = internal->rw;
|
54
|
+
size_t retval = 0;
|
55
|
+
|
56
|
+
/* !!! FIXME: dr_mp3 treats returning less than bytesToRead as EOF. So we can't EAGAIN. */
|
57
|
+
while (retval < bytesToRead)
|
58
|
+
{
|
59
|
+
const size_t rc = SDL_RWread(rwops, ptr, 1, bytesToRead);
|
60
|
+
if (rc == 0)
|
61
|
+
{
|
62
|
+
sample->flags |= SOUND_SAMPLEFLAG_EOF;
|
63
|
+
break;
|
64
|
+
} /* if */
|
65
|
+
else if (retval == -1)
|
66
|
+
{
|
67
|
+
sample->flags |= SOUND_SAMPLEFLAG_ERROR;
|
68
|
+
break;
|
69
|
+
} /* else if */
|
70
|
+
else
|
71
|
+
{
|
72
|
+
retval += rc;
|
73
|
+
ptr += rc;
|
74
|
+
} /* else */
|
75
|
+
} /* while */
|
76
|
+
|
77
|
+
return retval;
|
78
|
+
} /* mp3_read */
|
79
|
+
|
80
|
+
static drmp3_bool32 mp3_seek(void* pUserData, int offset, drmp3_seek_origin origin)
|
81
|
+
{
|
82
|
+
const int whence = (origin == drmp3_seek_origin_start) ? RW_SEEK_SET : RW_SEEK_CUR;
|
83
|
+
Sound_Sample *sample = (Sound_Sample *) pUserData;
|
84
|
+
Sound_SampleInternal *internal = (Sound_SampleInternal *) sample->opaque;
|
85
|
+
return (SDL_RWseek(internal->rw, offset, whence) != -1) ? DRMP3_TRUE : DRMP3_FALSE;
|
86
|
+
} /* mp3_seek */
|
87
|
+
|
88
|
+
|
89
|
+
static int MP3_init(void)
|
90
|
+
{
|
91
|
+
return 1; /* always succeeds. */
|
92
|
+
} /* MP3_init */
|
93
|
+
|
94
|
+
|
95
|
+
static void MP3_quit(void)
|
96
|
+
{
|
97
|
+
/* it's a no-op. */
|
98
|
+
} /* MP3_quit */
|
99
|
+
|
100
|
+
static int MP3_open(Sound_Sample *sample, const char *ext)
|
101
|
+
{
|
102
|
+
Sound_SampleInternal *internal = (Sound_SampleInternal *) sample->opaque;
|
103
|
+
drmp3 *dr = (drmp3 *) SDL_calloc(1, sizeof (drmp3));
|
104
|
+
|
105
|
+
BAIL_IF_MACRO(!dr, ERR_OUT_OF_MEMORY, 0);
|
106
|
+
if (drmp3_init(dr, mp3_read, mp3_seek, sample, NULL) != DRMP3_TRUE)
|
107
|
+
{
|
108
|
+
SDL_free(dr);
|
109
|
+
BAIL_IF_MACRO(sample->flags & SOUND_SAMPLEFLAG_ERROR, ERR_IO_ERROR, 0);
|
110
|
+
BAIL_MACRO("MP3: Not an MPEG-1 layer 1-3 stream.", 0);
|
111
|
+
} /* if */
|
112
|
+
|
113
|
+
SNDDBG(("MP3: Accepting data stream.\n"));
|
114
|
+
sample->flags = SOUND_SAMPLEFLAG_CANSEEK;
|
115
|
+
|
116
|
+
sample->actual.channels = dr->channels;
|
117
|
+
sample->actual.rate = dr->sampleRate;
|
118
|
+
sample->actual.format = AUDIO_F32SYS; /* dr_mp3 only does float. */
|
119
|
+
|
120
|
+
internal->total_time = -1; /* !!! FIXME? */
|
121
|
+
internal->decoder_private = dr;
|
122
|
+
|
123
|
+
return 1;
|
124
|
+
} /* MP3_open */
|
125
|
+
|
126
|
+
static void MP3_close(Sound_Sample *sample)
|
127
|
+
{
|
128
|
+
Sound_SampleInternal *internal = (Sound_SampleInternal *) sample->opaque;
|
129
|
+
drmp3 *dr = (drmp3 *) internal->decoder_private;
|
130
|
+
drmp3_uninit(dr);
|
131
|
+
SDL_free(dr);
|
132
|
+
} /* MP3_close */
|
133
|
+
|
134
|
+
static Uint32 MP3_read(Sound_Sample *sample)
|
135
|
+
{
|
136
|
+
Sound_SampleInternal *internal = (Sound_SampleInternal *) sample->opaque;
|
137
|
+
const int channels = (int) sample->actual.channels;
|
138
|
+
drmp3 *dr = (drmp3 *) internal->decoder_private;
|
139
|
+
const drmp3_uint64 frames_to_read = (internal->buffer_size / channels) / sizeof (float);
|
140
|
+
const drmp3_uint64 rc = drmp3_read_f32(dr, frames_to_read, (float *) internal->buffer);
|
141
|
+
/* !!! FIXME: the mp3_read callback sets ERROR and EOF flags, but this only tells you about i/o errors, not corruption. */
|
142
|
+
return rc * channels * sizeof (float);
|
143
|
+
} /* MP3_read */
|
144
|
+
|
145
|
+
static int MP3_rewind(Sound_Sample *sample)
|
146
|
+
{
|
147
|
+
Sound_SampleInternal *internal = (Sound_SampleInternal *) sample->opaque;
|
148
|
+
drmp3 *dr = (drmp3 *) internal->decoder_private;
|
149
|
+
return (drmp3_seek_to_frame(dr, 0) == DRMP3_TRUE);
|
150
|
+
} /* MP3_rewind */
|
151
|
+
|
152
|
+
static int MP3_seek(Sound_Sample *sample, Uint32 ms)
|
153
|
+
{
|
154
|
+
Sound_SampleInternal *internal = (Sound_SampleInternal *) sample->opaque;
|
155
|
+
drmp3 *dr = (drmp3 *) internal->decoder_private;
|
156
|
+
const float frames_per_ms = ((float) sample->actual.rate) / 1000.0f;
|
157
|
+
const drmp3_uint64 frame_offset = (drmp3_uint64) (frames_per_ms * ((float) ms));
|
158
|
+
return (drmp3_seek_to_frame(dr, frame_offset) == DRMP3_TRUE);
|
159
|
+
} /* MP3_seek */
|
160
|
+
|
161
|
+
/* dr_mp3 will play layer 1 and 2 files, too */
|
162
|
+
static const char *extensions_mp3[] = { "MP3", "MP2", "MP1", NULL };
|
163
|
+
const Sound_DecoderFunctions __Sound_DecoderFunctions_MP3 =
|
164
|
+
{
|
165
|
+
{
|
166
|
+
extensions_mp3,
|
167
|
+
"MPEG-1 Audio Layer I-III",
|
168
|
+
"Ryan C. Gordon <icculus@icculus.org>",
|
169
|
+
"https://icculus.org/SDL_sound/"
|
170
|
+
},
|
171
|
+
|
172
|
+
MP3_init, /* init() method */
|
173
|
+
MP3_quit, /* quit() method */
|
174
|
+
MP3_open, /* open() method */
|
175
|
+
MP3_close, /* close() method */
|
176
|
+
MP3_read, /* read() method */
|
177
|
+
MP3_rewind, /* rewind() method */
|
178
|
+
MP3_seek /* seek() method */
|
179
|
+
};
|
180
|
+
|
181
|
+
#endif /* SOUND_SUPPORTS_MP3 */
|
182
|
+
|
183
|
+
/* end of SDL_sound_mp3.c ... */
|
184
|
+
|
@@ -0,0 +1,164 @@
|
|
1
|
+
/**
|
2
|
+
* SDL_sound; A sound processing toolkit.
|
3
|
+
*
|
4
|
+
* Please see the file LICENSE.txt in the source's root directory.
|
5
|
+
*
|
6
|
+
* This file written by Ryan C. Gordon.
|
7
|
+
*/
|
8
|
+
|
9
|
+
/*
|
10
|
+
* RAW decoder for SDL_sound. This is as simple as it gets.
|
11
|
+
*
|
12
|
+
* This driver handles raw audio data. You must, regardless of where the
|
13
|
+
* data is actually coming from, specify the string "RAW" in the extension
|
14
|
+
* parameter of Sound_NewSample() (or, alternately, open a file with the
|
15
|
+
* extension ".raw" in Sound_NewSampleFromFile()). The string is checked
|
16
|
+
* case-insensitive. We need this check, because raw data, being raw, has
|
17
|
+
* no headers or magic number we can use to determine if we should handle a
|
18
|
+
* given file, so we needed some way to have this "decoder" discriminate.
|
19
|
+
*
|
20
|
+
* When calling Sound_NewSample*(), you must also specify a "desired"
|
21
|
+
* audio format. The "actual" format will always match what you specify, so
|
22
|
+
* there will be no conversion overhead, but these routines need to know how
|
23
|
+
* to treat the bits, since it's all random garbage otherwise.
|
24
|
+
*/
|
25
|
+
|
26
|
+
#define __SDL_SOUND_INTERNAL__
|
27
|
+
#include "SDL_sound_internal.h"
|
28
|
+
|
29
|
+
#if SOUND_SUPPORTS_RAW
|
30
|
+
|
31
|
+
static int RAW_init(void)
|
32
|
+
{
|
33
|
+
return 1; /* always succeeds. */
|
34
|
+
} /* RAW_init */
|
35
|
+
|
36
|
+
|
37
|
+
static void RAW_quit(void)
|
38
|
+
{
|
39
|
+
/* it's a no-op. */
|
40
|
+
} /* RAW_quit */
|
41
|
+
|
42
|
+
|
43
|
+
static int RAW_open(Sound_Sample *sample, const char *ext)
|
44
|
+
{
|
45
|
+
Sound_SampleInternal *internal = sample->opaque;
|
46
|
+
SDL_RWops *rw = internal->rw;
|
47
|
+
Uint32 pos, sample_rate;
|
48
|
+
|
49
|
+
/*
|
50
|
+
* We check this explicitly, since we have no other way to
|
51
|
+
* determine whether we should handle this data or not.
|
52
|
+
*/
|
53
|
+
if (SDL_strcasecmp(ext, "RAW") != 0)
|
54
|
+
BAIL_MACRO("RAW: extension isn't explicitly \"RAW\".", 0);
|
55
|
+
|
56
|
+
/*
|
57
|
+
* You must also specify a desired format, so we know how to
|
58
|
+
* treat the bits that are otherwise binary garbage.
|
59
|
+
*/
|
60
|
+
if ( (sample->desired.channels < 1) ||
|
61
|
+
(sample->desired.channels > 2) ||
|
62
|
+
(sample->desired.rate == 0) ||
|
63
|
+
(sample->desired.format == 0) )
|
64
|
+
{
|
65
|
+
BAIL_MACRO("RAW: invalid desired format.", 0);
|
66
|
+
} /* if */
|
67
|
+
|
68
|
+
SNDDBG(("RAW: Accepting data stream.\n"));
|
69
|
+
|
70
|
+
/*
|
71
|
+
* We never convert raw samples; what you ask for is what you get.
|
72
|
+
*/
|
73
|
+
SDL_memcpy(&sample->actual, &sample->desired, sizeof (Sound_AudioInfo));
|
74
|
+
sample->flags = SOUND_SAMPLEFLAG_CANSEEK;
|
75
|
+
|
76
|
+
if ( (pos = SDL_RWseek(internal->rw, 0, SEEK_END) ) <= 0) {
|
77
|
+
BAIL_MACRO("RAW: cannot seek the end of the file \"RAW\".", 0);
|
78
|
+
}
|
79
|
+
if ( SDL_RWseek(internal->rw, 0, SEEK_SET) ) {
|
80
|
+
BAIL_MACRO("RAW: cannot reset file \"RAW\".", 0);
|
81
|
+
}
|
82
|
+
|
83
|
+
sample_rate = (sample->actual.rate * sample->actual.channels
|
84
|
+
* ( (sample->actual.format & 0x0018) >> 3) );
|
85
|
+
internal->total_time = ( pos ) / sample_rate * 1000;
|
86
|
+
internal->total_time += (pos % sample_rate) * 1000 / sample_rate;
|
87
|
+
|
88
|
+
return 1; /* we'll handle this data. */
|
89
|
+
} /* RAW_open */
|
90
|
+
|
91
|
+
|
92
|
+
static void RAW_close(Sound_Sample *sample)
|
93
|
+
{
|
94
|
+
/* we don't allocate anything that we need to free. That's easy, eh? */
|
95
|
+
} /* RAW_close */
|
96
|
+
|
97
|
+
|
98
|
+
static Uint32 RAW_read(Sound_Sample *sample)
|
99
|
+
{
|
100
|
+
Uint32 retval;
|
101
|
+
Sound_SampleInternal *internal = (Sound_SampleInternal *) sample->opaque;
|
102
|
+
|
103
|
+
/*
|
104
|
+
* We don't actually do any decoding, so we read the raw data
|
105
|
+
* directly into the internal buffer...
|
106
|
+
*/
|
107
|
+
retval = SDL_RWread(internal->rw, internal->buffer,
|
108
|
+
1, internal->buffer_size);
|
109
|
+
|
110
|
+
/* Make sure the read went smoothly... */
|
111
|
+
if (retval == 0)
|
112
|
+
sample->flags |= SOUND_SAMPLEFLAG_EOF;
|
113
|
+
|
114
|
+
else if (retval == -1)
|
115
|
+
sample->flags |= SOUND_SAMPLEFLAG_ERROR;
|
116
|
+
|
117
|
+
/* (next call this EAGAIN may turn into an EOF or error.) */
|
118
|
+
else if (retval < internal->buffer_size)
|
119
|
+
sample->flags |= SOUND_SAMPLEFLAG_EAGAIN;
|
120
|
+
|
121
|
+
return retval;
|
122
|
+
} /* RAW_read */
|
123
|
+
|
124
|
+
|
125
|
+
static int RAW_rewind(Sound_Sample *sample)
|
126
|
+
{
|
127
|
+
Sound_SampleInternal *internal = (Sound_SampleInternal *) sample->opaque;
|
128
|
+
BAIL_IF_MACRO(SDL_RWseek(internal->rw, 0, SEEK_SET) != 0, ERR_IO_ERROR, 0);
|
129
|
+
return 1;
|
130
|
+
} /* RAW_rewind */
|
131
|
+
|
132
|
+
|
133
|
+
static int RAW_seek(Sound_Sample *sample, Uint32 ms)
|
134
|
+
{
|
135
|
+
Sound_SampleInternal *internal = (Sound_SampleInternal *) sample->opaque;
|
136
|
+
int pos = (int) __Sound_convertMsToBytePos(&sample->actual, ms);
|
137
|
+
int err = (SDL_RWseek(internal->rw, pos, SEEK_SET) != pos);
|
138
|
+
BAIL_IF_MACRO(err, ERR_IO_ERROR, 0);
|
139
|
+
return 1;
|
140
|
+
} /* RAW_seek */
|
141
|
+
|
142
|
+
static const char *extensions_raw[] = { "RAW", NULL };
|
143
|
+
const Sound_DecoderFunctions __Sound_DecoderFunctions_RAW =
|
144
|
+
{
|
145
|
+
{
|
146
|
+
extensions_raw,
|
147
|
+
"Raw audio",
|
148
|
+
"Ryan C. Gordon <icculus@icculus.org>",
|
149
|
+
"https://icculus.org/SDL_sound/"
|
150
|
+
},
|
151
|
+
|
152
|
+
RAW_init, /* init() method */
|
153
|
+
RAW_quit, /* quit() method */
|
154
|
+
RAW_open, /* open() method */
|
155
|
+
RAW_close, /* close() method */
|
156
|
+
RAW_read, /* read() method */
|
157
|
+
RAW_rewind, /* rewind() method */
|
158
|
+
RAW_seek /* seek() method */
|
159
|
+
};
|
160
|
+
|
161
|
+
#endif /* SOUND_SUPPORTS_RAW */
|
162
|
+
|
163
|
+
/* end of SDL_sound_raw.c ... */
|
164
|
+
|