-
Notifications
You must be signed in to change notification settings - Fork 0
/
out_raw.c
51 lines (43 loc) · 1.46 KB
/
out_raw.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#include "main.h"
int out_raw(unsigned char ** out_buffer, unsigned int const * frequencies, unsigned int const * volumes,
const unsigned long frame_count, const unsigned int n) {
unsigned char * out_buffer_value;
unsigned long idx;
unsigned long data_idx = 0;
unsigned int c, frequency;
unsigned long f;
if (n < 256) {
file_length = ((frame_count * psg_channels * 2) + 1); // Frequency(byte)/volume pairs
*out_buffer = calloc(file_length, sizeof(unsigned char));
if (*out_buffer == NULL)
return 0;
out_buffer_value = *out_buffer;
// For each frame
for (f = 0; f < frame_count - 1; f++) {
// For each channel
for (c = 0; c < psg_channels; c++) {
idx = (f * psg_channels) + c;
out_buffer_value[data_idx++] = frequencies[idx];
out_buffer_value[data_idx++] = volumes[idx];
}
}
} else {
file_length = ((frame_count * psg_channels * 3) + 1); // Frequency(word)/volume pairs
*out_buffer = calloc(file_length, sizeof(unsigned char));
if (*out_buffer == NULL)
return 0;
out_buffer_value = *out_buffer;
// For each frame
for (f = 0; f < frame_count - 1; f++) {
// For each channel
for (c = 0; c < psg_channels; c++) {
idx = (f * psg_channels) + c;
frequency = frequencies[idx];
out_buffer_value[data_idx++] = frequency >> 8;
out_buffer_value[data_idx++] = frequency & 0xFF;
out_buffer_value[data_idx++] = volumes[idx];
}
}
}
return 1;
}