-
Notifications
You must be signed in to change notification settings - Fork 6
/
format0025.c
100 lines (77 loc) · 2.91 KB
/
format0025.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
// Converts 0025 files to WAV
//FIXME: What's different with unk0 == 1 ?!
#include <stdint.h>
#include <stdbool.h>
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
// WAVE file header format
typedef struct {
unsigned char riff[4]; // RIFF string
unsigned int overall_size; // overall size of file in bytes
unsigned char wave[4]; // WAVE string
} RiffHeader;
typedef struct {
unsigned char fmt_chunk_marker[4];
unsigned int length_of_fmt; // length of the format data
uint16_t format_type; // format type. 1-PCM, 3- IEEE float, 6 - 8bit A law, 7 - 8bit mu law
uint16_t channels; // no.of channels
unsigned int sample_rate; // sampling rate (blocks per second)
unsigned int byterate; // SampleRate * NumChannels * BitsPerSample/8
uint16_t block_align; // NumChannels * BitsPerSample/8
uint16_t bits_per_sample; // bits per sample, 8- 8bits, 16- 16 bits etc
} WavHeader;
typedef struct {
unsigned char data_chunk_header[4]; // DATA string or FLLR string
unsigned int data_size; // NumSamples * NumChannels * BitsPerSample/8 - size of the next chunk that will be read
} WavDataHeader;
int main(int argc, char* argv[]) {
FILE* in = fopen(argv[1], "rb");
FILE* out = fopen(argv[2], "wb");
uint32_t unk0;
fread(&unk0, 4, 1, in);
printf("unk0: 0x%08X\n", unk0);
assert(unk0 == 0 || unk0 == 1);
uint8_t inWavHeader[16];
fread(&inWavHeader, sizeof(inWavHeader), 1, in);
RiffHeader riffHeader;
memcpy(riffHeader.riff, "RIFF", 4);
riffHeader.overall_size = 100000; //FIXME
memcpy(riffHeader.wave, "WAVE", 4);
fwrite(&riffHeader, sizeof(riffHeader), 1, out);
WavHeader wavHeader;
memcpy(wavHeader.fmt_chunk_marker, "fmt ", 4);
wavHeader.length_of_fmt = 16;
memcpy(&wavHeader.format_type, inWavHeader, sizeof(inWavHeader));
fwrite(&wavHeader, sizeof(wavHeader), 1, out);
WavDataHeader wavDataHeader;
fread(&wavDataHeader.data_chunk_header, 4, 1, in);
//FIXME: Assert that this header reads "wave" now
uint32_t unk1;
fread(&unk1, 4, 1, in);
printf("unk1: 0x%08X (%d)\n", unk1, unk1);
assert(unk1 == 1);
// FIXME: Assert zero
fseek(in, 28, SEEK_CUR);
uint32_t unk2;
fread(&unk2, 4, 1, in);
printf("unk2: 0x%08X (%d)\n", unk2, unk2);
fread(&wavDataHeader.data_size, 4, 1, in);
printf("data size: %d bytes\n", wavDataHeader.data_size);
fwrite(&wavDataHeader, sizeof(wavDataHeader), 1, out);
uint32_t unk3;
fread(&unk3, 4, 1, in);
printf("unk3: 0x%08X (%d)\n", unk3, unk3);
fseek(in, 1980, SEEK_CUR);
assert(ftell(in) == 2048);
//FIXME: Loop until dataLength instead
while(!feof(in)) {
uint8_t b;
fread(&b, 1, 1, in);
fwrite(&b, 1, 1, out);
}
fclose(in);
fclose(out);
return 0;
}