-
Notifications
You must be signed in to change notification settings - Fork 0
/
stegtest.rb
177 lines (165 loc) · 2.99 KB
/
stegtest.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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
#Steganography2a.rb
# 18 Oct 2017
#helper function
define :midi2note do |n2|
nn1=note(n2)
if nn1==nil
return nn1
else
nn1= note_info(nn1)
nnn1=nn1.to_s.split(":")
mmm1= nnn1[3].chop
return mmm1
end
end # midi2note
define :listnotes do |n1|
i1=0
while i1<n1.length
puts midi2note(n1[i1])
i1+=1
end
end
#define intervals
octave=12
#Define tempo and note lengths
#####
tempo=1.0 ### try changing tempo 0.75
#define note timings
whole=1.0
half=whole/2.0
#dothalf=half*1.5
quart=half/2.0
#dotquart=quart*1.5
eighth=quart/2.0
#doteighth=eighth*1.5
sixteenth=eighth/2
#########
### try different keys
key= note(:c4)
puts midi2note(key)
puts " "
### try minor
puts scale_names
mode= :major
#:dorian
#:zhi
#:yu
#:major
# setup chord progression in a and b
a=chord_invert(chord_degree :i, key, mode,3),0
listnotes (a)
b=chord_invert(chord_degree :ii, key, mode,3),0
listnotes(b)
### create list of possible melody notes that will blend
# with the chord progression avoid playing notes that differ by
# a halftone in pitch by inserting a rest in the melody
c1=scale(key,mode)
i=0
c=[[],[],[],[],[],[]]
while i<(c1.length-1)
j=0
while j<6
c[j]=c[j].push c1[i]
j+=1
end
i+=1
end
puts "c",midi2note(c[0][6])
c[0][6]=nil
puts c[0]
puts "e",midi2note(c[1][3])
c[1][3]=nil
puts c[1]
puts "g",c[2]
puts "d",c[3]
puts "f",midi2note(c[4][2])
c[4][2]=nil
puts c[4]
puts "A",c[5]
# index the exclusion arrays to the chord progression
d=[0,1,2,0,1,2,3,4,5,3,4,5]
#the plaintext to hide in the melody
plaintext="Lord Qwerty asked us to play"
plaintext+="Rhapsody in Blue"
plaintext+="0123456789"
ms0="-1,staff,0,voice,0;"
ms1="-1,staff,1,voice,0;"
define :staff0 do |p,d|
if (p==nil)
p=-1
else
p-=12
end
ms0+="1,"+(2/d).to_s+","+p.to_s+";"
end
define :staff1 do |p,d|
if (p==nil)
p=-1
else
p-=12
end
ms1+="1,"+(2/d).to_s+","+p.to_s+";"
end
stp=0
stplimit=4
live_loop :LL1 do
use_synth :fm
with_fx :level, amp: 0.2 do
jj=0
while jj<2*a.length
puts j,midi2note(a[jj])
play a[jj]
sleep quart*tempo
staff1(a[jj],quart)
jj+=1
end
jj=0
while jj<2*b.length
puts midi2note(b[jj])
play b[jj]
sleep quart*tempo
staff1(b[jj],quart)
jj+=1
end
if stp>stplimit
puts ms1+":/n"
stop
end
end
end #LL1
live_loop :LL2 do
sync :LL1
use_synth :fm
with_fx :level, amp: 0.2 do
i=0
j=0
while i<plaintext.length
n=plaintext[i].ord-32
oct=(n/64)*octave+octave
nn=n%8
nnn=(n/8)%8
nn=c[d[j]][nn]
j+=1
if j>11 then j=0 end
nnn=c[d[j]][nnn]
j+=1
if j>11 then j=0 end
if nn!=nil then nn+=oct end
if nnn!=nil then nnn+=oct end
puts midi2note(nn)
play nn
sleep quart*tempo
staff0(nn,quart)
puts midi2note(nnn)
play nnn
sleep quart*tempo
staff0(nnn,quart)
i+=1
end
stp+=1
if stp>stplimit
puts ms0+":"
stop
end
end
end #LL2