annotate playercode/sloader.c @ 22:d9f79436e0af default tip

Makefile Add ranlib for the library
author darius
date Fri, 24 Apr 1998 08:05:26 +0000
parents d14fd386d182
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
6
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
1 /*
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
2 --> Sample Loaders and Sample Processing
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
3
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
4 Name: sloader.c
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
5
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
6 Description:
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
7 Routines for loading samples. The sample loader utilizes the routines
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
8 provided by the "registered" sample loader. See SAMPLELOADER in
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
9 MIKMOD.H for the sample loader structure.
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
10
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
11 Portability:
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
12 All systems - all compilers
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
13
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
14 */
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
15
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
16 #include "mikmod.h"
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
17
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
18
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
19 static int sl_rlength;
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
20 static SWORD sl_old;
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
21 static SWORD *sl_buffer = NULL;
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
22 static SAMPLOAD *musiclist = NULL,
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
23 *sndfxlist = NULL;
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
24
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
25
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
26
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
27 BOOL SL_Init(SAMPLOAD *s) // returns 0 on error!
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
28 {
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
29 if(sl_buffer==NULL)
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
30 if((sl_buffer=_mm_malloc(4100)) == NULL) return 0;
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
31
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
32 sl_rlength = s->length;
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
33 if(s->infmt & SF_16BITS) sl_rlength>>=1;
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
34 sl_old = 0;
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
35
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
36 return 1;
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
37 }
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
38
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
39
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
40 void SL_Exit(SAMPLOAD *s)
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
41 {
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
42 if(sl_rlength > 0) _mm_fseek(s->fp,sl_rlength,SEEK_CUR);
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
43 }
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
44
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
45
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
46 void SL_Reset(void)
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
47 {
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
48 sl_old = 0;
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
49 }
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
50
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
51
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
52 void SL_Load(void *buffer, SAMPLOAD *smp, int length)
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
53 {
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
54 UWORD infmt = smp->infmt, outfmt = smp->outfmt;
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
55 SBYTE *bptr = (SBYTE *)buffer;
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
56 SWORD *wptr = (SWORD *)buffer;
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
57 int stodo;
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
58 int t, u;
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
59
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
60 while(length)
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
61 { stodo = (length<2048) ? length : 2048;
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
62
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
63 if(infmt & SF_16BITS)
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
64 { if(infmt & SF_BIG_ENDIAN)
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
65 _mm_read_M_SWORDS(sl_buffer,stodo,smp->fp);
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
66 else
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
67 _mm_read_I_SWORDS(sl_buffer,stodo,smp->fp);
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
68 } else
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
69 { SBYTE *s;
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
70 SWORD *d;
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
71
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
72 fread(sl_buffer,sizeof(SBYTE),stodo,smp->fp);
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
73
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
74 s = (SBYTE *)sl_buffer;
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
75 d = sl_buffer;
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
76 s += stodo;
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
77 d += stodo;
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
78
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
79 for(t=0; t<stodo; t++)
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
80 { s--;
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
81 d--;
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
82 *d = (*s)<<8;
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
83 }
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
84 }
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
85
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
86 if(infmt & SF_DELTA)
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
87 { for(t=0; t<stodo; t++)
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
88 { sl_buffer[t] += sl_old;
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
89 sl_old = sl_buffer[t];
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
90 }
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
91 }
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
92
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
93 if((infmt^outfmt) & SF_SIGNED)
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
94 { for(t=0; t<stodo; t++)
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
95 sl_buffer[t] ^= 0x8000;
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
96 }
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
97
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
98 if(smp->scalefactor)
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
99 { int idx = 0;
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
100 SLONG scaleval;
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
101
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
102 // Sample Scaling... average values for better results.
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
103 t = 0;
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
104 while(t<stodo && length)
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
105 { scaleval = 0;
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
106 for(u=smp->scalefactor; u && t<stodo; u--, t++)
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
107 scaleval += sl_buffer[t];
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
108 sl_buffer[idx++] = scaleval / (smp->scalefactor-u);
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
109 length--;
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
110 }
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
111 sl_rlength -= stodo;
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
112 stodo = idx;
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
113 } else
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
114 { length -= stodo;
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
115 sl_rlength -= stodo;
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
116 }
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
117
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
118 if(outfmt & SF_16BITS)
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
119 { for(t=0; t<stodo; t++) *(wptr++) = sl_buffer[t];
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
120 } else
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
121 { for(t=0; t<stodo; t++) *(bptr++) = sl_buffer[t]>>8;
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
122 }
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
123 }
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
124 }
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
125
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
126
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
127 void SL_LoadStream(void *buffer, UWORD infmt, UWORD outfmt, int length, FILE *fp)
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
128
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
129 // This is like SL_Load, but does not perform sample scaling, and does not
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
130 // require calls to SL_Init / SL_Exit.
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
131
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
132 {
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
133 SBYTE *bptr = (SBYTE *)buffer;
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
134 SWORD *wptr = (SWORD *)buffer;
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
135 int stodo;
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
136 int t;
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
137
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
138 // compute number of samples to load
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
139
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
140 if(sl_buffer==NULL)
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
141 if((sl_buffer=_mm_malloc(4100)) == NULL) return;
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
142
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
143 while(length)
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
144 { stodo = (length<2048) ? length : 2048;
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
145
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
146 if(infmt & SF_16BITS)
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
147 { if(infmt & SF_BIG_ENDIAN)
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
148 _mm_read_M_SWORDS(sl_buffer,stodo,fp);
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
149 else
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
150 _mm_read_I_SWORDS(sl_buffer,stodo,fp);
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
151 } else
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
152 { SBYTE *s;
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
153 SWORD *d;
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
154
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
155 fread(sl_buffer,sizeof(SBYTE),stodo,fp);
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
156
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
157 s = (SBYTE *)sl_buffer;
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
158 d = sl_buffer;
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
159 s += stodo;
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
160 d += stodo;
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
161
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
162 for(t=0; t<stodo; t++)
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
163 { s--;
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
164 d--;
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
165 *d = (*s)<<8;
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
166 }
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
167 }
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
168
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
169 if(infmt & SF_DELTA)
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
170 { for(t=0; t<stodo; t++)
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
171 { sl_buffer[t] += sl_old;
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
172 sl_old = sl_buffer[t];
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
173 }
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
174 }
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
175
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
176 if((infmt^outfmt) & SF_SIGNED)
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
177 { for(t=0; t<stodo; t++)
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
178 sl_buffer[t] ^= 0x8000;
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
179 }
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
180
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
181 length -= stodo;
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
182
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
183 if((infmt & SF_STEREO) && !(outfmt & SF_STEREO))
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
184 { // Dither stereo to mono .. average together every two samples
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
185 SLONG avgval;
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
186 int idx = 0;
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
187
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
188 t = 0;
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
189 while(t<stodo && length)
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
190 { avgval = sl_buffer[t++];
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
191 avgval += sl_buffer[t++];
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
192 sl_buffer[idx++] = avgval >> 1;
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
193 length-=2;
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
194 }
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
195 stodo = idx;
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
196 }
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
197
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
198 if(outfmt & SF_16BITS)
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
199 { for(t=0; t<stodo; t++) *(wptr++) = sl_buffer[t];
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
200 } else
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
201 { for(t=0; t<stodo; t++) *(bptr++) = sl_buffer[t]>>8;
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
202 }
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
203 }
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
204 }
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
205
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
206
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
207 SAMPLOAD *SL_RegisterSample(SAMPLE *s, int type, FILE *fp) // Returns 1 on error!
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
208
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
209 // Registers a sample for loading when SL_LoadSamples() is called.
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
210 // type - type of sample to be loaded ..
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
211 // MD_MUSIC, MD_SNDFX
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
212
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
213 {
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
214 SAMPLOAD *news, **samplist, *cruise;
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
215
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
216 if(type==MD_MUSIC)
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
217 { samplist = & musiclist;
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
218 cruise = musiclist;
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
219 } else
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
220 { samplist = &sndfxlist;
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
221 cruise = sndfxlist;
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
222 }
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
223
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
224 // Allocate and add structure to the END of the list
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
225
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
226 if((news=(SAMPLOAD *)_mm_calloc(1,sizeof(SAMPLOAD))) == NULL) return NULL;
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
227
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
228 if(cruise!=NULL)
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
229 { while(cruise->next!=NULL) cruise = cruise->next;
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
230 cruise->next = news;
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
231 } else
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
232 *samplist = news;
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
233
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
234 news->infmt = s->flags & 31;
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
235 news->outfmt = news->infmt;
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
236 news->fp = fp;
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
237 news->sample = s;
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
238 news->length = s->length;
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
239 news->loopstart = s->loopstart;
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
240 news->loopend = s->loopend;
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
241
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
242 return news;
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
243 }
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
244
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
245
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
246 static void FreeSampleList(SAMPLOAD *s)
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
247 {
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
248 SAMPLOAD *old;
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
249
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
250 while(s!=NULL)
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
251 { old = s;
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
252 s = s->next;
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
253 free(old);
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
254 }
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
255 }
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
256
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
257
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
258 static ULONG SampleTotal(SAMPLOAD *samplist, int type)
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
259 // Returns the total amount of memory required by the samplelist queue.
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
260 {
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
261 int total = 0;
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
262
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
263 while(samplist!=NULL)
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
264 { samplist->sample->flags = (samplist->sample->flags&~31) | samplist->outfmt;
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
265 total += MD_SampleLength(type,samplist->sample);
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
266 samplist = samplist->next;
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
267 }
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
268
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
269 return total;
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
270 }
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
271
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
272
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
273 static ULONG RealSpeed(SAMPLOAD *s)
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
274 {
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
275 return(s->sample->speed / ((s->scalefactor==0) ? 1 : s->scalefactor));
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
276 }
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
277
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
278
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
279 static BOOL DitherSamples(SAMPLOAD *samplist, int type)
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
280 {
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
281 SAMPLOAD *c2smp;
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
282 ULONG maxsize, speed;
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
283 SAMPLOAD *s;
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
284
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
285 if(samplist==NULL) return 0;
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
286
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
287 // make sure the samples will fit inside available RAM
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
288 if((maxsize = MD_SampleSpace(type)*1024) != 0)
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
289 { while(SampleTotal(samplist, type) > maxsize)
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
290 { // First Pass - check for any 16 bit samples
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
291 s = samplist;
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
292 while(s!=NULL)
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
293 { if(s->outfmt & SF_16BITS)
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
294 { SL_Sample16to8(s);
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
295 break;
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
296 }
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
297 s = s->next;
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
298 }
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
299
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
300 // Second pass (if no 16bits found above) is to take the sample
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
301 // with the highest speed and dither it by half.
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
302 if(s==NULL)
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
303 { s = samplist;
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
304 speed = 0;
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
305 while(s!=NULL)
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
306 { if((s->sample->length) && (RealSpeed(s) > speed))
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
307 { speed = RealSpeed(s);
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
308 c2smp = s;
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
309 }
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
310 s = s->next;
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
311 }
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
312 SL_HalveSample(c2smp);
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
313 }
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
314 }
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
315 }
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
316
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
317
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
318 // Samples dithered, now load them!
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
319 // ================================
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
320
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
321 s = samplist;
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
322 while(s != NULL)
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
323 { // sample has to be loaded ? -> increase number of
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
324 // samples, allocate memory and load sample.
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
325
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
326 if(s->sample->length)
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
327 { if(s->sample->seekpos)
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
328 _mm_fseek(s->fp, s->sample->seekpos, SEEK_SET);
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
329
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
330 // Call the sample load routine of the driver module.
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
331 // It has to return a 'handle' (>=0) that identifies
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
332 // the sample.
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
333
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
334 s->sample->handle = MD_SampleLoad(s, type, s->fp);
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
335 s->sample->flags = (s->sample->flags & ~31) | s->outfmt;
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
336 if(s->sample->handle < 0)
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
337 { FreeSampleList(samplist);
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
338 if(_mm_errorhandler!=NULL) _mm_errorhandler();
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
339 return 1;
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
340 }
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
341 }
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
342 s = s->next;
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
343 }
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
344
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
345 FreeSampleList(samplist);
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
346 return 0;
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
347 }
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
348
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
349
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
350 BOOL SL_LoadSamples(void) // Returns 1 on error!
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
351 {
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
352 BOOL ok;
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
353
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
354 _mm_critical = 0;
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
355
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
356 if((musiclist==NULL) && (sndfxlist==NULL)) return 0;
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
357 // MikMod_Exit();
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
358 // exit(1);
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
359 ok = DitherSamples(musiclist,MD_MUSIC) || DitherSamples(sndfxlist,MD_SNDFX);
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
360
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
361 musiclist = sndfxlist = NULL;
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
362
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
363 return ok;
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
364 }
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
365
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
366
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
367 void SL_Sample16to8(SAMPLOAD *s)
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
368 {
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
369 s->outfmt &= ~SF_16BITS;
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
370 s->sample->flags = (s->sample->flags&~31) | s->outfmt;
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
371 }
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
372
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
373
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
374 void SL_Sample8to16(SAMPLOAD *s)
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
375 {
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
376 s->outfmt |= SF_16BITS;
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
377 s->sample->flags = (s->sample->flags&~31) | s->outfmt;
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
378 }
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
379
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
380
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
381 void SL_SampleSigned(SAMPLOAD *s)
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
382 {
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
383 s->outfmt |= SF_SIGNED;
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
384 s->sample->flags = (s->sample->flags&~31) | s->outfmt;
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
385 }
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
386
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
387
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
388 void SL_SampleUnsigned(SAMPLOAD *s)
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
389 {
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
390 s->outfmt &= ~SF_SIGNED;
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
391 s->sample->flags = (s->sample->flags&~31) | s->outfmt;
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
392 }
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
393
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
394
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
395 void SL_HalveSample(SAMPLOAD *s)
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
396 {
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
397 if(s->scalefactor)
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
398 s->scalefactor++;
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
399 else
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
400 s->scalefactor = 2;
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
401
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
402 s->sample->divfactor = s->scalefactor;
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
403 s->sample->length = s->length / s->scalefactor;
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
404 s->sample->loopstart = s->loopstart / s->scalefactor;
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
405 s->sample->loopend = s->loopend / s->scalefactor;
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
406 }
d14fd386d182 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
407