PS2SDK
PS2 Homebrew Libraries
Loading...
Searching...
No Matches
vm_nowon.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 _SsVmKeyOnNow(s16 vag_count, s16 pitch)
14{
15 u16 m_voice_idx;
16 unsigned int left;
17 libsnd2_sequence_struct_t *score_struct;
18 unsigned int left_tmp2;
19 unsigned int right_tmp;
20 unsigned int left_tmp;
21 int bits_lower;
22 int bits_upper;
23 libsnd2_spu_voice_t *voice_struct;
24
25 (void)vag_count;
26
27 m_voice_idx = _svm_cur.m_voice_idx;
28 left = _svm_cur.m_voll * 0x3FFF * _svm_vh->mvol / 0x3F01 * _svm_cur.m_mvol * _svm_cur.m_vol / 0x3F01u;
29 left_tmp2 = left;
30 score_struct = NULL;
31 if ( _svm_cur.m_seq_sep_no != 33 )
32 {
33 score_struct = &_ss_score[(_svm_cur.m_seq_sep_no & 0xFF)][(_svm_cur.m_seq_sep_no & 0xFF00) >> 8];
34 }
35 if ( score_struct != NULL )
36 {
37 left_tmp2 = left * (u16)score_struct->m_voll / 0x7F;
38 left = left * (u16)score_struct->m_volr / 0x7F;
39 }
40 if ( (u8)_svm_cur.m_pan >= 0x40u )
41 {
42 left_tmp = left;
43 right_tmp = left_tmp2 * (127 - (u8)_svm_cur.m_pan) / 0x3F;
44 }
45 else
46 {
47 right_tmp = left_tmp2;
48 left_tmp = left * (u8)_svm_cur.m_pan / 0x3F;
49 }
50 if ( (u8)_svm_cur.m_mpan >= 0x40u )
51 right_tmp = right_tmp * (127 - (u8)_svm_cur.m_mpan) / 0x3F;
52 else
53 left_tmp = left_tmp * (u8)_svm_cur.m_mpan / 0x3F;
54 if ( (u8)_svm_cur.m_unk05 >= 0x40u )
55 right_tmp = right_tmp * (127 - (u8)_svm_cur.m_unk05) / 0x3F;
56 else
57 left_tmp = left_tmp * (u8)_svm_cur.m_unk05 / 0x3F;
58 if ( _svm_stereo_mono == 1 )
59 {
60 if ( right_tmp >= left_tmp )
61 left_tmp = right_tmp;
62 else
63 right_tmp = left_tmp;
64 }
65 if ( score_struct != NULL )
66 {
67 right_tmp = right_tmp * right_tmp / 0x3FFF;
68 left_tmp = left_tmp * left_tmp / 0x3FFF;
69 }
70 _svm_sreg_buf[m_voice_idx].m_pitch = pitch;
71 _svm_sreg_buf[m_voice_idx].m_vol_left = right_tmp;
72 _svm_sreg_buf[m_voice_idx].m_vol_right = left_tmp;
73 _svm_sreg_dirty[_svm_cur.m_voice_idx] |= 7u;
74 voice_struct = &_svm_voice[_svm_cur.m_voice_idx];
75 voice_struct->m_pitch = pitch;
76 if ( _svm_cur.m_voice_idx >= 16 )
77 {
78 bits_lower = 0;
79 bits_upper = 1 << ((_svm_cur.m_voice_idx & 0xFF) - 16);
80 }
81 else
82 {
83 bits_lower = 1 << (_svm_cur.m_voice_idx & 0xFF);
84 bits_upper = 0;
85 }
86 if ( (_svm_cur.m_mode & 4) != 0 )
87 {
88 _svm_orev1 |= bits_lower;
89 _svm_orev2 |= bits_upper;
90 }
91 else
92 {
93 _svm_orev1 &= ~(u16)bits_lower;
94 _svm_orev2 &= ~(u16)bits_upper;
95 }
96 _svm_onos1 &= ~(u16)bits_lower;
97 _svm_okon2 |= bits_upper;
98 _svm_onos2 &= ~(u16)bits_upper;
99 _svm_okon1 |= bits_lower;
100 _svm_okof1 &= ~_svm_okon1;
101 _svm_okof2 &= ~_svm_okon2;
102}