forked from gameblabla/sm64-port
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathgenerate_audiofile_cpp.py
136 lines (127 loc) · 3.25 KB
/
generate_audiofile_cpp.py
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
#!/usr/bin/env python
import os
import re
import sys
file_list = [
'Features.h',
'Compiler.h',
'error.h',
'extended.h',
'compression.h',
'aupvinternal.h',
'aupvlist.h',
'audiofile.h',
'afinternal.h',
'byteorder.h',
'AudioFormat.h',
'debug.h',
'util.h',
'units.h',
'UUID.h',
'Shared.h',
'Buffer.h',
'File.h',
'FileHandle.h',
'Instrument.h',
'Track.h',
'Marker.h',
'Setup.h',
'Tag.h',
'PacketTable.h',
'pcm.h',
'g711.h',
'af_vfs.h',
'Raw.h',
'WAVE.h',
'SampleVision.h',
'modules/Module.h',
'modules/ModuleState.h',
'modules/SimpleModule.h',
'modules/FileModule.h',
'modules/RebufferModule.h',
'modules/BlockCodec.h',
'modules/BlockCodec.cpp',
'modules/FileModule.cpp',
'modules/G711.h',
'modules/G711.cpp',
'modules/Module.cpp',
'modules/ModuleState.cpp',
'modules/MSADPCM.h',
'modules/MSADPCM.cpp',
'modules/PCM.h',
'modules/PCM.cpp',
'modules/SimpleModule.cpp',
'modules/RebufferModule.cpp',
'AIFF.h',
'AIFF.cpp',
'AudioFormat.cpp',
'Buffer.cpp',
'File.cpp',
'FileHandle.cpp',
'Instrument.cpp',
'Loop.cpp',
'Marker.cpp',
'Miscellaneous.cpp',
'PacketTable.cpp',
'Raw.cpp',
'Setup.cpp',
'Track.cpp',
'UUID.cpp',
'WAVE.cpp',
'aes.cpp',
'af_vfs.cpp',
'aupv.c',
'compression.cpp',
'data.cpp',
'debug.cpp',
'error.c',
'extended.c',
'format.cpp',
'g711.c',
'openclose.cpp',
'pcm.cpp',
'query.cpp',
'units.cpp',
'util.cpp',
]
file_header = \
"""// libaudiofile b62c902
// https://github.com/mpruett/audiofile
// To simplify compilation, all files have been concatenated into one.
// Support for all formats except WAVE, AIFF(C) and RAW has been stripped out.
"""
prepend_defs = \
"""#define HAVE_UNISTD_H 1
#if defined __BIG_ENDIAN__
# define WORDS_BIGENDIAN 1
#endif
#include <stdlib.h>
"""
def banned(line):
return '#pragma once' in line or '#include "' in line or '#include <config.h>' in line
def cat_file(fout, fin_name):
with open(fin_name) as fin:
lines = fin.readlines()
lines = [l.rstrip() for l in lines if not banned(l)]
for l in lines:
fout.write(l + '\n')
fout.write('\n')
def combine_libaudiofile(fout_name, libaudiofile_path):
with open(fout_name, 'w') as fout:
fout.write(file_header + "\n")
fout.write("/*\n")
cat_file(fout, os.path.join(libaudiofile_path, '../COPYING'))
fout.write("*/\n\n")
fout.write(prepend_defs + "\n")
for f in file_list:
fout.write(f"// file: {f}\n")
cat_file(fout, os.path.join(libaudiofile_path, f))
def main():
if len(sys.argv) > 1 and sys.argv[1] in ['-h', '--help']:
print('Usage: generate_audiofile_cpp.py [output_filename] [libaudiofile_src_dir]')
print('Defaults: [output_filename = "audiofile.cpp"] [libaudiofile_src_dir = "./audiofile/libaudiofile"]')
return
fout_name = sys.argv[1] if len(sys.argv) > 1 else 'audiofile.cpp'
libaudiofile_path = sys.argv[2] if len(sys.argv) > 2 else './audiofile/libaudiofile'
combine_libaudiofile(fout_name, os.path.expanduser(libaudiofile_path))
main()