質問編集履歴
1
ソースコードが読み込めない形式になっていたので変更しました。ご指摘ありがとうございます。
test
CHANGED
File without changes
|
test
CHANGED
@@ -12,87 +12,99 @@
|
|
12
12
|
|
13
13
|
### 該当のソースコード
|
14
14
|
|
15
|
+
```python
|
16
|
+
|
17
|
+
|
18
|
+
|
15
19
|
import wav
|
16
20
|
|
17
21
|
import numpy
|
18
22
|
|
19
23
|
|
20
24
|
|
21
|
-
|
25
|
+
freq = 500
|
26
|
+
|
27
|
+
low = 500
|
22
28
|
|
23
29
|
|
24
30
|
|
25
|
-
numch = wf.getnchannels() #チャンネル数
|
26
|
-
|
27
|
-
samplewidth = wf.getsampwidth()
|
28
|
-
|
29
|
-
|
31
|
+
wf = wave.open("sword-slash.wav", "rb")
|
30
|
-
|
31
|
-
numsamples = wf.getnframes() #フレーム数
|
32
32
|
|
33
33
|
|
34
34
|
|
35
|
-
|
35
|
+
numch = wf.getnchannels() #チャンネル数
|
36
36
|
|
37
|
-
|
37
|
+
samplewidth = wf.getsampwidth()
|
38
|
+
|
39
|
+
samplerate = wf.getframerate() #サンプリング周波数
|
40
|
+
|
41
|
+
numsamples = wf.getnframes() #フレーム数
|
38
42
|
|
39
43
|
|
40
44
|
|
41
|
-
|
45
|
+
buf = wf.readframes(wf.getnframes())
|
42
46
|
|
43
|
-
|
47
|
+
wf.close()
|
44
|
-
|
45
|
-
data = numpy.frombuffer(buf, dtype='int16')
|
46
|
-
|
47
|
-
after = numpy.zeros(numsamples, dtype='int16')
|
48
|
-
|
49
|
-
elif samplewidth == 4:
|
50
|
-
|
51
|
-
data = numpy.frombuffer(buf, dtype='int32')
|
52
|
-
|
53
|
-
after = numpy.zeros(numsamples, dtype='int32')
|
54
48
|
|
55
49
|
|
56
50
|
|
57
|
-
|
51
|
+
//配列に格納
|
58
52
|
|
53
|
+
if samplewidth == 2:
|
54
|
+
|
55
|
+
data = numpy.frombuffer(buf, dtype='int16')
|
56
|
+
|
57
|
+
after = numpy.zeros(numsamples, dtype='int16')
|
58
|
+
|
59
|
+
if samplewidth == 4:
|
60
|
+
|
61
|
+
data = numpy.frombuffer(buf, dtype='int32')
|
62
|
+
|
63
|
+
after = numpy.zeros(numsamples, dtype='int32')
|
64
|
+
|
65
|
+
|
66
|
+
|
67
|
+
N = numsamples
|
68
|
+
|
59
|
-
|
69
|
+
start = 0
|
60
70
|
|
61
71
|
|
62
72
|
|
63
|
-
|
73
|
+
G = numpy.fft.fft(data[start:start+N])
|
64
74
|
|
65
|
-
|
75
|
+
#G = abs(G)
|
66
76
|
|
67
|
-
|
77
|
+
flist = numpy.fft.fftfreq(N, d=1/samplerate)
|
68
78
|
|
69
79
|
|
70
80
|
|
71
|
-
|
81
|
+
G_roll = numpy.roll(flist, freq) #freq = 音の高さのパラメータ(音の高さを高くしたい)
|
72
82
|
|
73
|
-
|
83
|
+
G_roll[flist > low] = 0 #ローパスのパラメータ(lowより大きい周波数は0にしたい)
|
74
84
|
|
75
85
|
|
76
86
|
|
77
|
-
|
87
|
+
after = numpy.fft.ifft(G)
|
78
88
|
|
79
89
|
|
80
90
|
|
81
|
-
|
91
|
+
ww = wave.open("sample2.wav", "wb")
|
82
92
|
|
83
|
-
|
93
|
+
ww.setnchannels(numch)
|
84
94
|
|
85
|
-
|
95
|
+
ww.setsampwidth(samplewidth)
|
86
96
|
|
87
|
-
|
97
|
+
ww.setframerate(samplerate)
|
88
98
|
|
89
|
-
|
99
|
+
ww.setnframes(numsamples)
|
90
100
|
|
91
101
|
|
92
102
|
|
93
|
-
|
103
|
+
ww.writeframes(after)
|
94
104
|
|
95
105
|
|
106
|
+
|
107
|
+
```
|
96
108
|
|
97
109
|
|
98
110
|
|