|
114 | 114 | " y = lfilter(b, a, data)\n",
|
115 | 115 | " return y\n",
|
116 | 116 | "\n",
|
117 |
| - "def apply_highpass_mix(input, hipass_vol=0.5, mix_vol=0.8, cutoff=10000, fx=44100, order=6):\n", |
| 117 | + "def apply_highpass_mix(input, hipass_vol=0.5, mix_vol=0.8, cutoff=10000, fs=44100, order=6):\n", |
118 | 118 | " if type(input) == np.ndarray:\n",
|
119 | 119 | " data = input\n",
|
120 | 120 | " sr = fs\n",
|
121 | 121 | " else:\n",
|
122 | 122 | " data, sr = librosa.load(input, sr=None, mono=False)\n",
|
123 | 123 | " octave_up = librosa.effects.pitch_shift(data, sr=sr, n_steps=12, res_type='soxr_vhq') * hipass_vol\n",
|
124 |
| - " hipass = highpass_audio(octave_up, cutoff, fx, order)\n", |
| 124 | + " hipass = highpass_audio(octave_up, cutoff, fs, order)\n", |
125 | 125 | " return data*mix_vol+hipass\n",
|
126 | 126 | "\n",
|
127 | 127 | "output.clear()\n",
|
|
149 | 149 | "\n",
|
150 | 150 | "#@markdown #### Changing anything below is not recommended.\n",
|
151 | 151 | "\n",
|
152 |
| - "simulate_high_end = 0.2 #@param {type:\"slider\", min:0, max:0.5, step:0.05}\n", |
| 152 | + "simulate_high_end = 0.25 #@param {type:\"slider\", min:0, max:0.5, step:0.05}\n", |
153 | 153 | "cutoff = 11000 #@param {type: \"number\"}\n",
|
154 | 154 | "mix_vol = 0.8 #@ param {type: \"number\"}\n",
|
155 | 155 | "\n",
|
|
184 | 184 | "# Output\n",
|
185 | 185 | "if output_dir == '':\n",
|
186 | 186 | " dir_out = dir_in\n",
|
| 187 | + " op(c.warn, 'WARNING! You have not entered an output_dir')\n", |
| 188 | + " op(c.warn, '-> Files will be saved in the same directory where they are currently located.')\n", |
187 | 189 | "else:\n",
|
188 | 190 | " if not os.path.isdir(drive_root+output_dir):\n",
|
189 | 191 | " os.mkdir(drive_root+output_dir)\n",
|
190 | 192 | " dir_out = drive_root+fix_path(output_dir)\n",
|
191 | 193 | " \n",
|
192 | 194 | "timer_start = time.time()\n",
|
193 | 195 | "total = len(inputs)\n",
|
| 196 | + "op(c.title, 'Run ID:', uniq_id, time=True)\n", |
194 | 197 | "\n",
|
195 | 198 | "# -- DO THINGS --\n",
|
196 | 199 | "for i, input in enumerate(inputs, 1):\n",
|
197 | 200 | "\n",
|
198 |
| - " if i % 10: output.clear()\n", |
199 |
| - " \n", |
| 201 | + " if not i % 10:\n", |
| 202 | + " output.clear()\n", |
| 203 | + " op(c.warn, 'Cell output is cleared every 10 generations to keep Colab running smoothly.', time=True)\n", |
| 204 | + " op(c.warn, 'You can find all audio files from directory', dir_out.replace(drive_root, ''), time=True)\n", |
| 205 | + " print()\n", |
| 206 | + " op(c.title, 'Run ID:', uniq_id, time=True)\n", |
| 207 | + "\n", |
| 208 | + " print()\n", |
200 | 209 | " ndx_info = str(i)+'/'+str(total)+' '\n",
|
201 |
| - " op(c.title, ndx_info+'Processing', input.replace(drive_root, ''), time=True)\n", |
| 210 | + " op(c.title, ndx_info+'Processing', input.replace(drive_root, ''))\n", |
| 211 | + " print()\n", |
202 | 212 | "\n",
|
203 | 213 | " file_tmp = dir_tmp+basename(input)+'.wav'\n",
|
| 214 | + " if os.path.isfile(file_tmp): os.remove(file_tmp)\n", |
204 | 215 | " file_out = dir_out+uniq_id+'_44khz_'+basename(input)+'.wav'\n",
|
205 |
| - "\n", |
| 216 | + " \n", |
206 | 217 | " if show_players == True: \n",
|
207 |
| - " op(c.okb, 'Original audio')\n", |
| 218 | + " op(c.okb, 'Original audio:')\n", |
| 219 | + " print()\n", |
208 | 220 | " audio_player(input)\n",
|
| 221 | + " print()\n", |
209 | 222 | "\n",
|
210 | 223 | " !ffmpeg -hide_banner -loglevel panic -i \"{input}\" -acodec {new_format} -ar {new_sr} \"{file_tmp}\"\n",
|
211 | 224 | " \n",
|
|
220 | 233 | " result = hpf2\n",
|
221 | 234 | "\n",
|
222 | 235 | " if show_players == True: \n",
|
223 |
| - " op(c.okb, 'Upsampled audio')\n", |
| 236 | + " op(c.warn, 'Upsampled audio:')\n", |
| 237 | + " print()\n", |
224 | 238 | " audio_player(result)\n",
|
| 239 | + " print()\n", |
225 | 240 | "\n",
|
226 | 241 | " sf.write(file_out, result.T, new_sr, subtype='PCM_24')\n",
|
227 | 242 | " if os.path.isfile(file_out):\n",
|
228 | 243 | " op(c.ok, 'Upsampled audio saved as', file_out.replace(drive_root, ''))\n",
|
229 | 244 | " else:\n",
|
230 | 245 | " op(c.fail, 'Error saving file', file_out)\n",
|
231 | 246 | " print()\n",
|
| 247 | + "\n", |
| 248 | + " print()\n", |
| 249 | + " display(IPython.display.Markdown('---'))\n", |
232 | 250 | "# -- END THINGS --\n",
|
233 | 251 | "\n",
|
234 | 252 | "timer_end = time.time()\n",
|
|
245 | 263 | "colab": {
|
246 | 264 | "provenance": [],
|
247 | 265 | "mount_file_id": "1KsC80bOcnAJ9K5UfpsF_saOywtPg7qT8",
|
248 |
| - "authorship_tag": "ABX9TyOJCeccpZIzmdExU7GeEhRX", |
| 266 | + "authorship_tag": "ABX9TyN4bQzJfB0SgnFRUEPbtM/c", |
249 | 267 | "include_colab_link": true
|
250 | 268 | },
|
251 | 269 | "kernelspec": {
|
|
0 commit comments