|
21 | 21 |
|
22 | 22 |
|
23 | 23 | def get_fmod_path(
|
24 |
| - system: Union["Windows", "Linux", "Darwin"], arch: ["x64", "x86", "arm"] |
| 24 | + system: Union["Windows", "Linux", "Darwin"], arch: ["x64", "x86", "arm", "arm64"] |
25 | 25 | ) -> str:
|
26 | 26 | if system == "Darwin":
|
27 | 27 | # universal dylib
|
@@ -55,6 +55,9 @@ def import_pyfmodex():
|
55 | 55 | elif arch == "64bit":
|
56 | 56 | arch = "x64"
|
57 | 57 |
|
| 58 | + if system == "Linux" and "aarch64" in platform.machine(): |
| 59 | + arch = "arm64" |
| 60 | + |
58 | 61 | fmod_rel_path = get_fmod_path(system, arch)
|
59 | 62 | fmod_path = os.path.join(
|
60 | 63 | os.path.dirname(os.path.dirname(os.path.realpath(__file__))), fmod_rel_path
|
@@ -135,33 +138,59 @@ def dump_samples(clip: AudioClip, audio_data: bytes) -> Dict[str, bytes]:
|
135 | 138 |
|
136 | 139 | def subsound_to_wav(subsound) -> bytes:
|
137 | 140 | # get sound settings
|
| 141 | + sound_format = subsound.format.format |
138 | 142 | length = subsound.get_length(pyfmodex.enums.TIMEUNIT.PCMBYTES)
|
139 | 143 | channels = subsound.format.channels
|
140 | 144 | bits = subsound.format.bits
|
141 | 145 | sample_rate = int(subsound.default_frequency)
|
142 | 146 |
|
143 |
| - # write to buffer |
144 |
| - w = EndianBinaryWriter(endian="<") |
145 |
| - # riff chucnk |
146 |
| - w.write(b"RIFF") |
147 |
| - w.write_int(length + 36) # sizeof(FmtChunk) + sizeof(RiffChunk) + length |
148 |
| - w.write(b"WAVE") |
149 |
| - # fmt chunck |
150 |
| - w.write(b"fmt ") |
151 |
| - w.write_int(16) # sizeof(FmtChunk) - sizeof(RiffChunk) |
152 |
| - w.write_short(1) |
153 |
| - w.write_short(channels) |
154 |
| - w.write_int(sample_rate) |
155 |
| - w.write_int(sample_rate * channels * bits // 8) |
156 |
| - w.write_short(channels * bits // 8) |
157 |
| - w.write_short(bits) |
158 |
| - # data chunck |
159 |
| - w.write(b"data") |
160 |
| - w.write_int(length) |
161 |
| - # data |
162 |
| - lock = subsound.lock(0, length) |
163 |
| - for ptr, length in lock: |
164 |
| - ptr_data = ctypes.string_at(ptr, length.value) |
165 |
| - w.write(ptr_data) |
166 |
| - subsound.unlock(*lock) |
167 |
| - return w.bytes |
| 147 | + |
| 148 | + if sound_format == pyfmodex.enums.SOUND_FORMAT.PCM16: |
| 149 | + # write to buffer |
| 150 | + w = EndianBinaryWriter(endian="<") |
| 151 | + # riff chucnk |
| 152 | + w.write(b"RIFF") |
| 153 | + w.write_int(length + 36) # sizeof(FmtChunk) + sizeof(RiffChunk) + length |
| 154 | + w.write(b"WAVE") |
| 155 | + # fmt chunck |
| 156 | + w.write(b"fmt ") |
| 157 | + w.write_int(16) # sizeof(FmtChunk) - sizeof(RiffChunk) |
| 158 | + w.write_short(1) |
| 159 | + w.write_short(channels) |
| 160 | + w.write_int(sample_rate) |
| 161 | + w.write_int(sample_rate * channels * bits // 8) |
| 162 | + w.write_short(channels * bits // 8) |
| 163 | + w.write_short(bits) |
| 164 | + # data chunck |
| 165 | + w.write(b"data") |
| 166 | + w.write_int(length) |
| 167 | + # data |
| 168 | + lock = subsound.lock(0, length) |
| 169 | + for ptr, length in lock: |
| 170 | + ptr_data = ctypes.string_at(ptr, length.value) |
| 171 | + w.write(ptr_data) |
| 172 | + subsound.unlock(*lock) |
| 173 | + return w.bytes |
| 174 | + elif sound_format== pyfmodex.enums.SOUND_FORMAT.PCMFLOAT: |
| 175 | + w = EndianBinaryWriter(endian="<") |
| 176 | + w.write(b"RIFF") |
| 177 | + w.write_int(length + 44) |
| 178 | + w.write(b"WAVE") |
| 179 | + w.write(b"fmt ") |
| 180 | + w.write_int(16) |
| 181 | + w.write_short(3) |
| 182 | + w.write_short(subsound.format.channels) |
| 183 | + w.write_int(int(subsound.default_frequency)) |
| 184 | + w.write_int(int(subsound.default_frequency * subsound.format.channels * subsound.format.bits/8)) |
| 185 | + w.write_short(int(subsound.format.channels * subsound.format.bits/8)) |
| 186 | + w.write_short(32) |
| 187 | + w.write(b"data") |
| 188 | + w.write_int(length) |
| 189 | + lock = subsound.lock(0, length) |
| 190 | + for ptr, length in lock: |
| 191 | + ptr_data = ctypes.string_at(ptr, length.value) |
| 192 | + w.write(ptr_data) |
| 193 | + subsound.unlock(*lock) |
| 194 | + return w.bytes |
| 195 | + else: |
| 196 | + raise NotImplementedError("Sound format " + sound_format + " is not supported.") |
0 commit comments