Mercurial > repos > blastem
annotate cdd_fader.c @ 2136:01fcbcba5cf8
Fix regresion on mcd-verificator CDC flags test
author | Michael Pavone <pavone@retrodev.com> |
---|---|
date | Sat, 19 Mar 2022 00:14:07 -0700 |
parents | cfd53c94fffb |
children | 4fbe1e7c4a73 |
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 } | |
11 void cdd_fader_attenuation_write(cdd_fader *fader, uint16_t attenuation) | |
12 { | |
13 fader->dst_attenuation = attenuation & 0xFFF0; | |
14 fader->flags = attenuation & 0xE; | |
15 if (fader->dst_attenuation > fader->cur_attenuation) { | |
16 fader->attenuation_step = (fader->dst_attenuation - fader->cur_attenuation) >> 4; | |
17 } else if (fader->dst_attenuation < fader->cur_attenuation) { | |
18 fader->attenuation_step = (fader->cur_attenuation - fader->dst_attenuation) >> 4; | |
19 } else { | |
20 fader->attenuation_step = 0; | |
21 } | |
22 } | |
23 | |
24 void cdd_fader_data(cdd_fader *fader, uint8_t byte) | |
25 { | |
26 fader->bytes[fader->byte_counter++] = byte; | |
27 if (fader->byte_counter == sizeof(fader->bytes)) { | |
28 fader->byte_counter = 0; | |
29 int32_t left = (fader->bytes[1] << 8) | fader->bytes[0]; | |
30 int32_t right = (fader->bytes[3] << 8) | fader->bytes[2]; | |
31 if (left & 0x8000) { | |
32 left |= 0xFFFF0000; | |
33 } | |
34 if (right & 0x8000) { | |
35 right |= 0xFFFF0000; | |
36 } | |
37 if (!fader->cur_attenuation) { | |
38 left = right = 0; | |
39 } else if (fader->cur_attenuation >= 4) { | |
40 left *= fader->cur_attenuation & 0x7FF0; | |
41 right *= fader->cur_attenuation & 0x7FF0; | |
42 left >>= 14; | |
43 right >>= 14; | |
44 } else { | |
45 //TODO: FIXME | |
46 left = right = 0; | |
47 } | |
48 render_put_stereo_sample(fader->audio, left, right); | |
49 if (fader->attenuation_step) { | |
50 if (fader->dst_attenuation > fader->cur_attenuation) { | |
51 fader->cur_attenuation += fader->attenuation_step; | |
52 if (fader->cur_attenuation >= fader->dst_attenuation) { | |
53 fader->cur_attenuation = fader->dst_attenuation; | |
54 fader->attenuation_step = 0; | |
55 } | |
56 } else { | |
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 } | |
63 } | |
64 } | |
65 } |