Skip to content

Commit 5a4bd42

Browse files
committed
rescaled wav output
1 parent c52083e commit 5a4bd42

File tree

1 file changed

+20
-13
lines changed

1 file changed

+20
-13
lines changed

Exporter.py

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@ def __export(self, data, filename, normalize, samplingRate, bitsPerSample):
6868
assume_sorted=True, bounds_error=False, fill_value=0)
6969
dlg += 10
7070

71-
7271
arr = spl(xnew)
7372
dlg += 10
7473

@@ -78,18 +77,26 @@ def __export(self, data, filename, normalize, samplingRate, bitsPerSample):
7877
return
7978

8079
if normalize:
81-
# normalize values to -1.0 to 1.0
82-
arr = np.divide(arr, np.max(np.abs(arr)))
83-
dlg += 5
84-
85-
if dtype == np.dtype(np.uint8).type:
86-
arr = np.add(arr, 1)
87-
amplitude = amplitude // 2
88-
89-
arr = np.multiply(arr, amplitude)
90-
dlg += 5
91-
# samples only go from -(2**15) to (2**15) for 16-Bit PCM for example
92-
# => missing one possible value at (2**15)-1
80+
divide = np.max(np.abs(arr)) # scale to max range
81+
else:
82+
divide = 1000 #mA
83+
# scale to 1A maximum as per import into ltspice
84+
85+
# normalize values to -1.0 to 1.0
86+
arr = np.divide(arr, divide)
87+
dlg += 5
88+
89+
if dtype == np.dtype(np.uint8).type:
90+
arr = np.add(arr, 1)
91+
amplitude = amplitude // 2
92+
93+
arr = np.multiply(arr, amplitude)
94+
dlg += 5
95+
# samples only go from -(2**15) to (2**15) for 16-Bit PCM for example
96+
# => missing one possible value at (2**15)-1
97+
98+
if dtype != np.dtype(np.float).type:
99+
arr = np.round(arr, 0)
93100

94101
# convert to data type
95102
data_resampled = arr.astype(dtype)

0 commit comments

Comments
 (0)