Mercurial > repos > blastem
annotate cdd_fader.c @ 2208:3809a0bd680e
Fix a couple of Z80 debugger issues
author | Michael Pavone <pavone@retrodev.com> |
---|---|
date | Sat, 27 Aug 2022 22:02:09 -0700 |
parents | 4fbe1e7c4a73 |
children | 5a21bc0ec583 |
rev | line source |
---|---|
2080 | 1 #include "cdd_fader.h" |
2 #include <stdio.h> | |
3 | |
4 void cdd_fader_init(cdd_fader *fader) | |
5 { | |
2081
cfd53c94fffb
Initial stab at RF5C164 emulation
Michael Pavone <pavone@retrodev.com>
parents:
2080
diff
changeset
|
6 fader->audio = render_audio_source("CDDA", 16934400, 384, 2); |
2080 | 7 fader->cur_attenuation = 0x4000; |
8 fader->dst_attenuation = 0x4000; | |
9 fader->attenuation_step = 0; | |
10 } | |
2164
4fbe1e7c4a73
Don't leak all Sega CD resources when freeing a Genesis instance
Michael Pavone <pavone@retrodev.com>
parents:
2081
diff
changeset
|
11 |
4fbe1e7c4a73
Don't leak all Sega CD resources when freeing a Genesis instance
Michael Pavone <pavone@retrodev.com>
parents:
2081
diff
changeset
|
12 void cdd_fader_deinit(cdd_fader *fader) |
4fbe1e7c4a73
Don't leak all Sega CD resources when freeing a Genesis instance
Michael Pavone <pavone@retrodev.com>
parents:
2081
diff
changeset
|
13 { |
4fbe1e7c4a73
Don't leak all Sega CD resources when freeing a Genesis instance
Michael Pavone <pavone@retrodev.com>
parents:
2081
diff
changeset
|
14 render_free_source(fader->audio); |
4fbe1e7c4a73
Don't leak all Sega CD resources when freeing a Genesis instance
Michael Pavone <pavone@retrodev.com>
parents:
2081
diff
changeset
|
15 } |
4fbe1e7c4a73
Don't leak all Sega CD resources when freeing a Genesis instance
Michael Pavone <pavone@retrodev.com>
parents:
2081
diff
changeset
|
16 |
2080 | 17 void cdd_fader_attenuation_write(cdd_fader *fader, uint16_t attenuation) |
18 { | |
19 fader->dst_attenuation = attenuation & 0xFFF0; | |
20 fader->flags = attenuation & 0xE; | |
21 if (fader->dst_attenuation > fader->cur_attenuation) { | |
22 fader->attenuation_step = (fader->dst_attenuation - fader->cur_attenuation) >> 4; | |
23 } else if (fader->dst_attenuation < fader->cur_attenuation) { | |
24 fader->attenuation_step = (fader->cur_attenuation - fader->dst_attenuation) >> 4; | |
25 } else { | |
26 fader->attenuation_step = 0; | |
27 } | |
28 } | |
29 | |
30 void cdd_fader_data(cdd_fader *fader, uint8_t byte) | |
31 { | |
32 fader->bytes[fader->byte_counter++] = byte; | |
33 if (fader->byte_counter == sizeof(fader->bytes)) { | |
34 fader->byte_counter = 0; | |
35 int32_t left = (fader->bytes[1] << 8) | fader->bytes[0]; | |
36 int32_t right = (fader->bytes[3] << 8) | fader->bytes[2]; | |
37 if (left & 0x8000) { | |
38 left |= 0xFFFF0000; | |
39 } | |
40 if (right & 0x8000) { | |
41 right |= 0xFFFF0000; | |
42 } | |
43 if (!fader->cur_attenuation) { | |
44 left = right = 0; | |
45 } else if (fader->cur_attenuation >= 4) { | |
46 left *= fader->cur_attenuation & 0x7FF0; | |
47 right *= fader->cur_attenuation & 0x7FF0; | |
48 left >>= 14; | |
49 right >>= 14; | |
50 } else { | |
51 //TODO: FIXME | |
52 left = right = 0; | |
53 } | |
54 render_put_stereo_sample(fader->audio, left, right); | |
55 if (fader->attenuation_step) { | |
56 if (fader->dst_attenuation > fader->cur_attenuation) { | |
57 fader->cur_attenuation += fader->attenuation_step; | |
58 if (fader->cur_attenuation >= fader->dst_attenuation) { | |
59 fader->cur_attenuation = fader->dst_attenuation; | |
60 fader->attenuation_step = 0; | |
61 } | |
62 } else { | |
63 fader->cur_attenuation -= fader->attenuation_step; | |
64 if (fader->cur_attenuation <= fader->dst_attenuation) { | |
65 fader->cur_attenuation = fader->dst_attenuation; | |
66 fader->attenuation_step = 0; | |
67 } | |
68 } | |
69 } | |
70 } | |
71 } |