PS2SDK
PS2 Homebrew Libraries
sepinit.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 _SsInitSoundSep(s16 sep_no, int seq_no, u8 vab_id, u8 *addr)
14 {
15  int v5;
16  int v6;
17  libsnd2_sequence_struct_t *score_struct;
18  u8 v13;
19  u8 v15;
20  u8 v16;
21  u8 v17;
22  int tempo;
23  char v20;
24  char v21;
25  int v22;
26  u8 v23;
27  u8 v24;
28  u8 v25;
29  s32 delta_value;
30  int v27;
31  unsigned int v28;
32  int tmp1;
33  unsigned int tmp2;
34  int v33;
35 
36  v5 = 0;
37  score_struct = &_ss_score[sep_no][seq_no];
38  score_struct->m_l_count = 1;
39  score_struct->m_unk15 = 0;
40  score_struct->m_running_status = 0;
41  score_struct->m_channel_idx = 0;
42  score_struct->m_unk18 = 0;
43  score_struct->m_unk19 = 0;
44  score_struct->m_fn_idx = 0;
45  score_struct->m_unk1B = 0;
46  score_struct->m_unk1C = 0;
47  score_struct->m_unk1D = 0;
48  score_struct->m_unk1E = 0;
49  score_struct->m_unk1F = 0;
50  score_struct->m_play_mode = SSPLAY_PAUSE;
51  score_struct->m_unk21 = 0;
52  score_struct->m_unk52 = 1;
53  score_struct->m_resolution_of_quarter_note = 0;
54  score_struct->m_vab_id = vab_id;
55  score_struct->m_unk56 = 0;
56  score_struct->m_unk84 = 0;
57  score_struct->m_unk88 = 0;
58  score_struct->m_tempo = 0;
59  score_struct->m_delta_value = 0;
60  score_struct->m_channel_mute = 0;
61  score_struct->m_rhythm_n = 0;
62  score_struct->m_rhythm_d = 0;
63  for ( v6 = 0; v6 < 16; v6 += 1 )
64  {
65  score_struct->m_panpot[v6] = 64;
66  score_struct->m_programs[v6] = v6;
67  score_struct->m_vol[v6] = 127;
68  }
69  score_struct->m_seq_ptr = addr;
70  if ( (seq_no & 0xFFFF) != 0 )
71  {
72  score_struct->m_seq_ptr += 2;
73  v5 = 2;
74  }
75  else
76  {
77  int v10;
78 
79  v10 = *addr;
80  if ( v10 == 0x53 || v10 == 0x70 )
81  {
82  int v11;
83 
84  score_struct->m_seq_ptr += 5;
85  v11 = *(score_struct->m_seq_ptr);
86  score_struct->m_seq_ptr += 1;
87  if ( v11 )
88  {
89  printf("This is not SEP Data.\n");
90  return -1;
91  }
92  score_struct->m_seq_ptr += 2;
93  v5 = 8;
94  }
95  }
96  v13 = *(score_struct->m_seq_ptr);
97  score_struct->m_seq_ptr += 1;
98  v15 = *(score_struct->m_seq_ptr);
99  score_struct->m_seq_ptr += 1;
100  score_struct->m_resolution_of_quarter_note = v15 | (v13 << 8);
101  v16 = *(score_struct->m_seq_ptr);
102  score_struct->m_seq_ptr += 1;
103  v17 = *(score_struct->m_seq_ptr);
104  score_struct->m_seq_ptr += 1;
105  tempo = 60000000 / ((v16 << 16) | (v17 << 8) | *(score_struct->m_seq_ptr));
106  score_struct->m_seq_ptr += 1;
107  score_struct->m_tempo = tempo;
108  score_struct->m_unk94 = score_struct->m_tempo;
109  v20 = *(score_struct->m_seq_ptr);
110  score_struct->m_seq_ptr += 1;
111  score_struct->m_rhythm_n = v20;
112  v21 = *(score_struct->m_seq_ptr);
113  score_struct->m_seq_ptr += 1;
114  score_struct->m_rhythm_d = v21;
115  v22 = *(score_struct->m_seq_ptr);
116  score_struct->m_seq_ptr += 1;
117  v23 = *(score_struct->m_seq_ptr);
118  score_struct->m_seq_ptr += 1;
119  v24 = *(score_struct->m_seq_ptr);
120  score_struct->m_seq_ptr += 1;
121  v25 = *(score_struct->m_seq_ptr);
122  score_struct->m_seq_ptr += 1;
123  v27 = (v22 << 24) + (v23 << 16) + (v24 << 8) + v25;
124  delta_value = _SsReadDeltaValue(sep_no, seq_no);
125  v28 = score_struct->m_resolution_of_quarter_note * score_struct->m_tempo;
126  score_struct->m_unk84 = delta_value;
127  score_struct->m_delta_value = delta_value;
128  score_struct->m_unk10 = 0;
129  score_struct->m_unk08 = score_struct->m_seq_ptr;
130  score_struct->m_unk04 = score_struct->m_seq_ptr;
131  score_struct->m_unk0C = score_struct->m_seq_ptr;
132  tmp1 = VBLANK_MINUS;
133  tmp2 = 60 * tmp1;
134  v33 = v5 + 11;
135  if ( 10 * v28 < (unsigned int)(60 * tmp1) )
136  {
137  unsigned int v34;
138 
139  if ( !v28 )
140  __builtin_trap();
141  v34 = 600 * tmp1 / v28;
142  score_struct->m_unk52 = v34;
143  score_struct->m_unk54 = v34;
144  }
145  else
146  {
147  unsigned int v36;
148  unsigned int v37;
149 
150  v36 = 10 * score_struct->m_resolution_of_quarter_note * score_struct->m_tempo / tmp2;
151  v37 = 10 * score_struct->m_resolution_of_quarter_note * score_struct->m_tempo % tmp2;
152  score_struct->m_unk52 = -1;
153  score_struct->m_unk54 = v36;
154  if ( (unsigned int)(30 * tmp1) < v37 )
155  {
156  score_struct->m_unk54 = v36 + 1;
157  }
158  }
159  score_struct->m_unk56 = score_struct->m_unk54;
160  return v33 + v27;
161 }
libsnd2_sequence_struct_
Definition: libsnd2_internal.h:47