PS2SDK
PS2 Homebrew Libraries
Loading...
Searching...
No Matches
ut_keyv.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
13s16 SsUtKeyOnV(s16 vc, s16 vab_id, s16 prog, s16 tone, s16 note, s16 fine, s16 voll, s16 volr)
14{
15 const ProgAtr *pProg;
16 const VagAtr *pVag;
17 libsnd2_spu_voice_t *voice_struct;
18
19 if ( _snd_ev_flag == 1 )
20 return -1;
21 _snd_ev_flag = 1;
22 if ( (u16)vc >= 0x18u || _SsVmVSetUp(vab_id, prog) )
23 {
24 _snd_ev_flag = 0;
25 return -1;
26 }
27 _svm_cur.m_seq_sep_no = 33;
28 _svm_cur.m_note = note;
29 _svm_cur.m_fine = fine;
30 _svm_cur.m_tone = tone;
31 if ( voll == volr )
32 {
33 _svm_cur.m_unk05 = 64;
34 _svm_cur.m_voll = voll;
35 }
36 else
37 {
38 int volr_lshift_6;
39
40 volr_lshift_6 = volr << 6;
41 if ( volr >= voll )
42 {
43 int voll_lshift_6;
44
45 voll_lshift_6 = voll << 6;
46 if ( !volr )
47 __builtin_trap();
48 if ( volr == -1 && (unsigned int)voll_lshift_6 == 0x80000000 )
49 __builtin_trap();
50 _svm_cur.m_voll = volr;
51 _svm_cur.m_unk05 = 127 - voll_lshift_6 / volr;
52 }
53 else
54 {
55 if ( !voll )
56 __builtin_trap();
57 if ( voll == -1 && (unsigned int)volr_lshift_6 == 0x80000000 )
58 __builtin_trap();
59 _svm_cur.m_voll = voll;
60 _svm_cur.m_unk05 = volr_lshift_6 / voll;
61 }
62 }
63 pProg = &_svm_pg[prog];
64 _svm_cur.m_mvol = pProg->mvol;
65 _svm_cur.m_mpan = pProg->mpan;
66 _svm_cur.m_sep_sep_no_tonecount = pProg->tones;
67 pVag = &_svm_tn[16 * _svm_cur.m_fake_program + tone];
68 _svm_cur.m_prior = pVag->prior;
69 _svm_cur.m_vag_idx2 = pVag->vag;
70 _svm_cur.m_vol = pVag->vol;
71 _svm_cur.m_pan = pVag->pan;
72 _svm_cur.m_centre = pVag->center;
73 _svm_cur.m_shift = pVag->shift;
74 _svm_cur.m_mode = pVag->mode;
75 if ( _svm_cur.m_vag_idx2 == 0 )
76 {
77 _snd_ev_flag = 0;
78 return -1;
79 }
80 _svm_cur.m_voice_idx = vc;
81 voice_struct = &_svm_voice[vc];
82 voice_struct->m_seq_sep_no = 33;
83 voice_struct->m_vab_id = vab_id;
84 voice_struct->m_prog = prog;
85 voice_struct->m_fake_program = _svm_cur.m_fake_program;
86 voice_struct->m_vag_idx = _svm_cur.m_vag_idx2;
87 voice_struct->m_note = note;
88 voice_struct->m_unk1d = 1;
89 voice_struct->m_unk02 = 0;
90 voice_struct->m_tone = _svm_cur.m_tone;
91 voice_struct->m_voll2 = _svm_cur.m_voll;
92 _SsVmDoAllocate();
93 if ( _svm_cur.m_vag_idx2 == 255 )
94 {
95 vmNoiseOn(vc);
96 }
97 else
98 {
99 _SsVmKeyOnNow(1, note2pitch2(note, fine));
100 }
101 _snd_ev_flag = 0;
102 return vc;
103}
104
105s16 SsUtKeyOffV(s16 vc)
106{
107 if ( _snd_ev_flag == 1 )
108 return -1;
109 _snd_ev_flag = 1;
110 if ( (u16)vc >= 0x18u )
111 {
112 _snd_ev_flag = 0;
113 return -1;
114 }
115 _svm_cur.m_voice_idx = vc;
116 _SsVmKeyOffNow();
117 return 0;
118}