PS2SDK
PS2 Homebrew Libraries
Loading...
Searching...
No Matches
vm_aloc1.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 _SsVmAlloc(void)
14{
15 u8 voice_to_alloc_idx;
16 u16 lowest_key_stat;
17 char match_counter;
18 int lowest_unk02;
19 char lowest_match;
20 u8 i_cur_1;
21 u16 lowest_prior;
22 int m_priority;
23 unsigned int m_key_stat;
24 int m_unk02;
25
26 voice_to_alloc_idx = 99;
27 lowest_key_stat = -1;
28 match_counter = 0;
29 lowest_unk02 = 0;
30 lowest_match = 99;
31 lowest_prior = _svm_cur.m_prior;
32 for ( i_cur_1 = 0; i_cur_1 < _SsVmMaxVoice; i_cur_1 += 1 )
33 {
34 libsnd2_spu_voice_t *voice_struct;
35
36 voice_struct = &_svm_voice[i_cur_1];
37 if ( (_snd_vmask & (1 << i_cur_1)) == 0 )
38 {
39 if ( !voice_struct->m_unk1d )
40 {
41 if ( !voice_struct->m_key_stat )
42 {
43 voice_to_alloc_idx = i_cur_1;
44 break;
45 }
46 }
47 m_priority = voice_struct->m_priority;
48 if ( m_priority >= lowest_prior )
49 {
50 if ( m_priority == lowest_prior )
51 {
52 m_key_stat = (u16)voice_struct->m_key_stat;
53 match_counter += 1;
54 if ( m_key_stat >= lowest_key_stat )
55 {
56 if ( m_key_stat == lowest_key_stat )
57 {
58 m_unk02 = voice_struct->m_unk02;
59 if ( lowest_unk02 < m_unk02 )
60 {
61 lowest_unk02 = (u16)voice_struct->m_unk02;
62 lowest_match = i_cur_1;
63 }
64 }
65 }
66 else
67 {
68 lowest_unk02 = (u16)voice_struct->m_unk02;
69 lowest_key_stat = voice_struct->m_key_stat;
70 lowest_match = i_cur_1;
71 }
72 }
73 }
74 else
75 {
76 lowest_prior = voice_struct->m_priority;
77 lowest_match = i_cur_1;
78 lowest_key_stat = voice_struct->m_key_stat;
79 lowest_unk02 = (u16)voice_struct->m_unk02;
80 match_counter = 1;
81 }
82 }
83 }
84 if ( voice_to_alloc_idx == 99 )
85 {
86 voice_to_alloc_idx = lowest_match;
87 if ( !match_counter )
88 voice_to_alloc_idx = _SsVmMaxVoice;
89 }
90 if ( voice_to_alloc_idx < _SsVmMaxVoice )
91 {
92 int v16;
93 libsnd2_spu_voice_t *voice_struct;
94
95 for ( v16 = 0; (u8)v16 < _SsVmMaxVoice; v16 += 1 )
96 {
97 libsnd2_spu_voice_t *voice_struct_1;
98
99 voice_struct_1 = &_svm_voice[(u8)v16];
100 if ( (_snd_vmask & (1 << (u8)v16)) == 0 )
101 voice_struct_1->m_unk02 += 1;
102 }
103 voice_struct = &_svm_voice[voice_to_alloc_idx];
104 voice_struct->m_unk02 = 0;
105 voice_struct->m_b_auto_pan = 0;
106 voice_struct->m_b_auto_vol = 0;
107 voice_struct->m_priority = _svm_cur.m_prior;
108 }
109 return voice_to_alloc_idx;
110}