Mercurial > repos > blastem
annotate mediaplayer.c @ 2305:6aca1734d573
Merge
author | Michael Pavone <pavone@retrodev.com> |
---|---|
date | Wed, 15 Mar 2023 19:28:11 -0700 |
parents | 0343f0d5add0 |
children | 97f164d1f0f6 |
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 enum { |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
25 STATE_PLAY, |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
26 STATE_PAUSED |
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 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
|
30 { |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
31 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
|
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 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
|
35 { |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
36 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
|
37 } |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
38 |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
39 void ym_adjust(chip_info *chip) |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
40 { |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
41 ym2612_context *ym = chip->context; |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
42 if (ym->current_cycle >= MAX_NO_ADJUST) { |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
43 uint32_t deduction = ym->current_cycle - ADJUST_BUFFER; |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
44 chip->samples -= cycles_to_samples(chip->clock, deduction); |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
45 ym->current_cycle -= deduction; |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
46 } |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
47 } |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
48 |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
49 void psg_adjust(chip_info *chip) |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
50 { |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
51 psg_context *psg = chip->context; |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
52 if (psg->cycles >= MAX_NO_ADJUST) { |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
53 uint32_t deduction = psg->cycles - ADJUST_BUFFER; |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
54 chip->samples -= cycles_to_samples(chip->clock, deduction); |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
55 psg->cycles -= deduction; |
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 } |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
58 |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
59 void pcm_adjust(chip_info *chip) |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
60 { |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
61 rf5c164 *pcm = chip->context; |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
62 if (pcm->cycle >= MAX_NO_ADJUST) { |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
63 uint32_t deduction = pcm->cycle - ADJUST_BUFFER; |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
64 chip->samples -= cycles_to_samples(chip->clock, deduction); |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
65 pcm->cycle -= deduction; |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
66 } |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
67 } |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
68 |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
69 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
|
70 { |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
71 if (!head) { |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
72 return NULL; |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
73 } |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
74 while (head->size < offset) { |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
75 offset -= head->size; |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
76 head = head->next; |
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 if (head->size - offset < size) { |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
79 return NULL; |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
80 } |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
81 return head->data + offset; |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
82 } |
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 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
|
85 { |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
86 chip_info *chips = player->chips; |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
87 uint32_t num_chips = player->num_chips; |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
88 while (samples > MAX_RUN_SAMPLES) |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
89 { |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
90 vgm_wait(player, MAX_RUN_SAMPLES); |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
91 samples -= MAX_RUN_SAMPLES; |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
92 } |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
93 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
|
94 { |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
95 chips[i].samples += samples; |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
96 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
|
97 chips[i].adjust(chips + i); |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
98 } |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
99 } |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
100 |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
101 void vgm_stop(media_player *player) |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
102 { |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
103 player->state = STATE_PAUSED; |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
104 player->playback_time = 0; |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
105 player->current_offset = player->vgm->data_offset + offsetof(vgm_header, data_offset); |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
106 } |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
107 |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
108 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
|
109 { |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
110 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
|
111 { |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
112 if (player->chips[i].cmd == cmd) { |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
113 return player->chips + i; |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
114 } |
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 NULL; |
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 *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
|
120 { |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
121 chip_info *chip = find_chip(player, cmd); |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
122 return chip ? chip->context : NULL; |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
123 } |
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 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
|
126 { |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
127 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
|
128 { |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
129 if (player->chips[i].data_type == data_type) { |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
130 return &player->chips[i]; |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
131 } |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
132 } |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
133 return NULL; |
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 static uint8_t read_byte(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 uint8_t *buffer = player->media->buffer; |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
139 return buffer[player->current_offset++]; |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
140 } |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
141 |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
142 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
|
143 { |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
144 uint8_t *buffer = player->media->buffer; |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
145 uint16_t value = buffer[player->current_offset++]; |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
146 value |= buffer[player->current_offset++] << 8; |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
147 return value; |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
148 } |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
149 |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
150 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
|
151 { |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
152 uint8_t *buffer = player->media->buffer; |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
153 uint32_t value = buffer[player->current_offset++]; |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
154 value |= buffer[player->current_offset++] << 8; |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
155 value |= buffer[player->current_offset++] << 16; |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
156 return value; |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
157 } |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
158 |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
159 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
|
160 { |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
161 uint8_t *buffer = player->media->buffer; |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
162 uint32_t value = buffer[player->current_offset++]; |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
163 value |= buffer[player->current_offset++] << 8; |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
164 value |= buffer[player->current_offset++] << 16; |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
165 value |= buffer[player->current_offset++] << 24; |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
166 return value; |
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 void vgm_frame(media_player *player) |
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 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
|
172 { |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
173 if (player->wait_samples) { |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
174 uint32_t to_wait = player->wait_samples; |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
175 if (to_wait > remaining_samples) { |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
176 to_wait = remaining_samples; |
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 vgm_wait(player, to_wait); |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
179 player->wait_samples -= to_wait; |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
180 remaining_samples -= to_wait; |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
181 if (player->wait_samples) { |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
182 return; |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
183 } |
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 if (player->current_offset >= player->media->size) { |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
186 vgm_stop(player); |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
187 return; |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
188 } |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
189 uint8_t cmd = read_byte(player); |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
190 psg_context *psg; |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
191 ym2612_context *ym; |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
192 rf5c164 *pcm; |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
193 switch (cmd) |
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 case CMD_PSG_STEREO: |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
196 psg = find_chip_context(player, CMD_PSG); |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
197 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
|
198 vgm_stop(player); |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
199 return; |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
200 } |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
201 psg->pan = read_byte(player); |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
202 break; |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
203 case CMD_PSG: |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
204 psg = find_chip_context(player, CMD_PSG); |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
205 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
|
206 vgm_stop(player); |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
207 return; |
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 psg_write(psg, read_byte(player)); |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
210 break; |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
211 case CMD_YM2612_0: |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
212 ym = find_chip_context(player, CMD_YM2612_0); |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
213 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
|
214 vgm_stop(player); |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
215 return; |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
216 } |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
217 ym_address_write_part1(ym, read_byte(player)); |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
218 ym_data_write(ym, read_byte(player)); |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
219 break; |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
220 case CMD_YM2612_1: |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
221 ym = find_chip_context(player, CMD_YM2612_0); |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
222 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
|
223 vgm_stop(player); |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
224 return; |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
225 } |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
226 ym_address_write_part2(ym, read_byte(player)); |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
227 ym_data_write(ym, read_byte(player)); |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
228 break; |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
229 case CMD_WAIT: { |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
230 if (player->current_offset > player->media->size - 2) { |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
231 vgm_stop(player); |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
232 return; |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
233 } |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
234 player->wait_samples += read_word_le(player); |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
235 break; |
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 case CMD_WAIT_60: |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
238 player->wait_samples += 735; |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
239 break; |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
240 case CMD_WAIT_50: |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
241 player->wait_samples += 882; |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
242 break; |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
243 case CMD_END: |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
244 //TODO: loops |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
245 vgm_stop(player); |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
246 return; |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
247 case CMD_PCM_WRITE: { |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
248 if (player->current_offset > player->media->size - 11) { |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
249 vgm_stop(player); |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
250 return; |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
251 } |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
252 player->current_offset++; //skip compatibility command |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
253 uint8_t data_type = read_byte(player); |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
254 uint32_t read_offset = read_24_le(player); |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
255 uint32_t write_offset = read_24_le(player); |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
256 uint16_t size = read_24_le(player); |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
257 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
|
258 if (!chip || !chip->blocks) { |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
259 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
|
260 break; |
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 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
|
263 if (!src) { |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
264 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
|
265 break; |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
266 } |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
267 switch (data_type) |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
268 { |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
269 case DATA_RF5C68: |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
270 case DATA_RF5C164: |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
271 pcm = chip->context; |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
272 write_offset |= pcm->ram_bank; |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
273 write_offset &= 0xFFFF; |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
274 if (size + write_offset > 0x10000) { |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
275 size = 0x10000 - write_offset; |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
276 } |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
277 memcpy(pcm->ram + write_offset, src, size); |
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 default: |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
280 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
|
281 } |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
282 break; |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
283 } |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
284 case CMD_PCM68_REG: |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
285 pcm = find_chip_context(player, CMD_PCM68_REG); |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
286 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
|
287 vgm_stop(player); |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
288 return; |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
289 } else { |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
290 uint8_t reg = read_byte(player); |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
291 uint8_t value = read_byte(player); |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
292 rf5c164_write(pcm, reg, value); |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
293 } |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
294 break; |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
295 case CMD_PCM164_REG: |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
296 pcm = find_chip_context(player, CMD_PCM164_REG); |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
297 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
|
298 vgm_stop(player); |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
299 return; |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
300 } else { |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
301 uint8_t reg = read_byte(player); |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
302 uint8_t value = read_byte(player); |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
303 rf5c164_write(pcm, reg, value); |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
304 } |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
305 break; |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
306 case CMD_PCM68_RAM: |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
307 pcm = find_chip_context(player, CMD_PCM68_REG); |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
308 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
|
309 vgm_stop(player); |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
310 return; |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
311 } else { |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
312 uint16_t address = read_word_le(player); |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
313 address &= 0xFFF; |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
314 address |= 0x1000; |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
315 rf5c164_write(pcm, address, read_byte(player)); |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
316 } |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
317 break; |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
318 case CMD_PCM164_RAM: |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
319 pcm = find_chip_context(player, CMD_PCM164_REG); |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
320 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
|
321 vgm_stop(player); |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
322 return; |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
323 } else { |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
324 uint16_t address = read_word_le(player); |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
325 address &= 0xFFF; |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
326 address |= 0x1000; |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
327 rf5c164_write(pcm, address, read_byte(player)); |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
328 } |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
329 break; |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
330 case CMD_DATA: |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
331 if (player->current_offset > player->media->size - 6) { |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
332 vgm_stop(player); |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
333 return; |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
334 } else { |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
335 player->current_offset++; //skip compat command |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
336 uint8_t data_type = read_byte(player); |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
337 uint32_t data_size = read_long_le(player); |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
338 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
|
339 vgm_stop(player); |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
340 return; |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
341 } |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
342 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
|
343 if (chip) { |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
344 data_block **cur = &(chip->blocks); |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
345 while (*cur) |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
346 { |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
347 cur = &((*cur)->next); |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
348 } |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
349 *cur = calloc(1, sizeof(data_block)); |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
350 (*cur)->size = data_size; |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
351 (*cur)->type = data_type; |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
352 (*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
|
353 } else { |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
354 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
|
355 } |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
356 player->current_offset += data_size; |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
357 } |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
358 break; |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
359 case CMD_DATA_SEEK: |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
360 if (player->current_offset > player->media->size - 4) { |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
361 vgm_stop(player); |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
362 return; |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
363 } else { |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
364 uint32_t new_offset = read_long_le(player); |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
365 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
|
366 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
|
367 if (!chip) { |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
368 break; |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
369 } |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
370 player->ym_seek_block = chip->blocks; |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
371 player->ym_seek_offset = 0; |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
372 player->ym_block_offset = 0; |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
373 } |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
374 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
|
375 { |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
376 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
|
377 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
|
378 player->ym_block_offset = 0; |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
379 } |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
380 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
|
381 player->ym_seek_offset = new_offset; |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
382 } |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
383 break; |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
384 default: |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
385 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
|
386 uint32_t wait_time = (cmd & 0xF) + 1; |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
387 player->wait_samples += wait_time; |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
388 } 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
|
389 if (player->ym_seek_block) { |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
390 ym = find_chip_context(player, CMD_YM2612_0); |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
391 ym_address_write_part1(ym, 0x2A); |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
392 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
|
393 player->ym_seek_offset++; |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
394 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
|
395 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
|
396 player->ym_block_offset = 0; |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
397 } |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
398 } else { |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
399 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
|
400 } |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
401 player->wait_samples += cmd & 0xF; |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
402 } else { |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
403 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
|
404 vgm_stop(player); |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
405 return; |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
406 } |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
407 } |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
408 } |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
409 } |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
410 |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
411 void wave_frame(media_player *player) |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
412 { |
2290
c4980d89614b
Support WAVE files in media player
Michael Pavone <pavone@retrodev.com>
parents:
2289
diff
changeset
|
413 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
|
414 { |
c4980d89614b
Support WAVE files in media player
Michael Pavone <pavone@retrodev.com>
parents:
2289
diff
changeset
|
415 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
|
416 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
|
417 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
|
418 player->state = STATE_PAUSED; |
c4980d89614b
Support WAVE files in media player
Michael Pavone <pavone@retrodev.com>
parents:
2289
diff
changeset
|
419 return; |
c4980d89614b
Support WAVE files in media player
Michael Pavone <pavone@retrodev.com>
parents:
2289
diff
changeset
|
420 } |
c4980d89614b
Support WAVE files in media player
Michael Pavone <pavone@retrodev.com>
parents:
2289
diff
changeset
|
421 if (player->wave->bits_per_sample == 16) { |
c4980d89614b
Support WAVE files in media player
Michael Pavone <pavone@retrodev.com>
parents:
2289
diff
changeset
|
422 int16_t value = read_word_le(player); |
c4980d89614b
Support WAVE files in media player
Michael Pavone <pavone@retrodev.com>
parents:
2289
diff
changeset
|
423 if (player->wave->num_channels == 1) { |
c4980d89614b
Support WAVE files in media player
Michael Pavone <pavone@retrodev.com>
parents:
2289
diff
changeset
|
424 render_put_mono_sample(player->audio, value); |
c4980d89614b
Support WAVE files in media player
Michael Pavone <pavone@retrodev.com>
parents:
2289
diff
changeset
|
425 } else { |
c4980d89614b
Support WAVE files in media player
Michael Pavone <pavone@retrodev.com>
parents:
2289
diff
changeset
|
426 int16_t right = read_word_le(player); |
c4980d89614b
Support WAVE files in media player
Michael Pavone <pavone@retrodev.com>
parents:
2289
diff
changeset
|
427 render_put_stereo_sample(player->audio, value, right); |
c4980d89614b
Support WAVE files in media player
Michael Pavone <pavone@retrodev.com>
parents:
2289
diff
changeset
|
428 } |
c4980d89614b
Support WAVE files in media player
Michael Pavone <pavone@retrodev.com>
parents:
2289
diff
changeset
|
429 } else { |
c4980d89614b
Support WAVE files in media player
Michael Pavone <pavone@retrodev.com>
parents:
2289
diff
changeset
|
430 uint8_t sample = read_byte(player); |
c4980d89614b
Support WAVE files in media player
Michael Pavone <pavone@retrodev.com>
parents:
2289
diff
changeset
|
431 int16_t value = sample * 257 - 128 * 257; |
c4980d89614b
Support WAVE files in media player
Michael Pavone <pavone@retrodev.com>
parents:
2289
diff
changeset
|
432 if (player->wave->num_channels == 1) { |
c4980d89614b
Support WAVE files in media player
Michael Pavone <pavone@retrodev.com>
parents:
2289
diff
changeset
|
433 render_put_mono_sample(player->audio, value); |
c4980d89614b
Support WAVE files in media player
Michael Pavone <pavone@retrodev.com>
parents:
2289
diff
changeset
|
434 } else { |
c4980d89614b
Support WAVE files in media player
Michael Pavone <pavone@retrodev.com>
parents:
2289
diff
changeset
|
435 sample = read_byte(player); |
c4980d89614b
Support WAVE files in media player
Michael Pavone <pavone@retrodev.com>
parents:
2289
diff
changeset
|
436 int16_t right = sample * 257 - 128 * 257; |
c4980d89614b
Support WAVE files in media player
Michael Pavone <pavone@retrodev.com>
parents:
2289
diff
changeset
|
437 render_put_stereo_sample(player->audio, value, right); |
c4980d89614b
Support WAVE files in media player
Michael Pavone <pavone@retrodev.com>
parents:
2289
diff
changeset
|
438 } |
c4980d89614b
Support WAVE files in media player
Michael Pavone <pavone@retrodev.com>
parents:
2289
diff
changeset
|
439 } |
c4980d89614b
Support WAVE files in media player
Michael Pavone <pavone@retrodev.com>
parents:
2289
diff
changeset
|
440 |
c4980d89614b
Support WAVE files in media player
Michael Pavone <pavone@retrodev.com>
parents:
2289
diff
changeset
|
441 } |
2289
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
442 } |
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 void flac_frame(media_player *player) |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
445 { |
2296
789802d99629
Add basic FLAC decoder and add FLAC playback support to the media player
Michael Pavone <pavone@retrodev.com>
parents:
2290
diff
changeset
|
446 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
|
447 { |
789802d99629
Add basic FLAC decoder and add FLAC playback support to the media player
Michael Pavone <pavone@retrodev.com>
parents:
2290
diff
changeset
|
448 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
|
449 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
|
450 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
|
451 } else { |
789802d99629
Add basic FLAC decoder and add FLAC playback support to the media player
Michael Pavone <pavone@retrodev.com>
parents:
2290
diff
changeset
|
452 player->state = STATE_PAUSED; |
789802d99629
Add basic FLAC decoder and add FLAC playback support to the media player
Michael Pavone <pavone@retrodev.com>
parents:
2290
diff
changeset
|
453 return; |
789802d99629
Add basic FLAC decoder and add FLAC playback support to the media player
Michael Pavone <pavone@retrodev.com>
parents:
2290
diff
changeset
|
454 } |
789802d99629
Add basic FLAC decoder and add FLAC playback support to the media player
Michael Pavone <pavone@retrodev.com>
parents:
2290
diff
changeset
|
455 } |
2289
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
456 } |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
457 |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
458 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
|
459 { |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
460 player->vgm = calloc(1, sizeof(vgm_header)); |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
461 player->vgm_ext = NULL; |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
462 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
|
463 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
|
464 player->vgm->data_offset = 0xC; |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
465 } |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
466 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
|
467 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
|
468 } |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
469 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
|
470 player->vgm->ym2612_clk = player->vgm->ym2413_clk; |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
471 player->vgm->ym2413_clk = 0; |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
472 } |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
473 if (player->vgm->data_offset > 0xC) { |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
474 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
|
475 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
|
476 if (additional_header > sizeof(vgm_extended_header)) { |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
477 additional_header = sizeof(vgm_extended_header); |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
478 } |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
479 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
|
480 } |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
481 player->num_chips = 0; |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
482 if (player->vgm->sn76489_clk) { |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
483 player->num_chips++; |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
484 } |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
485 if (player->vgm->ym2612_clk) { |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
486 player->num_chips++; |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
487 } |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
488 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
|
489 player->num_chips++; |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
490 } |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
491 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
|
492 player->num_chips++; |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
493 } |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
494 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
|
495 uint32_t chip = 0; |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
496 if (player->vgm->sn76489_clk) { |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
497 psg_context *psg = calloc(1, sizeof(psg_context)); |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
498 psg_init(psg, player->vgm->sn76489_clk, 1); |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
499 player->chips[chip++] = (chip_info) { |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
500 .context = psg, |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
501 .run = (chip_run_fun)psg_run, |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
502 .adjust = psg_adjust, |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
503 .clock = player->vgm->sn76489_clk, |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
504 .samples = 0, |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
505 .cmd = CMD_PSG, |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
506 .data_type = 0xFF |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
507 }; |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
508 } |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
509 if (player->vgm->ym2612_clk) { |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
510 ym2612_context *ym = calloc(1, sizeof(ym2612_context)); |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
511 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
|
512 player->chips[chip++] = (chip_info) { |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
513 .context = ym, |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
514 .run = (chip_run_fun)ym_run, |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
515 .adjust = ym_adjust, |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
516 .clock = player->vgm->ym2612_clk, |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
517 .samples = 0, |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
518 .cmd = CMD_YM2612_0, |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
519 .data_type = DATA_YM2612_PCM |
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 } |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
522 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
|
523 rf5c164 *pcm = calloc(1, sizeof(rf5c164)); |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
524 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
|
525 player->chips[chip++] = (chip_info) { |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
526 .context = pcm, |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
527 .run = (chip_run_fun)rf5c164_run, |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
528 .adjust = pcm_adjust, |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
529 .clock = player->vgm_ext->rf5c68_clk, |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
530 .samples = 0, |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
531 .cmd = CMD_PCM68_REG, |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
532 .data_type = DATA_RF5C68 |
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 } |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
535 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
|
536 rf5c164 *pcm = calloc(1, sizeof(rf5c164)); |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
537 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
|
538 player->chips[chip++] = (chip_info) { |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
539 .context = pcm, |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
540 .run = (chip_run_fun)rf5c164_run, |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
541 .adjust = pcm_adjust, |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
542 .clock = player->vgm_ext->rf5c164_clk, |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
543 .samples = 0, |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
544 .cmd = CMD_PCM164_REG, |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
545 .data_type = DATA_RF5C164 |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
546 }; |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
547 } |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
548 player->current_offset = player->vgm->data_offset + offsetof(vgm_header, data_offset); |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
549 } |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
550 |
2290
c4980d89614b
Support WAVE files in media player
Michael Pavone <pavone@retrodev.com>
parents:
2289
diff
changeset
|
551 static void wave_player_init(media_player *player) |
c4980d89614b
Support WAVE files in media player
Michael Pavone <pavone@retrodev.com>
parents:
2289
diff
changeset
|
552 { |
c4980d89614b
Support WAVE files in media player
Michael Pavone <pavone@retrodev.com>
parents:
2289
diff
changeset
|
553 player->wave = calloc(1, sizeof(wave_header)); |
c4980d89614b
Support WAVE files in media player
Michael Pavone <pavone@retrodev.com>
parents:
2289
diff
changeset
|
554 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
|
555 if (memcmp(player->wave->chunk.format, "WAVE", 4)) { |
c4980d89614b
Support WAVE files in media player
Michael Pavone <pavone@retrodev.com>
parents:
2289
diff
changeset
|
556 goto format_error; |
c4980d89614b
Support WAVE files in media player
Michael Pavone <pavone@retrodev.com>
parents:
2289
diff
changeset
|
557 } |
c4980d89614b
Support WAVE files in media player
Michael Pavone <pavone@retrodev.com>
parents:
2289
diff
changeset
|
558 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
|
559 goto format_error; |
c4980d89614b
Support WAVE files in media player
Michael Pavone <pavone@retrodev.com>
parents:
2289
diff
changeset
|
560 } |
c4980d89614b
Support WAVE files in media player
Michael Pavone <pavone@retrodev.com>
parents:
2289
diff
changeset
|
561 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
|
562 goto format_error; |
c4980d89614b
Support WAVE files in media player
Michael Pavone <pavone@retrodev.com>
parents:
2289
diff
changeset
|
563 } |
c4980d89614b
Support WAVE files in media player
Michael Pavone <pavone@retrodev.com>
parents:
2289
diff
changeset
|
564 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
|
565 goto format_error; |
c4980d89614b
Support WAVE files in media player
Michael Pavone <pavone@retrodev.com>
parents:
2289
diff
changeset
|
566 } |
c4980d89614b
Support WAVE files in media player
Michael Pavone <pavone@retrodev.com>
parents:
2289
diff
changeset
|
567 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
|
568 goto format_error; |
c4980d89614b
Support WAVE files in media player
Michael Pavone <pavone@retrodev.com>
parents:
2289
diff
changeset
|
569 } |
c4980d89614b
Support WAVE files in media player
Michael Pavone <pavone@retrodev.com>
parents:
2289
diff
changeset
|
570 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
|
571 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
|
572 goto format_error; |
c4980d89614b
Support WAVE files in media player
Michael Pavone <pavone@retrodev.com>
parents:
2289
diff
changeset
|
573 } |
c4980d89614b
Support WAVE files in media player
Michael Pavone <pavone@retrodev.com>
parents:
2289
diff
changeset
|
574 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
|
575 player->current_offset = data_sub_chunk; |
c4980d89614b
Support WAVE files in media player
Michael Pavone <pavone@retrodev.com>
parents:
2289
diff
changeset
|
576 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
|
577 return; |
c4980d89614b
Support WAVE files in media player
Michael Pavone <pavone@retrodev.com>
parents:
2289
diff
changeset
|
578 format_error: |
c4980d89614b
Support WAVE files in media player
Michael Pavone <pavone@retrodev.com>
parents:
2289
diff
changeset
|
579 player->media_type = MEDIA_UNKNOWN; |
c4980d89614b
Support WAVE files in media player
Michael Pavone <pavone@retrodev.com>
parents:
2289
diff
changeset
|
580 free(player->wave); |
c4980d89614b
Support WAVE files in media player
Michael Pavone <pavone@retrodev.com>
parents:
2289
diff
changeset
|
581 } |
c4980d89614b
Support WAVE files in media player
Michael Pavone <pavone@retrodev.com>
parents:
2289
diff
changeset
|
582 |
2296
789802d99629
Add basic FLAC decoder and add FLAC playback support to the media player
Michael Pavone <pavone@retrodev.com>
parents:
2290
diff
changeset
|
583 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
|
584 { |
789802d99629
Add basic FLAC decoder and add FLAC playback support to the media player
Michael Pavone <pavone@retrodev.com>
parents:
2290
diff
changeset
|
585 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
|
586 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
|
587 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
|
588 } |
789802d99629
Add basic FLAC decoder and add FLAC playback support to the media player
Michael Pavone <pavone@retrodev.com>
parents:
2290
diff
changeset
|
589 } |
789802d99629
Add basic FLAC decoder and add FLAC playback support to the media player
Michael Pavone <pavone@retrodev.com>
parents:
2290
diff
changeset
|
590 |
2289
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
591 static void resume_player(system_header *system) |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
592 { |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
593 media_player *player = (media_player *)system; |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
594 player->should_return = 0; |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
595 while (!player->header.should_exit && !player->should_return) |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
596 { |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
597 switch (player->state) |
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 case STATE_PLAY: |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
600 switch(player->media_type) |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
601 { |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
602 case AUDIO_VGM: |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
603 vgm_frame(player); |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
604 break; |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
605 case AUDIO_WAVE: |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
606 wave_frame(player); |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
607 break; |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
608 case AUDIO_FLAC: |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
609 flac_frame(player); |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
610 break; |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
611 } |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
612 break; |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
613 case STATE_PAUSED: |
2302
0343f0d5add0
Fix libretro build for real
Michael Pavone <pavone@retrodev.com>
parents:
2296
diff
changeset
|
614 #ifndef IS_LIB |
2289
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
615 render_sleep_ms(15); |
2302
0343f0d5add0
Fix libretro build for real
Michael Pavone <pavone@retrodev.com>
parents:
2296
diff
changeset
|
616 #endif |
2289
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
617 break; |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
618 } |
2302
0343f0d5add0
Fix libretro build for real
Michael Pavone <pavone@retrodev.com>
parents:
2296
diff
changeset
|
619 //TODO: Fix this for libretro build properly |
0343f0d5add0
Fix libretro build for real
Michael Pavone <pavone@retrodev.com>
parents:
2296
diff
changeset
|
620 #ifndef IS_LIB |
2289
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
621 render_update_display(); |
2302
0343f0d5add0
Fix libretro build for real
Michael Pavone <pavone@retrodev.com>
parents:
2296
diff
changeset
|
622 #endif |
2289
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
623 } |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
624 } |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
625 |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
626 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
|
627 { |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
628 if (button >= BUTTON_A && button <= BUTTON_C) { |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
629 media_player *player = (media_player *)system; |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
630 if (player->state == STATE_PAUSED) { |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
631 player->state = STATE_PLAY; |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
632 puts("Now playing"); |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
633 } else { |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
634 player->state = STATE_PAUSED; |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
635 puts("Now paused"); |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
636 } |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
637 } |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
638 } |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
639 |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
640 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
|
641 { |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
642 } |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
643 |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
644 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
|
645 { |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
646 resume_player(system); |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
647 } |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
648 |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
649 static void free_player(system_header *system) |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
650 { |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
651 media_player *player = (media_player *)system; |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
652 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
|
653 { |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
654 //TODO properly free chips |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
655 free(player->chips[i].context); |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
656 } |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
657 free(player->chips); |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
658 free(player->vgm); |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
659 free(player); |
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 |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
662 uint8_t detect_media_type(system_media *media) |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
663 { |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
664 if (media->size < 4) { |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
665 return MEDIA_UNKNOWN; |
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 if (!memcmp(media->buffer, "Vgm ", 4)) { |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
668 if (media->size < sizeof(vgm_header)) { |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
669 return MEDIA_UNKNOWN; |
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 return AUDIO_VGM; |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
672 } |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
673 if (!memcmp(media->buffer, "RIFF", 4)) { |
2290
c4980d89614b
Support WAVE files in media player
Michael Pavone <pavone@retrodev.com>
parents:
2289
diff
changeset
|
674 if (media->size < sizeof(wave_header)) { |
c4980d89614b
Support WAVE files in media player
Michael Pavone <pavone@retrodev.com>
parents:
2289
diff
changeset
|
675 return MEDIA_UNKNOWN; |
c4980d89614b
Support WAVE files in media player
Michael Pavone <pavone@retrodev.com>
parents:
2289
diff
changeset
|
676 } |
2289
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
677 return AUDIO_WAVE; |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
678 } |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
679 if (!memcmp(media->buffer, "fLaC", 4)) { |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
680 return AUDIO_FLAC; |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
681 } |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
682 return MEDIA_UNKNOWN; |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
683 } |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
684 |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
685 static void request_exit(system_header *system) |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
686 { |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
687 media_player *player = (media_player *)system; |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
688 player->should_return = 1; |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
689 } |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
690 |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
691 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
|
692 { |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
693 media_player *player = calloc(1, sizeof(media_player)); |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
694 player->header.start_context = start_player; |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
695 player->header.resume_context = resume_player; |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
696 player->header.request_exit = request_exit; |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
697 player->header.free_context = free_player; |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
698 player->header.gamepad_down = gamepad_down; |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
699 player->header.gamepad_up = gamepad_down; |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
700 player->header.type = SYSTEM_MEDIA_PLAYER; |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
701 player->header.info.name = strdup(media->name); |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
702 |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
703 player->media = media; |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
704 player->media_type = detect_media_type(media); |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
705 player->state = STATE_PLAY; |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
706 switch (player->media_type) |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
707 { |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
708 case AUDIO_VGM: |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
709 vgm_init(player, opts); |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
710 break; |
2290
c4980d89614b
Support WAVE files in media player
Michael Pavone <pavone@retrodev.com>
parents:
2289
diff
changeset
|
711 case AUDIO_WAVE: |
c4980d89614b
Support WAVE files in media player
Michael Pavone <pavone@retrodev.com>
parents:
2289
diff
changeset
|
712 wave_player_init(player); |
c4980d89614b
Support WAVE files in media player
Michael Pavone <pavone@retrodev.com>
parents:
2289
diff
changeset
|
713 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
|
714 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
|
715 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
|
716 break; |
2289
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
717 } |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
718 |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
719 return player; |
92449b47cce8
Integrate VGM player into main blastem binary
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
720 } |