@@ -159,6 +159,13 @@ static dumb_off_t dfs_get_size(void *f)
159
159
160
160
/* Stream Functions */
161
161
162
+ static int loop_callback (void * data )
163
+ {
164
+ bool * internal_loop = (bool * )data ;
165
+ * internal_loop = true;
166
+ return 0 ;
167
+ }
168
+
162
169
static size_t modaudio_stream_update (ALLEGRO_AUDIO_STREAM * stream , void * data ,
163
170
size_t buf_size )
164
171
{
@@ -168,28 +175,34 @@ static size_t modaudio_stream_update(ALLEGRO_AUDIO_STREAM *stream, void *data,
168
175
const int sample_size = 4 ;
169
176
size_t written = 0 ;
170
177
size_t i ;
178
+ bool internal_loop = false;
171
179
172
180
DUMB_IT_SIGRENDERER * it_sig = lib .duh_get_it_sigrenderer (df -> sig );
173
181
if (it_sig ) {
174
182
lib .dumb_it_set_loop_callback (it_sig ,
175
183
stream -> spl .loop == _ALLEGRO_PLAYMODE_STREAM_ONCE
176
- ? lib .dumb_it_callback_terminate : NULL , NULL );
184
+ ? lib .dumb_it_callback_terminate : loop_callback , & internal_loop );
177
185
}
178
186
179
187
while (written < buf_size ) {
180
188
long size_to_read = (buf_size - written ) / sample_size ;
181
189
long position = lib .duh_sigrenderer_get_position (df -> sig );
182
- bool loop = false;
190
+ bool manual_loop = false;
191
+ internal_loop = false;
192
+ /* If manual looping is not enabled, then we need to implement
193
+ * short-stopping manually. */
183
194
if (stream -> spl .loop != _ALLEGRO_PLAYMODE_STREAM_ONCE && df -> loop_end != -1 &&
184
195
position + 65536 * size_to_read / 44100 >= df -> loop_end ) {
185
196
size_to_read = (df -> loop_end - position ) * 44100 / 65536 ;
186
197
if (size_to_read < 0 )
187
198
size_to_read = 0 ;
188
- loop = true;
199
+ manual_loop = true;
189
200
}
190
201
written += lib .duh_render (df -> sig , 16 , 0 , 1.0 , 65536.0 / 44100.0 ,
191
202
size_to_read , & (((char * )data )[written ])) * sample_size ;
192
- if (loop || (long )written < size_to_read * sample_size ) {
203
+ /* For internal loops, we don't rewind. */
204
+ if (!internal_loop &&
205
+ ((long )written < size_to_read * sample_size || manual_loop )) {
193
206
break ;
194
207
}
195
208
}
@@ -323,13 +336,13 @@ static ALLEGRO_AUDIO_STREAM *modaudio_stream_init(ALLEGRO_FILE* f,
323
336
mf -> length = lib .duh_get_length (duh ) / 65536.0 ;
324
337
if (mf -> length < 0 ) {
325
338
mf -> length = 0 ;
326
- mf -> loop_start = -1 ;
327
- mf -> loop_end = -1 ;
328
- }
329
- else {
330
- mf -> loop_start = 0 ;
331
- mf -> loop_end = (int )(mf -> length * 65536.0 );
332
339
}
340
+ /*
341
+ * Set these to -1, so that we can default to the internal loop
342
+ * points.
343
+ */
344
+ mf -> loop_start = -1 ;
345
+ mf -> loop_end = -1 ;
333
346
334
347
stream -> extra = mf ;
335
348
stream -> feeder = modaudio_stream_update ;
0 commit comments