PS2SDK
PS2 Homebrew Libraries
q_keyon.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 
13 void SsQueueKeyOn(int voices)
14 {
15  int v1;
16 
17  for ( v1 = 0; (char)v1 < _SsVmMaxVoice; v1 += 1 )
18  {
19  int v4;
20 
21  v4 = 1 << v1;
22  if ( (v4 & voices) != 0 )
23  {
24  if ( v1 >= 16 )
25  {
26  int v7;
27 
28  v7 = 1 << (v1 - 16);
29  _svm_okon2 |= v7;
30  _svm_okof2 &= ~(u16)v7;
31  }
32  else
33  {
34  _svm_okon1 |= v4;
35  _svm_okof1 &= ~(u16)v4;
36  }
37  }
38  }
39 }
40 
41 void SsQueueReverb(int voices, int reverb)
42 {
43  int v2;
44  int v8;
45  char v9;
46  int v10;
47 
48  for ( v2 = 0; (char)v2 < 24; v2 += 1 )
49  {
50  int v5;
51 
52  v5 = 1 << v2;
53  if ( (v5 & voices) != 0 )
54  {
55  v8 = v5 & reverb;
56  if ( v2 >= 16 )
57  {
58  v9 = v2 - 16;
59  if ( v8 == 0 )
60  v10 = _svm_orev2 & ~(1 << v9);
61  else
62  v10 = _svm_orev2 | (1 << v9);
63  _svm_orev2 = v10;
64  }
65  else
66  {
67  if ( v8 )
68  _svm_orev1 |= v5;
69  else
70  _svm_orev1 &= ~(u16)v5;
71  }
72  }
73  }
74 }
75 
76 void SsQueueRegisters(int vc, SndRegisterAttr *sra)
77 {
78  u32 mask;
79 
80  mask = sra->mask;
81  printf("SsQueueRegisters \n");
82  if ( mask == 0 )
83  mask = 0xFFFFFFFF;
84  if ( (mask & SND_VOLL) != 0 )
85  {
86  _svm_sreg_buf[vc].m_vol_left = sra->volume.left & ~0x8000;
87  _svm_sreg_dirty[vc] |= 1;
88  }
89  if ( (mask & SND_VOLR) != 0 )
90  {
91  _svm_sreg_buf[vc].m_vol_right = sra->volume.right & ~0x8000;
92  _svm_sreg_dirty[vc] |= 2;
93  }
94  if ( (mask & SND_ADSR1) != 0 )
95  {
96  _svm_sreg_buf[vc].m_adsr1 = sra->adsr1;
97  _svm_sreg_dirty[vc] |= 0x10;
98  }
99  if ( (mask & SND_ADSR2) != 0 )
100  {
101  _svm_sreg_buf[vc].m_adsr2 = sra->adsr2;
102  _svm_sreg_dirty[vc] |= 0x20;
103  }
104  if ( (mask & SND_PITCH) != 0 )
105  {
106  _svm_sreg_buf[vc].m_pitch = sra->pitch;
107  _svm_sreg_dirty[vc] |= 4;
108  }
109  if ( (mask & SND_ADDR) != 0 )
110  {
111  _svm_sreg_buf2[vc].m_vag_spu_addr = sra->addr;
112  _svm_sreg_dirty[vc] |= 8u;
113  }
114 }
115 
116 s16 SsGetActualProgFromProg(s16 vab_id, s16 prog)
117 {
118  if ( !((u16)vab_id < 0x11u && prog >= 0 && kMaxPrograms >= prog) )
119  return -1;
120  return _svm_vab_pg[vab_id][prog].m_fake_prog_idx;
121 }
122 
123 void SsSetVoiceSettings(int vc, const SndVoiceStats *snd_v_attr)
124 {
125  libsnd2_spu_voice_t *voice_struct;
126 
127  voice_struct = &_svm_voice[vc];
128  voice_struct->m_vag_idx = snd_v_attr->vagId;
129  voice_struct->m_pitch = snd_v_attr->pitch;
130  voice_struct->m_voll1 = snd_v_attr->vol;
131  voice_struct->m_pan = snd_v_attr->pan;
132  voice_struct->m_seq_sep_no = 33;
133  voice_struct->m_note = snd_v_attr->note;
134  voice_struct->m_fake_program = snd_v_attr->prog_actual;
135  voice_struct->m_prog = snd_v_attr->prog_num;
136  voice_struct->m_tone = snd_v_attr->tone;
137  voice_struct->m_vab_id = snd_v_attr->vabId;
138  voice_struct->m_voll2 = snd_v_attr->vol;
139 }
140 
141 s16 SsVoiceCheck(int vc, int vab_id, s16 note)
142 {
143  const libsnd2_spu_voice_t *voice_struct;
144 
145  if ( (unsigned int)vc >= 0x18 )
146  return -1;
147  voice_struct = &_svm_voice[vc];
148  if ( voice_struct->m_vab_id != vab_id >> 8 )
149  return -1;
150  if ( voice_struct->m_prog != (u8)vab_id )
151  return -1;
152  if ( voice_struct->m_note != note )
153  return -1;
154  return 0;
155 }
SndRegisterAttr
Definition: libsnd2.h:209
libsnd2_spu_voice_
Definition: libsnd2_internal.h:117
SndVoiceStats
Definition: libsnd2.h:219