Skip to content

Commit

Permalink
rescaled wav output
Browse files Browse the repository at this point in the history
  • Loading branch information
playduck committed Apr 21, 2020
1 parent c52083e commit 5a4bd42
Showing 1 changed file with 20 additions and 13 deletions.
33 changes: 20 additions & 13 deletions Exporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ def __export(self, data, filename, normalize, samplingRate, bitsPerSample):
assume_sorted=True, bounds_error=False, fill_value=0)
dlg += 10


arr = spl(xnew)
dlg += 10

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

if normalize:
# normalize values to -1.0 to 1.0
arr = np.divide(arr, np.max(np.abs(arr)))
dlg += 5

if dtype == np.dtype(np.uint8).type:
arr = np.add(arr, 1)
amplitude = amplitude // 2

arr = np.multiply(arr, amplitude)
dlg += 5
# samples only go from -(2**15) to (2**15) for 16-Bit PCM for example
# => missing one possible value at (2**15)-1
divide = np.max(np.abs(arr)) # scale to max range
else:
divide = 1000 #mA
# scale to 1A maximum as per import into ltspice

# normalize values to -1.0 to 1.0
arr = np.divide(arr, divide)
dlg += 5

if dtype == np.dtype(np.uint8).type:
arr = np.add(arr, 1)
amplitude = amplitude // 2

arr = np.multiply(arr, amplitude)
dlg += 5
# samples only go from -(2**15) to (2**15) for 16-Bit PCM for example
# => missing one possible value at (2**15)-1

if dtype != np.dtype(np.float).type:
arr = np.round(arr, 0)

# convert to data type
data_resampled = arr.astype(dtype)
Expand Down

0 comments on commit 5a4bd42

Please # to comment.