Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
MorsGames
GitHub Repository: MorsGames/sm64plus
Path: blob/master/tools/util/generate_audiofile_cpp.py
7858 views
1
#!/usr/bin/env python
2
3
import os
4
import re
5
import sys
6
7
file_list = [
8
'Features.h',
9
'Compiler.h',
10
'error.h',
11
'extended.h',
12
'compression.h',
13
'aupvinternal.h',
14
'aupvlist.h',
15
'audiofile.h',
16
'afinternal.h',
17
'byteorder.h',
18
'AudioFormat.h',
19
'debug.h',
20
'util.h',
21
'units.h',
22
'UUID.h',
23
'Shared.h',
24
'Buffer.h',
25
'File.h',
26
'FileHandle.h',
27
'Instrument.h',
28
'Track.h',
29
'Marker.h',
30
'Setup.h',
31
'Tag.h',
32
'PacketTable.h',
33
'pcm.h',
34
'g711.h',
35
'af_vfs.h',
36
'Raw.h',
37
'WAVE.h',
38
'SampleVision.h',
39
'modules/Module.h',
40
'modules/ModuleState.h',
41
'modules/SimpleModule.h',
42
'modules/FileModule.h',
43
'modules/RebufferModule.h',
44
'modules/BlockCodec.h',
45
'modules/BlockCodec.cpp',
46
'modules/FileModule.cpp',
47
'modules/G711.h',
48
'modules/G711.cpp',
49
'modules/Module.cpp',
50
'modules/ModuleState.cpp',
51
'modules/MSADPCM.h',
52
'modules/MSADPCM.cpp',
53
'modules/PCM.h',
54
'modules/PCM.cpp',
55
'modules/SimpleModule.cpp',
56
'modules/RebufferModule.cpp',
57
'AIFF.h',
58
'AIFF.cpp',
59
'AudioFormat.cpp',
60
'Buffer.cpp',
61
'File.cpp',
62
'FileHandle.cpp',
63
'Instrument.cpp',
64
'Loop.cpp',
65
'Marker.cpp',
66
'Miscellaneous.cpp',
67
'PacketTable.cpp',
68
'Raw.cpp',
69
'Setup.cpp',
70
'Track.cpp',
71
'UUID.cpp',
72
'WAVE.cpp',
73
'aes.cpp',
74
'af_vfs.cpp',
75
'aupv.c',
76
'compression.cpp',
77
'data.cpp',
78
'debug.cpp',
79
'error.c',
80
'extended.c',
81
'format.cpp',
82
'g711.c',
83
'openclose.cpp',
84
'pcm.cpp',
85
'query.cpp',
86
'units.cpp',
87
'util.cpp',
88
]
89
90
file_header = \
91
"""// libaudiofile b62c902
92
// https://github.com/mpruett/audiofile
93
// To simplify compilation, all files have been concatenated into one.
94
// Support for all formats except WAVE, AIFF(C) and RAW has been stripped out.
95
"""
96
97
prepend_defs = \
98
"""#define HAVE_UNISTD_H 1
99
#if defined __BIG_ENDIAN__
100
# define WORDS_BIGENDIAN 1
101
#endif
102
#include <stdlib.h>
103
"""
104
105
def banned(line):
106
return '#pragma once' in line or '#include "' in line or '#include <config.h>' in line
107
108
def cat_file(fout, fin_name):
109
with open(fin_name) as fin:
110
lines = fin.readlines()
111
lines = [l.rstrip() for l in lines if not banned(l)]
112
for l in lines:
113
fout.write(l + '\n')
114
fout.write('\n')
115
116
def combine_libaudiofile(fout_name, libaudiofile_path):
117
with open(fout_name, 'w') as fout:
118
fout.write(file_header + "\n")
119
fout.write("/*\n")
120
cat_file(fout, os.path.join(libaudiofile_path, '../COPYING'))
121
fout.write("*/\n\n")
122
fout.write(prepend_defs + "\n")
123
for f in file_list:
124
fout.write(f"// file: {f}\n")
125
cat_file(fout, os.path.join(libaudiofile_path, f))
126
127
def main():
128
if len(sys.argv) > 1 and sys.argv[1] in ['-h', '--help']:
129
print('Usage: generate_audiofile_cpp.py [output_filename] [libaudiofile_src_dir]')
130
print('Defaults: [output_filename = "audiofile.cpp"] [libaudiofile_src_dir = "./audiofile/libaudiofile"]')
131
return
132
fout_name = sys.argv[1] if len(sys.argv) > 1 else 'audiofile.cpp'
133
libaudiofile_path = sys.argv[2] if len(sys.argv) > 2 else './audiofile/libaudiofile'
134
combine_libaudiofile(fout_name, os.path.expanduser(libaudiofile_path))
135
136
main()
137
138