Hi <span class="sg">Giacomo,<br><br>Thanks! Those files are going to be really useful for me. <br><br>Best,<br>Greg<br><br></span><br><div><span class="gmail_quote">On 6/20/07, <b class="gmail_sendername">Giacomo Sommavilla
</b> <<a href="mailto:azeem@libero.it">azeem@libero.it</a>> wrote:</span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">hi greg!<br><br>
Here is a minimal program we use to analyze short speech audio chunks (we are developing a CLAM-based module for a TTS system) and store each one of them into a sdif file.<br>I also attach a standard xml analysis config file..
<br><br>..hope they are useful :-)<br><br>giacomo.<br><br><br><br><br>> Hi all,<br>><br>> I've been trying to get CLAM to load an audio file, analyze it, and write<br>> the results to an SDIF file. So far I have CLAM reading audio into a
<br>> segment, but when I give this segment to the class SpectralAnalysis<br>> everything goes down with a null pointer exception because the segment<br>> doesn't yet have any frames. I'm not sure what I need to do here. I could
<br>> create a new Frame object and add it to the Segment's frame list, but there<br>> must be a class that is responsible for chopping the audio data into<br>> frames. So, I really shouldn't need to do this. The question is what class
<br>> does this? After one loads audio data into a Segment what does one have to<br>> do to create the list of frames before passing the Segment on to the<br>> analysis routine?<br>><br>> I've included an example file below that illustrates what I'm talking
<br>> 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<br>> 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<br>> "/Users/greg/Music/samples/MyPatches/EBowGuitarWav/EBow_Guitar_A4_RS.wav"<br>> #define SDIF_OUT_FILE
<br>> "/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
<br>> 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." <<
<br>> std::endl;<br>> CLAM::Audio theAudio = aSegment.GetAudio();<br>> std::cout << "Retrieved " << theAudio.GetDuration() << "<br>> 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>> ());<br>> analConfig.SetSinZeroPadding(analZeroPaddingFactor);<br>>
analConfig.SetResWindowSize( helperResAnalWindowSize() );<br>> // analConfig.SetResWindowType(mGlobalConfig.GetResAnalysisWindowType<br>> ());<br>><br>> // analConfig.GetPeakDetect().SetMagThreshold(
<br>> mGlobalConfig.GetAnalysisPeakDetectMagThreshold());<br>> // analConfig.GetPeakDetect().SetMaxFreq(<br>> mGlobalConfig.GetAnalysisPeakDetectMaxFreq());<br>> // analConfig.GetSinTracking().SetIsHarmonic(
<br>> mGlobalConfig.GetAnalysisHarmonic());<br>> // analConfig.GetFundFreqDetect().SetReferenceFundFreq(<br>> mGlobalConfig.GetAnalysisReferenceFundFreq());<br>> // analConfig.GetFundFreqDetect().SetLowestFundFreq(
<br>> mGlobalConfig.GetAnalysisLowestFundFreq());<br>> // analConfig.GetFundFreqDetect().SetHighestFundFreq(<br>> 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
<br>> exist?" << std::endl;<br>> return false;<br>> }<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>Clam-devel mailing list<br><a href="mailto:Clam-devel@llistes.projectes.lafarga.org">Clam-devel@llistes.projectes.lafarga.org</a><br><a href="https://llistes.projectes.lafarga.org/cgi-bin/mailman/listinfo/clam-devel">
https://llistes.projectes.lafarga.org/cgi-bin/mailman/listinfo/clam-devel</a><br><br><br></blockquote></div><br>