Skip to content

Commit 09919e1

Browse files
martinwang2002K0lb3
authored andcommitted
feat: arm64 for fmod and AudioClipConverter
1 parent 6daa1f7 commit 09919e1

File tree

3 files changed

+55
-26
lines changed

3 files changed

+55
-26
lines changed

UnityPy/export/AudioClipConverter.py

Lines changed: 55 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121

2222

2323
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"]
2525
) -> str:
2626
if system == "Darwin":
2727
# universal dylib
@@ -55,6 +55,9 @@ def import_pyfmodex():
5555
elif arch == "64bit":
5656
arch = "x64"
5757

58+
if system == "Linux" and "aarch64" in platform.machine():
59+
arch = "arm64"
60+
5861
fmod_rel_path = get_fmod_path(system, arch)
5962
fmod_path = os.path.join(
6063
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]:
135138

136139
def subsound_to_wav(subsound) -> bytes:
137140
# get sound settings
141+
sound_format = subsound.format.format
138142
length = subsound.get_length(pyfmodex.enums.TIMEUNIT.PCMBYTES)
139143
channels = subsound.format.channels
140144
bits = subsound.format.bits
141145
sample_rate = int(subsound.default_frequency)
142146

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.")

UnityPy/lib/FMOD/Linux/arm64/__init__.py

Whitespace-only changes.
1.2 MB
Binary file not shown.

0 commit comments

Comments
 (0)