Skip to content

Commit 437b839

Browse files
committed
use longer fade-out time and some code optimization/cleanup
1 parent cd750f8 commit 437b839

File tree

1 file changed

+9
-10
lines changed

1 file changed

+9
-10
lines changed

tools/create_drumgizmo_kit.py

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,10 @@
2828

2929

3030
# conversion settings
31+
raspi_optimized_drumkit = False#True#
3132
disable_positional_sensing_support = False#True#
3233
only_master_channels_per_instrument = False#True#
33-
raspi_optimized_drumkit = False#True#
34+
do_shorten_samples = False#True#
3435

3536

3637
################################################################################
@@ -69,7 +70,7 @@
6970
#instruments = [["rolandsnare", ["SnareL"], [38], "", 0.03, 23]]
7071

7172
source_samples_dir_name = "source_samples" # root directory of recorded source samples
72-
fade_out_percent = 10 # % of sample at the end is faded out
73+
fade_out_percent = 30 # % of sample at the end is faded out
7374
thresh_from_max_for_start = 20 # dB
7475
add_samples_at_start = 20 # additional samples considered at strike start (also defines the fade-in time period)
7576
min_time_next_strike_s = 0.5 # minimum time in seconds between two different strikes
@@ -80,6 +81,7 @@
8081
# settings for optimized drum kit for Raspberry Pi (with limited RAM)
8182
if raspi_optimized_drumkit:
8283
disable_positional_sensing_support = True
84+
do_shorten_samples = True
8385
only_master_channels_per_instrument = True
8486
for instrument in instruments: # remove some instruments for lowest possible memory requirement
8587
if ("tom2" in instrument or "ride_side" in instrument or "crash_top" in instrument or "hihat_opentop" in instrument or
@@ -164,8 +166,8 @@
164166
if not above_thresh[i] and above_thresh[i - 1]:
165167
first_below_idx = i
166168
if above_thresh[i] and not above_thresh[i - 1]:
167-
if i - first_below_idx < min_time_next_strike:
168-
above_thresh[range(first_below_idx, i)] = True
169+
if i - first_below_idx + 1 < min_time_next_strike:
170+
above_thresh[first_below_idx:i + 1] = True
169171

170172
# remove very short on periods
171173
first_above_idx = -100 * sample_rate
@@ -174,7 +176,7 @@
174176
first_above_idx = i
175177
if not above_thresh[i] and above_thresh[i - 1]:
176178
if i - first_above_idx < min_strike_len:
177-
above_thresh[range(first_above_idx, i)] = False
179+
above_thresh[first_above_idx:i + 1] = False
178180

179181
strike_start = np.argwhere(np.diff(above_thresh.astype(float)) > 0)
180182
strike_end = np.argwhere(np.diff(above_thresh.astype(float)) < 0)
@@ -187,7 +189,7 @@
187189

188190
# fix start of strike: find first sample going left of the maximum peak which
189191
# is below a threshold which is defined 20 dB below the maximum
190-
x_cur_strike_master = x[range(strike_start[i][0], strike_end[i][0])]
192+
x_cur_strike_master = x[strike_start[i][0]:strike_end[i][0] + 1]
191193
strike_mean = np.mean(x_cur_strike_master)
192194
strike_max = np.max(x_cur_strike_master)
193195
below_max_thresh = np.power(10, -thresh_from_max_for_start / 10) # -[20] dB from maximum peak
@@ -210,7 +212,7 @@
210212
sample_powers[p][i] = strike_max / 32768 / 32768 # assuming 16 bit
211213

212214
# extract sample data of current strike
213-
if raspi_optimized_drumkit:
215+
if do_shorten_samples:
214216
x_cur_strike_master = x[strike_start[i][0]:strike_end[i][0] + 1]
215217
strike_max = np.max(x_cur_strike_master)
216218
last_index = np.max(np.argwhere(x_cur_strike_master > strike_max / np.power(10, 40 / 10))) # 40 dB below max
@@ -232,9 +234,6 @@
232234
fade_start = int(sample_len * (1 - fade_out_percent / 100))
233235
fade_len = sample_len - fade_start
234236
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)
238237

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

0 commit comments

Comments
 (0)