Hi all,<br><br>I've been trying to get CLAM to load an audio file, analyze it, and write the results to an SDIF file. So far I have CLAM reading audio into a segment, but when I give this segment to the class SpectralAnalysis everything goes down with a null pointer exception because the segment doesn't yet have any frames. I'm not sure what I need to do here. I could create a new Frame object and add it to the Segment's frame list, but there must be a class that is responsible for chopping the audio data into frames. So, I really shouldn't need to do this. The question is what class does this? After one loads audio data into a Segment what does one have to do to create the list of frames before passing the Segment on to the analysis routine?
<br><br>I've included an example file below that illustrates what I'm talking about. The null pointer exception comes at the line<br> while (aSpectralAnalysis.Do( aSegment )) {}<br>
And it's thrown inside the SpectralAnalysis object when that object tries to access a Frame object that doesn't exist.<br><br>Best,<br>Greg<br><br><br>#include "SimpleOscillator.hxx"<br>#include "SMSAnalysisCore.hxx
"<br>#include "SMSAnalysisConfig.hxx"<br>#include "SMSSynthesis.hxx"<br>#include "Audio.hxx"<br>#include "Frame.hxx"<br>#include "Segment.hxx"<br>#include "AudioOutPort.hxx
"<br>#include "MonoAudioFileReader.hxx"<br>#include "AudioDatabaseReader.hxx"<br>#include "Network.hxx"<br>#include "SpectralAnalysis.hxx"<br>#include "SpectralPeakDetect.hxx
"<br>#include "Spectrum.hxx"<br>#include "SpectralPeakArray.hxx"<br>#include "SDIFOut.hxx"<br>#include "SpectralAnalysis.hxx"<br>#include "SpectralAnalysisConfig.hxx"
<br>#include "AudioFileIn.hxx"<br>#include "AudioFileConfig.hxx"<br><br>#define AUDIO_IN_FILE "/Users/greg/Music/samples/MyPatches/EBowGuitarWav/EBow_Guitar_A4_RS.wav"<br>#define SDIF_OUT_FILE "/Users/greg/Music/samples/MyPatches/EBowGuitarSDIF/EBow_Guitar_A4_RS_cmd.sdif"
<br><br>class SDIFWriterApp;<br><br>class SDIFWriterApp<br>{<br>public:<br> void setUp()<br> {<br> }<br><br> CLAM::SMSSynthesis mSynthesis;<br><br> const int helperResAnalWindowSize() { return 1025; }<br>// const int helperAnalWindowSize() { return 2049; }
<br> const int helperAnalWindowSize() { return 1025; }<br> const int helperAnalHopSize() {return 512;}<br><br><br> //TODO: fix. it runs but produces a broken sinusoidal<br> void testAnalysisSynthesis() //no segment, no frame just streaming inner data
<br> {<br>// CLAM::ErrAssertionFailed::breakpointInCLAMAssertEnabled = true;<br><br> unsigned int buffersize = 1024;<br> int samplerate = 44100;<br> int frameSize = 2048;<br> <br> CLAM::Segment aSegment = CLAM::Segment();
<br> std::string filename = std::string(AUDIO_IN_FILE);<br> LoadSound(filename, aSegment);<br><br> aSegment.SetFramesArray(CLAM::List<CLAM::Frame>());<br> aSegment.SetChildren(CLAM::List<CLAM::Segment>());
<br> aSegment.mCurrentFrameIndex=0;<br> <br> CLAM::SpectralAnalysisConfig aSpectralAnalysisConfig;<br> aSpectralAnalysisConfig.SetprHopSize( 256 );<br> aSpectralAnalysisConfig.SetprZeroPadding
( 2 );<br> aSpectralAnalysisConfig.SetprFFTSize( 2048 );<br><br> std::cout << "About to request audio from the segment." << std::endl;<br> CLAM::Audio theAudio = aSegment.GetAudio
();<br> std::cout << "Retrieved " << theAudio.GetDuration() << " milliseconds of audio from the segment." << std::endl;<br> <br> CLAM::SpectralAnalysis aSpectralAnalysis( aSpectralAnalysisConfig );
<br> aSpectralAnalysis.Start();<br> while (aSpectralAnalysis.Do( aSegment )) {}<br> aSpectralAnalysis.Stop();<br><br> CLAM::SDIFOutConfig theSDIFOutConfig;<br> theSDIFOutConfig.SetEnableFundFreq
(false);<br> theSDIFOutConfig.SetEnablePeakArray(true);<br> theSDIFOutConfig.SetEnableResidual(true);<br> theSDIFOutConfig.SetFileName( SDIF_OUT_FILE );<br> theSDIFOutConfig.SetFrameSize(frameSize);
<br> theSDIFOutConfig.SetSamplingRate(samplerate);<br> theSDIFOutConfig.SetSpectrumSize(buffersize);<br> CLAM::SDIFOut theSDIFOut(theSDIFOutConfig);<br><br> theSDIFOut.Start();<br> int nFrames =
aSegment.GetnFrames();<br> for( int i=0; i<nFrames; i++ )<br> {<br> theSDIFOut.Do( aSegment.GetFrame( i ) );<br> }<br> theSDIFOut.Stop( );<br> //myMonoAudioFileReader.Stop();
<br> }<br> <br> // helper methods for the network tests<br> const CLAM::SMSAnalysisConfig& helperAnalysisConfigInstance()<br> {<br><br> int analHopSize = 512;<br>// analHopSize= (resAnalWindowSize-1)/2 ;
<br><br>// int synthFrameSize = analHopSize;<br> int analZeroPaddingFactor= 2;<br> <br> // SMS Analysis configuration <br> static CLAM::SMSAnalysisConfig analConfig;<br> <br>
analConfig.SetSinWindowSize(helperAnalWindowSize() );<br> analConfig.SetHopSize(analHopSize);<br>// analConfig.SetSinWindowType(mGlobalConfig.GetAnalysisWindowType());<br> analConfig.SetSinZeroPadding
(analZeroPaddingFactor);<br> analConfig.SetResWindowSize( helperResAnalWindowSize() );<br>// analConfig.SetResWindowType(mGlobalConfig.GetResAnalysisWindowType());<br><br>// analConfig.GetPeakDetect().SetMagThreshold(
mGlobalConfig.GetAnalysisPeakDetectMagThreshold());<br>// analConfig.GetPeakDetect().SetMaxFreq(mGlobalConfig.GetAnalysisPeakDetectMaxFreq());<br>// analConfig.GetSinTracking().SetIsHarmonic(mGlobalConfig.GetAnalysisHarmonic
());<br>// analConfig.GetFundFreqDetect().SetReferenceFundFreq(mGlobalConfig.GetAnalysisReferenceFundFreq());<br>// analConfig.GetFundFreqDetect().SetLowestFundFreq(mGlobalConfig.GetAnalysisLowestFundFreq());
<br>// analConfig.GetFundFreqDetect().SetHighestFundFreq(mGlobalConfig.GetAnalysisHighestFundFreq());<br><br> return analConfig;<br> }<br> <br> const CLAM::SMSSynthesisConfig & helperSynthesisConfigInstance()
<br> {<br> static CLAM::SMSSynthesisConfig synthConfig;<br> int synthFrameSize = helperAnalHopSize();<br> synthConfig.SetAnalWindowSize( helperResAnalWindowSize() );<br> synthConfig.SetFrameSize
(synthFrameSize);<br> synthConfig.SetHopSize(synthFrameSize);<br> return synthConfig;<br> }<br><br> bool LoadSound(const std::string& filename, CLAM::Segment& segment)<br> {<br> CLAM::AudioFileIn myAudioFileIn;
<br> CLAM::AudioFileConfig infilecfg;<br> infilecfg.SetFilename(filename);<br> infilecfg.SetFiletype(CLAM::EAudioFileType::eWave);<br> if(!myAudioFileIn.Configure(infilecfg))<br> {<br> std::cout << "Configuration of audio file failed. Does file exist?" << std::endl;
<br> return false;<br> }<br> <br> /////////////////////////////////////////////////////////////////////////////<br> // Initialization of the processing data objects :<br> CLAM::TSize fileSize=
myAudioFileIn.Size();<br> <br> int mSamplingRate = int(myAudioFileIn.SampleRate());<br> <br> // Spectral Segment that will actually hold data<br> float duration=fileSize/mSamplingRate;<br>
segment.SetEndTime(duration);<br> segment.SetSamplingRate(mSamplingRate);<br> segment.mCurrentFrameIndex=0;<br> segment.GetAudio().SetSize(fileSize);<br> segment.GetAudio().SetSampleRate(mSamplingRate);
<br> <br> <br> //Read Audio File<br> myAudioFileIn.Start();<br> bool response = myAudioFileIn.Do(segment.GetAudio());<br> myAudioFileIn.Stop();<br> return true;<br> }<br><br>
};<br><br>int main(int argc,char** argv)<br>{<br>// try<br>// {<br><br> SDIFWriterApp app;<br> app.testAnalysisSynthesis();<br> std::cout << "all done" << std::endl;<br>/*<br>
}<br> catch(Err error)<br> {<br> error.Print();<br> std::cerr << "Abnormal Program Termination" << std::endl;<br> return -1;<br> }<br> catch (std::exception e)<br>
{<br> std::cout << e.what() << std::endl;<br> return -1;<br> }<br>*/ <br> return 0;<br>}<br><br><br><br>