forked from sacchy777/mid2wav
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwtssynth_def.rb
125 lines (109 loc) · 4.2 KB
/
wtssynth_def.rb
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
=begin
* wtssynth_def.c generator
*
* freq_table.rb
*
*
* Copyright (c) 2013 sada.gussy (sada dot gussy at gmail dot com)
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
=end
SOURCE_FILE = "wtssynth_def.c"
def square(duty)
res = ""
res += "{"
32.times do |i|
res += i < duty ? "1.0, " : "-1.0, "
end
res += "}, "
res
end
def tria(duty) # duty 1..30
if duty == 0 or duty == 31
saw
return
end
r = -1.0
res = ""
res += "{"
32.times do |i|
if i < duty
res += (2.0 * i / duty - 1.0).to_s + ", "
elsif i > duty
res += (1.0 - 2.0 * (i - duty ) / (31 - duty) ).to_s + ", "
else
res += "1.0, "
end
end
res += "}, "
res
end
def saw
i = -1.0
res = ""
res += "{"
32.times do |i|
res += (- 2.0 * i/31.0 + 1.0).to_s + ", "
end
res += "}, "
res
end
def sin
res = ""
res += "{"
32.times do |i|
res += Math.sin(Math::PI * 2.0 * i /32).to_s + ", "
end
res += "}, "
res
end
def noise
res = ""
res += "{"
32.times do |i|
res += (rand()*2.0-1.0).to_s + ", "
end
res += "}, "
res
end
source_file = <<EOD
#include "wtssynth.h"
const wtstone_t wtstone_wave_presets[WTSTONE_NUM_PRESETS] = {
EOD
source_file += # at tl dt sl rt dummy
" {" + tria(3) + "0.0/44100.0, 0.5, 40000.0/44100.0, 0.01, 20000.0/44100.0, 0,0,0,0" + " },\n" + # @1-8, piano
" {" + square(15) + "0.0/44100.0, 0.3, 4000.0/44100.0, 0.01, 4000.0/44100.0, 0,0,0,0" + " },\n" + # @9-16, chromatic percussion
" {" + tria(15) + "0.0/44100.0, 0.90, 0.0/44100.0, 0.5, 4000.0/44100.0, 0,0,0,0" + " },\n" + # @17-24, organ
" {" + square(3) + "400.0/44100.0, 0.4, 60000.0/44100.0, 0.05, 10000.0/44100.0, 0,0,0,0" + " },\n" + # @25-32, guitar
" {" + saw + "0.0/44100.0, 0.5, 20000.0/44100.0, 0.05, 10000.0/44100.0, 0,0,0,0" + " },\n" + # @33-40, bass
" {" + tria(3) + "400.0/44100.0, 0.5, 100000.0/44100.0, 0.10, 30000.0/44100.0, 0,0,0,0" + " },\n" + # @41-48, strings
" {" + saw + "4000.0/44100.0, 0.3, 200000.0/44100.0, 0.05, 80000.0/44100.0, 0,0,0,0" + " },\n" + # @49-56, ensamble
" {" + square(3) + "4000.0/44100.0, 0.3, 200000.0/44100.0, 0.15, 40000.0/44100.0, 0,0,0,0" + " },\n" + # @57-64, brass
" {" + square(15) + "4000.0/44100.0, 0.3, 200000.0/44100.0, 0.05, 40000.0/44100.0, 0,0,0,0" + " },\n" + # @65-72, reed
" {" + tria(15) + "400.0/44100.0, 0.90, 100000.0/44100.0, 0.1, 10000.0/44100.0, 0,0,0,0" + " },\n" + # @73-80, woodwind
" {" + square(7) + "4000.0/44100.0, 0.3, 200000.0/44100.0, 0.1, 10000.0/44100.0, 0,0,0,0" + " },\n" + # @81-88, synth lead
" {" + tria(7) + "4000.0/44100.0, 0.6, 200000.0/44100.0, 0.05, 40000.0/44100.0, 0,0,0,0" + " },\n" + # @89-96, synth pad
" {" + noise + "4000.0/44100.0, 0.5, 1000.0/44100.0, 0.1, 4000.0/44100.0, 0,0,0,0" + " },\n" + # @97-104, synth effect
" {" + square(3) + "400.0/44100.0, 0.5, 1000.0/44100.0, 0.01, 4000.0/44100.0, 0,0,0,0" + " },\n" + # @105-112, ethnic
" {" + noise + "0.0/44100.0, 0.5, 100.0/44100.0, 0.0, 400.0/44100.0, 0,0,0,0" + " },\n" + # @113-128, purcussive
"" # end of tone parameters
source_file += <<EOD
};
EOD
File.write(SOURCE_FILE, source_file)