# 用AI玩編曲
---
## 我誰!
* 107級數位音樂社教學
* 107級運輸與物流管理學系
* 本業:軟體工程師(文件自動化相關)
* 副業:金融分析(自動交易、推播、爬蟲、回測)
* 樂器:鍵盤類
* 工作站:FL Studio
* 曲風:各式各樣
* 小作品:[網頁MIDI編輯器](https://chuboy.dev/midi/)
---
## 議程
### 音樂要素
* 節奏-鼓組對應
* 旋律-演奏方式
* 和弦-五度圈與曲風
* 音源-取樣機與合成器
----
### 安裝python程式
* MacOS系統套件管理
* [Homebrew](https://brew.sh/)
* `brew install miniforge`
* Windows系統套件管理
* [Chocolately](https://chocolatey.org/)
* `Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1'))`
* `choco install miniconda3`
* 啟用python虛擬環境
* `conda activate base`
----
### 取得音檔
* 下載音樂 [pytube](https://pypi.org/project/pytube/)
* `pip install pytube`
* `python -m pip install git+https://github.com/nficano/pytube`
* `pytube https://www.youtube.com/watch?v=M6gcoDN9jBc`
* ```mv `ls | grep Aimer` Aimer.mp4```
* 音訊轉檔 [ffmpeg](https://ffmpeg.org/)
* `ffmpeg -i Aimer.mp4 Aimer.mp3`
----
### 音軌切割
* [Deezer Spleeter](https://github.com/deezer/spleeter)
* `pip install spleeter`
* `spleeter separate -p spleeter:5stems -o Aimer Aimer.mp3`
----
### 音訊處理
* [Audacity](https://www.audacityteam.org/)
* [librosa](https://librosa.org/)
----
### 音高偵測 Pitch Detection
* [Scipy](https://stackoverflow.com/questions/32595404/pitch-detection-in-python)
* [CREPE](https://github.com/marl/crepe)
----
### 我試過的數位音樂工作站
* [Reason](https://www.reasonstudios.com/en/reason)
* [RL Studio](https://www.image-line.com/)
* [Ableton](https://www.ableton.com/)
* 搭配玩具更好玩:[Launchpad](https://novationmusic.com/en/launch)
* [Sonar](https://www.musictech.net/tag/cakewalk/)
* [Logic Pro](https://www.apple.com/tw/logic-pro/)
* [Studio One](https://www.presonus.com/products/studio-one/)
* [Soundation](https://soundation.com/)
----
### 音樂研究主題 [DL4M](https://github.com/ybayle/awesome-deep-learning-music)
* 中研院
* [musegan](https://salu133445.github.io/musegan/)
* [pypianoroll](https://github.com/salu133445/pypianoroll)
* Facebook
* [Sound Collection](https://business.facebook.com/creatorstudio/fm_sound_collection?reference=redirect_from_sound_collection) 免費聲音素材
* Google
* [magenta](https://magenta.tensorflow.org/demos)
* Openai
* [Musenet](https://openai.com/blog/musenet/)
* [Jukebox](https://jukebox.openai.com/)
---
## 節奏 Beat
----
### 節拍速度
* Largo 40
* Adagio 66
* Andante 76
* Moderato 108
* Allegro 120
* Presto 168
* Prestissimo 200
----
### 鼓的元素

----
### 鼓的MIDI位置

---
## 旋律 Melody
----
### MIDI資源下載
* https://www.cprato.com/
* https://musescore.com/
----
### 演奏方式
* 滑音(glide/portamento/glissando)
* 顫音(trill/trillo)
* 上漣音 (upper mordent/inverted mordent/pralltriller)
* 下漣音(lower mordent/mordent)
* 倚音
* 短倚音
----
* 圓滑線Slur
* 連結線Tie
* 加強音Marcato
* 斷奏Staccato
* 大斷奏Staccatissimo
* 保持音Tenuto
* 延音Fermata
----
### 強弱表達
* 強弱音義大利文符號
ppp|pp|p|mp
-|-|-|-
pianississimo|pianissimo|piano|mezzo-piano
極弱|非常弱|弱|中弱
mf|f|ff|fff
-|-|-|-
mezzo-forte|forte|fortissimo|fortississimo
中強|強|非常強|極強
----
* 強弱漸變
* crescendo(簡作 cresc.)漸強
* decrescendo(簡作 decresc.)漸弱
* diminuendo(簡作 dim.)漸弱
---
## 和弦 Chord
----
[一部影片之內,真的完全搞懂「五度圈」!(Circle of fifth)](https://www.youtube.com/watch?v=EyF7EBnmdEs)

----
### 曲風 Genre
流行 | KPOP, JPOP, CPOP, Cantopop
-|-
藍調 | R&B, 爵士
嘻哈 | Hihop
搖滾 | Rock
金屬 | Metal
電子 | EDM, Drum&Bass, Trance, Dubstep
環境 | Epic
---
## 取樣原理
----
### 取樣音源 sampler
* [鋼琴](https://github.com/tambien/Piano)
* [808鼓組](https://soundpacks.com/free-sound-packs/roland-mc-505-808-kit/)
* [原聲(acoustic)鼓組](https://github.com/gregharvey/drum-samples)
----
### 音高 pitch
$$
p=69+12*log_2(\frac{f}{440})
$$
----
### 頻率 frequency
$$
f=440*2^{\frac{(p-69)}{12}}
$$
----
### 鋼琴取樣機
音名|頻率|音階|八度
-|-|-|-
A4 | 440.00 | (10/12) | 0~7
C5 | 523.25 | (1/12) | 1~8
Ds5 | 622.25 | (4/12) | 1~7
Fs5 | 739.99 | (7/12) | 1~7
---
## 音訊處理 DSP
----
### 快速傅立葉轉換 FFT
* DFT 離散傅立葉轉換
$$
X_k=\sum^{N-1}_{n=0}x_n e^{-i2\pi k\frac{n}{N}}
$$
----
### 倒頻譜轉換 Mel
* Mel Scale
$$
m=2595*log_{10}(1+\frac{f}{700})
$$
----
### 視覺化 Visualize
> waveform 波形圖

----
> spectrum 頻譜圖

----
> spectrogram 時頻圖

---
Sine|Triangle|Square|Pulse|Saw|Random
-|-|-|-|-|-
正弦波|三角波|方波|脈衝波|鋸齒波|隨機波(雜訊)

----
### 波封 ADSR [3XOSC](https://codepen.io/HandsomeChuBoy/pen/LKpJEw)

----
### 等化器 Equalizer

----
## 雙聲道 Panner

----
## 壓縮器 Compressor

----
## 回(殘)響 Reverb
Convolver (convolution reverb)

----
## 延遲效果 Delay

----
## 相位 Phaser

----
## 失真 Distortion(Waveshaper)

---
## 合成器
----

----

---
## 音樂研究主題
----

----
### 捲積運算(特徵提取)

----
### UNET網路架構(音軌切割)

----
### AutoEncoder(自編碼器)

----
### GAN(音訊生成)

{"metaMigratedAt":"2023-06-16T00:39:36.243Z","metaMigratedFrom":"YAML","title":"用AI玩編曲","breaks":true,"slideOptions":"{\"theme\":\"night\",\"transition\":\"slide\",\"spotlight\":{\"enabled\":true}}","contributors":"[{\"id\":\"794553c4-57e8-424f-b9da-1f0d40a61e1b\",\"add\":34028,\"del\":26920}]"}