简体   繁体   English

Android中的吉他音高检测

[英]Guitar pitch detection in android

I try to develop a guitar game in android platform. 我尝试在Android平台上开发吉他游戏。

And I need to do the real-time pitch detection to get the frequency of guitar chord/String. 而且我需要进行实时音高检测以获得吉他和弦/弦的频率。

I will get the input from the microphone, and then analyze the input (the input playing which kind of guitar string/chord) 我将从麦克风获得输入,然后分析输入(该输入播放哪种吉他弦/和弦)

I find two kinds of method that I can use, one is YIN, another one is FFT. 我发现我可以使用两种方法,一种是YIN,另一种是FFT。

Which method can get better performance and exact result? 哪种方法可以获得更好的性能和准确的结果?

You need to first understand what ' pitch ' really is (read the Wikipedia link below). 您首先需要了解什么是“ 音高 ”(请阅读下面的Wikipedia链接)。 When a single note is made on a guitar or piano, what we hear is not just one frequency of sound vibration, but a composite of multiple sound vibrations occurring at different mathematically related frequencies. 当在吉他或钢琴上做单个音符时,我们听到的不仅是声音振动的一个频率,而是在不同的数学相关频率下发生的多个声音振动的组合。 The elements of this composite of vibrations at differing frequencies are referred to as harmonics or partials. 这种在不同频率下的振动合成的元素称为谐波或部分谐波。 For instance, if we press the Middle C key on the piano, the individual frequencies of the composite's harmonics will start at 261.6 Hz as the fundamental frequency, 523 Hz would be the 2nd Harmonic, 785 Hz would be the 3rd Harmonic, 1046 Hz would be the 4th Harmonic, etc. The later harmonics are integer multiples of the fundamental frequency, 261.6 Hz ( ex: 2 x 261.6 = 523, 3 x 261.6 = 785, 4 x 261.6 = 1046 ). 例如,如果我们按钢琴上的中音C键,则复合谐波的各个频率将从261.6 Hz开始作为基频,523 Hz为第二谐波,785 Hz为第三谐波,1046 Hz是4次谐波,等等。后面的谐波是基频261.6 Hz的整数倍(例如:2 x 261.6 = 523、3 x 261.6 = 785、4 x 261.6 = 1046)。

Below, at GitHub.com, is the C++ source code for an unusual two-stage algorithm that I devised which can do Realtime Pitch Detection on polyphonic MP3 files while being played on Windows. 下面是GitHub.com上的代码,它是我设计的一种不寻常的两阶段算法的C ++源代码,该算法可以在Windows上播放的同时对复音MP3文件进行实时音高检测。 This free application (PitchScope Player, available on web) is frequently used to detect the notes of a guitar or saxophone solo upon a MP3 recording. 这个免费的应用程序(PitchScope Player,可从Web上获得)通常用于检测MP3录音时吉他或萨克斯风的音符。 You could download the executable for Windows to see my algorithm at work on a mp3 file of your choosing. 您可以下载Windows可执行文件,以查看我在选择的mp3文件上运行的算法。 The algorithm is designed to detect the most dominant pitch (a musical note) at any given moment in time within a MP3 or WAV music file. 该算法旨在检测MP3或WAV音乐文件中任何给定时刻的最主要音高(音符)。 Note onsets are accurately inferred by a change in the most dominant pitch (a musical note) at any given moment during the MP3 recording. 通过在MP3录制期间的任何给定时刻改变最主要的音高(音符),可以准确地推断出音符的发作。

I use a modified DFT Logarithmic Transform (similar to a FFT) to first detect these possible Harmonics by looking for frequencies with peak levels (see diagram below). 我使用改进的DFT对数变换(类似于FFT),首先通过查找峰值电平的频率来检测这些可能的谐波(请参见下图)。 Because of the way that I gather data for my modified Log DFT, I do NOT have to apply a Windowing Function to the signal, nor do add and overlap. 由于我收集修改后的Log DFT数据的方式,我不必对信号应用开窗功能,也不必加和重叠。 And I have created the DFT so its frequency channels are logarithmically located in order to directly align with the frequencies where harmonics are created by the notes on a guitar, saxophone, etc. 我创建了DFT,以便将其频率通道对数定位,以便与吉他,萨克斯风等音符产生谐波的频率直接对齐。

My Pitch Detection Algorithm is actually a two stage process: a) First the ScalePitch is detected ('ScalePitch' has 12 possible pitch values: {E, F, F#, G, G#, A, A#, B, C, C#, D, D#} ) b) and after ScalePitch is determined, then the Octave is calculated by examining all the harmonics for the 4 possible Octave-Candidate notes. 我的音高检测算法实际上是一个两阶段过程:a)首先检测到ScalePitch(“ ScalePitch”具有12个可能的音高值:{E,F,F#,G,G#,A,A#,B,C,C#,D ,D#})b)并且确定ScalePitch之后,通过检查4个可能的八度候选音符的所有谐波来计算八度。 The algorithm is designed to detect the most dominant pitch (a musical note) at any given moment in time within a polyphonic MP3 file. 该算法旨在检测和弦MP3文件中任何给定时刻的最主要音高(音符)。 That usually corresponds to the notes of an instrumental solo. 这通常与器乐独奏的音符相对应。 Those interested in the C++ source code for my Two Stage Pitch Detection algorithm might want to start at the Estimate_ScalePitch() function within the SPitchCalc.cpp file at GitHub.com. 那些对我的两级音高检测算法的C ++源代码感兴趣的人可能想从GitHub.com上SPitchCalc.cpp文件中的Estimate_ScalePitch()函数开始。

https://github.com/CreativeDetectors/PitchScope_Player https://github.com/CreativeDetectors/PitchScope_Player

https://en.wikipedia.org/wiki/Transcription_(music)#Pitch_detection https://zh.wikipedia.org/wiki/Transcription_(音乐)#Pitch_detection

Below is the image of a Logarithmic DFT (created by my C++ software) for 3 seconds of a guitar solo on a polyphonic mp3 recording. 下图是对数DFT(由我的C ++软件创建)的图像,在多音mp3录音中吉他独奏3秒。 It shows how the harmonics appear for individual notes on a guitar, while playing a solo. 它显示了弹奏独奏时吉他上各个音符的谐波如何出现。 For each note on this Logarithmic DFT we can see its multiple harmonics extending vertically, because each harmonic will have the same time-width. 对于此对数DFT的每个音符,我们可以看到其多个谐波垂直延伸,因为每个谐波将具有相同的时间宽度。 After the Octave of the note is determined, then we know the frequency of the Fundamental. 确定音符的八度之后,我们便知道基本音的频率。

在此处输入图片说明

The diagram below demonstrates the Octave Detection algorithm which I developed to pick the correct Octave-Candidate note (that is, the correct Fundamental), once the ScalePitch for that note has been determined. 下图演示了八度音阶检测算法,一旦确定了该音阶的ScalePitch,我就会开发该算法来选择正确的八度音阶候选音符(即正确的基本音阶)。 Those wishing to see that method in C++ should go to the Calc_Best_Octave_Candidate() function inside the file called FundCandidCalcer.cpp, which is contained in my source code at GitHub. 那些希望在C ++中看到该方法的人应该转到名为FundCandidCalcer.cpp的文件内的Calc_Best_Octave_Candidate()函数,该文件包含在我在GitHub上的源代码中。

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM