[CLAM] how to use the SpectrumAnalysis object in pitch detection?
Martijn Bosma
M.Bosma at ai.rug.nl
Tue Mar 23 10:51:37 PST 2004
Hello,
I have some problems with finding the fundamental frequency of an audio
object.
The code of my function can be found below.
As its input it uses an audio object called chunk.
chunk contains one note of a melody. (more or less one second in length)
My main problem is to go from an audio object to its spectrum
- Is it possible for the SpectrumAnalysis object to analyse the spectrum
of this chunk at once?
- How do I configure the spectrum analysis object for this task?
(zeropadding, hopsize, windowsize, windowtype and circularshift?)
- when I run the program and the program reaches the do method of the
SpectralAnalysis object in my code, I get the following exception
breakpoint:
ASSERTION FAILED
spectrum.cxx line 647:
Spectrum::GetSize(): Complex size and Size mismatch.
this is probably because of a wrong configuration of the
spectralAnalysis object or because of the size of the audio chunk.
- for the configuration of the FundFreqDetect and the SpectralPeakDetect
objects I use the default values of their configuration classes.
(e.g. ffdConfig.DefaultValues();)
is this correct, or necessary?
I have sent this problem before to the clamlist, but then I
was not clear about what I would like to know.
I think now I have sent the code as well it is easier for people to see
where I go wrong here.
Thanks in advance for helping
Martijn
*************************************************************
//THE CODE:
// chunk is an audio object containing one note of the melody
// this method gets the fundamental frequency of chunk.
// It stores the resulting fundamental object in
// the "vector<Fundamental> pitches"
void MyCLAMApp::DoFunfreq(Audio chunk)
{
// make spectrum object
SpectrumConfig cfg;
cfg.SetSize(chunk_size / 2 + 1);
Spectrum spec;
spec.Configure(cfg);
spec.ToDB();
// spectrum analyzer
// sampleRate = samplerate of the audio object chunk
SpectralAnalysisConfig sac;
sac.AddAll();
sac.UpdateData();
sac.SetSamplingRate(sampleRate);
sac.SetZeroPadding(0);
sac.SetHopSize(0);
sac.SetWindowSize(513);
sac.SetWindowType(EWindowType::eHamming);
sac.SetHopSize((sac.GetWindowSize()-1)/2);
sac.GetCircularShift().SetAmount(-256);
SpectralAnalysis sa;
sa.Configure(sac);
sa.Start();
sa.Do(chunk, spec); // this line of code causes the exception
breakpoint
sa.Stop();
// get the spectralpeak array from spectrum
SpectralPeakDetectConfig detectPeaksConfig;
detectPeaksConfig.DefaultValues();
SpectralPeakDetect detectPeaks;
detectPeaks.Configure(detectPeaksConfig);
SpectralPeakArray peaks;
peaks.SetScale(EScale(EScale::eLog));
detectPeaks.Start();
detectPeaks.Do(spec, peaks);
detectPeaks.Stop();
// fundamental frequency detection
Fundamental fund;
fund.AddCandidatesFreq();
fund.AddCandidatesErr();
fund.UpdateData();
fund.SetnCandidates(0);
fund.SetnMaxCandidates(60);
FundFreqDetectConfig ffdConfig;
ffdConfig.DefaultValues();
FundFreqDetect ffd;
ffd.Configure(ffdConfig);
ffd.Start();
ffd.Do(peaks, fund);
ffd.Stop();
// store the fundamental object
pitches.push_back(fund);
}
More information about the clam-users
mailing list