11#include "libspu2_internal.h"
13static void __attribute__((optimize(
"no-unroll-loops"))) _spu_wait_SpuSetVoiceAttr(
void)
19 for ( i = 0; i < 2; i += 1 )
22 __asm__ __volatile__(
"" :
"+g"(v1) : :);
29 unsigned int attr_mask;
35 s16 vol_right_clamped;
39 unsigned int adsr_dr_part;
40 unsigned int adsr_sr_part;
42 unsigned int adsr_rr_part;
43 s16 attr_r_mode_converted;
46 attr_mask = arg->mask;
49 attr_mask = 0xFFFFFFFF;
51 for ( voice_num = 0; voice_num < 24; voice_num += 1 )
53 if ( (arg->voice & (1 << voice_num)) != 0 )
55 int converted_voice_num;
57 converted_voice_num = 8 * voice_num;
58 regtmp = 2 * (voice_num * 2 + voice_num);
59 if ( (attr_mask & SPU_VOICE_PITCH) != 0 )
60 _spu_RXX[512 * _spu_core + 2 + converted_voice_num] = arg->pitch;
61 if ( (attr_mask & SPU_VOICE_SAMPLE_NOTE) != 0 )
62 _spu_voice_centerNote[_spu_core][voice_num] = arg->sample_note;
63 if ( (attr_mask & SPU_VOICE_NOTE) != 0 )
64 _spu_RXX[512 * _spu_core + 2 + converted_voice_num] = _spu_note2pitch(
65 (_spu_voice_centerNote[_spu_core][voice_num] >> 8) & 0xFF,
66 (u8)_spu_voice_centerNote[_spu_core][voice_num],
67 (arg->note >> 8) & 0xFF,
69 if ( (attr_mask & SPU_VOICE_VOLL) != 0 )
72 vol_left_clamped = arg->volume.left & ~0x8000;
73 if ( (attr_mask & SPU_VOICE_VOLMODEL) != 0 )
75 switch ( arg->volmode.left )
77 case SPU_VOICE_LINEARIncN:
78 vol_left_upper = 0x8000;
80 case SPU_VOICE_LINEARIncR:
81 vol_left_upper = 0x9000;
83 case SPU_VOICE_LINEARDecN:
84 vol_left_upper = 0xa000;
86 case SPU_VOICE_LINEARDecR:
87 vol_left_upper = 0xb000;
89 case SPU_VOICE_EXPIncN:
90 vol_left_upper = 0xc000;
92 case SPU_VOICE_EXPIncR:
93 vol_left_upper = 0xd000;
95 case SPU_VOICE_EXPDec:
96 vol_left_upper = 0xe000;
102 if ( vol_left_upper )
104 vol_left = arg->volume.left;
105 if ( vol_left < 128 )
108 vol_left_clamped = 0;
112 vol_left_clamped = 127;
115 _spu_RXX[512 * _spu_core + converted_voice_num] = vol_left_clamped | vol_left_upper;
117 if ( (attr_mask & SPU_VOICE_VOLR) != 0 )
120 vol_right_clamped = arg->volume.right & ~0x8000;
121 if ( (attr_mask & SPU_VOICE_VOLMODER) != 0 )
123 switch ( arg->volmode.right )
125 case SPU_VOICE_LINEARIncN:
126 vol_right_upper = 0x8000;
128 case SPU_VOICE_LINEARIncR:
129 vol_right_upper = 0x9000;
131 case SPU_VOICE_LINEARDecN:
132 vol_right_upper = 0xa000;
134 case SPU_VOICE_LINEARDecR:
135 vol_right_upper = 0xb000;
137 case SPU_VOICE_EXPIncN:
138 vol_right_upper = 0xc000;
140 case SPU_VOICE_EXPIncR:
141 vol_right_upper = 0xd000;
143 case SPU_VOICE_EXPDec:
144 vol_right_upper = 0xe000;
150 if ( vol_right_upper )
152 vol_right = arg->volume.right;
153 if ( vol_right < 128 )
156 vol_right_clamped = 0;
160 vol_right_clamped = 127;
163 _spu_RXX[512 * _spu_core + 1 + converted_voice_num] = vol_right_clamped | vol_right_upper;
165 if ( (attr_mask & SPU_VOICE_WDSA) != 0 )
166 _spu_FsetRXX(regtmp + 224, (arg->addr >> 4) << 4, 1);
167 if ( (attr_mask & SPU_VOICE_LSAX) != 0 )
168 _spu_FsetRXX(regtmp + 226, (arg->loop_addr >> 4) << 4, 1);
169 if ( (attr_mask & SPU_VOICE_ADSR_ADSR1) != 0 )
170 _spu_RXX[512 * _spu_core + 3 + converted_voice_num] = arg->adsr1;
171 if ( (attr_mask & SPU_VOICE_ADSR_ADSR2) != 0 )
172 _spu_RXX[512 * _spu_core + 4 + converted_voice_num] = arg->adsr2;
173 if ( (attr_mask & SPU_VOICE_ADSR_AR) != 0 )
176 if ( attr_ar >= 0x80 )
179 if ( ((attr_mask & SPU_VOICE_ADSR_AMODE) != 0) && arg->a_mode == SPU_VOICE_EXPIncN )
181 _spu_RXX[512 * _spu_core + 3 + converted_voice_num] =
182 (u8)_spu_RXX[512 * _spu_core + 3 + converted_voice_num] | (u16)(((u16)attr_ar | (u16)adsr_ar_part) << 8);
184 if ( (attr_mask & SPU_VOICE_ADSR_DR) != 0 )
186 adsr_dr_part = arg->dr;
187 if ( adsr_dr_part >= 0x10 )
189 _spu_RXX[512 * _spu_core + 3 + converted_voice_num] =
190 (_spu_RXX[512 * _spu_core + 3 + converted_voice_num] & ~0xf0) | (16 * adsr_dr_part);
192 if ( (attr_mask & SPU_VOICE_ADSR_SR) != 0 )
194 adsr_sr_part = arg->sr;
195 if ( adsr_sr_part >= 0x80 )
197 converted_s_mode = 256;
198 if ( (attr_mask & SPU_VOICE_ADSR_SMODE) != 0 )
200 switch ( arg->s_mode )
202 case SPU_VOICE_LINEARIncN:
203 converted_s_mode = 0;
205 case SPU_VOICE_EXPIncN:
206 converted_s_mode = 512;
208 case SPU_VOICE_EXPDec:
209 converted_s_mode = 768;
215 _spu_RXX[512 * _spu_core + 4 + converted_voice_num] =
216 (_spu_RXX[512 * _spu_core + 4 + converted_voice_num] & 0x3F)
217 | (((u16)adsr_sr_part | (u16)converted_s_mode) << 6);
219 if ( (attr_mask & SPU_VOICE_ADSR_RR) != 0 )
221 adsr_rr_part = arg->rr;
222 if ( adsr_rr_part >= 0x20 )
224 attr_r_mode_converted = 0;
225 if ( (attr_mask & SPU_VOICE_ADSR_RMODE) != 0 )
227 if ( arg->r_mode == SPU_VOICE_EXPDec )
228 attr_r_mode_converted = 32;
230 _spu_RXX[512 * _spu_core + 4 + converted_voice_num] =
231 (_spu_RXX[512 * _spu_core + 4 + converted_voice_num] & ~0x3f) | adsr_rr_part | attr_r_mode_converted;
233 if ( (attr_mask & SPU_VOICE_ADSR_SL) != 0 )
236 if ( attr_sl >= 0x10 )
238 _spu_RXX[512 * _spu_core + 3 + converted_voice_num] =
239 (_spu_RXX[512 * _spu_core + 3 + converted_voice_num] & ~0xF) | attr_sl;
243 _spu_wait_SpuSetVoiceAttr();