[CLAM] Help with AudioCircularBuffer

Pau Arumi parumi at iua.upf.es
Thu May 19 05:50:29 PDT 2005

Xavier Amatriain wrote:

>Hi again,
>>Winamp feeds my music analysis plugin with frame audio data through a
>>callback function. I use the circular buffer to aggregate enought data to
>>do a FFT of a reasonably sized frame. How do you suggest I use In and
>>Outport in this case?
>If you are using it to connect to the "outside world" then it is a good
>choice. We use similar workarounds when developing VST plugins with CLAM.
>In this case the Port mechanism would not help.
Don't agree on that, I think the Ports are, actually, a very good choice 
for that problem.

Look the following test/example, or others in 

    void testAudioPortsProduceAndConsume_whenDifferentSizes()
        CLAM::AudioOutPort out;
        CLAM::AudioInPort in;
        int writerFrameSize = 4;
        int readerFrameSize = 6;
        out.SetSize( writerFrameSize );
        out.SetHop( writerFrameSize );
        in.SetSize( readerFrameSize );
        in.SetHop( readerFrameSize );
        CLAM::Audio & toProduce = out.GetAudio();
        for(int i=0;i<writerFrameSize;i++)
            toProduce.GetBuffer()[i] = i;
        CPPUNIT_ASSERT_EQUAL( false, in.CanConsume() );
        CLAM::Audio & toProduce2 = out.GetAudio();
        for(int i=0;i<writerFrameSize;i++)
            toProduce2.GetBuffer()[i] = i+writerFrameSize;
        const CLAM::Audio & toConsume = in.GetAudio();
        for(int i=0;i<readerFrameSize;i++)
            CPPUNIT_ASSERT_EQUAL( (CLAM::TData)i, 
toConsume.GetBuffer()[i] );

Of course you would need to set a different in.SetHop(...),
and copy the callback in-buffer to the out.GetAudio()

Also notice that there is an already usable SpectralAnalysis which
performs windowing, fft, etc. and is port based. That means that you could
connect the "auxiliary" out-port to the SpectralAnalysis in-port.

Actually, SpectralAnalysis it have two ports attributes: an InAudioPort 
and an
OutPort<Spectrum>. You can change the in-port hopsize as a configuration 

Hope this help


More information about the clam-users mailing list