11#include "libsnd2_internal.h"
13int _SsVmKeyOn(
int seq_sep_no, s16 vab_id, s16 prog, s16 note, s16 voll, s16 unknown27)
19 u8 selected_vag_count;
20 const VagAtr *vag_attr_ptr;
23 u8 vag_index_nums[128];
26 if ( seq_sep_no != 33 )
28 score_struct = &_ss_score[(u8)seq_sep_no][(seq_sep_no & 0xFF00) >> 8];
32 if ( _SsVmVSetUp(vab_id, prog) != 0 )
34 return on_keys_mask_2;
36 _svm_cur.m_seq_sep_no = seq_sep_no;
37 _svm_cur.m_note = note;
39 if ( score_struct != NULL )
40 _svm_cur.m_voll = (u16)voll * score_struct->m_vol[score_struct->m_channel_idx] / 127;
42 _svm_cur.m_voll = voll;
43 _svm_cur.m_unk05 = unknown27;
44 prog_attr_Ptr = &_svm_pg[prog];
45 _svm_cur.m_mvol = prog_attr_Ptr->mvol;
46 _svm_cur.m_mpan = prog_attr_Ptr->mpan;
47 _svm_cur.m_sep_sep_no_tonecount = prog_attr_Ptr->tones;
48 if ( _svm_cur.m_fake_program >= (
int)_svm_vh->ps )
53 return _SsVmKeyOff(seq_sep_no, vab_id, prog, note);
54 selected_vag_count = _SsVmSelectToneAndVag(vag_index_nums, vag_nums);
55 for ( v16 = 0; (u8)v16 < (
unsigned int)selected_vag_count; v16 += 1 )
57 _svm_cur.m_vag_idx2 = (u8)vag_nums[(u8)v16];
58 _svm_cur.m_tone = vag_index_nums[(u8)v16];
59 vag_attr_ptr = &_svm_tn[(u16)(_svm_cur.m_tone + 16 * _svm_cur.m_fake_program)];
60 _svm_cur.m_prior = vag_attr_ptr->prior;
61 _svm_cur.m_vol = vag_attr_ptr->vol;
62 _svm_cur.m_pan = vag_attr_ptr->pan;
63 _svm_cur.m_centre = vag_attr_ptr->center;
64 _svm_cur.m_shift = vag_attr_ptr->shift;
65 _svm_cur.m_mode = vag_attr_ptr->mode;
66 _svm_cur.m_voice_idx = (u8)_SsVmAlloc();
67 if ( _svm_cur.m_voice_idx >= _SsVmMaxVoice )
75 voice_struct = &_svm_voice[_svm_cur.m_voice_idx];
76 voice_struct->m_unk1d = 1;
77 voice_struct->m_unk02 = 0;
78 voice_struct->m_seq_sep_no = seq_sep_no;
79 voice_struct->m_vab_id = _svm_cur.m_vab_id;
80 voice_struct->m_fake_program = _svm_cur.m_fake_program;
81 voice_struct->m_prog = prog;
82 if ( score_struct != NULL )
84 voice_struct->m_voll1 = voll;
85 voice_struct->m_channel_idx = score_struct->m_channel_idx;
87 voice_struct->m_pan = unknown27;
88 voice_struct->m_voll2 = _svm_cur.m_voll;
89 voice_struct->m_tone = _svm_cur.m_tone;
90 voice_struct->m_note = note;
91 voice_struct->m_priority = _svm_cur.m_prior;
92 voice_struct->m_vag_idx = _svm_cur.m_vag_idx2;
94 if ( _svm_cur.m_vag_idx2 == 255 )
96 vmNoiseOn(_svm_cur.m_voice_idx);
100 _SsVmKeyOnNow(selected_vag_count, note2pitch());
102 on_keys_mask_1 |= 1 << (_svm_cur.m_voice_idx & 0xFF);
105 return on_keys_mask_1;
108int _SsVmKeyOff(
int seq_sep_no, s16 vab_id, s16 prog, s16 note)
114 for ( v4 = 0; (u8)v4 < _SsVmMaxVoice; v4 += 1 )
118 voice_struct = &_svm_voice[v4];
119 if ( !((_snd_vmask & (1 << v4)) != 0 || voice_struct->m_note != note || voice_struct->m_prog != prog
120 || voice_struct->m_seq_sep_no != (s16)seq_sep_no || voice_struct->m_vab_id != vab_id) )
123 if ( voice_struct->m_vag_idx == 255 )
129 _svm_cur.m_voice_idx = (u8)v4;
137int _SsVmSeKeyOn(s16 vab_id, s16 prog, u16 note,
int pitch, u16 voll, u16 volr)
149 else if ( volr >= (
unsigned int)voll )
152 unknown27 = 127 - (voll << 6) / volr;
157 unknown27 = (volr << 6) / voll;
159 return _SsVmKeyOn(33, vab_id, prog, note, voll_, unknown27);
162int _SsVmSeKeyOff(s16 vab_id, s16 prog, s16 note)
164 return _SsVmKeyOff(33, vab_id, prog, note);