Mercurial > repos > blastem
annotate mediaplayer.c @ 2476:aaf7bb58ffca
Fix bug in Gen/MD serialize routine that could cause a use-after free in some cases
author | Michael Pavone <pavone@retrodev.com> |
---|---|
date | Sun, 03 Mar 2024 13:47:59 -0800 |
parents | 9da3de58410d |
children | fb8f49b0aece |
rev | line source |
---|---|
2289
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1 #include <stdlib.h> |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
2 #include <stddef.h> |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
3 #include <limits.h> |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
4 #include <string.h> |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
5 #include "mediaplayer.h" |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
6 #include "io.h" |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
7 #include "ym2612.h" |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
8 #include "psg.h" |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
9 #include "rf5c164.h" |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
10 #include "util.h" |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
11 #include "render.h" |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
12 |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
13 #define ADJUST_BUFFER (12500000) |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
14 #define MAX_NO_ADJUST (UINT_MAX-ADJUST_BUFFER) |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
15 #define MAX_RUN_SAMPLES 128 |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
16 |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
17 enum { |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
18 AUDIO_VGM, |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
19 AUDIO_WAVE, |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
20 AUDIO_FLAC, |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
21 MEDIA_UNKNOWN |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
22 }; |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
23 |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
24 uint32_t cycles_to_samples(uint32_t clock_rate, uint32_t cycles) |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
25 { |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
26 return ((uint64_t)cycles) * ((uint64_t)44100) / ((uint64_t)clock_rate); |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
27 } |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
28 |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
29 uint32_t samples_to_cycles(uint32_t clock_rate, uint32_t cycles) |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
30 { |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
31 return ((uint64_t)cycles) * ((uint64_t)clock_rate) / ((uint64_t)44100); |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
32 } |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
33 |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
34 void ym_adjust(chip_info *chip) |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
35 { |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
36 ym2612_context *ym = chip->context; |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
37 if (ym->current_cycle >= MAX_NO_ADJUST) { |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
38 uint32_t deduction = ym->current_cycle - ADJUST_BUFFER; |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
39 chip->samples -= cycles_to_samples(chip->clock, deduction); |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
40 ym->current_cycle -= deduction; |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
41 } |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
42 } |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
43 |
2374
97f164d1f0f6
Re-enable VGM looping. Enable oscilloscope in VGM player. Fix VGM player PSG output
Michael Pavone <pavone@retrodev.com>
parents:
2302
diff
changeset
|
44 void ym_scope(chip_info *chip, oscilloscope *scope) |
97f164d1f0f6
Re-enable VGM looping. Enable oscilloscope in VGM player. Fix VGM player PSG output
Michael Pavone <pavone@retrodev.com>
parents:
2302
diff
changeset
|
45 { |
97f164d1f0f6
Re-enable VGM looping. Enable oscilloscope in VGM player. Fix VGM player PSG output
Michael Pavone <pavone@retrodev.com>
parents:
2302
diff
changeset
|
46 ym_enable_scope(chip->context, scope, chip->clock); |
97f164d1f0f6
Re-enable VGM looping. Enable oscilloscope in VGM player. Fix VGM player PSG output
Michael Pavone <pavone@retrodev.com>
parents:
2302
diff
changeset
|
47 } |
97f164d1f0f6
Re-enable VGM looping. Enable oscilloscope in VGM player. Fix VGM player PSG output
Michael Pavone <pavone@retrodev.com>
parents:
2302
diff
changeset
|
48 |
97f164d1f0f6
Re-enable VGM looping. Enable oscilloscope in VGM player. Fix VGM player PSG output
Michael Pavone <pavone@retrodev.com>
parents:
2302
diff
changeset
|
49 void ym_no_scope(void *context) |
97f164d1f0f6
Re-enable VGM looping. Enable oscilloscope in VGM player. Fix VGM player PSG output
Michael Pavone <pavone@retrodev.com>
parents:
2302
diff
changeset
|
50 { |
97f164d1f0f6
Re-enable VGM looping. Enable oscilloscope in VGM player. Fix VGM player PSG output
Michael Pavone <pavone@retrodev.com>
parents:
2302
diff
changeset
|
51 ym2612_context *ym = context; |
97f164d1f0f6
Re-enable VGM looping. Enable oscilloscope in VGM player. Fix VGM player PSG output
Michael Pavone <pavone@retrodev.com>
parents:
2302
diff
changeset
|
52 ym->scope = NULL; |
97f164d1f0f6
Re-enable VGM looping. Enable oscilloscope in VGM player. Fix VGM player PSG output
Michael Pavone <pavone@retrodev.com>
parents:
2302
diff
changeset
|
53 } |
97f164d1f0f6
Re-enable VGM looping. Enable oscilloscope in VGM player. Fix VGM player PSG output
Michael Pavone <pavone@retrodev.com>
parents:
2302
diff
changeset
|
54 |
2289
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
55 void psg_adjust(chip_info *chip) |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
56 { |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
57 psg_context *psg = chip->context; |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
58 if (psg->cycles >= MAX_NO_ADJUST) { |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
59 uint32_t deduction = psg->cycles - ADJUST_BUFFER; |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
60 chip->samples -= cycles_to_samples(chip->clock, deduction); |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
61 psg->cycles -= deduction; |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
62 } |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
63 } |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
64 |
2374
97f164d1f0f6
Re-enable VGM looping. Enable oscilloscope in VGM player. Fix VGM player PSG output
Michael Pavone <pavone@retrodev.com>
parents:
2302
diff
changeset
|
65 void psg_scope(chip_info *chip, oscilloscope *scope) |
97f164d1f0f6
Re-enable VGM looping. Enable oscilloscope in VGM player. Fix VGM player PSG output
Michael Pavone <pavone@retrodev.com>
parents:
2302
diff
changeset
|
66 { |
97f164d1f0f6
Re-enable VGM looping. Enable oscilloscope in VGM player. Fix VGM player PSG output
Michael Pavone <pavone@retrodev.com>
parents:
2302
diff
changeset
|
67 psg_enable_scope(chip->context, scope, chip->clock); |
97f164d1f0f6
Re-enable VGM looping. Enable oscilloscope in VGM player. Fix VGM player PSG output
Michael Pavone <pavone@retrodev.com>
parents:
2302
diff
changeset
|
68 } |
97f164d1f0f6
Re-enable VGM looping. Enable oscilloscope in VGM player. Fix VGM player PSG output
Michael Pavone <pavone@retrodev.com>
parents:
2302
diff
changeset
|
69 |
97f164d1f0f6
Re-enable VGM looping. Enable oscilloscope in VGM player. Fix VGM player PSG output
Michael Pavone <pavone@retrodev.com>
parents:
2302
diff
changeset
|
70 void psg_no_scope(void *context) |
97f164d1f0f6
Re-enable VGM looping. Enable oscilloscope in VGM player. Fix VGM player PSG output
Michael Pavone <pavone@retrodev.com>
parents:
2302
diff
changeset
|
71 { |
97f164d1f0f6
Re-enable VGM looping. Enable oscilloscope in VGM player. Fix VGM player PSG output
Michael Pavone <pavone@retrodev.com>
parents:
2302
diff
changeset
|
72 psg_context *psg = context; |
97f164d1f0f6
Re-enable VGM looping. Enable oscilloscope in VGM player. Fix VGM player PSG output
Michael Pavone <pavone@retrodev.com>
parents:
2302
diff
changeset
|
73 psg->scope = NULL; |
97f164d1f0f6
Re-enable VGM looping. Enable oscilloscope in VGM player. Fix VGM player PSG output
Michael Pavone <pavone@retrodev.com>
parents:
2302
diff
changeset
|
74 } |
97f164d1f0f6
Re-enable VGM looping. Enable oscilloscope in VGM player. Fix VGM player PSG output
Michael Pavone <pavone@retrodev.com>
parents:
2302
diff
changeset
|
75 |
2289
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
76 void pcm_adjust(chip_info *chip) |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
77 { |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
78 rf5c164 *pcm = chip->context; |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
79 if (pcm->cycle >= MAX_NO_ADJUST) { |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
80 uint32_t deduction = pcm->cycle - ADJUST_BUFFER; |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
81 chip->samples -= cycles_to_samples(chip->clock, deduction); |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
82 pcm->cycle -= deduction; |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
83 } |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
84 } |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
85 |
2374
97f164d1f0f6
Re-enable VGM looping. Enable oscilloscope in VGM player. Fix VGM player PSG output
Michael Pavone <pavone@retrodev.com>
parents:
2302
diff
changeset
|
86 void pcm_scope(chip_info *chip, oscilloscope *scope) |
97f164d1f0f6
Re-enable VGM looping. Enable oscilloscope in VGM player. Fix VGM player PSG output
Michael Pavone <pavone@retrodev.com>
parents:
2302
diff
changeset
|
87 { |
97f164d1f0f6
Re-enable VGM looping. Enable oscilloscope in VGM player. Fix VGM player PSG output
Michael Pavone <pavone@retrodev.com>
parents:
2302
diff
changeset
|
88 rf5c164_enable_scope(chip->context, scope); |
97f164d1f0f6
Re-enable VGM looping. Enable oscilloscope in VGM player. Fix VGM player PSG output
Michael Pavone <pavone@retrodev.com>
parents:
2302
diff
changeset
|
89 } |
97f164d1f0f6
Re-enable VGM looping. Enable oscilloscope in VGM player. Fix VGM player PSG output
Michael Pavone <pavone@retrodev.com>
parents:
2302
diff
changeset
|
90 |
97f164d1f0f6
Re-enable VGM looping. Enable oscilloscope in VGM player. Fix VGM player PSG output
Michael Pavone <pavone@retrodev.com>
parents:
2302
diff
changeset
|
91 void pcm_no_scope(void *context) |
97f164d1f0f6
Re-enable VGM looping. Enable oscilloscope in VGM player. Fix VGM player PSG output
Michael Pavone <pavone@retrodev.com>
parents:
2302
diff
changeset
|
92 { |
97f164d1f0f6
Re-enable VGM looping. Enable oscilloscope in VGM player. Fix VGM player PSG output
Michael Pavone <pavone@retrodev.com>
parents:
2302
diff
changeset
|
93 rf5c164 *pcm = context; |
97f164d1f0f6
Re-enable VGM looping. Enable oscilloscope in VGM player. Fix VGM player PSG output
Michael Pavone <pavone@retrodev.com>
parents:
2302
diff
changeset
|
94 pcm->scope = NULL; |
97f164d1f0f6
Re-enable VGM looping. Enable oscilloscope in VGM player. Fix VGM player PSG output
Michael Pavone <pavone@retrodev.com>
parents:
2302
diff
changeset
|
95 } |
97f164d1f0f6
Re-enable VGM looping. Enable oscilloscope in VGM player. Fix VGM player PSG output
Michael Pavone <pavone@retrodev.com>
parents:
2302
diff
changeset
|
96 |
2377
30e59954eab9
Properly free sound chips in VGM player
Michael Pavone <pavone@retrodev.com>
parents:
2376
diff
changeset
|
97 void pcm_free(void *context) |
30e59954eab9
Properly free sound chips in VGM player
Michael Pavone <pavone@retrodev.com>
parents:
2376
diff
changeset
|
98 { |
30e59954eab9
Properly free sound chips in VGM player
Michael Pavone <pavone@retrodev.com>
parents:
2376
diff
changeset
|
99 rf5c164 *pcm = context; |
30e59954eab9
Properly free sound chips in VGM player
Michael Pavone <pavone@retrodev.com>
parents:
2376
diff
changeset
|
100 rf5c164_deinit(pcm); |
30e59954eab9
Properly free sound chips in VGM player
Michael Pavone <pavone@retrodev.com>
parents:
2376
diff
changeset
|
101 free(pcm); |
30e59954eab9
Properly free sound chips in VGM player
Michael Pavone <pavone@retrodev.com>
parents:
2376
diff
changeset
|
102 } |
30e59954eab9
Properly free sound chips in VGM player
Michael Pavone <pavone@retrodev.com>
parents:
2376
diff
changeset
|
103 |
2289
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
104 uint8_t *find_block(data_block *head, uint32_t offset, uint32_t size) |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
105 { |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
106 if (!head) { |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
107 return NULL; |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
108 } |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
109 while (head->size < offset) { |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
110 offset -= head->size; |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
111 head = head->next; |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
112 } |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
113 if (head->size - offset < size) { |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
114 return NULL; |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
115 } |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
116 return head->data + offset; |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
117 } |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
118 |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
119 void vgm_wait(media_player *player, uint32_t samples) |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
120 { |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
121 chip_info *chips = player->chips; |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
122 uint32_t num_chips = player->num_chips; |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
123 while (samples > MAX_RUN_SAMPLES) |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
124 { |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
125 vgm_wait(player, MAX_RUN_SAMPLES); |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
126 samples -= MAX_RUN_SAMPLES; |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
127 } |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
128 for (uint32_t i = 0; i < num_chips; i++) |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
129 { |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
130 chips[i].samples += samples; |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
131 chips[i].run(chips[i].context, samples_to_cycles(chips[i].clock, chips[i].samples)); |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
132 chips[i].adjust(chips + i); |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
133 } |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
134 } |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
135 |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
136 void vgm_stop(media_player *player) |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
137 { |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
138 player->state = STATE_PAUSED; |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
139 player->playback_time = 0; |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
140 player->current_offset = player->vgm->data_offset + offsetof(vgm_header, data_offset); |
2374
97f164d1f0f6
Re-enable VGM looping. Enable oscilloscope in VGM player. Fix VGM player PSG output
Michael Pavone <pavone@retrodev.com>
parents:
2302
diff
changeset
|
141 player->loop_count = 2; |
2289
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
142 } |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
143 |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
144 chip_info *find_chip(media_player *player, uint8_t cmd) |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
145 { |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
146 for (uint32_t i = 0; i < player->num_chips; i++) |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
147 { |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
148 if (player->chips[i].cmd == cmd) { |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
149 return player->chips + i; |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
150 } |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
151 } |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
152 return NULL; |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
153 } |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
154 |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
155 void *find_chip_context(media_player *player, uint8_t cmd) |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
156 { |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
157 chip_info *chip = find_chip(player, cmd); |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
158 return chip ? chip->context : NULL; |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
159 } |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
160 |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
161 chip_info *find_chip_by_data(media_player *player, uint8_t data_type) |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
162 { |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
163 for (uint32_t i = 0; i < player->num_chips; i++) |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
164 { |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
165 if (player->chips[i].data_type == data_type) { |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
166 return &player->chips[i]; |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
167 } |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
168 } |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
169 return NULL; |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
170 } |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
171 |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
172 static uint8_t read_byte(media_player *player) |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
173 { |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
174 uint8_t *buffer = player->media->buffer; |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
175 return buffer[player->current_offset++]; |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
176 } |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
177 |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
178 static uint16_t read_word_le(media_player *player) |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
179 { |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
180 uint8_t *buffer = player->media->buffer; |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
181 uint16_t value = buffer[player->current_offset++]; |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
182 value |= buffer[player->current_offset++] << 8; |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
183 return value; |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
184 } |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
185 |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
186 static uint32_t read_24_le(media_player *player) |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
187 { |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
188 uint8_t *buffer = player->media->buffer; |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
189 uint32_t value = buffer[player->current_offset++]; |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
190 value |= buffer[player->current_offset++] << 8; |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
191 value |= buffer[player->current_offset++] << 16; |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
192 return value; |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
193 } |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
194 |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
195 static uint32_t read_long_le(media_player *player) |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
196 { |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
197 uint8_t *buffer = player->media->buffer; |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
198 uint32_t value = buffer[player->current_offset++]; |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
199 value |= buffer[player->current_offset++] << 8; |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
200 value |= buffer[player->current_offset++] << 16; |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
201 value |= buffer[player->current_offset++] << 24; |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
202 return value; |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
203 } |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
204 |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
205 void vgm_frame(media_player *player) |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
206 { |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
207 for (uint32_t remaining_samples = 44100 / 60; remaining_samples > 0;) |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
208 { |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
209 if (player->wait_samples) { |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
210 uint32_t to_wait = player->wait_samples; |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
211 if (to_wait > remaining_samples) { |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
212 to_wait = remaining_samples; |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
213 } |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
214 vgm_wait(player, to_wait); |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
215 player->wait_samples -= to_wait; |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
216 remaining_samples -= to_wait; |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
217 if (player->wait_samples) { |
2374
97f164d1f0f6
Re-enable VGM looping. Enable oscilloscope in VGM player. Fix VGM player PSG output
Michael Pavone <pavone@retrodev.com>
parents:
2302
diff
changeset
|
218 goto frame_end; |
2289
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
219 } |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
220 } |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
221 if (player->current_offset >= player->media->size) { |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
222 vgm_stop(player); |
2374
97f164d1f0f6
Re-enable VGM looping. Enable oscilloscope in VGM player. Fix VGM player PSG output
Michael Pavone <pavone@retrodev.com>
parents:
2302
diff
changeset
|
223 goto frame_end; |
2289
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
224 } |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
225 uint8_t cmd = read_byte(player); |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
226 psg_context *psg; |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
227 ym2612_context *ym; |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
228 rf5c164 *pcm; |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
229 switch (cmd) |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
230 { |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
231 case CMD_PSG_STEREO: |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
232 psg = find_chip_context(player, CMD_PSG); |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
233 if (!psg || player->current_offset > player->media->size - 1) { |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
234 vgm_stop(player); |
2374
97f164d1f0f6
Re-enable VGM looping. Enable oscilloscope in VGM player. Fix VGM player PSG output
Michael Pavone <pavone@retrodev.com>
parents:
2302
diff
changeset
|
235 goto frame_end; |
2289
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
236 } |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
237 psg->pan = read_byte(player); |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
238 break; |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
239 case CMD_PSG: |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
240 psg = find_chip_context(player, CMD_PSG); |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
241 if (!psg || player->current_offset > player->media->size - 1) { |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
242 vgm_stop(player); |
2374
97f164d1f0f6
Re-enable VGM looping. Enable oscilloscope in VGM player. Fix VGM player PSG output
Michael Pavone <pavone@retrodev.com>
parents:
2302
diff
changeset
|
243 goto frame_end; |
2289
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
244 } |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
245 psg_write(psg, read_byte(player)); |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
246 break; |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
247 case CMD_YM2612_0: |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
248 ym = find_chip_context(player, CMD_YM2612_0); |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
249 if (!ym || player->current_offset > player->media->size - 2) { |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
250 vgm_stop(player); |
2374
97f164d1f0f6
Re-enable VGM looping. Enable oscilloscope in VGM player. Fix VGM player PSG output
Michael Pavone <pavone@retrodev.com>
parents:
2302
diff
changeset
|
251 goto frame_end; |
2289
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
252 } |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
253 ym_address_write_part1(ym, read_byte(player)); |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
254 ym_data_write(ym, read_byte(player)); |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
255 break; |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
256 case CMD_YM2612_1: |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
257 ym = find_chip_context(player, CMD_YM2612_0); |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
258 if (!ym || player->current_offset > player->media->size - 2) { |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
259 vgm_stop(player); |
2374
97f164d1f0f6
Re-enable VGM looping. Enable oscilloscope in VGM player. Fix VGM player PSG output
Michael Pavone <pavone@retrodev.com>
parents:
2302
diff
changeset
|
260 goto frame_end; |
2289
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
261 } |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
262 ym_address_write_part2(ym, read_byte(player)); |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
263 ym_data_write(ym, read_byte(player)); |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
264 break; |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
265 case CMD_WAIT: { |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
266 if (player->current_offset > player->media->size - 2) { |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
267 vgm_stop(player); |
2374
97f164d1f0f6
Re-enable VGM looping. Enable oscilloscope in VGM player. Fix VGM player PSG output
Michael Pavone <pavone@retrodev.com>
parents:
2302
diff
changeset
|
268 goto frame_end; |
2289
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
269 } |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
270 player->wait_samples += read_word_le(player); |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
271 break; |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
272 } |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
273 case CMD_WAIT_60: |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
274 player->wait_samples += 735; |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
275 break; |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
276 case CMD_WAIT_50: |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
277 player->wait_samples += 882; |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
278 break; |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
279 case CMD_END: |
2374
97f164d1f0f6
Re-enable VGM looping. Enable oscilloscope in VGM player. Fix VGM player PSG output
Michael Pavone <pavone@retrodev.com>
parents:
2302
diff
changeset
|
280 if (player->vgm->loop_offset && --player->loop_count) { |
97f164d1f0f6
Re-enable VGM looping. Enable oscilloscope in VGM player. Fix VGM player PSG output
Michael Pavone <pavone@retrodev.com>
parents:
2302
diff
changeset
|
281 player->current_offset = player->vgm->loop_offset + offsetof(vgm_header, loop_offset); |
97f164d1f0f6
Re-enable VGM looping. Enable oscilloscope in VGM player. Fix VGM player PSG output
Michael Pavone <pavone@retrodev.com>
parents:
2302
diff
changeset
|
282 if (player->current_offset < player->vgm->data_offset + offsetof(vgm_header, data_offset)) { |
97f164d1f0f6
Re-enable VGM looping. Enable oscilloscope in VGM player. Fix VGM player PSG output
Michael Pavone <pavone@retrodev.com>
parents:
2302
diff
changeset
|
283 // invalid loop offset |
97f164d1f0f6
Re-enable VGM looping. Enable oscilloscope in VGM player. Fix VGM player PSG output
Michael Pavone <pavone@retrodev.com>
parents:
2302
diff
changeset
|
284 vgm_stop(player); |
97f164d1f0f6
Re-enable VGM looping. Enable oscilloscope in VGM player. Fix VGM player PSG output
Michael Pavone <pavone@retrodev.com>
parents:
2302
diff
changeset
|
285 goto frame_end; |
97f164d1f0f6
Re-enable VGM looping. Enable oscilloscope in VGM player. Fix VGM player PSG output
Michael Pavone <pavone@retrodev.com>
parents:
2302
diff
changeset
|
286 } |
97f164d1f0f6
Re-enable VGM looping. Enable oscilloscope in VGM player. Fix VGM player PSG output
Michael Pavone <pavone@retrodev.com>
parents:
2302
diff
changeset
|
287 } else { |
97f164d1f0f6
Re-enable VGM looping. Enable oscilloscope in VGM player. Fix VGM player PSG output
Michael Pavone <pavone@retrodev.com>
parents:
2302
diff
changeset
|
288 //TODO: fade out? |
97f164d1f0f6
Re-enable VGM looping. Enable oscilloscope in VGM player. Fix VGM player PSG output
Michael Pavone <pavone@retrodev.com>
parents:
2302
diff
changeset
|
289 vgm_stop(player); |
97f164d1f0f6
Re-enable VGM looping. Enable oscilloscope in VGM player. Fix VGM player PSG output
Michael Pavone <pavone@retrodev.com>
parents:
2302
diff
changeset
|
290 goto frame_end; |
97f164d1f0f6
Re-enable VGM looping. Enable oscilloscope in VGM player. Fix VGM player PSG output
Michael Pavone <pavone@retrodev.com>
parents:
2302
diff
changeset
|
291 } |
2289
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
292 return; |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
293 case CMD_PCM_WRITE: { |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
294 if (player->current_offset > player->media->size - 11) { |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
295 vgm_stop(player); |
2374
97f164d1f0f6
Re-enable VGM looping. Enable oscilloscope in VGM player. Fix VGM player PSG output
Michael Pavone <pavone@retrodev.com>
parents:
2302
diff
changeset
|
296 goto frame_end; |
2289
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
297 } |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
298 player->current_offset++; //skip compatibility command |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
299 uint8_t data_type = read_byte(player); |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
300 uint32_t read_offset = read_24_le(player); |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
301 uint32_t write_offset = read_24_le(player); |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
302 uint16_t size = read_24_le(player); |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
303 chip_info *chip = find_chip_by_data(player, data_type); |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
304 if (!chip || !chip->blocks) { |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
305 warning("Failed to find data block list for type %d\n", data_type); |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
306 break; |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
307 } |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
308 uint8_t *src = find_block(chip->blocks, read_offset, size); |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
309 if (!src) { |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
310 warning("Failed to find data offset %X with size %X for chip type %d\n", read_offset, size, data_type); |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
311 break; |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
312 } |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
313 switch (data_type) |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
314 { |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
315 case DATA_RF5C68: |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
316 case DATA_RF5C164: |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
317 pcm = chip->context; |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
318 write_offset |= pcm->ram_bank; |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
319 write_offset &= 0xFFFF; |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
320 if (size + write_offset > 0x10000) { |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
321 size = 0x10000 - write_offset; |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
322 } |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
323 memcpy(pcm->ram + write_offset, src, size); |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
324 break; |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
325 default: |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
326 warning("Unknown PCM write read_offset %X, write_offset %X, size %X\n", read_offset, write_offset, size); |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
327 } |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
328 break; |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
329 } |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
330 case CMD_PCM68_REG: |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
331 pcm = find_chip_context(player, CMD_PCM68_REG); |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
332 if (!pcm || player->current_offset > player->media->size - 2) { |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
333 vgm_stop(player); |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
334 return; |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
335 } else { |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
336 uint8_t reg = read_byte(player); |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
337 uint8_t value = read_byte(player); |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
338 rf5c164_write(pcm, reg, value); |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
339 } |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
340 break; |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
341 case CMD_PCM164_REG: |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
342 pcm = find_chip_context(player, CMD_PCM164_REG); |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
343 if (!pcm || player->current_offset > player->media->size - 2) { |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
344 vgm_stop(player); |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
345 return; |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
346 } else { |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
347 uint8_t reg = read_byte(player); |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
348 uint8_t value = read_byte(player); |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
349 rf5c164_write(pcm, reg, value); |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
350 } |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
351 break; |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
352 case CMD_PCM68_RAM: |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
353 pcm = find_chip_context(player, CMD_PCM68_REG); |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
354 if (!pcm || player->current_offset > player->media->size - 3) { |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
355 vgm_stop(player); |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
356 return; |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
357 } else { |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
358 uint16_t address = read_word_le(player); |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
359 address &= 0xFFF; |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
360 address |= 0x1000; |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
361 rf5c164_write(pcm, address, read_byte(player)); |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
362 } |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
363 break; |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
364 case CMD_PCM164_RAM: |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
365 pcm = find_chip_context(player, CMD_PCM164_REG); |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
366 if (!pcm || player->current_offset > player->media->size - 3) { |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
367 vgm_stop(player); |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
368 return; |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
369 } else { |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
370 uint16_t address = read_word_le(player); |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
371 address &= 0xFFF; |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
372 address |= 0x1000; |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
373 rf5c164_write(pcm, address, read_byte(player)); |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
374 } |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
375 break; |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
376 case CMD_DATA: |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
377 if (player->current_offset > player->media->size - 6) { |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
378 vgm_stop(player); |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
379 return; |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
380 } else { |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
381 player->current_offset++; //skip compat command |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
382 uint8_t data_type = read_byte(player); |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
383 uint32_t data_size = read_long_le(player); |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
384 if (data_size > player->media->size || player->current_offset > player->media->size - data_size) { |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
385 vgm_stop(player); |
2374
97f164d1f0f6
Re-enable VGM looping. Enable oscilloscope in VGM player. Fix VGM player PSG output
Michael Pavone <pavone@retrodev.com>
parents:
2302
diff
changeset
|
386 goto frame_end; |
2289
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
387 } |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
388 chip_info *chip = find_chip_by_data(player, data_type); |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
389 if (chip) { |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
390 data_block **cur = &(chip->blocks); |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
391 while (*cur) |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
392 { |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
393 cur = &((*cur)->next); |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
394 } |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
395 *cur = calloc(1, sizeof(data_block)); |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
396 (*cur)->size = data_size; |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
397 (*cur)->type = data_type; |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
398 (*cur)->data = ((uint8_t *)player->media->buffer) + player->current_offset; |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
399 } else { |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
400 fprintf(stderr, "Skipping data block with unrecognized type %X\n", data_type); |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
401 } |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
402 player->current_offset += data_size; |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
403 } |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
404 break; |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
405 case CMD_DATA_SEEK: |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
406 if (player->current_offset > player->media->size - 4) { |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
407 vgm_stop(player); |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
408 return; |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
409 } else { |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
410 uint32_t new_offset = read_long_le(player); |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
411 if (!player->ym_seek_block || new_offset < player->ym_seek_offset) { |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
412 chip_info *chip = find_chip(player, CMD_YM2612_0); |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
413 if (!chip) { |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
414 break; |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
415 } |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
416 player->ym_seek_block = chip->blocks; |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
417 player->ym_seek_offset = 0; |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
418 player->ym_block_offset = 0; |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
419 } |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
420 while (player->ym_seek_block && (player->ym_seek_offset - player->ym_block_offset + player->ym_seek_block->size) < new_offset) |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
421 { |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
422 player->ym_seek_offset += player->ym_seek_block->size - player->ym_block_offset; |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
423 player->ym_seek_block = player->ym_seek_block->next; |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
424 player->ym_block_offset = 0; |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
425 } |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
426 player->ym_block_offset += new_offset - player->ym_seek_offset; |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
427 player->ym_seek_offset = new_offset; |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
428 } |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
429 break; |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
430 default: |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
431 if (cmd >= CMD_WAIT_SHORT && cmd < (CMD_WAIT_SHORT + 0x10)) { |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
432 uint32_t wait_time = (cmd & 0xF) + 1; |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
433 player->wait_samples += wait_time; |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
434 } else if (cmd >= CMD_YM2612_DAC && cmd < CMD_DAC_STREAM_SETUP) { |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
435 if (player->ym_seek_block) { |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
436 ym = find_chip_context(player, CMD_YM2612_0); |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
437 ym_address_write_part1(ym, 0x2A); |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
438 ym_data_write(ym, player->ym_seek_block->data[player->ym_block_offset++]); |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
439 player->ym_seek_offset++; |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
440 if (player->ym_block_offset > player->ym_seek_block->size) { |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
441 player->ym_seek_block = player->ym_seek_block->next; |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
442 player->ym_block_offset = 0; |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
443 } |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
444 } else { |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
445 fputs("Encountered DAC write command but data seek pointer is invalid!\n", stderr); |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
446 } |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
447 player->wait_samples += cmd & 0xF; |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
448 } else { |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
449 warning("unimplemented command: %X at offset %X\n", cmd, player->current_offset); |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
450 vgm_stop(player); |
2374
97f164d1f0f6
Re-enable VGM looping. Enable oscilloscope in VGM player. Fix VGM player PSG output
Michael Pavone <pavone@retrodev.com>
parents:
2302
diff
changeset
|
451 goto frame_end; |
2289
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
452 } |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
453 } |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
454 } |
2374
97f164d1f0f6
Re-enable VGM looping. Enable oscilloscope in VGM player. Fix VGM player PSG output
Michael Pavone <pavone@retrodev.com>
parents:
2302
diff
changeset
|
455 frame_end: |
2457 | 456 #ifndef IS_LIB |
2374
97f164d1f0f6
Re-enable VGM looping. Enable oscilloscope in VGM player. Fix VGM player PSG output
Michael Pavone <pavone@retrodev.com>
parents:
2302
diff
changeset
|
457 if (player->scope) { |
97f164d1f0f6
Re-enable VGM looping. Enable oscilloscope in VGM player. Fix VGM player PSG output
Michael Pavone <pavone@retrodev.com>
parents:
2302
diff
changeset
|
458 scope_render(player->scope); |
97f164d1f0f6
Re-enable VGM looping. Enable oscilloscope in VGM player. Fix VGM player PSG output
Michael Pavone <pavone@retrodev.com>
parents:
2302
diff
changeset
|
459 } |
2457 | 460 #endif |
461 return; | |
2289
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
462 } |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
463 |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
464 void wave_frame(media_player *player) |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
465 { |
2290
c4980d89614b
Support WAVE files in media player
Michael Pavone <pavone@retrodev.com>
parents:
2289
diff
changeset
|
466 for (uint32_t remaining_samples = player->wave->sample_rate / 60; remaining_samples > 0; remaining_samples--) |
c4980d89614b
Support WAVE files in media player
Michael Pavone <pavone@retrodev.com>
parents:
2289
diff
changeset
|
467 { |
c4980d89614b
Support WAVE files in media player
Michael Pavone <pavone@retrodev.com>
parents:
2289
diff
changeset
|
468 uint32_t sample_size = player->wave->bits_per_sample * player->wave->num_channels / 8; |
c4980d89614b
Support WAVE files in media player
Michael Pavone <pavone@retrodev.com>
parents:
2289
diff
changeset
|
469 if (sample_size > player->media->size || player->current_offset > player->media->size - sample_size) { |
c4980d89614b
Support WAVE files in media player
Michael Pavone <pavone@retrodev.com>
parents:
2289
diff
changeset
|
470 player->current_offset = player->wave->format_header.size + offsetof(wave_header, audio_format); |
c4980d89614b
Support WAVE files in media player
Michael Pavone <pavone@retrodev.com>
parents:
2289
diff
changeset
|
471 player->state = STATE_PAUSED; |
2376
1c09f5be285b
Very basic UI for media player
Michael Pavone <pavone@retrodev.com>
parents:
2375
diff
changeset
|
472 player->playback_time = 0; |
2290
c4980d89614b
Support WAVE files in media player
Michael Pavone <pavone@retrodev.com>
parents:
2289
diff
changeset
|
473 return; |
c4980d89614b
Support WAVE files in media player
Michael Pavone <pavone@retrodev.com>
parents:
2289
diff
changeset
|
474 } |
c4980d89614b
Support WAVE files in media player
Michael Pavone <pavone@retrodev.com>
parents:
2289
diff
changeset
|
475 if (player->wave->bits_per_sample == 16) { |
c4980d89614b
Support WAVE files in media player
Michael Pavone <pavone@retrodev.com>
parents:
2289
diff
changeset
|
476 int16_t value = read_word_le(player); |
c4980d89614b
Support WAVE files in media player
Michael Pavone <pavone@retrodev.com>
parents:
2289
diff
changeset
|
477 if (player->wave->num_channels == 1) { |
c4980d89614b
Support WAVE files in media player
Michael Pavone <pavone@retrodev.com>
parents:
2289
diff
changeset
|
478 render_put_mono_sample(player->audio, value); |
c4980d89614b
Support WAVE files in media player
Michael Pavone <pavone@retrodev.com>
parents:
2289
diff
changeset
|
479 } else { |
c4980d89614b
Support WAVE files in media player
Michael Pavone <pavone@retrodev.com>
parents:
2289
diff
changeset
|
480 int16_t right = read_word_le(player); |
c4980d89614b
Support WAVE files in media player
Michael Pavone <pavone@retrodev.com>
parents:
2289
diff
changeset
|
481 render_put_stereo_sample(player->audio, value, right); |
c4980d89614b
Support WAVE files in media player
Michael Pavone <pavone@retrodev.com>
parents:
2289
diff
changeset
|
482 } |
c4980d89614b
Support WAVE files in media player
Michael Pavone <pavone@retrodev.com>
parents:
2289
diff
changeset
|
483 } else { |
c4980d89614b
Support WAVE files in media player
Michael Pavone <pavone@retrodev.com>
parents:
2289
diff
changeset
|
484 uint8_t sample = read_byte(player); |
c4980d89614b
Support WAVE files in media player
Michael Pavone <pavone@retrodev.com>
parents:
2289
diff
changeset
|
485 int16_t value = sample * 257 - 128 * 257; |
c4980d89614b
Support WAVE files in media player
Michael Pavone <pavone@retrodev.com>
parents:
2289
diff
changeset
|
486 if (player->wave->num_channels == 1) { |
c4980d89614b
Support WAVE files in media player
Michael Pavone <pavone@retrodev.com>
parents:
2289
diff
changeset
|
487 render_put_mono_sample(player->audio, value); |
c4980d89614b
Support WAVE files in media player
Michael Pavone <pavone@retrodev.com>
parents:
2289
diff
changeset
|
488 } else { |
c4980d89614b
Support WAVE files in media player
Michael Pavone <pavone@retrodev.com>
parents:
2289
diff
changeset
|
489 sample = read_byte(player); |
c4980d89614b
Support WAVE files in media player
Michael Pavone <pavone@retrodev.com>
parents:
2289
diff
changeset
|
490 int16_t right = sample * 257 - 128 * 257; |
c4980d89614b
Support WAVE files in media player
Michael Pavone <pavone@retrodev.com>
parents:
2289
diff
changeset
|
491 render_put_stereo_sample(player->audio, value, right); |
c4980d89614b
Support WAVE files in media player
Michael Pavone <pavone@retrodev.com>
parents:
2289
diff
changeset
|
492 } |
c4980d89614b
Support WAVE files in media player
Michael Pavone <pavone@retrodev.com>
parents:
2289
diff
changeset
|
493 } |
c4980d89614b
Support WAVE files in media player
Michael Pavone <pavone@retrodev.com>
parents:
2289
diff
changeset
|
494 |
c4980d89614b
Support WAVE files in media player
Michael Pavone <pavone@retrodev.com>
parents:
2289
diff
changeset
|
495 } |
2289
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
496 } |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
497 |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
498 void flac_frame(media_player *player) |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
499 { |
2296
789802d99629
Add basic FLAC decoder and add FLAC playback support to the media player
Michael Pavone <pavone@retrodev.com>
parents:
2290
diff
changeset
|
500 for (uint32_t remaining_samples = player->flac->sample_rate / 60; remaining_samples > 0; remaining_samples--) |
789802d99629
Add basic FLAC decoder and add FLAC playback support to the media player
Michael Pavone <pavone@retrodev.com>
parents:
2290
diff
changeset
|
501 { |
789802d99629
Add basic FLAC decoder and add FLAC playback support to the media player
Michael Pavone <pavone@retrodev.com>
parents:
2290
diff
changeset
|
502 int16_t samples[2]; |
789802d99629
Add basic FLAC decoder and add FLAC playback support to the media player
Michael Pavone <pavone@retrodev.com>
parents:
2290
diff
changeset
|
503 if (flac_get_sample(player->flac, samples, 2)) { |
789802d99629
Add basic FLAC decoder and add FLAC playback support to the media player
Michael Pavone <pavone@retrodev.com>
parents:
2290
diff
changeset
|
504 render_put_stereo_sample(player->audio, samples[0], samples[1]); |
789802d99629
Add basic FLAC decoder and add FLAC playback support to the media player
Michael Pavone <pavone@retrodev.com>
parents:
2290
diff
changeset
|
505 } else { |
789802d99629
Add basic FLAC decoder and add FLAC playback support to the media player
Michael Pavone <pavone@retrodev.com>
parents:
2290
diff
changeset
|
506 player->state = STATE_PAUSED; |
2376
1c09f5be285b
Very basic UI for media player
Michael Pavone <pavone@retrodev.com>
parents:
2375
diff
changeset
|
507 player->playback_time = 0; |
2296
789802d99629
Add basic FLAC decoder and add FLAC playback support to the media player
Michael Pavone <pavone@retrodev.com>
parents:
2290
diff
changeset
|
508 return; |
789802d99629
Add basic FLAC decoder and add FLAC playback support to the media player
Michael Pavone <pavone@retrodev.com>
parents:
2290
diff
changeset
|
509 } |
789802d99629
Add basic FLAC decoder and add FLAC playback support to the media player
Michael Pavone <pavone@retrodev.com>
parents:
2290
diff
changeset
|
510 } |
2289
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
511 } |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
512 |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
513 void vgm_init(media_player *player, uint32_t opts) |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
514 { |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
515 player->vgm = calloc(1, sizeof(vgm_header)); |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
516 player->vgm_ext = NULL; |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
517 memcpy(player->vgm, player->media->buffer, sizeof(vgm_header)); |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
518 if (player->vgm->version < 0x150 || !player->vgm->data_offset) { |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
519 player->vgm->data_offset = 0xC; |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
520 } |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
521 if (player->vgm->data_offset + offsetof(vgm_header, data_offset) > player->media->size) { |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
522 player->vgm->data_offset = player->media->size - offsetof(vgm_header, data_offset); |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
523 } |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
524 if (player->vgm->version <= 0x101 && player->vgm->ym2413_clk > 4000000) { |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
525 player->vgm->ym2612_clk = player->vgm->ym2413_clk; |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
526 player->vgm->ym2413_clk = 0; |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
527 } |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
528 if (player->vgm->data_offset > 0xC) { |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
529 player->vgm_ext = calloc(1, sizeof(vgm_extended_header)); |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
530 size_t additional_header = player->vgm->data_offset + offsetof(vgm_header, data_offset) - sizeof(vgm_header); |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
531 if (additional_header > sizeof(vgm_extended_header)) { |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
532 additional_header = sizeof(vgm_extended_header); |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
533 } |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
534 memcpy(player->vgm_ext, ((uint8_t *)player->media->buffer) + sizeof(vgm_header), additional_header); |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
535 } |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
536 player->num_chips = 0; |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
537 if (player->vgm->sn76489_clk) { |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
538 player->num_chips++; |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
539 } |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
540 if (player->vgm->ym2612_clk) { |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
541 player->num_chips++; |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
542 } |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
543 if (player->vgm_ext && player->vgm_ext->rf5c68_clk) { |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
544 player->num_chips++; |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
545 } |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
546 if (player->vgm_ext && player->vgm_ext->rf5c164_clk) { |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
547 player->num_chips++; |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
548 } |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
549 player->chips = calloc(player->num_chips, sizeof(chip_info)); |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
550 uint32_t chip = 0; |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
551 if (player->vgm->ym2612_clk) { |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
552 ym2612_context *ym = calloc(1, sizeof(ym2612_context)); |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
553 ym_init(ym, player->vgm->ym2612_clk, 1, opts); |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
554 player->chips[chip++] = (chip_info) { |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
555 .context = ym, |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
556 .run = (chip_run_fun)ym_run, |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
557 .adjust = ym_adjust, |
2374
97f164d1f0f6
Re-enable VGM looping. Enable oscilloscope in VGM player. Fix VGM player PSG output
Michael Pavone <pavone@retrodev.com>
parents:
2302
diff
changeset
|
558 .scope = ym_scope, |
97f164d1f0f6
Re-enable VGM looping. Enable oscilloscope in VGM player. Fix VGM player PSG output
Michael Pavone <pavone@retrodev.com>
parents:
2302
diff
changeset
|
559 .no_scope = ym_no_scope, |
2377
30e59954eab9
Properly free sound chips in VGM player
Michael Pavone <pavone@retrodev.com>
parents:
2376
diff
changeset
|
560 .free = (chip_noarg_fun)ym_free, |
2289
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
561 .clock = player->vgm->ym2612_clk, |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
562 .samples = 0, |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
563 .cmd = CMD_YM2612_0, |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
564 .data_type = DATA_YM2612_PCM |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
565 }; |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
566 } |
2374
97f164d1f0f6
Re-enable VGM looping. Enable oscilloscope in VGM player. Fix VGM player PSG output
Michael Pavone <pavone@retrodev.com>
parents:
2302
diff
changeset
|
567 if (player->vgm->sn76489_clk) { |
97f164d1f0f6
Re-enable VGM looping. Enable oscilloscope in VGM player. Fix VGM player PSG output
Michael Pavone <pavone@retrodev.com>
parents:
2302
diff
changeset
|
568 psg_context *psg = calloc(1, sizeof(psg_context)); |
97f164d1f0f6
Re-enable VGM looping. Enable oscilloscope in VGM player. Fix VGM player PSG output
Michael Pavone <pavone@retrodev.com>
parents:
2302
diff
changeset
|
569 psg_init(psg, player->vgm->sn76489_clk, 16); |
97f164d1f0f6
Re-enable VGM looping. Enable oscilloscope in VGM player. Fix VGM player PSG output
Michael Pavone <pavone@retrodev.com>
parents:
2302
diff
changeset
|
570 player->chips[chip++] = (chip_info) { |
97f164d1f0f6
Re-enable VGM looping. Enable oscilloscope in VGM player. Fix VGM player PSG output
Michael Pavone <pavone@retrodev.com>
parents:
2302
diff
changeset
|
571 .context = psg, |
97f164d1f0f6
Re-enable VGM looping. Enable oscilloscope in VGM player. Fix VGM player PSG output
Michael Pavone <pavone@retrodev.com>
parents:
2302
diff
changeset
|
572 .run = (chip_run_fun)psg_run, |
97f164d1f0f6
Re-enable VGM looping. Enable oscilloscope in VGM player. Fix VGM player PSG output
Michael Pavone <pavone@retrodev.com>
parents:
2302
diff
changeset
|
573 .adjust = psg_adjust, |
97f164d1f0f6
Re-enable VGM looping. Enable oscilloscope in VGM player. Fix VGM player PSG output
Michael Pavone <pavone@retrodev.com>
parents:
2302
diff
changeset
|
574 .scope = psg_scope, |
97f164d1f0f6
Re-enable VGM looping. Enable oscilloscope in VGM player. Fix VGM player PSG output
Michael Pavone <pavone@retrodev.com>
parents:
2302
diff
changeset
|
575 .no_scope = ym_no_scope, |
2377
30e59954eab9
Properly free sound chips in VGM player
Michael Pavone <pavone@retrodev.com>
parents:
2376
diff
changeset
|
576 .free = (chip_noarg_fun)psg_free, |
2374
97f164d1f0f6
Re-enable VGM looping. Enable oscilloscope in VGM player. Fix VGM player PSG output
Michael Pavone <pavone@retrodev.com>
parents:
2302
diff
changeset
|
577 .clock = player->vgm->sn76489_clk, |
97f164d1f0f6
Re-enable VGM looping. Enable oscilloscope in VGM player. Fix VGM player PSG output
Michael Pavone <pavone@retrodev.com>
parents:
2302
diff
changeset
|
578 .samples = 0, |
97f164d1f0f6
Re-enable VGM looping. Enable oscilloscope in VGM player. Fix VGM player PSG output
Michael Pavone <pavone@retrodev.com>
parents:
2302
diff
changeset
|
579 .cmd = CMD_PSG, |
97f164d1f0f6
Re-enable VGM looping. Enable oscilloscope in VGM player. Fix VGM player PSG output
Michael Pavone <pavone@retrodev.com>
parents:
2302
diff
changeset
|
580 .data_type = 0xFF |
97f164d1f0f6
Re-enable VGM looping. Enable oscilloscope in VGM player. Fix VGM player PSG output
Michael Pavone <pavone@retrodev.com>
parents:
2302
diff
changeset
|
581 }; |
97f164d1f0f6
Re-enable VGM looping. Enable oscilloscope in VGM player. Fix VGM player PSG output
Michael Pavone <pavone@retrodev.com>
parents:
2302
diff
changeset
|
582 } |
2289
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
583 if (player->vgm_ext && player->vgm_ext->rf5c68_clk) { |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
584 rf5c164 *pcm = calloc(1, sizeof(rf5c164)); |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
585 rf5c164_init(pcm, player->vgm_ext->rf5c68_clk, 1); |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
586 player->chips[chip++] = (chip_info) { |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
587 .context = pcm, |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
588 .run = (chip_run_fun)rf5c164_run, |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
589 .adjust = pcm_adjust, |
2374
97f164d1f0f6
Re-enable VGM looping. Enable oscilloscope in VGM player. Fix VGM player PSG output
Michael Pavone <pavone@retrodev.com>
parents:
2302
diff
changeset
|
590 .scope = pcm_scope, |
97f164d1f0f6
Re-enable VGM looping. Enable oscilloscope in VGM player. Fix VGM player PSG output
Michael Pavone <pavone@retrodev.com>
parents:
2302
diff
changeset
|
591 .no_scope = pcm_no_scope, |
2377
30e59954eab9
Properly free sound chips in VGM player
Michael Pavone <pavone@retrodev.com>
parents:
2376
diff
changeset
|
592 .free = pcm_free, |
2289
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
593 .clock = player->vgm_ext->rf5c68_clk, |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
594 .samples = 0, |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
595 .cmd = CMD_PCM68_REG, |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
596 .data_type = DATA_RF5C68 |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
597 }; |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
598 } |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
599 if (player->vgm_ext && player->vgm_ext->rf5c164_clk) { |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
600 rf5c164 *pcm = calloc(1, sizeof(rf5c164)); |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
601 rf5c164_init(pcm, player->vgm_ext->rf5c164_clk, 1); |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
602 player->chips[chip++] = (chip_info) { |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
603 .context = pcm, |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
604 .run = (chip_run_fun)rf5c164_run, |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
605 .adjust = pcm_adjust, |
2374
97f164d1f0f6
Re-enable VGM looping. Enable oscilloscope in VGM player. Fix VGM player PSG output
Michael Pavone <pavone@retrodev.com>
parents:
2302
diff
changeset
|
606 .scope = pcm_scope, |
97f164d1f0f6
Re-enable VGM looping. Enable oscilloscope in VGM player. Fix VGM player PSG output
Michael Pavone <pavone@retrodev.com>
parents:
2302
diff
changeset
|
607 .no_scope = pcm_no_scope, |
2377
30e59954eab9
Properly free sound chips in VGM player
Michael Pavone <pavone@retrodev.com>
parents:
2376
diff
changeset
|
608 .free = pcm_free, |
2289
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
609 .clock = player->vgm_ext->rf5c164_clk, |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
610 .samples = 0, |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
611 .cmd = CMD_PCM164_REG, |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
612 .data_type = DATA_RF5C164 |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
613 }; |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
614 } |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
615 player->current_offset = player->vgm->data_offset + offsetof(vgm_header, data_offset); |
2374
97f164d1f0f6
Re-enable VGM looping. Enable oscilloscope in VGM player. Fix VGM player PSG output
Michael Pavone <pavone@retrodev.com>
parents:
2302
diff
changeset
|
616 player->loop_count = 2; |
2289
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
617 } |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
618 |
2290
c4980d89614b
Support WAVE files in media player
Michael Pavone <pavone@retrodev.com>
parents:
2289
diff
changeset
|
619 static void wave_player_init(media_player *player) |
c4980d89614b
Support WAVE files in media player
Michael Pavone <pavone@retrodev.com>
parents:
2289
diff
changeset
|
620 { |
c4980d89614b
Support WAVE files in media player
Michael Pavone <pavone@retrodev.com>
parents:
2289
diff
changeset
|
621 player->wave = calloc(1, sizeof(wave_header)); |
c4980d89614b
Support WAVE files in media player
Michael Pavone <pavone@retrodev.com>
parents:
2289
diff
changeset
|
622 memcpy(player->wave, player->media->buffer, offsetof(wave_header, data_header)); |
c4980d89614b
Support WAVE files in media player
Michael Pavone <pavone@retrodev.com>
parents:
2289
diff
changeset
|
623 if (memcmp(player->wave->chunk.format, "WAVE", 4)) { |
c4980d89614b
Support WAVE files in media player
Michael Pavone <pavone@retrodev.com>
parents:
2289
diff
changeset
|
624 goto format_error; |
c4980d89614b
Support WAVE files in media player
Michael Pavone <pavone@retrodev.com>
parents:
2289
diff
changeset
|
625 } |
c4980d89614b
Support WAVE files in media player
Michael Pavone <pavone@retrodev.com>
parents:
2289
diff
changeset
|
626 if (player->wave->chunk.size < offsetof(wave_header, data_header)) { |
c4980d89614b
Support WAVE files in media player
Michael Pavone <pavone@retrodev.com>
parents:
2289
diff
changeset
|
627 goto format_error; |
c4980d89614b
Support WAVE files in media player
Michael Pavone <pavone@retrodev.com>
parents:
2289
diff
changeset
|
628 } |
c4980d89614b
Support WAVE files in media player
Michael Pavone <pavone@retrodev.com>
parents:
2289
diff
changeset
|
629 if (memcmp(player->wave->format_header.id, "fmt ", 4)) { |
c4980d89614b
Support WAVE files in media player
Michael Pavone <pavone@retrodev.com>
parents:
2289
diff
changeset
|
630 goto format_error; |
c4980d89614b
Support WAVE files in media player
Michael Pavone <pavone@retrodev.com>
parents:
2289
diff
changeset
|
631 } |
c4980d89614b
Support WAVE files in media player
Michael Pavone <pavone@retrodev.com>
parents:
2289
diff
changeset
|
632 if (player->wave->format_header.size < offsetof(wave_header, data_header) - offsetof(wave_header, audio_format)) { |
c4980d89614b
Support WAVE files in media player
Michael Pavone <pavone@retrodev.com>
parents:
2289
diff
changeset
|
633 goto format_error; |
c4980d89614b
Support WAVE files in media player
Michael Pavone <pavone@retrodev.com>
parents:
2289
diff
changeset
|
634 } |
c4980d89614b
Support WAVE files in media player
Michael Pavone <pavone@retrodev.com>
parents:
2289
diff
changeset
|
635 if (player->wave->bits_per_sample != 8 && player->wave->bits_per_sample != 16) { |
c4980d89614b
Support WAVE files in media player
Michael Pavone <pavone@retrodev.com>
parents:
2289
diff
changeset
|
636 goto format_error; |
c4980d89614b
Support WAVE files in media player
Michael Pavone <pavone@retrodev.com>
parents:
2289
diff
changeset
|
637 } |
c4980d89614b
Support WAVE files in media player
Michael Pavone <pavone@retrodev.com>
parents:
2289
diff
changeset
|
638 uint32_t data_sub_chunk = player->wave->format_header.size + offsetof(wave_header, audio_format); |
c4980d89614b
Support WAVE files in media player
Michael Pavone <pavone@retrodev.com>
parents:
2289
diff
changeset
|
639 if (data_sub_chunk > player->media->size || player->media->size - data_sub_chunk < sizeof(riff_sub_chunk)) { |
c4980d89614b
Support WAVE files in media player
Michael Pavone <pavone@retrodev.com>
parents:
2289
diff
changeset
|
640 goto format_error; |
c4980d89614b
Support WAVE files in media player
Michael Pavone <pavone@retrodev.com>
parents:
2289
diff
changeset
|
641 } |
c4980d89614b
Support WAVE files in media player
Michael Pavone <pavone@retrodev.com>
parents:
2289
diff
changeset
|
642 memcpy(&player->wave->data_header, ((uint8_t *)player->media->buffer) + data_sub_chunk, sizeof(riff_sub_chunk)); |
c4980d89614b
Support WAVE files in media player
Michael Pavone <pavone@retrodev.com>
parents:
2289
diff
changeset
|
643 player->current_offset = data_sub_chunk; |
c4980d89614b
Support WAVE files in media player
Michael Pavone <pavone@retrodev.com>
parents:
2289
diff
changeset
|
644 player->audio = render_audio_source("Audio File", player->wave->sample_rate, 1, player->wave->num_channels); |
c4980d89614b
Support WAVE files in media player
Michael Pavone <pavone@retrodev.com>
parents:
2289
diff
changeset
|
645 return; |
c4980d89614b
Support WAVE files in media player
Michael Pavone <pavone@retrodev.com>
parents:
2289
diff
changeset
|
646 format_error: |
c4980d89614b
Support WAVE files in media player
Michael Pavone <pavone@retrodev.com>
parents:
2289
diff
changeset
|
647 player->media_type = MEDIA_UNKNOWN; |
c4980d89614b
Support WAVE files in media player
Michael Pavone <pavone@retrodev.com>
parents:
2289
diff
changeset
|
648 free(player->wave); |
c4980d89614b
Support WAVE files in media player
Michael Pavone <pavone@retrodev.com>
parents:
2289
diff
changeset
|
649 } |
c4980d89614b
Support WAVE files in media player
Michael Pavone <pavone@retrodev.com>
parents:
2289
diff
changeset
|
650 |
2296
789802d99629
Add basic FLAC decoder and add FLAC playback support to the media player
Michael Pavone <pavone@retrodev.com>
parents:
2290
diff
changeset
|
651 static void flac_player_init(media_player *player) |
789802d99629
Add basic FLAC decoder and add FLAC playback support to the media player
Michael Pavone <pavone@retrodev.com>
parents:
2290
diff
changeset
|
652 { |
789802d99629
Add basic FLAC decoder and add FLAC playback support to the media player
Michael Pavone <pavone@retrodev.com>
parents:
2290
diff
changeset
|
653 player->flac = flac_file_from_buffer(player->media->buffer, player->media->size); |
789802d99629
Add basic FLAC decoder and add FLAC playback support to the media player
Michael Pavone <pavone@retrodev.com>
parents:
2290
diff
changeset
|
654 if (player->flac) { |
789802d99629
Add basic FLAC decoder and add FLAC playback support to the media player
Michael Pavone <pavone@retrodev.com>
parents:
2290
diff
changeset
|
655 player->audio = render_audio_source("Audio File", player->flac->sample_rate, 1, 2); |
789802d99629
Add basic FLAC decoder and add FLAC playback support to the media player
Michael Pavone <pavone@retrodev.com>
parents:
2290
diff
changeset
|
656 } |
789802d99629
Add basic FLAC decoder and add FLAC playback support to the media player
Michael Pavone <pavone@retrodev.com>
parents:
2290
diff
changeset
|
657 } |
789802d99629
Add basic FLAC decoder and add FLAC playback support to the media player
Michael Pavone <pavone@retrodev.com>
parents:
2290
diff
changeset
|
658 |
2289
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
659 static void resume_player(system_header *system) |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
660 { |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
661 media_player *player = (media_player *)system; |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
662 player->should_return = 0; |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
663 while (!player->header.should_exit && !player->should_return) |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
664 { |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
665 switch (player->state) |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
666 { |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
667 case STATE_PLAY: |
2376
1c09f5be285b
Very basic UI for media player
Michael Pavone <pavone@retrodev.com>
parents:
2375
diff
changeset
|
668 player->playback_time++; |
2289
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
669 switch(player->media_type) |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
670 { |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
671 case AUDIO_VGM: |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
672 vgm_frame(player); |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
673 break; |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
674 case AUDIO_WAVE: |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
675 wave_frame(player); |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
676 break; |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
677 case AUDIO_FLAC: |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
678 flac_frame(player); |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
679 break; |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
680 } |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
681 break; |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
682 case STATE_PAUSED: |
2302
0343f0d5add0
Fix libretro build for real
Michael Pavone <pavone@retrodev.com>
parents:
2296
diff
changeset
|
683 #ifndef IS_LIB |
2289
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
684 render_sleep_ms(15); |
2302
0343f0d5add0
Fix libretro build for real
Michael Pavone <pavone@retrodev.com>
parents:
2296
diff
changeset
|
685 #endif |
2289
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
686 break; |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
687 } |
2302
0343f0d5add0
Fix libretro build for real
Michael Pavone <pavone@retrodev.com>
parents:
2296
diff
changeset
|
688 //TODO: Fix this for libretro build properly |
0343f0d5add0
Fix libretro build for real
Michael Pavone <pavone@retrodev.com>
parents:
2296
diff
changeset
|
689 #ifndef IS_LIB |
2289
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
690 render_update_display(); |
2302
0343f0d5add0
Fix libretro build for real
Michael Pavone <pavone@retrodev.com>
parents:
2296
diff
changeset
|
691 #endif |
2289
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
692 } |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
693 } |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
694 |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
695 static void gamepad_down(system_header *system, uint8_t pad, uint8_t button) |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
696 { |
2375
02c04196c2da
Fix mediaplayer play/pause handling
Michael Pavone <pavone@retrodev.com>
parents:
2374
diff
changeset
|
697 if (pad != 1) { |
02c04196c2da
Fix mediaplayer play/pause handling
Michael Pavone <pavone@retrodev.com>
parents:
2374
diff
changeset
|
698 return; |
02c04196c2da
Fix mediaplayer play/pause handling
Michael Pavone <pavone@retrodev.com>
parents:
2374
diff
changeset
|
699 } |
02c04196c2da
Fix mediaplayer play/pause handling
Michael Pavone <pavone@retrodev.com>
parents:
2374
diff
changeset
|
700 media_player *player = (media_player *)system; |
02c04196c2da
Fix mediaplayer play/pause handling
Michael Pavone <pavone@retrodev.com>
parents:
2374
diff
changeset
|
701 if (player->button_state[button]) { |
02c04196c2da
Fix mediaplayer play/pause handling
Michael Pavone <pavone@retrodev.com>
parents:
2374
diff
changeset
|
702 //already pressed |
02c04196c2da
Fix mediaplayer play/pause handling
Michael Pavone <pavone@retrodev.com>
parents:
2374
diff
changeset
|
703 return; |
02c04196c2da
Fix mediaplayer play/pause handling
Michael Pavone <pavone@retrodev.com>
parents:
2374
diff
changeset
|
704 } |
02c04196c2da
Fix mediaplayer play/pause handling
Michael Pavone <pavone@retrodev.com>
parents:
2374
diff
changeset
|
705 player->button_state[button] = 1; |
02c04196c2da
Fix mediaplayer play/pause handling
Michael Pavone <pavone@retrodev.com>
parents:
2374
diff
changeset
|
706 if (button == BUTTON_A || button == BUTTON_C || button == BUTTON_START) { |
2289
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
707 if (player->state == STATE_PAUSED) { |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
708 player->state = STATE_PLAY; |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
709 puts("Now playing"); |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
710 } else { |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
711 player->state = STATE_PAUSED; |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
712 puts("Now paused"); |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
713 } |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
714 } |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
715 } |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
716 |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
717 static void gamepad_up(system_header *system, uint8_t pad, uint8_t button) |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
718 { |
2375
02c04196c2da
Fix mediaplayer play/pause handling
Michael Pavone <pavone@retrodev.com>
parents:
2374
diff
changeset
|
719 if (pad != 1) { |
02c04196c2da
Fix mediaplayer play/pause handling
Michael Pavone <pavone@retrodev.com>
parents:
2374
diff
changeset
|
720 return; |
02c04196c2da
Fix mediaplayer play/pause handling
Michael Pavone <pavone@retrodev.com>
parents:
2374
diff
changeset
|
721 } |
02c04196c2da
Fix mediaplayer play/pause handling
Michael Pavone <pavone@retrodev.com>
parents:
2374
diff
changeset
|
722 media_player *player = (media_player *)system; |
02c04196c2da
Fix mediaplayer play/pause handling
Michael Pavone <pavone@retrodev.com>
parents:
2374
diff
changeset
|
723 player->button_state[button] = 0; |
2289
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
724 } |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
725 |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
726 static void start_player(system_header *system, char *statefile) |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
727 { |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
728 resume_player(system); |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
729 } |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
730 |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
731 static void free_player(system_header *system) |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
732 { |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
733 media_player *player = (media_player *)system; |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
734 for (uint32_t i = 0; i < player->num_chips; i++) |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
735 { |
2377
30e59954eab9
Properly free sound chips in VGM player
Michael Pavone <pavone@retrodev.com>
parents:
2376
diff
changeset
|
736 player->chips[i].free(player->chips[i].context); |
2289
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
737 } |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
738 free(player->chips); |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
739 free(player->vgm); |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
740 free(player); |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
741 } |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
742 |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
743 uint8_t detect_media_type(system_media *media) |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
744 { |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
745 if (media->size < 4) { |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
746 return MEDIA_UNKNOWN; |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
747 } |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
748 if (!memcmp(media->buffer, "Vgm ", 4)) { |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
749 if (media->size < sizeof(vgm_header)) { |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
750 return MEDIA_UNKNOWN; |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
751 } |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
752 return AUDIO_VGM; |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
753 } |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
754 if (!memcmp(media->buffer, "RIFF", 4)) { |
2290
c4980d89614b
Support WAVE files in media player
Michael Pavone <pavone@retrodev.com>
parents:
2289
diff
changeset
|
755 if (media->size < sizeof(wave_header)) { |
c4980d89614b
Support WAVE files in media player
Michael Pavone <pavone@retrodev.com>
parents:
2289
diff
changeset
|
756 return MEDIA_UNKNOWN; |
c4980d89614b
Support WAVE files in media player
Michael Pavone <pavone@retrodev.com>
parents:
2289
diff
changeset
|
757 } |
2289
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
758 return AUDIO_WAVE; |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
759 } |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
760 if (!memcmp(media->buffer, "fLaC", 4)) { |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
761 return AUDIO_FLAC; |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
762 } |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
763 return MEDIA_UNKNOWN; |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
764 } |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
765 |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
766 static void request_exit(system_header *system) |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
767 { |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
768 media_player *player = (media_player *)system; |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
769 player->should_return = 1; |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
770 } |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
771 |
2374
97f164d1f0f6
Re-enable VGM looping. Enable oscilloscope in VGM player. Fix VGM player PSG output
Michael Pavone <pavone@retrodev.com>
parents:
2302
diff
changeset
|
772 static void toggle_debug_view(system_header *system, uint8_t debug_view) |
97f164d1f0f6
Re-enable VGM looping. Enable oscilloscope in VGM player. Fix VGM player PSG output
Michael Pavone <pavone@retrodev.com>
parents:
2302
diff
changeset
|
773 { |
97f164d1f0f6
Re-enable VGM looping. Enable oscilloscope in VGM player. Fix VGM player PSG output
Michael Pavone <pavone@retrodev.com>
parents:
2302
diff
changeset
|
774 #ifndef IS_LIB |
97f164d1f0f6
Re-enable VGM looping. Enable oscilloscope in VGM player. Fix VGM player PSG output
Michael Pavone <pavone@retrodev.com>
parents:
2302
diff
changeset
|
775 media_player *player = (media_player *)system; |
97f164d1f0f6
Re-enable VGM looping. Enable oscilloscope in VGM player. Fix VGM player PSG output
Michael Pavone <pavone@retrodev.com>
parents:
2302
diff
changeset
|
776 if (debug_view == DEBUG_OSCILLOSCOPE && player->chips) { |
97f164d1f0f6
Re-enable VGM looping. Enable oscilloscope in VGM player. Fix VGM player PSG output
Michael Pavone <pavone@retrodev.com>
parents:
2302
diff
changeset
|
777 if (player->scope) { |
97f164d1f0f6
Re-enable VGM looping. Enable oscilloscope in VGM player. Fix VGM player PSG output
Michael Pavone <pavone@retrodev.com>
parents:
2302
diff
changeset
|
778 for (uint32_t i = 0; i < player->num_chips; i++) |
97f164d1f0f6
Re-enable VGM looping. Enable oscilloscope in VGM player. Fix VGM player PSG output
Michael Pavone <pavone@retrodev.com>
parents:
2302
diff
changeset
|
779 { |
97f164d1f0f6
Re-enable VGM looping. Enable oscilloscope in VGM player. Fix VGM player PSG output
Michael Pavone <pavone@retrodev.com>
parents:
2302
diff
changeset
|
780 player->chips[i].no_scope(player->chips[i].context); |
97f164d1f0f6
Re-enable VGM looping. Enable oscilloscope in VGM player. Fix VGM player PSG output
Michael Pavone <pavone@retrodev.com>
parents:
2302
diff
changeset
|
781 } |
97f164d1f0f6
Re-enable VGM looping. Enable oscilloscope in VGM player. Fix VGM player PSG output
Michael Pavone <pavone@retrodev.com>
parents:
2302
diff
changeset
|
782 scope_close(player->scope); |
97f164d1f0f6
Re-enable VGM looping. Enable oscilloscope in VGM player. Fix VGM player PSG output
Michael Pavone <pavone@retrodev.com>
parents:
2302
diff
changeset
|
783 player->scope = NULL; |
97f164d1f0f6
Re-enable VGM looping. Enable oscilloscope in VGM player. Fix VGM player PSG output
Michael Pavone <pavone@retrodev.com>
parents:
2302
diff
changeset
|
784 } else { |
97f164d1f0f6
Re-enable VGM looping. Enable oscilloscope in VGM player. Fix VGM player PSG output
Michael Pavone <pavone@retrodev.com>
parents:
2302
diff
changeset
|
785 player->scope = create_oscilloscope(); |
97f164d1f0f6
Re-enable VGM looping. Enable oscilloscope in VGM player. Fix VGM player PSG output
Michael Pavone <pavone@retrodev.com>
parents:
2302
diff
changeset
|
786 for (uint32_t i = 0; i < player->num_chips; i++) |
97f164d1f0f6
Re-enable VGM looping. Enable oscilloscope in VGM player. Fix VGM player PSG output
Michael Pavone <pavone@retrodev.com>
parents:
2302
diff
changeset
|
787 { |
97f164d1f0f6
Re-enable VGM looping. Enable oscilloscope in VGM player. Fix VGM player PSG output
Michael Pavone <pavone@retrodev.com>
parents:
2302
diff
changeset
|
788 player->chips[i].scope(player->chips + i, player->scope); |
97f164d1f0f6
Re-enable VGM looping. Enable oscilloscope in VGM player. Fix VGM player PSG output
Michael Pavone <pavone@retrodev.com>
parents:
2302
diff
changeset
|
789 } |
97f164d1f0f6
Re-enable VGM looping. Enable oscilloscope in VGM player. Fix VGM player PSG output
Michael Pavone <pavone@retrodev.com>
parents:
2302
diff
changeset
|
790 } |
97f164d1f0f6
Re-enable VGM looping. Enable oscilloscope in VGM player. Fix VGM player PSG output
Michael Pavone <pavone@retrodev.com>
parents:
2302
diff
changeset
|
791 } |
97f164d1f0f6
Re-enable VGM looping. Enable oscilloscope in VGM player. Fix VGM player PSG output
Michael Pavone <pavone@retrodev.com>
parents:
2302
diff
changeset
|
792 #endif |
97f164d1f0f6
Re-enable VGM looping. Enable oscilloscope in VGM player. Fix VGM player PSG output
Michael Pavone <pavone@retrodev.com>
parents:
2302
diff
changeset
|
793 } |
97f164d1f0f6
Re-enable VGM looping. Enable oscilloscope in VGM player. Fix VGM player PSG output
Michael Pavone <pavone@retrodev.com>
parents:
2302
diff
changeset
|
794 |
2289
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
795 media_player *alloc_media_player(system_media *media, uint32_t opts) |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
796 { |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
797 media_player *player = calloc(1, sizeof(media_player)); |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
798 player->header.start_context = start_player; |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
799 player->header.resume_context = resume_player; |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
800 player->header.request_exit = request_exit; |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
801 player->header.free_context = free_player; |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
802 player->header.gamepad_down = gamepad_down; |
2375
02c04196c2da
Fix mediaplayer play/pause handling
Michael Pavone <pavone@retrodev.com>
parents:
2374
diff
changeset
|
803 player->header.gamepad_up = gamepad_up; |
2374
97f164d1f0f6
Re-enable VGM looping. Enable oscilloscope in VGM player. Fix VGM player PSG output
Michael Pavone <pavone@retrodev.com>
parents:
2302
diff
changeset
|
804 player->header.toggle_debug_view = toggle_debug_view; |
2289
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
805 player->header.type = SYSTEM_MEDIA_PLAYER; |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
806 player->header.info.name = strdup(media->name); |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
807 |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
808 player->media = media; |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
809 player->media_type = detect_media_type(media); |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
810 player->state = STATE_PLAY; |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
811 switch (player->media_type) |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
812 { |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
813 case AUDIO_VGM: |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
814 vgm_init(player, opts); |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
815 break; |
2290
c4980d89614b
Support WAVE files in media player
Michael Pavone <pavone@retrodev.com>
parents:
2289
diff
changeset
|
816 case AUDIO_WAVE: |
c4980d89614b
Support WAVE files in media player
Michael Pavone <pavone@retrodev.com>
parents:
2289
diff
changeset
|
817 wave_player_init(player); |
c4980d89614b
Support WAVE files in media player
Michael Pavone <pavone@retrodev.com>
parents:
2289
diff
changeset
|
818 break; |
2296
789802d99629
Add basic FLAC decoder and add FLAC playback support to the media player
Michael Pavone <pavone@retrodev.com>
parents:
2290
diff
changeset
|
819 case AUDIO_FLAC: |
789802d99629
Add basic FLAC decoder and add FLAC playback support to the media player
Michael Pavone <pavone@retrodev.com>
parents:
2290
diff
changeset
|
820 flac_player_init(player); |
789802d99629
Add basic FLAC decoder and add FLAC playback support to the media player
Michael Pavone <pavone@retrodev.com>
parents:
2290
diff
changeset
|
821 break; |
2289
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
822 } |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
823 |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
824 return player; |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
825 } |