-
Notifications
You must be signed in to change notification settings - Fork 24
/
fade_out_the_end_of_sound_file.praat
81 lines (67 loc) · 2.27 KB
/
fade_out_the_end_of_sound_file.praat
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# This script will fade out the end of a sound file
# by filtering it with the latter half of a Hanning window.
#
# This script is distributed under the GNU General Public License.
# Copyright Mietta Lennes 25.9.2003
#
form Fade out the end of a sound file
comment Give the directory path of the original sound:
text file /home/lennes/projektit/cbru/syllables/1ka2_takka.wav
comment Give the directory path of the resulting sound:
text file2 /home/lennes/tmp/filtered.wav
positive Fade_from_time_(s) 0.05
positive zero_at_time 0.09
endform
if fileReadable (file$)
Read from file... 'file$'
# Test that the sound has the minimum duration required:
duration = Get duration
if duration >= zero_at_time
#you can uncomment the next line if you want a copy of the original sound somewhere...
#Write to WAV file... /home/lennes/tmp/original.wav
call CutSoundToDuration zero_at_time
call Fadeout fade_from_time
Write to WAV file... 'file2$'
else
printline File 'file$' is not long enough for fading!
printline (it's only about 'duration:5' seconds)
endif
Remove
else
printline File 'file$' is not readable.
endif
#-----
#
procedure CutSoundToDuration tempdur
sound$ = selected$ ("Sound")
Extract part... 0 tempdur Rectangular 1.0 no
Rename... temp
select Sound 'sound$'
Remove
select Sound temp
Rename... 'sound$'
endproc
#-----
# This procedure filters the end of the sound object with a Hanning window.
procedure Fadeout fadetime
numberOfSamples = Get number of samples
index_at_fadetime = Get index from time... fadetime
index_at_fadetime = index_at_fadetime - 1
effective_samples = numberOfSamples - index_at_fadetime
doubled_effective_samples = effective_samples * 2
printline Filtering sound...
for index from index_at_fadetime to numberOfSamples
oldvalue = Get value at index... index
effective_index = index - index_at_fadetime
if effective_index > 0
# The following is supposed to implement the latter half of the Hanning window:
newvalue = oldvalue * (0.5 * (1 - (cos ((2 * pi * (effective_index + effective_samples)) / (doubled_effective_samples - 1)))))
if index < numberOfSamples
Set value at index... index newvalue
else
# The very last sample should have zero value.
Set value at index... index 0
endif
endif
endfor
endproc