[CLAM] problem using pitch detection. especially: spectrumAnalysis
Xavier Amatriain
xamat at iua.upf.es
Thu Mar 18 09:12:23 PST 2004
Hello Martijn,
Martijn Bosma wrote:
>Hello,
>
>I try to use clam for pitch detection in a wave file. I have downloaded
>clam -0.5.7. There are many example programs that show very clearly how to
>do some actions in clam, but I couldn't find an example that shows how to do pitch detection.
>My first question is:
>
>1) Is there (somewhere) an example that shows how to do pitch detection?
> (or can someone give me one?)
>
>
We are currently working on integrating a lot of code from a previous
project that includes different examples and applications that perform
PitchDetection. I will try and see if I can send you a simple example
even before the release.
In the meantime, I can tell you that the clearest example of Pitch
detection is in the SMSAnalysis class. In the
SMSAnalysis::SinusoidalAnalysis method you will find the following code:
// Convert Spectrum to dB
outSp.ToDB();
// Peak Detection
SpectralPeakArray tmpPk;
tmpPk.SetScale( EScale::eLog );
mPO_PeakDetect.Do(outSp,tmpPk);
// If not possible to detect anything with this peak information,
FundDetect will return a false
bool fundFreqFound = mPO_FundDetect.Do(tmpPk,outFn);
// Sinusoidal Tracking
mPO_SinTracking.Do(tmpPk,pkArray,outFn.GetFreq(0));
// Convert Spectrum back to linear
outSp.ToLinear();
This code works fine and it's the one used in the SMSTools example.
Before that, the Spectral Analysis is also called in SMSAnalysis::Do(
Audio& in, Spectrum& outGlobalSpec, Spectrum& sinGlobalSpec,
SpectralPeakArray& outPk, Fundamental& outFn, Spectrum& outResSpec )
As a matter of fact, another possibility you have for testing the rest
of your code is using SMSAnalysis directly. Of course you will get more
thing than you need like Peak Continuation or Residual Spectrum, but...
>
>
>Because I couldn't find it I tried it myself.
>To get a spectrum out of the audio object I use: SpectralAnalysis.
>To get a SpectralPeakArray I use: SpectralPeakDetect.
>Finally, to get a list of candidate frequencies I use: FundFreqDetect .
>
>When I use the SpectralAnalysis Do(audio, spectrum) function I get the
>following exception breakpoint:
>
>
>"
>ASSERTION FAILED
>spectrum.cxx line 647:
>Spectrum::GetSize(): Complex size and Size mismatch.
>"
>
>
>When I look in the code of the spectrum object I find that the size of
>the complex array is not equal to size.
>
>
>"
> if(HasComplexArray() && GetComplexArray().Size())
> CLAM_ASSERT(GetComplexArray().Size() == size,
> "Spectrum::GetSize(): Complex size and Size mismatch.");
>"
>
>
>But I cannot find out where in the program these sizes are set, and why
>they are not equal. Maybe I initialized / configured the spectrum or the spectrum
>analysis object in the wrong way, so my second question is:
>
>2) how do I have to configure the spectrum and the spectrumAnalysis object
> to do first spectrum analysis and in the end pitch detection?
>
>
>
To do a Spectral Analysis you only need to configure the size of the
spectrum (AudioFrameSize/2+1). That's all, no need to worry about
whether it is MagPhase or Complex... the Spectral analysis does this for
you. The question is how you got to have this error, it would be
interesting to see the code.
>Because I couldn't really solve the error, I tried cheating. I make both
>sizes equal just before the check. The code on the same place in the spectrum object looks now like this:
>
>
>"
> if(HasComplexArray() && GetComplexArray().Size())
> {
> GetComplexArray().Resize(size);
> GetComplexArray().SetSize(size);
> CLAM_ASSERT(GetComplexArray().Size() == size,
> "Spectrum::GetSize(): Complex size and Size
>mismatch.");
> }
>"
>
>
>Now I am sure that both sizes are always equal when checked.
>The program works, but I don't detect the right frequencies yet.
>This can have several causes. One of them can be my lines of "cheat-code".
>Question three is:
>
>3) Does it harm the resulting spectrum when I add these two lines of
> cheat-code?
>
>
Difficult to say, but it is quite error-prone I must say. If you really
want to cheat you should add these lines outside the Spectrum class, in
your code just before calling the SpectralAnalysis.
>
>So far my questions and the description of my problem.
>I hope someone can provide the answers.
>
>
>
Thanks for your feedback,
xamat at clam-devel
--
/**
* Xavier Amatriain
* Music Technology Group
* Universitat Pompeu Fabra
* http://iua.upf.es/mtg/~xamat
*
*/
--
/**
* Xavier Amatriain
* Music Technology Group
* Universitat Pompeu Fabra
* http://iua.upf.es/mtg/~xamat
*
*/
More information about the clam-users
mailing list