Skip to content

Commit cd750f8

Browse files
committed
added sample shortening for Raspberry Pi usage and some other MIDI assignment optimizations
1 parent 1db2563 commit cd750f8

File tree

1 file changed

+28
-8
lines changed

1 file changed

+28
-8
lines changed

tools/create_drumgizmo_kit.py

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -51,16 +51,16 @@
5151
["hihat_closedtop", ["Hihat", "OHLeft", "OHRight"], [42, 46], "hihat", "80", 0.2, 20], \
5252
["hihat_open", ["Hihat", "OHLeft", "OHRight"], [26], "hihat", "0", 0.7, 23], \
5353
["hihat_open1", ["Hihat", "OHLeft", "OHRight"], [26], "hihat", "55", 0.7, 23], \
54-
["hihat_open2", ["Hihat", "OHLeft", "OHRight"], [26], "hihat", "20", 0.7, 23], \
54+
["hihat_open2", ["Hihat", "OHLeft", "OHRight"], [26], "hihat", "27", 0.7, 23], \
5555
["hihat_opentop", ["Hihat", "OHLeft", "OHRight"], [46], "hihat", "0", 0.7, 24], \
5656
["hihat_open1top", ["Hihat", "OHLeft", "OHRight"], [46], "hihat", "55", 0.7, 21], \
57-
["hihat_open2top", ["Hihat", "OHLeft", "OHRight"], [46], "hihat", "20", 0.7, 23], \
57+
["hihat_open2top", ["Hihat", "OHLeft", "OHRight"], [46], "hihat", "27", 0.7, 23], \
5858
["hihat_foot", ["Hihat", "OHLeft", "OHRight"], [44], "hihat", "", 0.1, 23], \
5959
["tom1", ["Tom1", "OHLeft", "OHRight"], [48, 50], "", "", 0.2, 15], \
6060
["tom2", ["Tom2", "OHLeft", "OHRight"], [45, 47], "", "", 0.2, 15], \
6161
["tom3", ["Tom3", "OHLeft", "OHRight"], [43, 58], "", "", 0.4, 15], \
62-
["crash", ["OHLeft", "OHRight"], [55], "", "", 0.5, 15], \
63-
["crash_top", ["OHLeft", "OHRight"], [49], "", "", 0.4, 15], \
62+
["crash", ["OHLeft", "OHRight"], [55, 52], "", "", 0.5, 15], \
63+
["crash_top", ["OHLeft", "OHRight"], [49, 57], "", "", 0.4, 15], \
6464
["ride", ["OHRight", "OHLeft"], [51], "", "", 1.0, 15], \
6565
["ride_bell", ["OHRight", "OHLeft"], [53], "", "", 1.0, 16], \
6666
["ride_side", ["OHRight", "OHLeft"], [59], "", "", 1.0, 15]]
@@ -82,7 +82,8 @@
8282
disable_positional_sensing_support = True
8383
only_master_channels_per_instrument = True
8484
for instrument in instruments: # remove some instruments for lowest possible memory requirement
85-
if "tom2" in instrument or "ride_side" in instrument or "crash_top" in instrument or "hihat_opentop" in instrument:
85+
if ("tom2" in instrument or "ride_side" in instrument or "crash_top" in instrument or "hihat_opentop" in instrument or
86+
"hihat_open1top" in instrument or "hihat_open2top" in instrument or "hihat_closedtop" in instrument):
8687
instruments.remove(instrument)
8788
for instrument in instruments: # assign now missing MIDI notes to remaining instruments
8889
if "ride" in instrument:
@@ -91,6 +92,13 @@
9192
instrument[2].append(49)
9293
if "hihat_open" in instrument:
9394
instrument[2].append(46)
95+
if "hihat_closed" in instrument:
96+
instrument[2].append(42)
97+
instrument[2].append(46)
98+
if "hihat_open1" in instrument:
99+
instrument[2].append(46)
100+
if "hihat_open2" in instrument:
101+
instrument[2].append(46)
94102

95103

96104
for instrument in instruments:
@@ -202,10 +210,19 @@
202210
sample_powers[p][i] = strike_max / 32768 / 32768 # assuming 16 bit
203211

204212
# extract sample data of current strike
205-
sample_strikes[p][i] = np.zeros((strike_end[i][0] - strike_start[i][0] + 1, num_channels), np.int16)
213+
if raspi_optimized_drumkit:
214+
x_cur_strike_master = x[strike_start[i][0]:strike_end[i][0] + 1]
215+
strike_max = np.max(x_cur_strike_master)
216+
last_index = np.max(np.argwhere(x_cur_strike_master > strike_max / np.power(10, 40 / 10))) # 40 dB below max
217+
mod_strike_end = strike_start[i][0] + last_index;
218+
else:
219+
mod_strike_end = strike_end[i][0]
220+
221+
sample_strikes[p][i] = np.zeros((mod_strike_end - strike_start[i][0] + 1, num_channels), np.int16)
206222
for c in range(0, num_channels):
207-
strike_cut_pos[strike_start[i][0]:strike_end[i][0] + 1].fill(True) # for debugging
208-
sample_strikes[p][i][:, c] = sample[c][strike_start[i][0]:strike_end[i][0] + 1]
223+
strike_cut_pos[strike_start[i][0]:mod_strike_end + 1].fill(True) # for debugging
224+
sample_strikes[p][i][:, c] = sample[c][strike_start[i][0]:mod_strike_end + 1]
225+
209226

210227
# audio fade-in at the beginning
211228
sample_strikes[p][i][:add_samples_at_start, c] = np.int16(sample_strikes[p][i][:add_samples_at_start, c].astype(float) * np.arange(1, add_samples_at_start + 1, 1) / add_samples_at_start)
@@ -215,6 +232,9 @@
215232
fade_start = int(sample_len * (1 - fade_out_percent / 100))
216233
fade_len = sample_len - fade_start
217234
sample_strikes[p][i][fade_start:, c] = np.int16(sample_strikes[p][i][fade_start:, c].astype(float) * np.arange(fade_len + 1, 1, -1) / fade_len)
235+
# TEST -> new logarithmic fade-out (instead of linear)
236+
#fade_gain = np.power(10, (np.arange(fade_len + 1, 1, -1) / fade_len - np.ones(fade_len)) * 10 / 10) # 10 dB fade-out
237+
#sample_strikes[p][i][fade_start:, c] = np.int16(sample_strikes[p][i][fade_start:, c].astype(float) * fade_gain)
218238

219239
#print(sample_powers[p][i])
220240
#plt.plot(sample_strikes[p][i][:, master_channel])

0 commit comments

Comments
 (0)