11#include "libsnd2_internal.h"
13void SeAutoPan(s16 vc, s16 start_pan, s16 end_pan, s16 delta_time)
17 voice_struct = &_svm_voice[vc];
18 if ( start_pan == end_pan )
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;
24 ((start_pan - end_pan >= 0) && (start_pan - end_pan < delta_time))
25 || ((start_pan - end_pan < 0) && (end_pan - start_pan < delta_time)) )
29 if ( end_pan >= start_pan )
35 v13 = start_pan - end_pan;
36 if ( v13 == -1 && (
unsigned int)v12 == 0x80000000 )
38 voice_struct->m_auto_pan_amount = 1;
46 v9 = start_pan - end_pan;
47 if ( v9 == -1 && (
unsigned int)v8 == 0x80000000 )
50 voice_struct->m_auto_pan_amount = -1;
52 voice_struct->m_auto_pan_dt1 = v8;
53 voice_struct->m_auto_pan_dt2 = v8;
59 v14 = start_pan - end_pan;
62 if ( delta_time == -1 && (
unsigned int)v14 == 0x80000000 )
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);
70void SetAutoPan(
int vc)
74 int m_auto_pan_amount;
75 char m_auto_pan_start;
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 )
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 )
95 if ( m_auto_pan_amount < 0 && (s16)v5 <= voice_struct->m_auto_pan_end )
97 voice_struct->m_auto_pan_start = voice_struct->m_auto_pan_end;
98 voice_struct->m_b_auto_pan = 0;
101 else if ( (s16)v5 >= voice_struct->m_auto_pan_end )
103 voice_struct->m_auto_pan_start = voice_struct->m_auto_pan_end;
104 voice_struct->m_b_auto_pan = 0;
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;
116 v18 = (v16 * (127 - pan)) >> 6;
126 mpan = (char)_svm_pg[voice_struct->m_prog].mpan;
131 v22 = (u16)v18 * (127 - mpan);
132 v18 = (
unsigned int)v22 >> 6;
134 v18 = (
unsigned int)(v22 + 63) >> 6;
140 v21 = (u16)v19 * mpan;
141 v19 = (
unsigned int)v21 >> 6;
143 v19 = (
unsigned int)(v21 + 63) >> 6;
145 if ( m_auto_pan_start >= 64 )
149 v24 = (u16)v18 * (127 - m_auto_pan_start);
150 v18 = (
unsigned int)v24 >> 6;
152 v18 = (
unsigned int)(v24 + 63) >> 6;
158 v23 = (u16)v19 * m_auto_pan_start;
159 v19 = (
unsigned int)v23 >> 6;
161 v19 = (
unsigned int)(v23 + 63) >> 6;
163 if ( _svm_stereo_mono == 1 )
165 if ( (u16)v18 >= (
unsigned int)(u16)v19 )
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;