comparison mediaplayer.c @ 2377:30e59954eab9

Properly free sound chips in VGM player
author Michael Pavone <pavone@retrodev.com>
date Sat, 18 Nov 2023 09:36:29 -0800
parents 1c09f5be285b
children 9da3de58410d
comparison
equal deleted inserted replaced
2376:1c09f5be285b 2377:30e59954eab9
90 90
91 void pcm_no_scope(void *context) 91 void pcm_no_scope(void *context)
92 { 92 {
93 rf5c164 *pcm = context; 93 rf5c164 *pcm = context;
94 pcm->scope = NULL; 94 pcm->scope = NULL;
95 }
96
97 void pcm_free(void *context)
98 {
99 rf5c164 *pcm = context;
100 rf5c164_deinit(pcm);
101 free(pcm);
95 } 102 }
96 103
97 uint8_t *find_block(data_block *head, uint32_t offset, uint32_t size) 104 uint8_t *find_block(data_block *head, uint32_t offset, uint32_t size)
98 { 105 {
99 if (!head) { 106 if (!head) {
545 .context = ym, 552 .context = ym,
546 .run = (chip_run_fun)ym_run, 553 .run = (chip_run_fun)ym_run,
547 .adjust = ym_adjust, 554 .adjust = ym_adjust,
548 .scope = ym_scope, 555 .scope = ym_scope,
549 .no_scope = ym_no_scope, 556 .no_scope = ym_no_scope,
557 .free = (chip_noarg_fun)ym_free,
550 .clock = player->vgm->ym2612_clk, 558 .clock = player->vgm->ym2612_clk,
551 .samples = 0, 559 .samples = 0,
552 .cmd = CMD_YM2612_0, 560 .cmd = CMD_YM2612_0,
553 .data_type = DATA_YM2612_PCM 561 .data_type = DATA_YM2612_PCM
554 }; 562 };
560 .context = psg, 568 .context = psg,
561 .run = (chip_run_fun)psg_run, 569 .run = (chip_run_fun)psg_run,
562 .adjust = psg_adjust, 570 .adjust = psg_adjust,
563 .scope = psg_scope, 571 .scope = psg_scope,
564 .no_scope = ym_no_scope, 572 .no_scope = ym_no_scope,
573 .free = (chip_noarg_fun)psg_free,
565 .clock = player->vgm->sn76489_clk, 574 .clock = player->vgm->sn76489_clk,
566 .samples = 0, 575 .samples = 0,
567 .cmd = CMD_PSG, 576 .cmd = CMD_PSG,
568 .data_type = 0xFF 577 .data_type = 0xFF
569 }; 578 };
575 .context = pcm, 584 .context = pcm,
576 .run = (chip_run_fun)rf5c164_run, 585 .run = (chip_run_fun)rf5c164_run,
577 .adjust = pcm_adjust, 586 .adjust = pcm_adjust,
578 .scope = pcm_scope, 587 .scope = pcm_scope,
579 .no_scope = pcm_no_scope, 588 .no_scope = pcm_no_scope,
589 .free = pcm_free,
580 .clock = player->vgm_ext->rf5c68_clk, 590 .clock = player->vgm_ext->rf5c68_clk,
581 .samples = 0, 591 .samples = 0,
582 .cmd = CMD_PCM68_REG, 592 .cmd = CMD_PCM68_REG,
583 .data_type = DATA_RF5C68 593 .data_type = DATA_RF5C68
584 }; 594 };
590 .context = pcm, 600 .context = pcm,
591 .run = (chip_run_fun)rf5c164_run, 601 .run = (chip_run_fun)rf5c164_run,
592 .adjust = pcm_adjust, 602 .adjust = pcm_adjust,
593 .scope = pcm_scope, 603 .scope = pcm_scope,
594 .no_scope = pcm_no_scope, 604 .no_scope = pcm_no_scope,
605 .free = pcm_free,
595 .clock = player->vgm_ext->rf5c164_clk, 606 .clock = player->vgm_ext->rf5c164_clk,
596 .samples = 0, 607 .samples = 0,
597 .cmd = CMD_PCM164_REG, 608 .cmd = CMD_PCM164_REG,
598 .data_type = DATA_RF5C164 609 .data_type = DATA_RF5C164
599 }; 610 };
717 static void free_player(system_header *system) 728 static void free_player(system_header *system)
718 { 729 {
719 media_player *player = (media_player *)system; 730 media_player *player = (media_player *)system;
720 for (uint32_t i = 0; i < player->num_chips; i++) 731 for (uint32_t i = 0; i < player->num_chips; i++)
721 { 732 {
722 //TODO properly free chips 733 player->chips[i].free(player->chips[i].context);
723 free(player->chips[i].context);
724 } 734 }
725 free(player->chips); 735 free(player->chips);
726 free(player->vgm); 736 free(player->vgm);
727 free(player); 737 free(player);
728 } 738 }