Debian Codegraph @

android/app/jni/extern/vgsound_emu-modified/vgsound_emu/src/es550x/es550x_alu.cpp

raw
1 /*
2 License: Zlib
3 see https://gitlab.com/cam900/vgsound_emu/-/blob/main/LICENSE for more details
4
5 Copyright holder(s): cam900
6 Ensoniq ES5504/ES5505/ES5506 Shared Accumulator emulation core
7 */
8
9 #include "es550x.hpp"
10
11 // Accumulator functions
12 void es550x_shared_core::es550x_voice_t::es550x_alu_t::reset()
13 {
14 m_cr.reset();
15 m_fc = 0;
16 m_start = 0;
17 m_end = 0;
18 m_accum = 0;
19 m_last_accum=0;
20 m_sample[0] = m_sample[1] = 0;
21 }
22
23 bool es550x_shared_core::es550x_voice_t::es550x_alu_t::busy() { return !(m_cr.m_stop0 || m_cr.m_stop1); }
24
25 bool es550x_shared_core::es550x_voice_t::es550x_alu_t::tick()
26 {
27 m_last_accum = m_accum;
28 if (m_cr.dir())
29 {
30 m_accum -= m_fc;
31 }
32 else
33 {
34 m_accum += m_fc;
35 }
36
37 m_accum &= m_accum_mask;
38 return ((!m_cr.m_lei) &&
39 (((m_cr.m_dir) && (m_accum < m_start)) || ((!m_cr.m_dir) && (m_accum > m_end))))
40 ? true
41 : false;
42 }
43
44 void es550x_shared_core::es550x_voice_t::es550x_alu_t::loop_exec()
45 {
46 if (m_cr.m_dir) // Reverse playback
47 {
48 if (m_cr.m_lpe) // Loop enable
49 {
50 if (m_cr.m_ble) // Bidirectional
51 {
52 m_cr.set_dir(false);
53 m_accum = m_start + (m_start - m_accum);
54 }
55 else
56 { // Normal
57 m_accum = m_end - (m_start - m_accum);
58 }
59 }
60 else if (m_cr.m_ble && m_transwave) // m_transwave
61 {
62 m_cr.set_loop(0);
63 m_cr.set_lei(true); // Loop end ignore
64 m_accum = m_end - (m_start - m_accum);
65 }
66 else
67 { // Stop
68 m_cr.set_stop0(true);
69 }
70 }
71 else
72 {
73 if (m_cr.m_lpe) // Loop enable
74 {
75 if (m_cr.m_ble) // Bidirectional
76 {
77 m_cr.set_dir(true);
78 m_accum = m_end - (m_end - m_accum);
79 }
80 else
81 { // Normal
82 m_accum = (m_accum - m_end) + m_start;
83 }
84 }
85 else if (m_cr.m_ble && m_transwave) // m_transwave
86 {
87 m_cr.set_loop(0);
88 m_cr.set_lei(true); // Loop end ignore
89 m_accum = (m_accum - m_end) + m_start;
90 }
91 else
92 { // Stop
93 m_cr.set_stop0(true);
94 }
95 }
96 }
97
98 s32 es550x_shared_core::es550x_voice_t::es550x_alu_t::interpolation()
99 {
100 // SF = S1 + ACCfr * (S2 - S1)
101 return m_sample[0] + (((((int)m_accum>>(int)2)&(int)511) *
102 (m_sample[1] - m_sample[0])) >>
103 9);
104 }
105
106 u32 es550x_shared_core::es550x_voice_t::es550x_alu_t::get_accum_integer()
107 {
108 return (m_accum>>m_fraction)&((1<<m_integer)-1);
109 }
110
111 void es550x_shared_core::es550x_voice_t::es550x_alu_t::irq_exec(es550x_intf &intf,
112 es550x_irq_t &irqv,
113 u8 index)
114 {
115 const bool prev = irqv.irqb();
116 if (m_cr.irq())
117 {
118 if (irqv.irqb())
119 {
120 irqv.set(index);
121 m_cr.set_irq(false);
122 }
123 }
124 if (prev != irqv.irqb())
125 {
126 irq_update(intf, irqv);
127 }
128 }