|
28 | 28 |
|
29 | 29 |
|
30 | 30 | # conversion settings
|
| 31 | +raspi_optimized_drumkit = False#True# |
31 | 32 | disable_positional_sensing_support = False#True#
|
32 | 33 | only_master_channels_per_instrument = False#True#
|
33 |
| -raspi_optimized_drumkit = False#True# |
| 34 | +do_shorten_samples = False#True# |
34 | 35 |
|
35 | 36 |
|
36 | 37 | ################################################################################
|
|
69 | 70 | #instruments = [["rolandsnare", ["SnareL"], [38], "", 0.03, 23]]
|
70 | 71 |
|
71 | 72 | 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 |
73 | 74 | thresh_from_max_for_start = 20 # dB
|
74 | 75 | add_samples_at_start = 20 # additional samples considered at strike start (also defines the fade-in time period)
|
75 | 76 | min_time_next_strike_s = 0.5 # minimum time in seconds between two different strikes
|
|
80 | 81 | # settings for optimized drum kit for Raspberry Pi (with limited RAM)
|
81 | 82 | if raspi_optimized_drumkit:
|
82 | 83 | disable_positional_sensing_support = True
|
| 84 | + do_shorten_samples = True |
83 | 85 | only_master_channels_per_instrument = True
|
84 | 86 | for instrument in instruments: # remove some instruments for lowest possible memory requirement
|
85 | 87 | if ("tom2" in instrument or "ride_side" in instrument or "crash_top" in instrument or "hihat_opentop" in instrument or
|
|
164 | 166 | if not above_thresh[i] and above_thresh[i - 1]:
|
165 | 167 | first_below_idx = i
|
166 | 168 | 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 |
169 | 171 |
|
170 | 172 | # remove very short on periods
|
171 | 173 | first_above_idx = -100 * sample_rate
|
|
174 | 176 | first_above_idx = i
|
175 | 177 | if not above_thresh[i] and above_thresh[i - 1]:
|
176 | 178 | 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 |
178 | 180 |
|
179 | 181 | strike_start = np.argwhere(np.diff(above_thresh.astype(float)) > 0)
|
180 | 182 | strike_end = np.argwhere(np.diff(above_thresh.astype(float)) < 0)
|
|
187 | 189 |
|
188 | 190 | # fix start of strike: find first sample going left of the maximum peak which
|
189 | 191 | # 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] |
191 | 193 | strike_mean = np.mean(x_cur_strike_master)
|
192 | 194 | strike_max = np.max(x_cur_strike_master)
|
193 | 195 | below_max_thresh = np.power(10, -thresh_from_max_for_start / 10) # -[20] dB from maximum peak
|
|
210 | 212 | sample_powers[p][i] = strike_max / 32768 / 32768 # assuming 16 bit
|
211 | 213 |
|
212 | 214 | # extract sample data of current strike
|
213 |
| - if raspi_optimized_drumkit: |
| 215 | + if do_shorten_samples: |
214 | 216 | x_cur_strike_master = x[strike_start[i][0]:strike_end[i][0] + 1]
|
215 | 217 | strike_max = np.max(x_cur_strike_master)
|
216 | 218 | last_index = np.max(np.argwhere(x_cur_strike_master > strike_max / np.power(10, 40 / 10))) # 40 dB below max
|
|
232 | 234 | fade_start = int(sample_len * (1 - fade_out_percent / 100))
|
233 | 235 | fade_len = sample_len - fade_start
|
234 | 236 | 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) |
238 | 237 |
|
239 | 238 | #print(sample_powers[p][i])
|
240 | 239 | #plt.plot(sample_strikes[p][i][:, master_channel])
|
|
0 commit comments