Mercurial > repos > blastem
comparison mediaplayer.c @ 2305:6aca1734d573
Merge
author | Michael Pavone <pavone@retrodev.com> |
---|---|
date | Wed, 15 Mar 2023 19:28:11 -0700 |
parents | 0343f0d5add0 |
children | 97f164d1f0f6 |
comparison
equal
deleted
inserted
replaced
2304:b3832f73444f | 2305:6aca1734d573 |
---|---|
441 } | 441 } |
442 } | 442 } |
443 | 443 |
444 void flac_frame(media_player *player) | 444 void flac_frame(media_player *player) |
445 { | 445 { |
446 render_sleep_ms(15); | 446 for (uint32_t remaining_samples = player->flac->sample_rate / 60; remaining_samples > 0; remaining_samples--) |
447 { | |
448 int16_t samples[2]; | |
449 if (flac_get_sample(player->flac, samples, 2)) { | |
450 render_put_stereo_sample(player->audio, samples[0], samples[1]); | |
451 } else { | |
452 player->state = STATE_PAUSED; | |
453 return; | |
454 } | |
455 } | |
447 } | 456 } |
448 | 457 |
449 void vgm_init(media_player *player, uint32_t opts) | 458 void vgm_init(media_player *player, uint32_t opts) |
450 { | 459 { |
451 player->vgm = calloc(1, sizeof(vgm_header)); | 460 player->vgm = calloc(1, sizeof(vgm_header)); |
569 format_error: | 578 format_error: |
570 player->media_type = MEDIA_UNKNOWN; | 579 player->media_type = MEDIA_UNKNOWN; |
571 free(player->wave); | 580 free(player->wave); |
572 } | 581 } |
573 | 582 |
583 static void flac_player_init(media_player *player) | |
584 { | |
585 player->flac = flac_file_from_buffer(player->media->buffer, player->media->size); | |
586 if (player->flac) { | |
587 player->audio = render_audio_source("Audio File", player->flac->sample_rate, 1, 2); | |
588 } | |
589 } | |
590 | |
574 static void resume_player(system_header *system) | 591 static void resume_player(system_header *system) |
575 { | 592 { |
576 media_player *player = (media_player *)system; | 593 media_player *player = (media_player *)system; |
577 player->should_return = 0; | 594 player->should_return = 0; |
578 while (!player->header.should_exit && !player->should_return) | 595 while (!player->header.should_exit && !player->should_return) |
592 flac_frame(player); | 609 flac_frame(player); |
593 break; | 610 break; |
594 } | 611 } |
595 break; | 612 break; |
596 case STATE_PAUSED: | 613 case STATE_PAUSED: |
614 #ifndef IS_LIB | |
597 render_sleep_ms(15); | 615 render_sleep_ms(15); |
598 break; | 616 #endif |
599 } | 617 break; |
618 } | |
619 //TODO: Fix this for libretro build properly | |
620 #ifndef IS_LIB | |
600 render_update_display(); | 621 render_update_display(); |
622 #endif | |
601 } | 623 } |
602 } | 624 } |
603 | 625 |
604 static void gamepad_down(system_header *system, uint8_t pad, uint8_t button) | 626 static void gamepad_down(system_header *system, uint8_t pad, uint8_t button) |
605 { | 627 { |
687 vgm_init(player, opts); | 709 vgm_init(player, opts); |
688 break; | 710 break; |
689 case AUDIO_WAVE: | 711 case AUDIO_WAVE: |
690 wave_player_init(player); | 712 wave_player_init(player); |
691 break; | 713 break; |
714 case AUDIO_FLAC: | |
715 flac_player_init(player); | |
716 break; | |
692 } | 717 } |
693 | 718 |
694 return player; | 719 return player; |
695 } | 720 } |