7
7
import pandas as pd
8
8
import numpy as np
9
9
from scipy .io import wavfile
10
- from scipy .signal import resample
10
+ from scipy .interpolate import interp1d
11
11
import wave
12
12
import Config
13
13
@@ -26,6 +26,7 @@ def __saveDialog(filetype):
26
26
# function based on
27
27
# https://stackoverflow.com/a/41586167/12231900
28
28
def __exportWave (data , filename ):
29
+ SMPLS = 44100
29
30
# normalize values to -1.0 to 1.0
30
31
arr = np .array (data .interpData ["y" ])
31
32
arr = np .divide (arr , np .max (np .abs (data .interpData ["y" ])))
@@ -36,12 +37,22 @@ def __exportWave(data, filename):
36
37
# samples only go from -(2**15) to (2**15)
37
38
# => missing one possible value at (2**15)-1
38
39
39
- # resample values, otherwise length wont match (?)
40
- data_resampled = resample ( arr , len (data .interpData ["y" ]) )
40
+ # resample values with same algorithms to match sampling rate
41
+ xnew = np .linspace (
42
+ data .interpData ["x" ].min (), # from
43
+ data .interpData ["x" ].max (), # to
44
+ int (
45
+ np .ceil (((data .interpData ["x" ].max () - data .interpData ["x" ].min ()) / Config .DIVISION ) * SMPLS )
46
+ )
47
+ )
48
+ spl = interp1d (data .interpData ["x" ], data .interpData ["y" ], kind = data .config ["interpolation" ], copy = True ,
49
+ assume_sorted = True , bounds_error = False , fill_value = 0 )
50
+ data_resampled = spl (xnew )
51
+
41
52
# convert for 16 bit PCM
42
53
data_resampled = data_resampled .astype (np .int16 )
43
54
44
- wavfile .write (filename , 44100 , data_resampled )
55
+ wavfile .write (filename , SMPLS , data_resampled )
45
56
46
57
47
58
def export (data , export ):
0 commit comments