PS2SDK
PS2 Homebrew Libraries
vm_pb.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 int _SsVmPBVoice(s16 vc, s16 seq_sep_num, s16 vab_id, s16 prog, s16 pitch)
14 {
15  s16 pitch_converted;
16  int bend_min;
17  int bend_max;
18  libsnd2_spu_voice_t *voice_struct;
19 
20  voice_struct = &_svm_voice[vc];
21  if ( voice_struct->m_seq_sep_no != seq_sep_num || voice_struct->m_vab_id != vab_id || voice_struct->m_prog != prog )
22  {
23  return 0;
24  }
25  pitch_converted = pitch - 64;
26  bend_min = (u16)voice_struct->m_note;
27  if ( pitch_converted <= 0 )
28  {
29  if ( pitch_converted >= 0 )
30  {
31  bend_max = 0;
32  }
33  else
34  {
35  int pbmin_tmp;
36 
37  pbmin_tmp = pitch_converted * _svm_tn[(u16)(voice_struct->m_tone + 16 * _svm_cur.m_fake_program)].pbmin;
38  bend_min = bend_min + pbmin_tmp / 64 - 1;
39  bend_max = 2 * (pbmin_tmp % 64) + 127;
40  }
41  }
42  else
43  {
44  int pbmax_tmp;
45 
46  pbmax_tmp = pitch_converted * _svm_tn[(u16)(voice_struct->m_tone + 16 * _svm_cur.m_fake_program)].pbmax;
47  bend_min += pbmax_tmp / 63;
48  bend_max = 2 * (pbmax_tmp % 63);
49  }
50  _svm_cur.m_voice_idx = vc;
51  _svm_cur.m_tone = voice_struct->m_tone;
52  _svm_sreg_buf[vc].m_pitch = note2pitch2(bend_min, bend_max);
53  _svm_sreg_dirty[vc] |= 4;
54  return 1;
55 }
56 
57 int _SsVmPitchBend(s16 seq_sep_no, int vab_id, int prog, s16 pitch)
58 {
59  int voice_i_tmp;
60  int voice_offs_tmp;
61 
62  _SsVmVSetUp(vab_id, prog);
63  _svm_cur.m_seq_sep_no = seq_sep_no;
64  voice_offs_tmp = 0;
65  for ( voice_i_tmp = 0; (s16)voice_i_tmp < _SsVmMaxVoice; voice_i_tmp += 1 )
66  {
67  voice_offs_tmp += (s16)_SsVmPBVoice(voice_i_tmp, seq_sep_no, vab_id, prog, pitch);
68  }
69  return voice_offs_tmp;
70 }
libsnd2_spu_voice_
Definition: libsnd2_internal.h:117