Mercurial > audlegacy-plugins
comparison src/wav/wav.c @ 1380:1387432199cf
Fixed various bugs i the wav (not wav-sndfile) plugin:
- Use playback->playing and playback->eof instead of own vars.
- Handle songend and set playback->playing = 0 internaly.
author | Christian Birchinger <joker@netswarm.net> |
---|---|
date | Thu, 26 Jul 2007 21:07:10 +0200 |
parents | c75fd6894758 |
children | 761e17b23e0c |
comparison
equal
deleted
inserted
replaced
1379:33e9906b3b8a | 1380:1387432199cf |
---|---|
259 | 259 |
260 blk_size = 512 * (wav_file->bits_per_sample / 8) * wav_file->channels; | 260 blk_size = 512 * (wav_file->bits_per_sample / 8) * wav_file->channels; |
261 rate = | 261 rate = |
262 wav_file->samples_per_sec * wav_file->channels * | 262 wav_file->samples_per_sec * wav_file->channels * |
263 (wav_file->bits_per_sample / 8); | 263 (wav_file->bits_per_sample / 8); |
264 while (wav_file->going) { | 264 while (playback->playing) { |
265 if (!wav_file->eof) { | 265 if (!playback->eof) { |
266 bytes = blk_size; | 266 bytes = blk_size; |
267 if (wav_file->length - wav_file->position < bytes) | 267 if (wav_file->length - wav_file->position < bytes) |
268 bytes = wav_file->length - wav_file->position; | 268 bytes = wav_file->length - wav_file->position; |
269 if (bytes > 0) { | 269 if (bytes > 0) { |
270 actual_read = vfs_fread(data, 1, bytes, wav_file->file); | 270 actual_read = vfs_fread(data, 1, bytes, wav_file->file); |
271 | 271 |
272 if (actual_read == 0) { | 272 if (actual_read == 0) |
273 wav_file->eof = 1; | 273 playback->eof = TRUE; |
274 playback->output->buffer_free(); | |
275 playback->output->buffer_free(); | |
276 } | |
277 else { | 274 else { |
278 if (wav_file->seek_to == -1) | 275 if (wav_file->seek_to == -1) |
279 produce_audio(playback->output->written_time(), | 276 produce_audio(playback->output->written_time(), |
280 (wav_file->bits_per_sample == | 277 (wav_file->bits_per_sample == |
281 16) ? FMT_S16_LE : FMT_U8, | 278 16) ? FMT_S16_LE : FMT_U8, |
282 wav_file->channels, bytes, data, | 279 wav_file->channels, bytes, data, |
283 &wav_file->going); | 280 &playback->playing); |
284 wav_file->position += actual_read; | 281 wav_file->position += actual_read; |
285 } | 282 } |
286 } | 283 } |
287 else { | 284 else |
288 wav_file->eof = TRUE; | 285 playback->eof = TRUE; |
289 playback->output->buffer_free(); | 286 } |
290 playback->output->buffer_free(); | 287 else { |
291 xmms_usleep(10000); | 288 playback->output->buffer_free (); |
292 } | 289 playback->output->buffer_free (); |
293 } | 290 while (playback->output->buffer_playing()) |
294 else | 291 g_usleep(10000); |
295 xmms_usleep(10000); | 292 playback->playing = 0; |
293 } | |
294 | |
296 if (wav_file->seek_to != -1) { | 295 if (wav_file->seek_to != -1) { |
297 wav_file->position = (unsigned long)((gint64)wav_file->seek_to * (gint64)rate / 1000L); | 296 wav_file->position = (unsigned long)((gint64)wav_file->seek_to * (gint64)rate / 1000L); |
298 vfs_fseek(wav_file->file, | 297 vfs_fseek(wav_file->file, |
299 wav_file->position + wav_file->data_offset, SEEK_SET); | 298 wav_file->position + wav_file->data_offset, SEEK_SET); |
300 playback->output->flush(wav_file->seek_to); | 299 playback->output->flush(wav_file->seek_to); |
398 } | 397 } |
399 wav_file->data_offset = vfs_ftell(wav_file->file); | 398 wav_file->data_offset = vfs_ftell(wav_file->file); |
400 wav_file->length = len; | 399 wav_file->length = len; |
401 | 400 |
402 wav_file->position = 0; | 401 wav_file->position = 0; |
403 wav_file->going = 1; | 402 playback->playing = 1; |
404 | 403 |
405 if (playback->output-> | 404 if (playback->output-> |
406 open_audio((wav_file->bits_per_sample == | 405 open_audio((wav_file->bits_per_sample == |
407 16) ? FMT_S16_LE : FMT_U8, | 406 16) ? FMT_S16_LE : FMT_U8, |
408 wav_file->samples_per_sec, wav_file->channels) == 0) { | 407 wav_file->samples_per_sec, wav_file->channels) == 0) { |
426 } | 425 } |
427 | 426 |
428 static void | 427 static void |
429 stop(InputPlayback * playback) | 428 stop(InputPlayback * playback) |
430 { | 429 { |
431 if (wav_file && wav_file->going) { | 430 if (wav_file && playback->playing) { |
432 wav_file->going = 0; | 431 playback->playing = 0; |
433 g_thread_join(decode_thread); | 432 g_thread_join(decode_thread); |
434 playback->output->close_audio(); | 433 playback->output->close_audio(); |
435 g_free(wav_file); | 434 g_free(wav_file); |
436 wav_file = NULL; | 435 wav_file = NULL; |
437 } | 436 } |
442 { | 441 { |
443 playback->output->pause(p); | 442 playback->output->pause(p); |
444 } | 443 } |
445 | 444 |
446 static void | 445 static void |
447 mseek(InputPlayback * data, gulong millisecond) | 446 mseek(InputPlayback * playback, gulong millisecond) |
448 { | 447 { |
449 wav_file->seek_to = millisecond; | 448 wav_file->seek_to = millisecond; |
450 | 449 |
451 wav_file->eof = FALSE; | 450 playback->eof = FALSE; |
452 | 451 |
453 while (wav_file->seek_to != -1) | 452 while (wav_file->seek_to != -1) |
454 xmms_usleep(10000); | 453 xmms_usleep(10000); |
455 } | 454 } |
456 | 455 |
466 { | 465 { |
467 if (audio_error) | 466 if (audio_error) |
468 return -2; | 467 return -2; |
469 if (!wav_file) | 468 if (!wav_file) |
470 return -1; | 469 return -1; |
471 if (!wav_file->going | 470 if (!playback->playing |
472 || (wav_file->eof && !playback->output->buffer_playing())) | 471 || (playback->eof && !playback->output->buffer_playing())) |
473 return -1; | 472 return -1; |
474 else { | 473 else { |
475 return playback->output->output_time(); | 474 return playback->output->output_time(); |
476 } | 475 } |
477 } | 476 } |