11#include "libsnd2_internal.h"
15 u8 voice_to_alloc_idx;
23 unsigned int m_key_stat;
26 voice_to_alloc_idx = 99;
31 lowest_prior = _svm_cur.m_prior;
32 for ( i_cur_1 = 0; i_cur_1 < _SsVmMaxVoice; i_cur_1 += 1 )
36 voice_struct = &_svm_voice[i_cur_1];
37 if ( (_snd_vmask & (1 << i_cur_1)) == 0 )
39 if ( !voice_struct->m_unk1d )
41 if ( !voice_struct->m_key_stat )
43 voice_to_alloc_idx = i_cur_1;
47 m_priority = voice_struct->m_priority;
48 if ( m_priority >= lowest_prior )
50 if ( m_priority == lowest_prior )
52 m_key_stat = (u16)voice_struct->m_key_stat;
54 if ( m_key_stat >= lowest_key_stat )
56 if ( m_key_stat == lowest_key_stat )
58 m_unk02 = voice_struct->m_unk02;
59 if ( lowest_unk02 < m_unk02 )
61 lowest_unk02 = (u16)voice_struct->m_unk02;
62 lowest_match = i_cur_1;
68 lowest_unk02 = (u16)voice_struct->m_unk02;
69 lowest_key_stat = voice_struct->m_key_stat;
70 lowest_match = i_cur_1;
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;
84 if ( voice_to_alloc_idx == 99 )
86 voice_to_alloc_idx = lowest_match;
88 voice_to_alloc_idx = _SsVmMaxVoice;
90 if ( voice_to_alloc_idx < _SsVmMaxVoice )
95 for ( v16 = 0; (u8)v16 < _SsVmMaxVoice; v16 += 1 )
99 voice_struct_1 = &_svm_voice[(u8)v16];
100 if ( (_snd_vmask & (1 << (u8)v16)) == 0 )
101 voice_struct_1->m_unk02 += 1;
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;
109 return voice_to_alloc_idx;