PS2SDK
PS2 Homebrew Libraries
Loading...
Searching...
No Matches
vm_autop.c
1/*
2# _____ ___ ____ ___ ____
3# ____| | ____| | | |____|
4# | ___| |____ ___| ____| | \ PS2DEV Open Source Project.
5#-----------------------------------------------------------------------
6# Copyright ps2dev - http://www.ps2dev.org
7# Licenced under Academic Free License version 2.0
8# Review ps2sdk README & LICENSE files for further details.
9*/
10
11#include "libsnd2_internal.h"
12
13void SeAutoPan(s16 vc, s16 start_pan, s16 end_pan, s16 delta_time)
14{
15 libsnd2_spu_voice_t *voice_struct;
16
17 voice_struct = &_svm_voice[vc];
18 if ( start_pan == end_pan )
19 return;
20 voice_struct->m_b_auto_pan = 1;
21 voice_struct->m_auto_pan_start = start_pan;
22 voice_struct->m_auto_pan_end = end_pan;
23 if (
24 ((start_pan - end_pan >= 0) && (start_pan - end_pan < delta_time))
25 || ((start_pan - end_pan < 0) && (end_pan - start_pan < delta_time)) )
26 {
27 int v8;
28
29 if ( end_pan >= start_pan )
30 {
31 int v12;
32 int v13;
33
34 v12 = delta_time;
35 v13 = start_pan - end_pan;
36 if ( v13 == -1 && (unsigned int)v12 == 0x80000000 )
37 __builtin_trap();
38 voice_struct->m_auto_pan_amount = 1;
39 v8 = -(v12 / v13);
40 }
41 else
42 {
43 int v9;
44
45 v8 = delta_time;
46 v9 = start_pan - end_pan;
47 if ( v9 == -1 && (unsigned int)v8 == 0x80000000 )
48 __builtin_trap();
49 v8 = v8 / v9;
50 voice_struct->m_auto_pan_amount = -1;
51 }
52 voice_struct->m_auto_pan_dt1 = v8;
53 voice_struct->m_auto_pan_dt2 = v8;
54 }
55 else
56 {
57 int v14;
58
59 v14 = start_pan - end_pan;
60 if ( !delta_time )
61 __builtin_trap();
62 if ( delta_time == -1 && (unsigned int)v14 == 0x80000000 )
63 __builtin_trap();
64 voice_struct->m_auto_pan_dt1 = 0;
65 voice_struct->m_auto_pan_dt2 = 0;
66 voice_struct->m_auto_pan_amount = -(s16)(v14 / delta_time);
67 }
68}
69
70void SetAutoPan(int vc)
71{
72 int m_auto_pan_dt2;
73 int v5;
74 int m_auto_pan_amount;
75 char m_auto_pan_start;
76 const VagAtr *pVag;
77 int pan;
78 unsigned int v15;
79 unsigned int v16;
80 unsigned int v18;
81 unsigned int v19;
82 int mpan;
83 libsnd2_spu_voice_t *voice_struct;
84
85 voice_struct = &_svm_voice[(s16)vc];
86 m_auto_pan_dt2 = (u16)voice_struct->m_auto_pan_dt2;
87 voice_struct->m_auto_pan_dt2 = m_auto_pan_dt2 - 1;
88 if ( m_auto_pan_dt2 > 0 )
89 return;
90 v5 = (u16)voice_struct->m_auto_pan_start + (u16)voice_struct->m_auto_pan_amount;
91 voice_struct->m_auto_pan_start = v5;
92 m_auto_pan_amount = voice_struct->m_auto_pan_amount;
93 if ( m_auto_pan_amount <= 0 )
94 {
95 if ( m_auto_pan_amount < 0 && (s16)v5 <= voice_struct->m_auto_pan_end )
96 {
97 voice_struct->m_auto_pan_start = voice_struct->m_auto_pan_end;
98 voice_struct->m_b_auto_pan = 0;
99 }
100 }
101 else if ( (s16)v5 >= voice_struct->m_auto_pan_end )
102 {
103 voice_struct->m_auto_pan_start = voice_struct->m_auto_pan_end;
104 voice_struct->m_b_auto_pan = 0;
105 }
106 m_auto_pan_start = voice_struct->m_auto_pan_start;
107 if ( _svm_cur.m_voice_idx == (s16)vc )
108 _svm_cur.m_unk05 = voice_struct->m_auto_pan_start;
109 pVag = &_svm_tn[(u16)voice_struct->m_tone + (voice_struct->m_fake_program * 16)];
110 pan = (char)pVag->pan;
111 v15 = voice_struct->m_voll2 * 0x3FFF * _svm_vh->mvol / 0x3F01 * _svm_pg[voice_struct->m_prog].mvol * pVag->vol;
112 v16 = v15 / 0x3F01;
113 if ( pan >= 64 )
114 {
115 v19 = v15 / 0x3F01;
116 v18 = (v16 * (127 - pan)) >> 6;
117 }
118 else
119 {
120 unsigned int v17;
121
122 v17 = v16 * pan;
123 v18 = v15 / 0x3F01;
124 v19 = v17 >> 6;
125 }
126 mpan = (char)_svm_pg[voice_struct->m_prog].mpan;
127 if ( mpan >= 64 )
128 {
129 int v22;
130
131 v22 = (u16)v18 * (127 - mpan);
132 v18 = (unsigned int)v22 >> 6;
133 if ( v22 < 0 )
134 v18 = (unsigned int)(v22 + 63) >> 6;
135 }
136 else
137 {
138 int v21;
139
140 v21 = (u16)v19 * mpan;
141 v19 = (unsigned int)v21 >> 6;
142 if ( v21 < 0 )
143 v19 = (unsigned int)(v21 + 63) >> 6;
144 }
145 if ( m_auto_pan_start >= 64 )
146 {
147 int v24;
148
149 v24 = (u16)v18 * (127 - m_auto_pan_start);
150 v18 = (unsigned int)v24 >> 6;
151 if ( v24 < 0 )
152 v18 = (unsigned int)(v24 + 63) >> 6;
153 }
154 else
155 {
156 int v23;
157
158 v23 = (u16)v19 * m_auto_pan_start;
159 v19 = (unsigned int)v23 >> 6;
160 if ( v23 < 0 )
161 v19 = (unsigned int)(v23 + 63) >> 6;
162 }
163 if ( _svm_stereo_mono == 1 )
164 {
165 if ( (u16)v18 >= (unsigned int)(u16)v19 )
166 v19 = v18;
167 else
168 v18 = v19;
169 }
170 voice_struct->m_auto_pan_dt2 = voice_struct->m_auto_pan_dt1;
171 _svm_sreg_buf[vc].m_vol_left = v18;
172 _svm_sreg_buf[vc].m_vol_right = v19;
173 _svm_sreg_dirty[(s16)vc] |= 3;
174}