PS2SDK
PS2 Homebrew Libraries
Loading...
Searching...
No Matches
vm_aloc3.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
13char SsBlockVoiceAllocation(void)
14{
15 if ( _snd_ev_flag == 1 )
16 return -1;
17 _snd_ev_flag = 1;
18 return 1;
19}
20
21char SsUnBlockVoiceAllocation(void)
22{
23 if ( !_snd_ev_flag )
24 return -1;
25 _snd_ev_flag = 0;
26 return 1;
27}
28
29int SsAllocateVoices(u8 voices, u8 priority)
30{
31 int v2;
32 int v3;
33 u16 v4;
34 u16 v5;
35 char v9;
36 int m_priority;
37 unsigned int m_key_stat;
38 int v16;
39 int v17;
40
41 v3 = 0;
42 for ( v2 = 0; (u8)v2 < (unsigned int)voices; v2 += 1 )
43 {
44 int m_unk02;
45 char v7;
46 char v8;
47
48 v4 = -1;
49 v5 = priority;
50 m_unk02 = 0;
51 v7 = 99;
52 v8 = 99;
53 for ( v9 = 0; (u8)v9 < _SsVmMaxVoice; v9 += 1 )
54 {
55 if ( ((1 << (u8)v9) & v3) == 0 )
56 {
57 libsnd2_spu_voice_t *voice_struct;
58
59 voice_struct = &_svm_voice[(u8)v9];
60 if ( !voice_struct->m_unk1d && !voice_struct->m_key_stat )
61 {
62 v8 = v9;
63 break;
64 }
65 m_priority = voice_struct->m_priority;
66 if ( m_priority >= v5 )
67 {
68 if ( m_priority == v5 )
69 {
70 m_key_stat = (u16)voice_struct->m_key_stat;
71 if ( m_key_stat >= v4 )
72 {
73 if ( m_key_stat != v4 || m_unk02 >= voice_struct->m_unk02 )
74 continue;
75 m_unk02 = (u16)voice_struct->m_unk02;
76 }
77 else
78 {
79 m_unk02 = (u16)voice_struct->m_unk02;
80 v4 = voice_struct->m_key_stat;
81 }
82 v7 = v9;
83 }
84 }
85 else
86 {
87 v5 = voice_struct->m_priority;
88 v4 = voice_struct->m_key_stat;
89 m_unk02 = (u16)voice_struct->m_unk02;
90 v7 = v9;
91 }
92 }
93 }
94 if ( v7 != 99 )
95 {
96 v3 |= 1 << v7;
97 }
98 else if ( v8 != 99 )
99 {
100 v3 |= 1 << v8;
101 }
102 else
103 {
104 return -1;
105 }
106 }
107 v16 = voices;
108 for ( v17 = 0; (u8)v17 < _SsVmMaxVoice; v17 += 1 )
109 {
110 libsnd2_spu_voice_t *voice_struct;
111
112 voice_struct = &_svm_voice[(u8)v17];
113 if ( ((1 << v17) & v3) != 0 )
114 {
115 v16 -= 1;
116 voice_struct->m_unk02 = (u8)v16;
117 voice_struct->m_priority = priority;
118 voice_struct->m_b_auto_vol = 0;
119 voice_struct->m_b_auto_pan = 0;
120 if ( voice_struct->m_unk1d == 2 )
121 SpuSetNoiseVoice(SPU_OFF, 1 << v17);
122 voice_struct->m_unk1d = 1;
123 }
124 else
125 {
126 voice_struct->m_unk02 += voices;
127 }
128 }
129 return v3;
130}