-
Notifications
You must be signed in to change notification settings - Fork 14
/
adpcmwave.py
47 lines (34 loc) · 1.21 KB
/
adpcmwave.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
import os
import subprocess
import tmpfile
import helper
def decode_data(data, rate, channels, bits):
input_filename = tmpfile.mkstemp()
output_filename = tmpfile.mkstemp()
with open(input_filename, "wb") as f:
f.write(data)
prefix = ""
if helper.is_wsl():
prefix = "./"
elif os.name != "nt":
prefix = "wine "
cmd = "{}adpcmwavetool.exe d \"{}\" \"{}\" {}".format(prefix, helper.get_windows_path(input_filename), helper.get_windows_path(output_filename), channels)
subprocess.call(cmd, shell=True)
with open(output_filename, "rb") as f:
data = bytearray(f.read())
return data
def encode_data(data, channels):
input_filename = tmpfile.mkstemp()
output_filename = tmpfile.mkstemp()
with open(input_filename, "wb") as f:
f.write(data)
prefix = ""
if helper.is_wsl():
prefix = "./"
elif os.name != "nt":
prefix = "wine "
cmd = "{}adpcmwavetool.exe e \"{}\" \"{}\" {}".format(prefix, helper.get_windows_path(input_filename), helper.get_windows_path(output_filename), channels)
subprocess.call(cmd, shell=True)
with open(output_filename, "rb") as f:
data = bytearray(f.read())
return data