annotate decoders/mikmod.c @ 536:8a814bbbedfa

Merged r544:545 from branches/stable-1.0: converted to UTF-8 encoding.
author Ryan C. Gordon <icculus@icculus.org>
date Thu, 17 Apr 2008 18:08:02 +0000
parents 3e705c9180e5
children 2e8907ff98e9
rev   line source
207
857e53c5a2da Renamed from mod.c (see modplug.c for the OTHER mod decoder).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1 /*
857e53c5a2da Renamed from mod.c (see modplug.c for the OTHER mod decoder).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
2 * SDL_sound -- An abstract sound format decoding API.
857e53c5a2da Renamed from mod.c (see modplug.c for the OTHER mod decoder).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
3 * Copyright (C) 2001 Ryan C. Gordon.
857e53c5a2da Renamed from mod.c (see modplug.c for the OTHER mod decoder).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
4 *
857e53c5a2da Renamed from mod.c (see modplug.c for the OTHER mod decoder).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
5 * This library is free software; you can redistribute it and/or
857e53c5a2da Renamed from mod.c (see modplug.c for the OTHER mod decoder).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
6 * modify it under the terms of the GNU Lesser General Public
857e53c5a2da Renamed from mod.c (see modplug.c for the OTHER mod decoder).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
7 * License as published by the Free Software Foundation; either
857e53c5a2da Renamed from mod.c (see modplug.c for the OTHER mod decoder).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
8 * version 2.1 of the License, or (at your option) any later version.
857e53c5a2da Renamed from mod.c (see modplug.c for the OTHER mod decoder).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
9 *
857e53c5a2da Renamed from mod.c (see modplug.c for the OTHER mod decoder).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
10 * This library is distributed in the hope that it will be useful,
857e53c5a2da Renamed from mod.c (see modplug.c for the OTHER mod decoder).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
857e53c5a2da Renamed from mod.c (see modplug.c for the OTHER mod decoder).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
857e53c5a2da Renamed from mod.c (see modplug.c for the OTHER mod decoder).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
13 * Lesser General Public License for more details.
857e53c5a2da Renamed from mod.c (see modplug.c for the OTHER mod decoder).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
14 *
857e53c5a2da Renamed from mod.c (see modplug.c for the OTHER mod decoder).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
15 * You should have received a copy of the GNU Lesser General Public
857e53c5a2da Renamed from mod.c (see modplug.c for the OTHER mod decoder).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
16 * License along with this library; if not, write to the Free Software
857e53c5a2da Renamed from mod.c (see modplug.c for the OTHER mod decoder).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
857e53c5a2da Renamed from mod.c (see modplug.c for the OTHER mod decoder).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
18 */
857e53c5a2da Renamed from mod.c (see modplug.c for the OTHER mod decoder).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
19
857e53c5a2da Renamed from mod.c (see modplug.c for the OTHER mod decoder).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
20 /*
857e53c5a2da Renamed from mod.c (see modplug.c for the OTHER mod decoder).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
21 * Module player for SDL_sound. This driver handles anything MikMod does, and
857e53c5a2da Renamed from mod.c (see modplug.c for the OTHER mod decoder).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
22 * is based on SDL_mixer.
857e53c5a2da Renamed from mod.c (see modplug.c for the OTHER mod decoder).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
23 *
857e53c5a2da Renamed from mod.c (see modplug.c for the OTHER mod decoder).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
24 * Please see the file COPYING in the source's root directory.
857e53c5a2da Renamed from mod.c (see modplug.c for the OTHER mod decoder).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
25 *
536
8a814bbbedfa Merged r544:545 from branches/stable-1.0: converted to UTF-8 encoding.
Ryan C. Gordon <icculus@icculus.org>
parents: 477
diff changeset
26 * This file written by Torbjörn Andersson (d91tan@Update.UU.SE)
207
857e53c5a2da Renamed from mod.c (see modplug.c for the OTHER mod decoder).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
27 */
857e53c5a2da Renamed from mod.c (see modplug.c for the OTHER mod decoder).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
28
857e53c5a2da Renamed from mod.c (see modplug.c for the OTHER mod decoder).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
29 #if HAVE_CONFIG_H
857e53c5a2da Renamed from mod.c (see modplug.c for the OTHER mod decoder).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
30 # include <config.h>
857e53c5a2da Renamed from mod.c (see modplug.c for the OTHER mod decoder).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
31 #endif
857e53c5a2da Renamed from mod.c (see modplug.c for the OTHER mod decoder).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
32
857e53c5a2da Renamed from mod.c (see modplug.c for the OTHER mod decoder).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
33 #ifdef SOUND_SUPPORTS_MIKMOD
857e53c5a2da Renamed from mod.c (see modplug.c for the OTHER mod decoder).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
34
857e53c5a2da Renamed from mod.c (see modplug.c for the OTHER mod decoder).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
35 #include <stdio.h>
857e53c5a2da Renamed from mod.c (see modplug.c for the OTHER mod decoder).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
36 #include <stdlib.h>
857e53c5a2da Renamed from mod.c (see modplug.c for the OTHER mod decoder).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
37 #include <string.h>
857e53c5a2da Renamed from mod.c (see modplug.c for the OTHER mod decoder).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
38
857e53c5a2da Renamed from mod.c (see modplug.c for the OTHER mod decoder).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
39 #include "SDL_sound.h"
857e53c5a2da Renamed from mod.c (see modplug.c for the OTHER mod decoder).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
40
857e53c5a2da Renamed from mod.c (see modplug.c for the OTHER mod decoder).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
41 #define __SDL_SOUND_INTERNAL__
857e53c5a2da Renamed from mod.c (see modplug.c for the OTHER mod decoder).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
42 #include "SDL_sound_internal.h"
857e53c5a2da Renamed from mod.c (see modplug.c for the OTHER mod decoder).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
43
857e53c5a2da Renamed from mod.c (see modplug.c for the OTHER mod decoder).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
44 #include "mikmod.h"
857e53c5a2da Renamed from mod.c (see modplug.c for the OTHER mod decoder).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
45
857e53c5a2da Renamed from mod.c (see modplug.c for the OTHER mod decoder).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
46
857e53c5a2da Renamed from mod.c (see modplug.c for the OTHER mod decoder).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
47 static int MIKMOD_init(void);
857e53c5a2da Renamed from mod.c (see modplug.c for the OTHER mod decoder).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
48 static void MIKMOD_quit(void);
857e53c5a2da Renamed from mod.c (see modplug.c for the OTHER mod decoder).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
49 static int MIKMOD_open(Sound_Sample *sample, const char *ext);
857e53c5a2da Renamed from mod.c (see modplug.c for the OTHER mod decoder).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
50 static void MIKMOD_close(Sound_Sample *sample);
857e53c5a2da Renamed from mod.c (see modplug.c for the OTHER mod decoder).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
51 static Uint32 MIKMOD_read(Sound_Sample *sample);
221
c9772a9f5271 Initial implementation or stubs for rewind method. Other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 211
diff changeset
52 static int MIKMOD_rewind(Sound_Sample *sample);
306
c97be6e1bd27 Added framework for Sound_Seek() support.
Ryan C. Gordon <icculus@icculus.org>
parents: 305
diff changeset
53 static int MIKMOD_seek(Sound_Sample *sample, Uint32 ms);
207
857e53c5a2da Renamed from mod.c (see modplug.c for the OTHER mod decoder).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
54
857e53c5a2da Renamed from mod.c (see modplug.c for the OTHER mod decoder).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
55 static const char *extensions_mikmod[] =
857e53c5a2da Renamed from mod.c (see modplug.c for the OTHER mod decoder).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
56 {
211
b35c04e4691e Patched to select streams to handle more carefully.
Ryan C. Gordon <icculus@icculus.org>
parents: 207
diff changeset
57 "669", /* Composer 669 */
b35c04e4691e Patched to select streams to handle more carefully.
Ryan C. Gordon <icculus@icculus.org>
parents: 207
diff changeset
58 "AMF", /* DMP Advanced Module Format */
b35c04e4691e Patched to select streams to handle more carefully.
Ryan C. Gordon <icculus@icculus.org>
parents: 207
diff changeset
59 "DSM", /* DSIK internal format */
b35c04e4691e Patched to select streams to handle more carefully.
Ryan C. Gordon <icculus@icculus.org>
parents: 207
diff changeset
60 "FAR", /* Farandole module */
b35c04e4691e Patched to select streams to handle more carefully.
Ryan C. Gordon <icculus@icculus.org>
parents: 207
diff changeset
61 "GDM", /* General DigiMusic module */
b35c04e4691e Patched to select streams to handle more carefully.
Ryan C. Gordon <icculus@icculus.org>
parents: 207
diff changeset
62 "IMF", /* Imago Orpheus module */
b35c04e4691e Patched to select streams to handle more carefully.
Ryan C. Gordon <icculus@icculus.org>
parents: 207
diff changeset
63 "IT", /* Impulse tracker */
b35c04e4691e Patched to select streams to handle more carefully.
Ryan C. Gordon <icculus@icculus.org>
parents: 207
diff changeset
64 "M15", /* 15 instrument MOD / Ultimate Sound Tracker (old M15 format) */
b35c04e4691e Patched to select streams to handle more carefully.
Ryan C. Gordon <icculus@icculus.org>
parents: 207
diff changeset
65 "MED", /* Amiga MED module */
b35c04e4691e Patched to select streams to handle more carefully.
Ryan C. Gordon <icculus@icculus.org>
parents: 207
diff changeset
66 "MOD", /* Generic MOD (Protracker, StarTracker, FastTracker, etc) */
b35c04e4691e Patched to select streams to handle more carefully.
Ryan C. Gordon <icculus@icculus.org>
parents: 207
diff changeset
67 "MTM", /* MTM module */
b35c04e4691e Patched to select streams to handle more carefully.
Ryan C. Gordon <icculus@icculus.org>
parents: 207
diff changeset
68 "OKT", /* Oktalyzer module */
b35c04e4691e Patched to select streams to handle more carefully.
Ryan C. Gordon <icculus@icculus.org>
parents: 207
diff changeset
69 "S3M", /* Screamtracker module */
b35c04e4691e Patched to select streams to handle more carefully.
Ryan C. Gordon <icculus@icculus.org>
parents: 207
diff changeset
70 "STM", /* Screamtracker 2 module */
b35c04e4691e Patched to select streams to handle more carefully.
Ryan C. Gordon <icculus@icculus.org>
parents: 207
diff changeset
71 "STX", /* STMIK 0.2 module */
b35c04e4691e Patched to select streams to handle more carefully.
Ryan C. Gordon <icculus@icculus.org>
parents: 207
diff changeset
72 "ULT", /* Ultratracker module */
b35c04e4691e Patched to select streams to handle more carefully.
Ryan C. Gordon <icculus@icculus.org>
parents: 207
diff changeset
73 "UNI", /* UNIMOD - libmikmod's and APlayer's internal module format */
b35c04e4691e Patched to select streams to handle more carefully.
Ryan C. Gordon <icculus@icculus.org>
parents: 207
diff changeset
74 "XM", /* Fasttracker module */
207
857e53c5a2da Renamed from mod.c (see modplug.c for the OTHER mod decoder).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
75 NULL
857e53c5a2da Renamed from mod.c (see modplug.c for the OTHER mod decoder).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
76 };
857e53c5a2da Renamed from mod.c (see modplug.c for the OTHER mod decoder).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
77
857e53c5a2da Renamed from mod.c (see modplug.c for the OTHER mod decoder).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
78 const Sound_DecoderFunctions __Sound_DecoderFunctions_MIKMOD =
857e53c5a2da Renamed from mod.c (see modplug.c for the OTHER mod decoder).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
79 {
857e53c5a2da Renamed from mod.c (see modplug.c for the OTHER mod decoder).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
80 {
857e53c5a2da Renamed from mod.c (see modplug.c for the OTHER mod decoder).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
81 extensions_mikmod,
857e53c5a2da Renamed from mod.c (see modplug.c for the OTHER mod decoder).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
82 "Play modules through MikMod",
536
8a814bbbedfa Merged r544:545 from branches/stable-1.0: converted to UTF-8 encoding.
Ryan C. Gordon <icculus@icculus.org>
parents: 477
diff changeset
83 "Torbjörn Andersson <d91tan@Update.UU.SE>",
473
1edb89260487 Fixed MikMod URL.
Ryan C. Gordon <icculus@icculus.org>
parents: 434
diff changeset
84 "http://mikmod.raphnet.net/"
207
857e53c5a2da Renamed from mod.c (see modplug.c for the OTHER mod decoder).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
85 },
857e53c5a2da Renamed from mod.c (see modplug.c for the OTHER mod decoder).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
86
221
c9772a9f5271 Initial implementation or stubs for rewind method. Other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 211
diff changeset
87 MIKMOD_init, /* init() method */
c9772a9f5271 Initial implementation or stubs for rewind method. Other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 211
diff changeset
88 MIKMOD_quit, /* quit() method */
c9772a9f5271 Initial implementation or stubs for rewind method. Other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 211
diff changeset
89 MIKMOD_open, /* open() method */
c9772a9f5271 Initial implementation or stubs for rewind method. Other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 211
diff changeset
90 MIKMOD_close, /* close() method */
c9772a9f5271 Initial implementation or stubs for rewind method. Other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 211
diff changeset
91 MIKMOD_read, /* read() method */
306
c97be6e1bd27 Added framework for Sound_Seek() support.
Ryan C. Gordon <icculus@icculus.org>
parents: 305
diff changeset
92 MIKMOD_rewind, /* rewind() method */
c97be6e1bd27 Added framework for Sound_Seek() support.
Ryan C. Gordon <icculus@icculus.org>
parents: 305
diff changeset
93 MIKMOD_seek /* seek() method */
207
857e53c5a2da Renamed from mod.c (see modplug.c for the OTHER mod decoder).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
94 };
857e53c5a2da Renamed from mod.c (see modplug.c for the OTHER mod decoder).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
95
857e53c5a2da Renamed from mod.c (see modplug.c for the OTHER mod decoder).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
96
857e53c5a2da Renamed from mod.c (see modplug.c for the OTHER mod decoder).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
97 /* Make MikMod read from a RWops... */
857e53c5a2da Renamed from mod.c (see modplug.c for the OTHER mod decoder).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
98
857e53c5a2da Renamed from mod.c (see modplug.c for the OTHER mod decoder).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
99 typedef struct MRWOPSREADER {
857e53c5a2da Renamed from mod.c (see modplug.c for the OTHER mod decoder).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
100 MREADER core;
857e53c5a2da Renamed from mod.c (see modplug.c for the OTHER mod decoder).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
101 Sound_Sample *sample;
857e53c5a2da Renamed from mod.c (see modplug.c for the OTHER mod decoder).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
102 int end;
857e53c5a2da Renamed from mod.c (see modplug.c for the OTHER mod decoder).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
103 } MRWOPSREADER;
857e53c5a2da Renamed from mod.c (see modplug.c for the OTHER mod decoder).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
104
857e53c5a2da Renamed from mod.c (see modplug.c for the OTHER mod decoder).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
105 static BOOL _mm_RWopsReader_eof(MREADER *reader)
857e53c5a2da Renamed from mod.c (see modplug.c for the OTHER mod decoder).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
106 {
857e53c5a2da Renamed from mod.c (see modplug.c for the OTHER mod decoder).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
107 MRWOPSREADER *rwops_reader = (MRWOPSREADER *) reader;
857e53c5a2da Renamed from mod.c (see modplug.c for the OTHER mod decoder).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
108 Sound_Sample *sample = rwops_reader->sample;
857e53c5a2da Renamed from mod.c (see modplug.c for the OTHER mod decoder).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
109 Sound_SampleInternal *internal = (Sound_SampleInternal *) sample->opaque;
857e53c5a2da Renamed from mod.c (see modplug.c for the OTHER mod decoder).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
110 int pos = SDL_RWtell(internal->rw);
857e53c5a2da Renamed from mod.c (see modplug.c for the OTHER mod decoder).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
111
857e53c5a2da Renamed from mod.c (see modplug.c for the OTHER mod decoder).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
112 if (rwops_reader->end == pos)
857e53c5a2da Renamed from mod.c (see modplug.c for the OTHER mod decoder).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
113 return(1);
857e53c5a2da Renamed from mod.c (see modplug.c for the OTHER mod decoder).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
114
857e53c5a2da Renamed from mod.c (see modplug.c for the OTHER mod decoder).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
115 return(0);
857e53c5a2da Renamed from mod.c (see modplug.c for the OTHER mod decoder).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
116 } /* _mm_RWopsReader_eof */
857e53c5a2da Renamed from mod.c (see modplug.c for the OTHER mod decoder).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
117
857e53c5a2da Renamed from mod.c (see modplug.c for the OTHER mod decoder).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
118
857e53c5a2da Renamed from mod.c (see modplug.c for the OTHER mod decoder).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
119 static BOOL _mm_RWopsReader_read(MREADER *reader, void *ptr, size_t size)
857e53c5a2da Renamed from mod.c (see modplug.c for the OTHER mod decoder).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
120 {
857e53c5a2da Renamed from mod.c (see modplug.c for the OTHER mod decoder).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
121 MRWOPSREADER *rwops_reader = (MRWOPSREADER *) reader;
857e53c5a2da Renamed from mod.c (see modplug.c for the OTHER mod decoder).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
122 Sound_Sample *sample = rwops_reader->sample;
857e53c5a2da Renamed from mod.c (see modplug.c for the OTHER mod decoder).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
123 Sound_SampleInternal *internal = (Sound_SampleInternal *) sample->opaque;
857e53c5a2da Renamed from mod.c (see modplug.c for the OTHER mod decoder).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
124 return(SDL_RWread(internal->rw, ptr, size, 1));
857e53c5a2da Renamed from mod.c (see modplug.c for the OTHER mod decoder).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
125 } /* _mm_RWopsReader_Read */
857e53c5a2da Renamed from mod.c (see modplug.c for the OTHER mod decoder).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
126
857e53c5a2da Renamed from mod.c (see modplug.c for the OTHER mod decoder).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
127
857e53c5a2da Renamed from mod.c (see modplug.c for the OTHER mod decoder).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
128 static int _mm_RWopsReader_get(MREADER *reader)
857e53c5a2da Renamed from mod.c (see modplug.c for the OTHER mod decoder).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
129 {
857e53c5a2da Renamed from mod.c (see modplug.c for the OTHER mod decoder).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
130 char buf;
857e53c5a2da Renamed from mod.c (see modplug.c for the OTHER mod decoder).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
131 MRWOPSREADER *rwops_reader = (MRWOPSREADER *) reader;
857e53c5a2da Renamed from mod.c (see modplug.c for the OTHER mod decoder).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
132 Sound_Sample *sample = rwops_reader->sample;
857e53c5a2da Renamed from mod.c (see modplug.c for the OTHER mod decoder).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
133 Sound_SampleInternal *internal = (Sound_SampleInternal *) sample->opaque;
857e53c5a2da Renamed from mod.c (see modplug.c for the OTHER mod decoder).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
134
857e53c5a2da Renamed from mod.c (see modplug.c for the OTHER mod decoder).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
135 if (SDL_RWread(internal->rw, &buf, 1, 1) != 1)
857e53c5a2da Renamed from mod.c (see modplug.c for the OTHER mod decoder).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
136 return(EOF);
857e53c5a2da Renamed from mod.c (see modplug.c for the OTHER mod decoder).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
137
857e53c5a2da Renamed from mod.c (see modplug.c for the OTHER mod decoder).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
138 return((int) buf);
857e53c5a2da Renamed from mod.c (see modplug.c for the OTHER mod decoder).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
139 } /* _mm_RWopsReader_get */
857e53c5a2da Renamed from mod.c (see modplug.c for the OTHER mod decoder).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
140
857e53c5a2da Renamed from mod.c (see modplug.c for the OTHER mod decoder).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
141
857e53c5a2da Renamed from mod.c (see modplug.c for the OTHER mod decoder).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
142 static BOOL _mm_RWopsReader_seek(MREADER *reader, long offset, int whence)
857e53c5a2da Renamed from mod.c (see modplug.c for the OTHER mod decoder).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
143 {
857e53c5a2da Renamed from mod.c (see modplug.c for the OTHER mod decoder).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
144 MRWOPSREADER *rwops_reader = (MRWOPSREADER *) reader;
857e53c5a2da Renamed from mod.c (see modplug.c for the OTHER mod decoder).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
145 Sound_Sample *sample = rwops_reader->sample;
857e53c5a2da Renamed from mod.c (see modplug.c for the OTHER mod decoder).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
146 Sound_SampleInternal *internal = (Sound_SampleInternal *) sample->opaque;
857e53c5a2da Renamed from mod.c (see modplug.c for the OTHER mod decoder).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
147
857e53c5a2da Renamed from mod.c (see modplug.c for the OTHER mod decoder).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
148 return(SDL_RWseek(internal->rw, offset, whence));
857e53c5a2da Renamed from mod.c (see modplug.c for the OTHER mod decoder).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
149 } /* _mm_RWopsReader_seek */
857e53c5a2da Renamed from mod.c (see modplug.c for the OTHER mod decoder).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
150
857e53c5a2da Renamed from mod.c (see modplug.c for the OTHER mod decoder).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
151
857e53c5a2da Renamed from mod.c (see modplug.c for the OTHER mod decoder).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
152 static long _mm_RWopsReader_tell(MREADER *reader)
857e53c5a2da Renamed from mod.c (see modplug.c for the OTHER mod decoder).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
153 {
857e53c5a2da Renamed from mod.c (see modplug.c for the OTHER mod decoder).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
154 MRWOPSREADER *rwops_reader = (MRWOPSREADER *) reader;
857e53c5a2da Renamed from mod.c (see modplug.c for the OTHER mod decoder).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
155 Sound_Sample *sample = rwops_reader->sample;
857e53c5a2da Renamed from mod.c (see modplug.c for the OTHER mod decoder).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
156 Sound_SampleInternal *internal = (Sound_SampleInternal *) sample->opaque;
857e53c5a2da Renamed from mod.c (see modplug.c for the OTHER mod decoder).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
157
857e53c5a2da Renamed from mod.c (see modplug.c for the OTHER mod decoder).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
158 return(SDL_RWtell(internal->rw));
857e53c5a2da Renamed from mod.c (see modplug.c for the OTHER mod decoder).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
159 } /* _mm_RWopsReader_tell */
857e53c5a2da Renamed from mod.c (see modplug.c for the OTHER mod decoder).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
160
857e53c5a2da Renamed from mod.c (see modplug.c for the OTHER mod decoder).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
161
857e53c5a2da Renamed from mod.c (see modplug.c for the OTHER mod decoder).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
162 static MREADER *_mm_new_rwops_reader(Sound_Sample *sample)
857e53c5a2da Renamed from mod.c (see modplug.c for the OTHER mod decoder).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
163 {
857e53c5a2da Renamed from mod.c (see modplug.c for the OTHER mod decoder).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
164 Sound_SampleInternal *internal = (Sound_SampleInternal *) sample->opaque;
857e53c5a2da Renamed from mod.c (see modplug.c for the OTHER mod decoder).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
165
857e53c5a2da Renamed from mod.c (see modplug.c for the OTHER mod decoder).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
166 MRWOPSREADER *reader = (MRWOPSREADER *) malloc(sizeof (MRWOPSREADER));
857e53c5a2da Renamed from mod.c (see modplug.c for the OTHER mod decoder).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
167 if (reader != NULL)
857e53c5a2da Renamed from mod.c (see modplug.c for the OTHER mod decoder).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
168 {
397
077cdba5d5f6 FIXME cleanup.
Ryan C. Gordon <icculus@icculus.org>
parents: 375
diff changeset
169 int failed_seek = 1;
207
857e53c5a2da Renamed from mod.c (see modplug.c for the OTHER mod decoder).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
170 int here;
857e53c5a2da Renamed from mod.c (see modplug.c for the OTHER mod decoder).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
171 reader->core.Eof = _mm_RWopsReader_eof;
857e53c5a2da Renamed from mod.c (see modplug.c for the OTHER mod decoder).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
172 reader->core.Read = _mm_RWopsReader_read;
857e53c5a2da Renamed from mod.c (see modplug.c for the OTHER mod decoder).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
173 reader->core.Get = _mm_RWopsReader_get;
857e53c5a2da Renamed from mod.c (see modplug.c for the OTHER mod decoder).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
174 reader->core.Seek = _mm_RWopsReader_seek;
857e53c5a2da Renamed from mod.c (see modplug.c for the OTHER mod decoder).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
175 reader->core.Tell = _mm_RWopsReader_tell;
857e53c5a2da Renamed from mod.c (see modplug.c for the OTHER mod decoder).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
176 reader->sample = sample;
857e53c5a2da Renamed from mod.c (see modplug.c for the OTHER mod decoder).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
177
857e53c5a2da Renamed from mod.c (see modplug.c for the OTHER mod decoder).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
178 /* RWops does not explicitly support an eof check, so we shall find
857e53c5a2da Renamed from mod.c (see modplug.c for the OTHER mod decoder).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
179 the end manually - this requires seek support for the RWop */
857e53c5a2da Renamed from mod.c (see modplug.c for the OTHER mod decoder).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
180 here = SDL_RWtell(internal->rw);
397
077cdba5d5f6 FIXME cleanup.
Ryan C. Gordon <icculus@icculus.org>
parents: 375
diff changeset
181 if (here != -1)
077cdba5d5f6 FIXME cleanup.
Ryan C. Gordon <icculus@icculus.org>
parents: 375
diff changeset
182 {
077cdba5d5f6 FIXME cleanup.
Ryan C. Gordon <icculus@icculus.org>
parents: 375
diff changeset
183 reader->end = SDL_RWseek(internal->rw, 0, SEEK_END);
077cdba5d5f6 FIXME cleanup.
Ryan C. Gordon <icculus@icculus.org>
parents: 375
diff changeset
184 if (reader->end != -1)
077cdba5d5f6 FIXME cleanup.
Ryan C. Gordon <icculus@icculus.org>
parents: 375
diff changeset
185 {
077cdba5d5f6 FIXME cleanup.
Ryan C. Gordon <icculus@icculus.org>
parents: 375
diff changeset
186 /* Move back */
077cdba5d5f6 FIXME cleanup.
Ryan C. Gordon <icculus@icculus.org>
parents: 375
diff changeset
187 if (SDL_RWseek(internal->rw, here, SEEK_SET) != -1)
077cdba5d5f6 FIXME cleanup.
Ryan C. Gordon <icculus@icculus.org>
parents: 375
diff changeset
188 failed_seek = 0;
077cdba5d5f6 FIXME cleanup.
Ryan C. Gordon <icculus@icculus.org>
parents: 375
diff changeset
189 } /* if */
077cdba5d5f6 FIXME cleanup.
Ryan C. Gordon <icculus@icculus.org>
parents: 375
diff changeset
190 } /* if */
077cdba5d5f6 FIXME cleanup.
Ryan C. Gordon <icculus@icculus.org>
parents: 375
diff changeset
191
077cdba5d5f6 FIXME cleanup.
Ryan C. Gordon <icculus@icculus.org>
parents: 375
diff changeset
192 if (failed_seek)
077cdba5d5f6 FIXME cleanup.
Ryan C. Gordon <icculus@icculus.org>
parents: 375
diff changeset
193 {
077cdba5d5f6 FIXME cleanup.
Ryan C. Gordon <icculus@icculus.org>
parents: 375
diff changeset
194 free(reader);
077cdba5d5f6 FIXME cleanup.
Ryan C. Gordon <icculus@icculus.org>
parents: 375
diff changeset
195 reader = NULL;
077cdba5d5f6 FIXME cleanup.
Ryan C. Gordon <icculus@icculus.org>
parents: 375
diff changeset
196 } /* if */
207
857e53c5a2da Renamed from mod.c (see modplug.c for the OTHER mod decoder).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
197 } /* if */
857e53c5a2da Renamed from mod.c (see modplug.c for the OTHER mod decoder).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
198
857e53c5a2da Renamed from mod.c (see modplug.c for the OTHER mod decoder).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
199 return((MREADER *) reader);
857e53c5a2da Renamed from mod.c (see modplug.c for the OTHER mod decoder).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
200 } /* _mm_new_rwops_reader */
857e53c5a2da Renamed from mod.c (see modplug.c for the OTHER mod decoder).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
201
857e53c5a2da Renamed from mod.c (see modplug.c for the OTHER mod decoder).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
202
857e53c5a2da Renamed from mod.c (see modplug.c for the OTHER mod decoder).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
203 static void _mm_delete_rwops_reader(MREADER *reader)
857e53c5a2da Renamed from mod.c (see modplug.c for the OTHER mod decoder).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
204 {
474
c66080364dff Most decoders now report total sample play time, now. Technically, this
Ryan C. Gordon <icculus@icculus.org>
parents: 473
diff changeset
205 /* SDL_sound will delete the RWops and sample at a higher level... */
207
857e53c5a2da Renamed from mod.c (see modplug.c for the OTHER mod decoder).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
206 if (reader != NULL)
857e53c5a2da Renamed from mod.c (see modplug.c for the OTHER mod decoder).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
207 free(reader);
857e53c5a2da Renamed from mod.c (see modplug.c for the OTHER mod decoder).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
208 } /* _mm_delete_rwops_reader */
857e53c5a2da Renamed from mod.c (see modplug.c for the OTHER mod decoder).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
209
857e53c5a2da Renamed from mod.c (see modplug.c for the OTHER mod decoder).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
210
857e53c5a2da Renamed from mod.c (see modplug.c for the OTHER mod decoder).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
211
857e53c5a2da Renamed from mod.c (see modplug.c for the OTHER mod decoder).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
212 static int MIKMOD_init(void)
857e53c5a2da Renamed from mod.c (see modplug.c for the OTHER mod decoder).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
213 {
857e53c5a2da Renamed from mod.c (see modplug.c for the OTHER mod decoder).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
214 MikMod_RegisterDriver(&drv_nos);
434
c09cf7c046cd Prevent a clash between SDL_mixer and SDL_sound in mikmod initialization.
Ryan C. Gordon <icculus@icculus.org>
parents: 397
diff changeset
215
474
c66080364dff Most decoders now report total sample play time, now. Technically, this
Ryan C. Gordon <icculus@icculus.org>
parents: 473
diff changeset
216 /*
c66080364dff Most decoders now report total sample play time, now. Technically, this
Ryan C. Gordon <icculus@icculus.org>
parents: 473
diff changeset
217 * Quick and dirty hack to prevent an infinite loop problem
c66080364dff Most decoders now report total sample play time, now. Technically, this
Ryan C. Gordon <icculus@icculus.org>
parents: 473
diff changeset
218 * found when using SDL_mixer and SDL_sound together and
c66080364dff Most decoders now report total sample play time, now. Technically, this
Ryan C. Gordon <icculus@icculus.org>
parents: 473
diff changeset
219 * both have MikMod compiled in. So, check to see if
c66080364dff Most decoders now report total sample play time, now. Technically, this
Ryan C. Gordon <icculus@icculus.org>
parents: 473
diff changeset
220 * MikMod has already been registered first before calling
c66080364dff Most decoders now report total sample play time, now. Technically, this
Ryan C. Gordon <icculus@icculus.org>
parents: 473
diff changeset
221 * RegisterAllLoaders()
c66080364dff Most decoders now report total sample play time, now. Technically, this
Ryan C. Gordon <icculus@icculus.org>
parents: 473
diff changeset
222 */
c66080364dff Most decoders now report total sample play time, now. Technically, this
Ryan C. Gordon <icculus@icculus.org>
parents: 473
diff changeset
223 if (MikMod_InfoLoader() == NULL)
434
c09cf7c046cd Prevent a clash between SDL_mixer and SDL_sound in mikmod initialization.
Ryan C. Gordon <icculus@icculus.org>
parents: 397
diff changeset
224 {
c09cf7c046cd Prevent a clash between SDL_mixer and SDL_sound in mikmod initialization.
Ryan C. Gordon <icculus@icculus.org>
parents: 397
diff changeset
225 MikMod_RegisterAllLoaders();
474
c66080364dff Most decoders now report total sample play time, now. Technically, this
Ryan C. Gordon <icculus@icculus.org>
parents: 473
diff changeset
226 } /* if */
c66080364dff Most decoders now report total sample play time, now. Technically, this
Ryan C. Gordon <icculus@icculus.org>
parents: 473
diff changeset
227
207
857e53c5a2da Renamed from mod.c (see modplug.c for the OTHER mod decoder).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
228 /*
857e53c5a2da Renamed from mod.c (see modplug.c for the OTHER mod decoder).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
229 * Both DMODE_SOFT_MUSIC and DMODE_16BITS should be set by default,
857e53c5a2da Renamed from mod.c (see modplug.c for the OTHER mod decoder).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
230 * so this is just for clarity. I haven't experimented with any of
857e53c5a2da Renamed from mod.c (see modplug.c for the OTHER mod decoder).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
231 * the other flags. There are a few which are said to give better
857e53c5a2da Renamed from mod.c (see modplug.c for the OTHER mod decoder).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
232 * sound quality.
857e53c5a2da Renamed from mod.c (see modplug.c for the OTHER mod decoder).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
233 */
857e53c5a2da Renamed from mod.c (see modplug.c for the OTHER mod decoder).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
234 md_mode |= (DMODE_SOFT_MUSIC | DMODE_16BITS);
857e53c5a2da Renamed from mod.c (see modplug.c for the OTHER mod decoder).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
235 md_mixfreq = 0;
375
6095d0a52a20 Added a reverb setting, moved assert.h include out.
Ryan C. Gordon <icculus@icculus.org>
parents: 351
diff changeset
236 md_reverb = 1;
207
857e53c5a2da Renamed from mod.c (see modplug.c for the OTHER mod decoder).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
237
857e53c5a2da Renamed from mod.c (see modplug.c for the OTHER mod decoder).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
238 BAIL_IF_MACRO(MikMod_Init(""), MikMod_strerror(MikMod_errno), 0);
857e53c5a2da Renamed from mod.c (see modplug.c for the OTHER mod decoder).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
239
857e53c5a2da Renamed from mod.c (see modplug.c for the OTHER mod decoder).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
240 return(1); /* success. */
857e53c5a2da Renamed from mod.c (see modplug.c for the OTHER mod decoder).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
241 } /* MIKMOD_init */
857e53c5a2da Renamed from mod.c (see modplug.c for the OTHER mod decoder).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
242
857e53c5a2da Renamed from mod.c (see modplug.c for the OTHER mod decoder).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
243
857e53c5a2da Renamed from mod.c (see modplug.c for the OTHER mod decoder).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
244 static void MIKMOD_quit(void)
857e53c5a2da Renamed from mod.c (see modplug.c for the OTHER mod decoder).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
245 {
857e53c5a2da Renamed from mod.c (see modplug.c for the OTHER mod decoder).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
246 MikMod_Exit();
857e53c5a2da Renamed from mod.c (see modplug.c for the OTHER mod decoder).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
247 md_mixfreq = 0;
857e53c5a2da Renamed from mod.c (see modplug.c for the OTHER mod decoder).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
248 } /* MIKMOD_quit */
857e53c5a2da Renamed from mod.c (see modplug.c for the OTHER mod decoder).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
249
857e53c5a2da Renamed from mod.c (see modplug.c for the OTHER mod decoder).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
250
857e53c5a2da Renamed from mod.c (see modplug.c for the OTHER mod decoder).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
251 static int MIKMOD_open(Sound_Sample *sample, const char *ext)
857e53c5a2da Renamed from mod.c (see modplug.c for the OTHER mod decoder).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
252 {
857e53c5a2da Renamed from mod.c (see modplug.c for the OTHER mod decoder).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
253 Sound_SampleInternal *internal = (Sound_SampleInternal *) sample->opaque;
857e53c5a2da Renamed from mod.c (see modplug.c for the OTHER mod decoder).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
254 MREADER *reader;
857e53c5a2da Renamed from mod.c (see modplug.c for the OTHER mod decoder).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
255 MODULE *module;
474
c66080364dff Most decoders now report total sample play time, now. Technically, this
Ryan C. Gordon <icculus@icculus.org>
parents: 473
diff changeset
256 Uint32 i; /* temp counter for time computation */
c66080364dff Most decoders now report total sample play time, now. Technically, this
Ryan C. Gordon <icculus@icculus.org>
parents: 473
diff changeset
257 double segment_time = 0.0; /* temp holder for time */
c66080364dff Most decoders now report total sample play time, now. Technically, this
Ryan C. Gordon <icculus@icculus.org>
parents: 473
diff changeset
258
207
857e53c5a2da Renamed from mod.c (see modplug.c for the OTHER mod decoder).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
259 reader = _mm_new_rwops_reader(sample);
857e53c5a2da Renamed from mod.c (see modplug.c for the OTHER mod decoder).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
260 BAIL_IF_MACRO(reader == NULL, ERR_OUT_OF_MEMORY, 0);
857e53c5a2da Renamed from mod.c (see modplug.c for the OTHER mod decoder).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
261 module = Player_LoadGeneric(reader, 64, 0);
857e53c5a2da Renamed from mod.c (see modplug.c for the OTHER mod decoder).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
262 _mm_delete_rwops_reader(reader);
857e53c5a2da Renamed from mod.c (see modplug.c for the OTHER mod decoder).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
263 BAIL_IF_MACRO(module == NULL, "MIKMOD: Not a module file.", 0);
857e53c5a2da Renamed from mod.c (see modplug.c for the OTHER mod decoder).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
264
857e53c5a2da Renamed from mod.c (see modplug.c for the OTHER mod decoder).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
265 module->extspd = 1;
857e53c5a2da Renamed from mod.c (see modplug.c for the OTHER mod decoder).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
266 module->panflag = 1;
857e53c5a2da Renamed from mod.c (see modplug.c for the OTHER mod decoder).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
267 module->wrap = 0;
857e53c5a2da Renamed from mod.c (see modplug.c for the OTHER mod decoder).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
268 module->loop = 0;
857e53c5a2da Renamed from mod.c (see modplug.c for the OTHER mod decoder).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
269
857e53c5a2da Renamed from mod.c (see modplug.c for the OTHER mod decoder).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
270 if (md_mixfreq == 0)
857e53c5a2da Renamed from mod.c (see modplug.c for the OTHER mod decoder).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
271 md_mixfreq = (!sample->desired.rate) ? 44100 : sample->desired.rate;
857e53c5a2da Renamed from mod.c (see modplug.c for the OTHER mod decoder).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
272
857e53c5a2da Renamed from mod.c (see modplug.c for the OTHER mod decoder).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
273 sample->actual.channels = 2;
857e53c5a2da Renamed from mod.c (see modplug.c for the OTHER mod decoder).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
274 sample->actual.rate = md_mixfreq;
857e53c5a2da Renamed from mod.c (see modplug.c for the OTHER mod decoder).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
275 sample->actual.format = AUDIO_S16SYS;
857e53c5a2da Renamed from mod.c (see modplug.c for the OTHER mod decoder).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
276 internal->decoder_private = (void *) module;
857e53c5a2da Renamed from mod.c (see modplug.c for the OTHER mod decoder).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
277
857e53c5a2da Renamed from mod.c (see modplug.c for the OTHER mod decoder).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
278 Player_Start(module);
857e53c5a2da Renamed from mod.c (see modplug.c for the OTHER mod decoder).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
279 Player_SetPosition(0);
857e53c5a2da Renamed from mod.c (see modplug.c for the OTHER mod decoder).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
280
312
498240aa76f1 Seek implementations.
Ryan C. Gordon <icculus@icculus.org>
parents: 306
diff changeset
281 sample->flags = SOUND_SAMPLEFLAG_NONE;
207
857e53c5a2da Renamed from mod.c (see modplug.c for the OTHER mod decoder).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
282
474
c66080364dff Most decoders now report total sample play time, now. Technically, this
Ryan C. Gordon <icculus@icculus.org>
parents: 473
diff changeset
283 /*
c66080364dff Most decoders now report total sample play time, now. Technically, this
Ryan C. Gordon <icculus@icculus.org>
parents: 473
diff changeset
284 * module->sngtime = current song time in 2^-10 seconds
477
3e705c9180e5 Fixed binary compatibility, added Sound_GetDuration().
Ryan C. Gordon <icculus@icculus.org>
parents: 474
diff changeset
285 * internal->total_time = (module->sngtime * 1000) / (1<<10)
474
c66080364dff Most decoders now report total sample play time, now. Technically, this
Ryan C. Gordon <icculus@icculus.org>
parents: 473
diff changeset
286 */
477
3e705c9180e5 Fixed binary compatibility, added Sound_GetDuration().
Ryan C. Gordon <icculus@icculus.org>
parents: 474
diff changeset
287 internal->total_time = (module->sngtime * 1000) / (1<<10);
474
c66080364dff Most decoders now report total sample play time, now. Technically, this
Ryan C. Gordon <icculus@icculus.org>
parents: 473
diff changeset
288
207
857e53c5a2da Renamed from mod.c (see modplug.c for the OTHER mod decoder).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
289 SNDDBG(("MIKMOD: Name: %s\n", module->songname));
857e53c5a2da Renamed from mod.c (see modplug.c for the OTHER mod decoder).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
290 SNDDBG(("MIKMOD: Type: %s\n", module->modtype));
857e53c5a2da Renamed from mod.c (see modplug.c for the OTHER mod decoder).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
291 SNDDBG(("MIKMOD: Accepting data stream\n"));
857e53c5a2da Renamed from mod.c (see modplug.c for the OTHER mod decoder).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
292
474
c66080364dff Most decoders now report total sample play time, now. Technically, this
Ryan C. Gordon <icculus@icculus.org>
parents: 473
diff changeset
293
c66080364dff Most decoders now report total sample play time, now. Technically, this
Ryan C. Gordon <icculus@icculus.org>
parents: 473
diff changeset
294 /*
c66080364dff Most decoders now report total sample play time, now. Technically, this
Ryan C. Gordon <icculus@icculus.org>
parents: 473
diff changeset
295 * This is a quick and dirty way for getting the play time
c66080364dff Most decoders now report total sample play time, now. Technically, this
Ryan C. Gordon <icculus@icculus.org>
parents: 473
diff changeset
296 * of a file. This will often be wrong because the tracker format
c66080364dff Most decoders now report total sample play time, now. Technically, this
Ryan C. Gordon <icculus@icculus.org>
parents: 473
diff changeset
297 * allows for so much. If you want a better one, use ModPlug,
c66080364dff Most decoders now report total sample play time, now. Technically, this
Ryan C. Gordon <icculus@icculus.org>
parents: 473
diff changeset
298 * demand that the Mikmod people write better functionality,
c66080364dff Most decoders now report total sample play time, now. Technically, this
Ryan C. Gordon <icculus@icculus.org>
parents: 473
diff changeset
299 * or write a more complicated version of the code below.
c66080364dff Most decoders now report total sample play time, now. Technically, this
Ryan C. Gordon <icculus@icculus.org>
parents: 473
diff changeset
300 *
c66080364dff Most decoders now report total sample play time, now. Technically, this
Ryan C. Gordon <icculus@icculus.org>
parents: 473
diff changeset
301 * There are two dumb ways to compute the length. The really
c66080364dff Most decoders now report total sample play time, now. Technically, this
Ryan C. Gordon <icculus@icculus.org>
parents: 473
diff changeset
302 * dumb way is to look at the header and take the initial
c66080364dff Most decoders now report total sample play time, now. Technically, this
Ryan C. Gordon <icculus@icculus.org>
parents: 473
diff changeset
303 * speed/tempo values. However, speed values can change throughout
c66080364dff Most decoders now report total sample play time, now. Technically, this
Ryan C. Gordon <icculus@icculus.org>
parents: 473
diff changeset
304 * the file. The slightly smarter way is to iterate through
c66080364dff Most decoders now report total sample play time, now. Technically, this
Ryan C. Gordon <icculus@icculus.org>
parents: 473
diff changeset
305 * all the positions and add up each segment's time based
c66080364dff Most decoders now report total sample play time, now. Technically, this
Ryan C. Gordon <icculus@icculus.org>
parents: 473
diff changeset
306 * on the idea that each segment will give us its own
c66080364dff Most decoders now report total sample play time, now. Technically, this
Ryan C. Gordon <icculus@icculus.org>
parents: 473
diff changeset
307 * speed value. The hope is that this is more accurate.
c66080364dff Most decoders now report total sample play time, now. Technically, this
Ryan C. Gordon <icculus@icculus.org>
parents: 473
diff changeset
308 * However, this demands that the file be seekable
c66080364dff Most decoders now report total sample play time, now. Technically, this
Ryan C. Gordon <icculus@icculus.org>
parents: 473
diff changeset
309 * and that we can change the position of the sample.
c66080364dff Most decoders now report total sample play time, now. Technically, this
Ryan C. Gordon <icculus@icculus.org>
parents: 473
diff changeset
310 * Depending on the assumptions of SDL_sound, this block
c66080364dff Most decoders now report total sample play time, now. Technically, this
Ryan C. Gordon <icculus@icculus.org>
parents: 473
diff changeset
311 * of code should be enabled or disabled. If disabled,
c66080364dff Most decoders now report total sample play time, now. Technically, this
Ryan C. Gordon <icculus@icculus.org>
parents: 473
diff changeset
312 * you still can make the computations doing the first method.
c66080364dff Most decoders now report total sample play time, now. Technically, this
Ryan C. Gordon <icculus@icculus.org>
parents: 473
diff changeset
313 * For now, we will assume it's acceptable to seek a Mod file
c66080364dff Most decoders now report total sample play time, now. Technically, this
Ryan C. Gordon <icculus@icculus.org>
parents: 473
diff changeset
314 * since this is essentially how Modplug also does it.
c66080364dff Most decoders now report total sample play time, now. Technically, this
Ryan C. Gordon <icculus@icculus.org>
parents: 473
diff changeset
315 *
c66080364dff Most decoders now report total sample play time, now. Technically, this
Ryan C. Gordon <icculus@icculus.org>
parents: 473
diff changeset
316 * Keep in mind that this will be incorrect for loops, jumps, short
c66080364dff Most decoders now report total sample play time, now. Technically, this
Ryan C. Gordon <icculus@icculus.org>
parents: 473
diff changeset
317 * patterns and other features.
c66080364dff Most decoders now report total sample play time, now. Technically, this
Ryan C. Gordon <icculus@icculus.org>
parents: 473
diff changeset
318 */
c66080364dff Most decoders now report total sample play time, now. Technically, this
Ryan C. Gordon <icculus@icculus.org>
parents: 473
diff changeset
319 sample->flags |= SOUND_SAMPLEFLAG_CANSEEK;
c66080364dff Most decoders now report total sample play time, now. Technically, this
Ryan C. Gordon <icculus@icculus.org>
parents: 473
diff changeset
320
c66080364dff Most decoders now report total sample play time, now. Technically, this
Ryan C. Gordon <icculus@icculus.org>
parents: 473
diff changeset
321 /*
c66080364dff Most decoders now report total sample play time, now. Technically, this
Ryan C. Gordon <icculus@icculus.org>
parents: 473
diff changeset
322 * For each position (which corresponds to a particular pattern),
c66080364dff Most decoders now report total sample play time, now. Technically, this
Ryan C. Gordon <icculus@icculus.org>
parents: 473
diff changeset
323 * get the speed values and compute the time length of the segment
c66080364dff Most decoders now report total sample play time, now. Technically, this
Ryan C. Gordon <icculus@icculus.org>
parents: 473
diff changeset
324 */
477
3e705c9180e5 Fixed binary compatibility, added Sound_GetDuration().
Ryan C. Gordon <icculus@icculus.org>
parents: 474
diff changeset
325 internal->total_time = 0;
474
c66080364dff Most decoders now report total sample play time, now. Technically, this
Ryan C. Gordon <icculus@icculus.org>
parents: 473
diff changeset
326 for (i = 0; i < module->numpos; i++)
c66080364dff Most decoders now report total sample play time, now. Technically, this
Ryan C. Gordon <icculus@icculus.org>
parents: 473
diff changeset
327 {
c66080364dff Most decoders now report total sample play time, now. Technically, this
Ryan C. Gordon <icculus@icculus.org>
parents: 473
diff changeset
328 Player_SetPosition(i);
c66080364dff Most decoders now report total sample play time, now. Technically, this
Ryan C. Gordon <icculus@icculus.org>
parents: 473
diff changeset
329 /* Must call update, or the speed values won't get reset */
c66080364dff Most decoders now report total sample play time, now. Technically, this
Ryan C. Gordon <icculus@icculus.org>
parents: 473
diff changeset
330 MikMod_Update();
c66080364dff Most decoders now report total sample play time, now. Technically, this
Ryan C. Gordon <icculus@icculus.org>
parents: 473
diff changeset
331 /* Now the magic formula:
c66080364dff Most decoders now report total sample play time, now. Technically, this
Ryan C. Gordon <icculus@icculus.org>
parents: 473
diff changeset
332 * Multiply the number of positions by the
c66080364dff Most decoders now report total sample play time, now. Technically, this
Ryan C. Gordon <icculus@icculus.org>
parents: 473
diff changeset
333 * Number of rows (usually 64 but can be different) by the
c66080364dff Most decoders now report total sample play time, now. Technically, this
Ryan C. Gordon <icculus@icculus.org>
parents: 473
diff changeset
334 * time it takes to read one row (1/50)
c66080364dff Most decoders now report total sample play time, now. Technically, this
Ryan C. Gordon <icculus@icculus.org>
parents: 473
diff changeset
335 * by the speed by the
c66080364dff Most decoders now report total sample play time, now. Technically, this
Ryan C. Gordon <icculus@icculus.org>
parents: 473
diff changeset
336 * magic reference beats per minute / the beats per minute
c66080364dff Most decoders now report total sample play time, now. Technically, this
Ryan C. Gordon <icculus@icculus.org>
parents: 473
diff changeset
337 *
c66080364dff Most decoders now report total sample play time, now. Technically, this
Ryan C. Gordon <icculus@icculus.org>
parents: 473
diff changeset
338 * We're using positions instead of patterns because in our
c66080364dff Most decoders now report total sample play time, now. Technically, this
Ryan C. Gordon <icculus@icculus.org>
parents: 473
diff changeset
339 * test cases, this seems to be the correct value for the
c66080364dff Most decoders now report total sample play time, now. Technically, this
Ryan C. Gordon <icculus@icculus.org>
parents: 473
diff changeset
340 * number of sections you hear during normal playback.
c66080364dff Most decoders now report total sample play time, now. Technically, this
Ryan C. Gordon <icculus@icculus.org>
parents: 473
diff changeset
341 * They typically map to a fewer number of patterns
c66080364dff Most decoders now report total sample play time, now. Technically, this
Ryan C. Gordon <icculus@icculus.org>
parents: 473
diff changeset
342 * where some patterns get replayed multiple times
c66080364dff Most decoders now report total sample play time, now. Technically, this
Ryan C. Gordon <icculus@icculus.org>
parents: 473
diff changeset
343 * in a song (think chorus). Since we're in a for-loop,
c66080364dff Most decoders now report total sample play time, now. Technically, this
Ryan C. Gordon <icculus@icculus.org>
parents: 473
diff changeset
344 * the multiplication is implicit while we're adding
c66080364dff Most decoders now report total sample play time, now. Technically, this
Ryan C. Gordon <icculus@icculus.org>
parents: 473
diff changeset
345 * all the segments.
c66080364dff Most decoders now report total sample play time, now. Technically, this
Ryan C. Gordon <icculus@icculus.org>
parents: 473
diff changeset
346 *
c66080364dff Most decoders now report total sample play time, now. Technically, this
Ryan C. Gordon <icculus@icculus.org>
parents: 473
diff changeset
347 * From a tracker format spec, it seems that 64 rows
c66080364dff Most decoders now report total sample play time, now. Technically, this
Ryan C. Gordon <icculus@icculus.org>
parents: 473
diff changeset
348 * is the normal (00-3F), but I've seen songs that
c66080364dff Most decoders now report total sample play time, now. Technically, this
Ryan C. Gordon <icculus@icculus.org>
parents: 473
diff changeset
349 * either have less or are jumping positions in the
c66080364dff Most decoders now report total sample play time, now. Technically, this
Ryan C. Gordon <icculus@icculus.org>
parents: 473
diff changeset
350 * middle of a pattern. It looks like Mikmod might
c66080364dff Most decoders now report total sample play time, now. Technically, this
Ryan C. Gordon <icculus@icculus.org>
parents: 473
diff changeset
351 * reveal this number for us.
c66080364dff Most decoders now report total sample play time, now. Technically, this
Ryan C. Gordon <icculus@icculus.org>
parents: 473
diff changeset
352 *
c66080364dff Most decoders now report total sample play time, now. Technically, this
Ryan C. Gordon <icculus@icculus.org>
parents: 473
diff changeset
353 * According to the spec, it seems that a speed of 1
c66080364dff Most decoders now report total sample play time, now. Technically, this
Ryan C. Gordon <icculus@icculus.org>
parents: 473
diff changeset
354 * corresponds to reading 1 row in 50 ticks. However,
c66080364dff Most decoders now report total sample play time, now. Technically, this
Ryan C. Gordon <icculus@icculus.org>
parents: 473
diff changeset
355 * I'm not sure if ticks are real seconds or this
c66080364dff Most decoders now report total sample play time, now. Technically, this
Ryan C. Gordon <icculus@icculus.org>
parents: 473
diff changeset
356 * notion of second units:
c66080364dff Most decoders now report total sample play time, now. Technically, this
Ryan C. Gordon <icculus@icculus.org>
parents: 473
diff changeset
357 * Assuming that it's just normal seconds, we get 1/50 = 0.02.
c66080364dff Most decoders now report total sample play time, now. Technically, this
Ryan C. Gordon <icculus@icculus.org>
parents: 473
diff changeset
358 *
c66080364dff Most decoders now report total sample play time, now. Technically, this
Ryan C. Gordon <icculus@icculus.org>
parents: 473
diff changeset
359 * The current speed and current tempo (beats per minute)
c66080364dff Most decoders now report total sample play time, now. Technically, this
Ryan C. Gordon <icculus@icculus.org>
parents: 473
diff changeset
360 * we can just grab. However, we need a magic number
c66080364dff Most decoders now report total sample play time, now. Technically, this
Ryan C. Gordon <icculus@icculus.org>
parents: 473
diff changeset
361 * to figure out what the tempo is based on. Our primitive
c66080364dff Most decoders now report total sample play time, now. Technically, this
Ryan C. Gordon <icculus@icculus.org>
parents: 473
diff changeset
362 * stopwatch results and intuition seem to imply 120-130bpm
c66080364dff Most decoders now report total sample play time, now. Technically, this
Ryan C. Gordon <icculus@icculus.org>
parents: 473
diff changeset
363 * is the magic number. Looking at the majority of tracker
c66080364dff Most decoders now report total sample play time, now. Technically, this
Ryan C. Gordon <icculus@icculus.org>
parents: 473
diff changeset
364 * files I have, 125 seems to be the common value. Furthermore
c66080364dff Most decoders now report total sample play time, now. Technically, this
Ryan C. Gordon <icculus@icculus.org>
parents: 473
diff changeset
365 * most (if not all) of my Future Crew .S3M (Scream Tracker 3)
c66080364dff Most decoders now report total sample play time, now. Technically, this
Ryan C. Gordon <icculus@icculus.org>
parents: 473
diff changeset
366 * files also use 125. Since they invented that format,
c66080364dff Most decoders now report total sample play time, now. Technically, this
Ryan C. Gordon <icculus@icculus.org>
parents: 473
diff changeset
367 * I'll also assume that's the base number.
c66080364dff Most decoders now report total sample play time, now. Technically, this
Ryan C. Gordon <icculus@icculus.org>
parents: 473
diff changeset
368 */
c66080364dff Most decoders now report total sample play time, now. Technically, this
Ryan C. Gordon <icculus@icculus.org>
parents: 473
diff changeset
369 if(module->bpm == 0)
c66080364dff Most decoders now report total sample play time, now. Technically, this
Ryan C. Gordon <icculus@icculus.org>
parents: 473
diff changeset
370 {
c66080364dff Most decoders now report total sample play time, now. Technically, this
Ryan C. Gordon <icculus@icculus.org>
parents: 473
diff changeset
371 /*
c66080364dff Most decoders now report total sample play time, now. Technically, this
Ryan C. Gordon <icculus@icculus.org>
parents: 473
diff changeset
372 * Should never get here, but I don't want any
c66080364dff Most decoders now report total sample play time, now. Technically, this
Ryan C. Gordon <icculus@icculus.org>
parents: 473
diff changeset
373 * divide by zero errors
c66080364dff Most decoders now report total sample play time, now. Technically, this
Ryan C. Gordon <icculus@icculus.org>
parents: 473
diff changeset
374 */
c66080364dff Most decoders now report total sample play time, now. Technically, this
Ryan C. Gordon <icculus@icculus.org>
parents: 473
diff changeset
375 continue;
c66080364dff Most decoders now report total sample play time, now. Technically, this
Ryan C. Gordon <icculus@icculus.org>
parents: 473
diff changeset
376 } /* if */
c66080364dff Most decoders now report total sample play time, now. Technically, this
Ryan C. Gordon <icculus@icculus.org>
parents: 473
diff changeset
377 segment_time += (module->numrow * .02 * module->sngspd *
c66080364dff Most decoders now report total sample play time, now. Technically, this
Ryan C. Gordon <icculus@icculus.org>
parents: 473
diff changeset
378 125.0 / module->bpm);
c66080364dff Most decoders now report total sample play time, now. Technically, this
Ryan C. Gordon <icculus@icculus.org>
parents: 473
diff changeset
379 } /* for */
c66080364dff Most decoders now report total sample play time, now. Technically, this
Ryan C. Gordon <icculus@icculus.org>
parents: 473
diff changeset
380 /* Now convert to milliseconds and store the value */
477
3e705c9180e5 Fixed binary compatibility, added Sound_GetDuration().
Ryan C. Gordon <icculus@icculus.org>
parents: 474
diff changeset
381 internal->total_time = (Sint32)(segment_time * 1000);
474
c66080364dff Most decoders now report total sample play time, now. Technically, this
Ryan C. Gordon <icculus@icculus.org>
parents: 473
diff changeset
382
c66080364dff Most decoders now report total sample play time, now. Technically, this
Ryan C. Gordon <icculus@icculus.org>
parents: 473
diff changeset
383 /* Reset the sample to the beginning */
c66080364dff Most decoders now report total sample play time, now. Technically, this
Ryan C. Gordon <icculus@icculus.org>
parents: 473
diff changeset
384 Player_SetPosition(0);
c66080364dff Most decoders now report total sample play time, now. Technically, this
Ryan C. Gordon <icculus@icculus.org>
parents: 473
diff changeset
385 MikMod_Update();
c66080364dff Most decoders now report total sample play time, now. Technically, this
Ryan C. Gordon <icculus@icculus.org>
parents: 473
diff changeset
386
207
857e53c5a2da Renamed from mod.c (see modplug.c for the OTHER mod decoder).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
387 return(1); /* we'll handle this data. */
857e53c5a2da Renamed from mod.c (see modplug.c for the OTHER mod decoder).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
388 } /* MIKMOD_open */
857e53c5a2da Renamed from mod.c (see modplug.c for the OTHER mod decoder).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
389
857e53c5a2da Renamed from mod.c (see modplug.c for the OTHER mod decoder).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
390
857e53c5a2da Renamed from mod.c (see modplug.c for the OTHER mod decoder).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
391 static void MIKMOD_close(Sound_Sample *sample)
857e53c5a2da Renamed from mod.c (see modplug.c for the OTHER mod decoder).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
392 {
857e53c5a2da Renamed from mod.c (see modplug.c for the OTHER mod decoder).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
393 Sound_SampleInternal *internal = (Sound_SampleInternal *) sample->opaque;
857e53c5a2da Renamed from mod.c (see modplug.c for the OTHER mod decoder).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
394 MODULE *module = (MODULE *) internal->decoder_private;
857e53c5a2da Renamed from mod.c (see modplug.c for the OTHER mod decoder).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
395
857e53c5a2da Renamed from mod.c (see modplug.c for the OTHER mod decoder).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
396 Player_Free(module);
857e53c5a2da Renamed from mod.c (see modplug.c for the OTHER mod decoder).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
397 } /* MIKMOD_close */
857e53c5a2da Renamed from mod.c (see modplug.c for the OTHER mod decoder).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
398
857e53c5a2da Renamed from mod.c (see modplug.c for the OTHER mod decoder).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
399
857e53c5a2da Renamed from mod.c (see modplug.c for the OTHER mod decoder).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
400 static Uint32 MIKMOD_read(Sound_Sample *sample)
857e53c5a2da Renamed from mod.c (see modplug.c for the OTHER mod decoder).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
401 {
857e53c5a2da Renamed from mod.c (see modplug.c for the OTHER mod decoder).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
402 Sound_SampleInternal *internal = (Sound_SampleInternal *) sample->opaque;
857e53c5a2da Renamed from mod.c (see modplug.c for the OTHER mod decoder).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
403 MODULE *module = (MODULE *) internal->decoder_private;
857e53c5a2da Renamed from mod.c (see modplug.c for the OTHER mod decoder).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
404
857e53c5a2da Renamed from mod.c (see modplug.c for the OTHER mod decoder).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
405 /* Switch to the current module, stopping any previous one. */
857e53c5a2da Renamed from mod.c (see modplug.c for the OTHER mod decoder).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
406 Player_Start(module);
857e53c5a2da Renamed from mod.c (see modplug.c for the OTHER mod decoder).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
407 if (!Player_Active())
857e53c5a2da Renamed from mod.c (see modplug.c for the OTHER mod decoder).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
408 {
857e53c5a2da Renamed from mod.c (see modplug.c for the OTHER mod decoder).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
409 sample->flags |= SOUND_SAMPLEFLAG_EOF;
857e53c5a2da Renamed from mod.c (see modplug.c for the OTHER mod decoder).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
410 return(0);
857e53c5a2da Renamed from mod.c (see modplug.c for the OTHER mod decoder).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
411 } /* if */
857e53c5a2da Renamed from mod.c (see modplug.c for the OTHER mod decoder).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
412 return((Uint32) VC_WriteBytes(internal->buffer, internal->buffer_size));
857e53c5a2da Renamed from mod.c (see modplug.c for the OTHER mod decoder).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
413 } /* MIKMOD_read */
857e53c5a2da Renamed from mod.c (see modplug.c for the OTHER mod decoder).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
414
221
c9772a9f5271 Initial implementation or stubs for rewind method. Other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 211
diff changeset
415
c9772a9f5271 Initial implementation or stubs for rewind method. Other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 211
diff changeset
416 static int MIKMOD_rewind(Sound_Sample *sample)
c9772a9f5271 Initial implementation or stubs for rewind method. Other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 211
diff changeset
417 {
231
d3dc34315ac7 Rewind method implemented by Torbj�rn.
Ryan C. Gordon <icculus@icculus.org>
parents: 221
diff changeset
418 Sound_SampleInternal *internal = (Sound_SampleInternal *) sample->opaque;
d3dc34315ac7 Rewind method implemented by Torbj�rn.
Ryan C. Gordon <icculus@icculus.org>
parents: 221
diff changeset
419 MODULE *module = (MODULE *) internal->decoder_private;
d3dc34315ac7 Rewind method implemented by Torbj�rn.
Ryan C. Gordon <icculus@icculus.org>
parents: 221
diff changeset
420
d3dc34315ac7 Rewind method implemented by Torbj�rn.
Ryan C. Gordon <icculus@icculus.org>
parents: 221
diff changeset
421 Player_Start(module);
d3dc34315ac7 Rewind method implemented by Torbj�rn.
Ryan C. Gordon <icculus@icculus.org>
parents: 221
diff changeset
422 Player_SetPosition(0);
d3dc34315ac7 Rewind method implemented by Torbj�rn.
Ryan C. Gordon <icculus@icculus.org>
parents: 221
diff changeset
423 return(1);
221
c9772a9f5271 Initial implementation or stubs for rewind method. Other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 211
diff changeset
424 } /* MIKMOD_rewind */
c9772a9f5271 Initial implementation or stubs for rewind method. Other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 211
diff changeset
425
c9772a9f5271 Initial implementation or stubs for rewind method. Other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 211
diff changeset
426
306
c97be6e1bd27 Added framework for Sound_Seek() support.
Ryan C. Gordon <icculus@icculus.org>
parents: 305
diff changeset
427 static int MIKMOD_seek(Sound_Sample *sample, Uint32 ms)
c97be6e1bd27 Added framework for Sound_Seek() support.
Ryan C. Gordon <icculus@icculus.org>
parents: 305
diff changeset
428 {
312
498240aa76f1 Seek implementations.
Ryan C. Gordon <icculus@icculus.org>
parents: 306
diff changeset
429 Sound_SampleInternal *internal = (Sound_SampleInternal *) sample->opaque;
498240aa76f1 Seek implementations.
Ryan C. Gordon <icculus@icculus.org>
parents: 306
diff changeset
430 MODULE *module = (MODULE *) internal->decoder_private;
474
c66080364dff Most decoders now report total sample play time, now. Technically, this
Ryan C. Gordon <icculus@icculus.org>
parents: 473
diff changeset
431 double last_time = 0.0;
c66080364dff Most decoders now report total sample play time, now. Technically, this
Ryan C. Gordon <icculus@icculus.org>
parents: 473
diff changeset
432 double current_time = 0.0;
c66080364dff Most decoders now report total sample play time, now. Technically, this
Ryan C. Gordon <icculus@icculus.org>
parents: 473
diff changeset
433 double target_time;
c66080364dff Most decoders now report total sample play time, now. Technically, this
Ryan C. Gordon <icculus@icculus.org>
parents: 473
diff changeset
434 Uint32 i;
312
498240aa76f1 Seek implementations.
Ryan C. Gordon <icculus@icculus.org>
parents: 306
diff changeset
435
498240aa76f1 Seek implementations.
Ryan C. Gordon <icculus@icculus.org>
parents: 306
diff changeset
436 /*
498240aa76f1 Seek implementations.
Ryan C. Gordon <icculus@icculus.org>
parents: 306
diff changeset
437 * Heaven may know what the argument to Player_SetPosition() is.
498240aa76f1 Seek implementations.
Ryan C. Gordon <icculus@icculus.org>
parents: 306
diff changeset
438 * I, however, haven't the faintest idea.
498240aa76f1 Seek implementations.
Ryan C. Gordon <icculus@icculus.org>
parents: 306
diff changeset
439 */
498240aa76f1 Seek implementations.
Ryan C. Gordon <icculus@icculus.org>
parents: 306
diff changeset
440 Player_Start(module);
474
c66080364dff Most decoders now report total sample play time, now. Technically, this
Ryan C. Gordon <icculus@icculus.org>
parents: 473
diff changeset
441
c66080364dff Most decoders now report total sample play time, now. Technically, this
Ryan C. Gordon <icculus@icculus.org>
parents: 473
diff changeset
442 /*
c66080364dff Most decoders now report total sample play time, now. Technically, this
Ryan C. Gordon <icculus@icculus.org>
parents: 473
diff changeset
443 * Mikmod only lets you seek to the beginning of a pattern.
c66080364dff Most decoders now report total sample play time, now. Technically, this
Ryan C. Gordon <icculus@icculus.org>
parents: 473
diff changeset
444 * This means we'll get very coarse grain seeks. The
c66080364dff Most decoders now report total sample play time, now. Technically, this
Ryan C. Gordon <icculus@icculus.org>
parents: 473
diff changeset
445 * value we pass to SetPosition is a value between 0
c66080364dff Most decoders now report total sample play time, now. Technically, this
Ryan C. Gordon <icculus@icculus.org>
parents: 473
diff changeset
446 * and the number of positions in the file. The
c66080364dff Most decoders now report total sample play time, now. Technically, this
Ryan C. Gordon <icculus@icculus.org>
parents: 473
diff changeset
447 * dumb approach would be to take our total_time that
c66080364dff Most decoders now report total sample play time, now. Technically, this
Ryan C. Gordon <icculus@icculus.org>
parents: 473
diff changeset
448 * we've already calculated and divide it up by the
c66080364dff Most decoders now report total sample play time, now. Technically, this
Ryan C. Gordon <icculus@icculus.org>
parents: 473
diff changeset
449 * number of positions and seek to the position that results.
c66080364dff Most decoders now report total sample play time, now. Technically, this
Ryan C. Gordon <icculus@icculus.org>
parents: 473
diff changeset
450 * However, because songs can alter their speed/tempo during
c66080364dff Most decoders now report total sample play time, now. Technically, this
Ryan C. Gordon <icculus@icculus.org>
parents: 473
diff changeset
451 * playback, different patterns in the song can take
c66080364dff Most decoders now report total sample play time, now. Technically, this
Ryan C. Gordon <icculus@icculus.org>
parents: 473
diff changeset
452 * up different amounts of time. So the slightly
c66080364dff Most decoders now report total sample play time, now. Technically, this
Ryan C. Gordon <icculus@icculus.org>
parents: 473
diff changeset
453 * smarter approach is to repeat what was done in the
c66080364dff Most decoders now report total sample play time, now. Technically, this
Ryan C. Gordon <icculus@icculus.org>
parents: 473
diff changeset
454 * total_time computation and traverse through the file
c66080364dff Most decoders now report total sample play time, now. Technically, this
Ryan C. Gordon <icculus@icculus.org>
parents: 473
diff changeset
455 * until we find the closest position.
c66080364dff Most decoders now report total sample play time, now. Technically, this
Ryan C. Gordon <icculus@icculus.org>
parents: 473
diff changeset
456 * The follwing is basically cut and paste from the
c66080364dff Most decoders now report total sample play time, now. Technically, this
Ryan C. Gordon <icculus@icculus.org>
parents: 473
diff changeset
457 * open function.
c66080364dff Most decoders now report total sample play time, now. Technically, this
Ryan C. Gordon <icculus@icculus.org>
parents: 473
diff changeset
458 */
c66080364dff Most decoders now report total sample play time, now. Technically, this
Ryan C. Gordon <icculus@icculus.org>
parents: 473
diff changeset
459 if (ms == 0) /* Check end conditions to simplify things */
c66080364dff Most decoders now report total sample play time, now. Technically, this
Ryan C. Gordon <icculus@icculus.org>
parents: 473
diff changeset
460 {
c66080364dff Most decoders now report total sample play time, now. Technically, this
Ryan C. Gordon <icculus@icculus.org>
parents: 473
diff changeset
461 Player_SetPosition(0);
c66080364dff Most decoders now report total sample play time, now. Technically, this
Ryan C. Gordon <icculus@icculus.org>
parents: 473
diff changeset
462 return(1);
c66080364dff Most decoders now report total sample play time, now. Technically, this
Ryan C. Gordon <icculus@icculus.org>
parents: 473
diff changeset
463 } /* if */
c66080364dff Most decoders now report total sample play time, now. Technically, this
Ryan C. Gordon <icculus@icculus.org>
parents: 473
diff changeset
464
477
3e705c9180e5 Fixed binary compatibility, added Sound_GetDuration().
Ryan C. Gordon <icculus@icculus.org>
parents: 474
diff changeset
465 if (ms >= internal->total_time)
474
c66080364dff Most decoders now report total sample play time, now. Technically, this
Ryan C. Gordon <icculus@icculus.org>
parents: 473
diff changeset
466 Player_SetPosition(module->numpos);
c66080364dff Most decoders now report total sample play time, now. Technically, this
Ryan C. Gordon <icculus@icculus.org>
parents: 473
diff changeset
467
c66080364dff Most decoders now report total sample play time, now. Technically, this
Ryan C. Gordon <icculus@icculus.org>
parents: 473
diff changeset
468 /* Convert time to seconds (double) to make comparisons easier */
c66080364dff Most decoders now report total sample play time, now. Technically, this
Ryan C. Gordon <icculus@icculus.org>
parents: 473
diff changeset
469 target_time = ms / 1000.0;
c66080364dff Most decoders now report total sample play time, now. Technically, this
Ryan C. Gordon <icculus@icculus.org>
parents: 473
diff changeset
470
c66080364dff Most decoders now report total sample play time, now. Technically, this
Ryan C. Gordon <icculus@icculus.org>
parents: 473
diff changeset
471 for (i = 0; i < module->numpos; i++)
c66080364dff Most decoders now report total sample play time, now. Technically, this
Ryan C. Gordon <icculus@icculus.org>
parents: 473
diff changeset
472 {
c66080364dff Most decoders now report total sample play time, now. Technically, this
Ryan C. Gordon <icculus@icculus.org>
parents: 473
diff changeset
473 Player_SetPosition(i);
c66080364dff Most decoders now report total sample play time, now. Technically, this
Ryan C. Gordon <icculus@icculus.org>
parents: 473
diff changeset
474 /* Must call update, or the speed values won't get reset */
c66080364dff Most decoders now report total sample play time, now. Technically, this
Ryan C. Gordon <icculus@icculus.org>
parents: 473
diff changeset
475 MikMod_Update();
c66080364dff Most decoders now report total sample play time, now. Technically, this
Ryan C. Gordon <icculus@icculus.org>
parents: 473
diff changeset
476 /* Divide by zero check */
c66080364dff Most decoders now report total sample play time, now. Technically, this
Ryan C. Gordon <icculus@icculus.org>
parents: 473
diff changeset
477 if(module->bpm == 0)
c66080364dff Most decoders now report total sample play time, now. Technically, this
Ryan C. Gordon <icculus@icculus.org>
parents: 473
diff changeset
478 continue;
c66080364dff Most decoders now report total sample play time, now. Technically, this
Ryan C. Gordon <icculus@icculus.org>
parents: 473
diff changeset
479 last_time = current_time;
c66080364dff Most decoders now report total sample play time, now. Technically, this
Ryan C. Gordon <icculus@icculus.org>
parents: 473
diff changeset
480 /* See the notes in the open function about the formula */
c66080364dff Most decoders now report total sample play time, now. Technically, this
Ryan C. Gordon <icculus@icculus.org>
parents: 473
diff changeset
481 current_time += (module->numrow * .02
c66080364dff Most decoders now report total sample play time, now. Technically, this
Ryan C. Gordon <icculus@icculus.org>
parents: 473
diff changeset
482 * module->sngspd * 125.0 / module->bpm);
c66080364dff Most decoders now report total sample play time, now. Technically, this
Ryan C. Gordon <icculus@icculus.org>
parents: 473
diff changeset
483 if(target_time <= current_time)
c66080364dff Most decoders now report total sample play time, now. Technically, this
Ryan C. Gordon <icculus@icculus.org>
parents: 473
diff changeset
484 break; /* We now have our interval, so break out */
c66080364dff Most decoders now report total sample play time, now. Technically, this
Ryan C. Gordon <icculus@icculus.org>
parents: 473
diff changeset
485 } /* for */
c66080364dff Most decoders now report total sample play time, now. Technically, this
Ryan C. Gordon <icculus@icculus.org>
parents: 473
diff changeset
486
c66080364dff Most decoders now report total sample play time, now. Technically, this
Ryan C. Gordon <icculus@icculus.org>
parents: 473
diff changeset
487 if( (target_time-last_time) > (current_time-target_time) )
c66080364dff Most decoders now report total sample play time, now. Technically, this
Ryan C. Gordon <icculus@icculus.org>
parents: 473
diff changeset
488 {
c66080364dff Most decoders now report total sample play time, now. Technically, this
Ryan C. Gordon <icculus@icculus.org>
parents: 473
diff changeset
489 /* The target time is closer to the higher position, so go there */
c66080364dff Most decoders now report total sample play time, now. Technically, this
Ryan C. Gordon <icculus@icculus.org>
parents: 473
diff changeset
490 Player_SetPosition(i+1);
c66080364dff Most decoders now report total sample play time, now. Technically, this
Ryan C. Gordon <icculus@icculus.org>
parents: 473
diff changeset
491 } /* if */
c66080364dff Most decoders now report total sample play time, now. Technically, this
Ryan C. Gordon <icculus@icculus.org>
parents: 473
diff changeset
492 else
c66080364dff Most decoders now report total sample play time, now. Technically, this
Ryan C. Gordon <icculus@icculus.org>
parents: 473
diff changeset
493 {
c66080364dff Most decoders now report total sample play time, now. Technically, this
Ryan C. Gordon <icculus@icculus.org>
parents: 473
diff changeset
494 /* The target time is closer to the lower position, so go there */
c66080364dff Most decoders now report total sample play time, now. Technically, this
Ryan C. Gordon <icculus@icculus.org>
parents: 473
diff changeset
495 Player_SetPosition(i);
c66080364dff Most decoders now report total sample play time, now. Technically, this
Ryan C. Gordon <icculus@icculus.org>
parents: 473
diff changeset
496 } /* else */
c66080364dff Most decoders now report total sample play time, now. Technically, this
Ryan C. Gordon <icculus@icculus.org>
parents: 473
diff changeset
497
312
498240aa76f1 Seek implementations.
Ryan C. Gordon <icculus@icculus.org>
parents: 306
diff changeset
498 return(1);
306
c97be6e1bd27 Added framework for Sound_Seek() support.
Ryan C. Gordon <icculus@icculus.org>
parents: 305
diff changeset
499 } /* MIKMOD_seek */
221
c9772a9f5271 Initial implementation or stubs for rewind method. Other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 211
diff changeset
500
207
857e53c5a2da Renamed from mod.c (see modplug.c for the OTHER mod decoder).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
501 #endif /* SOUND_SUPPORTS_MIKMOD */
857e53c5a2da Renamed from mod.c (see modplug.c for the OTHER mod decoder).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
502
857e53c5a2da Renamed from mod.c (see modplug.c for the OTHER mod decoder).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
503
857e53c5a2da Renamed from mod.c (see modplug.c for the OTHER mod decoder).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
504 /* end of mikmod.c ... */