Search code examples
audioadcdacchuck

How do i get the frequency of the microphone in ChucK?


I need to get the frequency that comes out of the microphone input, in order to play certain notes on a sequencer or any instrument depending on the microphone tone. I use this code to output de microphone

adc => dac;  
while(true){
    0.1::second=>now;
    }

Is there any function that is used on adb to be able to do what I want? Thanks! :D


Solution

  • The easiest way to do this is to modify the Spectral Centroid UAna example.

    /// sending the mic through the analysis instead of SinOsc
    adc => FFT fft =^ Centroid cent => blackhole;
    
    float trackedFrequency; 
    
    512 => fft.size;
    Windowing.hann(512) => fft.window;
    
    second / samp => float srate;
    
    while( true )
    {
        cent.upchuck();
    
        // modifying the example to put the analysis in a variable
        cent.fval(0) * srate / 2 => trackedFrequency; 
        <<< trackedFrequency >>>; // use it set the frequency of something else
    
        fft.size()::samp => now; // advance time
    }