ギターチューナーってスマホアプリにはあるんですが、スマホアプリだと以下のようないろいろ問題があります。
とっても、うっとおしいくて使い物になりません。
There is a guitar tuner in the smartphone app, but there are the following annoying problems.
It's very disgusting and inconvenient.
専用のものをゲットすればいいのですが、よく考えると M5StickC には必要な装備が全てそろっているので、コンテストきっかけで作ってみました。
M5StickC has all the necessary devices in it, so I decided to try making it for the contest.
たまには普通に使えそうなものを、真面目に作ってみた…
M5StickC マイクからサンプリングしたギター音声の周波数を解析して、目標音とのズレとその量を視覚的に表示するものとなります。
It analyzes the frequency of the sampled guitar sound in the M5StickC microphone, and shows the deviation to the target sound and its amount.
音声解析部と表示部の2部構成となっていて、 ESP32 が持つ2つのコアを別々のタスクに割り当てて処理しています。(RTOS機能を使用) それぞれの部について説明します。
It consists of two parts, the audio analysis part and the display part. I split these two parts into two ESP32 cores to separate the tasks and process them using the RTOS feature.
下記の手順にて、主にサンプリングと FFT による周波数成分解析の処理、一番大きい音の周波数測定を行います。
The analysis part primarily performs frequency component analysis, sampling and FFT processing, and frequency measurement of the loudest sound, as follows.
M5 ライブラリのマイク入力機能を使ってバッファに蓄積します。
It puts the voice data into the buffer using the microphone input function of the M5 library.
Arduino FFT というライブラリを使ってフーリエ変換を行い、音声データを周波数成分ごとのレベルに変換します。フーリエ変換のコア処理はライブラリ任せです。
I used the "Arduino FFT" library to convert sound data into levels for each frequency component.
フーリエ変換結果のうち音量の大きい周波数を検索し周波数を割り出します。
It finds the frequency with the loudest volume among the Fourier transform results and determine the frequency.
このままでは、周波数の分解能が足りず数Hz ごとの値しか出なかったため少し工夫しました。 近隣の周波数成分の信号レベルに係数をかけた値から中心からのズレを演算するとで、小数点1桁目くらいまでの分解能を疑似的に算出しています。
Since the frequency resolution was not enough to tune accurately, I devised the calculation a little.
音声解析部で測定した周波数により弦を自動選択し、その弦の目標周波数とのズレを調整ゲージに表示します。 ユーザーは調整ゲージの針が中心になるように調整することでチューニングすることが出来ます。
A string to tune is automatically selected according to the frequency measured by the sound analysis part. The user can adjust by adjusting the line of the adjustment gauge to be centered.
6弦のうちどれに近いかを計算し、いずれかの弦の±1音範囲に入った弦を自動選択します。 数回同じ範囲に入った時点で自動選択し、いったん選択されたら特定時間大幅にずれるまでは選択状態を維持します。 選択されたら、その言番号と音程、目標周波数を表示します。
Calculates which of the 6 strings is closest, and selects strings automatically that is, within ±1 note range of any string. When selected, it remains selected until it deviates significantly for a while. Then, it displays its string number, pitch and target frequency.
現在周波数を更新するとともに、インジケータを ±1音範囲がインジケータの左右範囲になる様に、調整ゲージ内に線を表示します。そうすることで、ゲージが中央に来た時が、周波数が目標と一致してチューニング完了となります。
The indicator shows a line is displayed on the adjustment gauge so that the range of ±1 note is the left and right range of the indicator. When the gauge comes to the center, the frequency matches the target and tuning is done.
±1音範囲から一定時間の間離れたら弦の選択を解除します。
Deselect strings after leaving the ±1 note range for a while.