PS2SDK
PS2 Homebrew Libraries
Loading...
Searching...
No Matches
vm_autov.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 SeAutoVol(s16 vc, s16 start_vol, s16 end_vol, s16 delta_time)
14{
15 libsnd2_spu_voice_t *voice_struct;
16
17 voice_struct = &_svm_voice[vc];
18 if ( start_vol == end_vol )
19 return;
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;
23 if (
24 ((start_vol - end_vol >= 0) && (start_vol - end_vol < delta_time))
25 || ((start_vol - end_vol < 0) && (end_vol - start_vol < delta_time)) )
26 {
27 int v8;
28
29 if ( end_vol >= start_vol )
30 {
31 int v12;
32 int v13;
33
34 v12 = delta_time;
35 v13 = start_vol - end_vol;
36 if ( v13 == -1 && (unsigned int)v12 == 0x80000000 )
37 __builtin_trap();
38 voice_struct->m_auto_vol_amount = 1;
39 v8 = -(v12 / v13);
40 }
41 else
42 {
43 int v9;
44
45 v8 = delta_time;
46 v9 = start_vol - end_vol;
47 if ( v9 == -1 && (unsigned int)v8 == 0x80000000 )
48 __builtin_trap();
49 voice_struct->m_auto_vol_amount = -1;
50 v8 = v8 / v9;
51 }
52 voice_struct->m_auto_vol_dt1 = v8;
53 voice_struct->m_auto_vol_dt2 = v8;
54 }
55 else
56 {
57 int v14;
58
59 v14 = start_vol - end_vol;
60 if ( !delta_time )
61 __builtin_trap();
62 if ( delta_time == -1 && (unsigned int)v14 == 0x80000000 )
63 __builtin_trap();
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);
67 }
68}
69
70void SetAutoVol(int vc)
71{
72 int m_auto_vol_dt2;
73 s16 v5;
74 int m_auto_vol_amount;
75 s16 m_auto_vol_start;
76 unsigned int v9;
77 unsigned int v10;
78 unsigned int v11;
79 libsnd2_spu_voice_t *voice_struct;
80
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 )
85 return;
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 )
90 {
91 if ( voice_struct->m_auto_vol_end <= v5 )
92 {
93 voice_struct->m_auto_vol_start = voice_struct->m_auto_vol_end;
94 voice_struct->m_b_auto_vol = 0;
95 }
96 }
97 if ( m_auto_vol_amount < 0 )
98 {
99 if ( voice_struct->m_auto_vol_end >= v5 )
100 {
101 voice_struct->m_auto_vol_start = voice_struct->m_auto_vol_end;
102 voice_struct->m_b_auto_vol = 0;
103 }
104 }
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 )
109 {
110 v11 = v9;
111 v10 = (v9 * (127 - (u8)_svm_cur.m_pan)) >> 6;
112 }
113 else
114 {
115 v10 = v9;
116 v11 = (v9 * (u8)_svm_cur.m_pan) >> 6;
117 }
118 if ( (u8)_svm_cur.m_mpan >= 0x40u )
119 {
120 int v13;
121
122 v13 = (u16)v10 * (127 - (u8)_svm_cur.m_mpan);
123 v10 = (unsigned int)v13 >> 6;
124 if ( v13 < 0 )
125 v10 = (unsigned int)(v13 + 63) >> 6;
126 }
127 else
128 {
129 int v12;
130
131 v12 = (u16)v11 * (u8)_svm_cur.m_mpan;
132 v11 = (unsigned int)v12 >> 6;
133 if ( v12 < 0 )
134 v11 = (unsigned int)(v12 + 63) >> 6;
135 }
136 if ( (u8)_svm_cur.m_unk05 >= 0x40u )
137 {
138 int v15;
139
140 v15 = (u16)v10 * (127 - (u8)_svm_cur.m_unk05);
141 v10 = (unsigned int)v15 >> 6;
142 if ( v15 < 0 )
143 v10 = (unsigned int)(v15 + 63) >> 6;
144 }
145 else
146 {
147 int v14;
148
149 v14 = (u16)v11 * (u8)_svm_cur.m_unk05;
150 v11 = (unsigned int)v14 >> 6;
151 if ( v14 < 0 )
152 v11 = (unsigned int)(v14 + 63) >> 6;
153 }
154 if ( _svm_stereo_mono == 1 )
155 {
156 if ( (u16)v10 >= (unsigned int)(u16)v11 )
157 v11 = v10;
158 else
159 v10 = v11;
160 }
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;
165}