11#include "libsnd2_internal.h"
13void SeAutoVol(s16 vc, s16 start_vol, s16 end_vol, s16 delta_time)
17 voice_struct = &_svm_voice[vc];
18 if ( start_vol == end_vol )
20 voice_struct->m_b_auto_vol = 1;
21 voice_struct->m_auto_vol_start = start_vol;
22 voice_struct->m_auto_vol_end = end_vol;
24 ((start_vol - end_vol >= 0) && (start_vol - end_vol < delta_time))
25 || ((start_vol - end_vol < 0) && (end_vol - start_vol < delta_time)) )
29 if ( end_vol >= start_vol )
35 v13 = start_vol - end_vol;
36 if ( v13 == -1 && (
unsigned int)v12 == 0x80000000 )
38 voice_struct->m_auto_vol_amount = 1;
46 v9 = start_vol - end_vol;
47 if ( v9 == -1 && (
unsigned int)v8 == 0x80000000 )
49 voice_struct->m_auto_vol_amount = -1;
52 voice_struct->m_auto_vol_dt1 = v8;
53 voice_struct->m_auto_vol_dt2 = v8;
59 v14 = start_vol - end_vol;
62 if ( delta_time == -1 && (
unsigned int)v14 == 0x80000000 )
64 voice_struct->m_auto_vol_dt1 = 0;
65 voice_struct->m_auto_vol_dt2 = 0;
66 voice_struct->m_auto_vol_amount = -(s16)(v14 / delta_time);
70void SetAutoVol(
int vc)
74 int m_auto_vol_amount;
81 voice_struct = &_svm_voice[(s16)vc];
82 m_auto_vol_dt2 = (u16)voice_struct->m_auto_vol_dt2;
83 voice_struct->m_auto_vol_dt2 = m_auto_vol_dt2 - 1;
84 if ( m_auto_vol_dt2 > 0 )
86 v5 = voice_struct->m_auto_vol_start + voice_struct->m_auto_vol_amount;
87 voice_struct->m_auto_vol_start = v5;
88 m_auto_vol_amount = voice_struct->m_auto_vol_amount;
89 if ( m_auto_vol_amount > 0 )
91 if ( voice_struct->m_auto_vol_end <= v5 )
93 voice_struct->m_auto_vol_start = voice_struct->m_auto_vol_end;
94 voice_struct->m_b_auto_vol = 0;
97 if ( m_auto_vol_amount < 0 )
99 if ( voice_struct->m_auto_vol_end >= v5 )
101 voice_struct->m_auto_vol_start = voice_struct->m_auto_vol_end;
102 voice_struct->m_b_auto_vol = 0;
105 m_auto_vol_start = voice_struct->m_auto_vol_start;
106 _svm_cur.m_voll = m_auto_vol_start;
107 v9 = m_auto_vol_start * 0x3FFF * _svm_vh->mvol / 0x3F01 * _svm_cur.m_mvol * _svm_cur.m_vol / 0x3F01u;
108 if ( (u8)_svm_cur.m_pan >= 0x40u )
111 v10 = (v9 * (127 - (u8)_svm_cur.m_pan)) >> 6;
116 v11 = (v9 * (u8)_svm_cur.m_pan) >> 6;
118 if ( (u8)_svm_cur.m_mpan >= 0x40u )
122 v13 = (u16)v10 * (127 - (u8)_svm_cur.m_mpan);
123 v10 = (
unsigned int)v13 >> 6;
125 v10 = (
unsigned int)(v13 + 63) >> 6;
131 v12 = (u16)v11 * (u8)_svm_cur.m_mpan;
132 v11 = (
unsigned int)v12 >> 6;
134 v11 = (
unsigned int)(v12 + 63) >> 6;
136 if ( (u8)_svm_cur.m_unk05 >= 0x40u )
140 v15 = (u16)v10 * (127 - (u8)_svm_cur.m_unk05);
141 v10 = (
unsigned int)v15 >> 6;
143 v10 = (
unsigned int)(v15 + 63) >> 6;
149 v14 = (u16)v11 * (u8)_svm_cur.m_unk05;
150 v11 = (
unsigned int)v14 >> 6;
152 v11 = (
unsigned int)(v14 + 63) >> 6;
154 if ( _svm_stereo_mono == 1 )
156 if ( (u16)v10 >= (
unsigned int)(u16)v11 )
161 voice_struct->m_auto_vol_dt2 = voice_struct->m_auto_vol_dt1;
162 _svm_sreg_buf[vc].m_vol_left = v10;
163 _svm_sreg_buf[vc].m_vol_right = v11;
164 _svm_sreg_dirty[(s16)vc] |= 3;