pattern.c
void vMagVisualization ( const uint32_t ulPatternCount )
{
    /* The real FFT does not provide symmetry so divide FFT_SIZE by 2. */
    float32_t ufFourierFrequency[RFFT_SIZE] = { 0.0F };

    /* FFT max variables */
    static float32_t fPrevMaxFFTMag = 0.0F;
    static uint32_t usPrevMaxFFTIdx = 0U;
    float32_t fMaxFFTMag = 0.0F;
    uint32_t usMaxFFTIdx = 0U;

    /* Do the FFT. */
    vPerformFFT( ufFourierFrequency );

    /* Get the max FFT magnitude and its index. */
    ufFourierFrequency[0] = 0.0F;
    arm_max_f32( ufFourierFrequency, RFFT_SIZE, &fMaxFFTMag, &usMaxFFTIdx );
    
    // Saturate the FFT magnitude
    if ( fMaxFFTMag > configAUDIO_MAGNITUDE_VIS_MAX_BRIGHTNESS )
    {
        fMaxFFTMag = configAUDIO_MAGNITUDE_VIS_MAX_BRIGHTNESS;
    }

    if ( fPrevMaxFFTMag + configAUDIO_MAGNITUDE_VIS_SWITCH_HYSTERESIS > fMaxFFTMag )
    {
        // Current must be bigger by configAUDIO_MAGNITUDE_VIS_SWITCH_HYSTERESIS
        // or more in order for the new frequency to be switched to
        fMaxFFTMag = fPrevMaxFFTMag;
        usMaxFFTIdx = usPrevMaxFFTIdx;
    }

    float32_t bins[6] = { 0.0F };
    //bins[0] = configAUDIO_MAGNITUDE_VIS_TRIANG_GAIN * fTriangWeight(ufFourierFrequency,  100.0F,   90.0F);
    bins[1] = configAUDIO_MAGNITUDE_VIS_TRIANG_GAIN * fTriangWeight(ufFourierFrequency,  150.0F,  150.0F);
    bins[2] = configAUDIO_MAGNITUDE_VIS_TRIANG_GAIN * fTriangWeight(ufFourierFrequency,  500.0F,  300.0F);
    bins[3] = configAUDIO_MAGNITUDE_VIS_TRIANG_GAIN * fTriangWeight(ufFourierFrequency, 1100.0F,  1500.0F);
    //bins[4] = configAUDIO_MAGNITUDE_VIS_TRIANG_GAIN * fTriangWeight(ufFourierFrequency, 2500.0F, 3750.0F);
    //bins[5] = configAUDIO_MAGNITUDE_VIS_TRIANG_GAIN * fTriangWeight(ufFourierFrequency, 6250.0F, 9750.0F);

    /** Set R, G and B */
    uint8_t ucR = (uint8_t)bins[1];
    uint8_t ucG = (uint8_t)bins[2];
    uint8_t ucB = (uint8_t)bins[3];

    // Right now we use only 3 bins to determine color but we use the whole frequency spectrum
    // to determine the brightness.  Is this a bad thing? Maybe people like it?
    // Should we use the whole frequency spectrum?  Should we only use the three bins?
    /* Modulate the number of LEDs that are lit based on the brightness. */
    uint16_t usLedsToLight = (uint16_t)( ( NUMBER_OF_LEDS / 2 ) * fMaxFFTMag / configAUDIO_MAGNITUDE_VIS_MAX_BRIGHTNESS );

    /* Set the LEDs */
    for ( int16_t i = (NUMBER_OF_LEDS / 2); i >= 0 ; i-- )
    {
        if ( i > (NUMBER_OF_LEDS / 2) - usLedsToLight )
        {
            /* Light the LEDs. */
            vSetLed( i, ucR, ucG, ucB );
            vSetLed( NUMBER_OF_LEDS - i, ucR, ucG, ucB );
        }
        else
        {
            /* Turn leds off. */
            vSetLed( i, 0, 0, 0 );
            vSetLed( NUMBER_OF_LEDS - i, 0, 0, 0 );
        }
    }

    fPrevMaxFFTMag = fMaxFFTMag - configAUDIO_MAGNITUDE_VIS_PREV_DECAY_RATE;
    if (fPrevMaxFFTMag < 0)
    {
        fPrevMaxFFTMag = 0;
    }
}
/**
  * @brief  Create magnitude visualization pattern.
  * @retval None
  */
@brief  Create magnitude visualization pattern.
@retval None
@brief Create magnitude visualization pattern . @retval None
void vMagVisualization ( const uint32_t ulPatternCount )
{
    float32_t ufFourierFrequency[RFFT_SIZE] = { 0.0F };
    static float32_t fPrevMaxFFTMag = 0.0F;
    static uint32_t usPrevMaxFFTIdx = 0U;
    float32_t fMaxFFTMag = 0.0F;
    uint32_t usMaxFFTIdx = 0U;
    vPerformFFT( ufFourierFrequency );
    ufFourierFrequency[0] = 0.0F;
    arm_max_f32( ufFourierFrequency, RFFT_SIZE, &fMaxFFTMag, &usMaxFFTIdx );
    if ( fMaxFFTMag > configAUDIO_MAGNITUDE_VIS_MAX_BRIGHTNESS )
    {
        fMaxFFTMag = configAUDIO_MAGNITUDE_VIS_MAX_BRIGHTNESS;
    }
    if ( fPrevMaxFFTMag + configAUDIO_MAGNITUDE_VIS_SWITCH_HYSTERESIS > fMaxFFTMag )
    {
        fMaxFFTMag = fPrevMaxFFTMag;
        usMaxFFTIdx = usPrevMaxFFTIdx;
    }
    float32_t bins[6] = { 0.0F };
    bins[1] = configAUDIO_MAGNITUDE_VIS_TRIANG_GAIN * fTriangWeight(ufFourierFrequency,  150.0F,  150.0F);
    bins[2] = configAUDIO_MAGNITUDE_VIS_TRIANG_GAIN * fTriangWeight(ufFourierFrequency,  500.0F,  300.0F);
    bins[3] = configAUDIO_MAGNITUDE_VIS_TRIANG_GAIN * fTriangWeight(ufFourierFrequency, 1100.0F,  1500.0F);
    uint8_t ucR = (uint8_t)bins[1];
    uint8_t ucG = (uint8_t)bins[2];
    uint8_t ucB = (uint8_t)bins[3];
    uint16_t usLedsToLight = (uint16_t)( ( NUMBER_OF_LEDS / 2 ) * fMaxFFTMag / configAUDIO_MAGNITUDE_VIS_MAX_BRIGHTNESS );
    for ( int16_t i = (NUMBER_OF_LEDS / 2); i >= 0 ; i-- )
    {
        if ( i > (NUMBER_OF_LEDS / 2) - usLedsToLight )
        {
            vSetLed( i, ucR, ucG, ucB );
            vSetLed( NUMBER_OF_LEDS - i, ucR, ucG, ucB );
        }
        else
        {
            vSetLed( i, 0, 0, 0 );
            vSetLed( NUMBER_OF_LEDS - i, 0, 0, 0 );
        }
    }
    fPrevMaxFFTMag = fMaxFFTMag - configAUDIO_MAGNITUDE_VIS_PREV_DECAY_RATE;
    if (fPrevMaxFFTMag < 0)
    {
        fPrevMaxFFTMag = 0;
    }
}
void vMagVisualization ( const uint32_t ulPatternCount ) { float32_t ufFourierFrequency [ RFFT_SIZE ] = { 0.0F } ; static float32_t fPrevMaxFFTMag = 0.0F ; static uint32_t usPrevMaxFFTIdx = 0U ; float32_t fMaxFFTMag = 0.0F ; uint32_t usMaxFFTIdx = 0U ; vPerformFFT ( ufFourierFrequency ) ; ufFourierFrequency [ 0 ] = 0.0F ; arm_max_f32 ( ufFourierFrequency , RFFT_SIZE , & fMaxFFTMag , & usMaxFFTIdx ) ; if ( fMaxFFTMag > configAUDIO_MAGNITUDE_VIS_MAX_BRIGHTNESS ) { fMaxFFTMag = configAUDIO_MAGNITUDE_VIS_MAX_BRIGHTNESS ; } if ( fPrevMaxFFTMag + configAUDIO_MAGNITUDE_VIS_SWITCH_HYSTERESIS > fMaxFFTMag ) { fMaxFFTMag = fPrevMaxFFTMag ; usMaxFFTIdx = usPrevMaxFFTIdx ; } float32_t bins [ 6 ] = { 0.0F } ; bins [ 1 ] = configAUDIO_MAGNITUDE_VIS_TRIANG_GAIN * fTriangWeight ( ufFourierFrequency , 150.0F , 150.0F ) ; bins [ 2 ] = configAUDIO_MAGNITUDE_VIS_TRIANG_GAIN * fTriangWeight ( ufFourierFrequency , 500.0F , 300.0F ) ; bins [ 3 ] = configAUDIO_MAGNITUDE_VIS_TRIANG_GAIN * fTriangWeight ( ufFourierFrequency , 1100.0F , 1500.0F ) ; uint8_t ucR = ( uint8_t ) bins [ 1 ] ; uint8_t ucG = ( uint8_t ) bins [ 2 ] ; uint8_t ucB = ( uint8_t ) bins [ 3 ] ; uint16_t usLedsToLight = ( uint16_t ) ( ( NUMBER_OF_LEDS / 2 ) * fMaxFFTMag / configAUDIO_MAGNITUDE_VIS_MAX_BRIGHTNESS ) ; for ( int16_t i = ( NUMBER_OF_LEDS / 2 ) ; i >= 0 ; i -- ) { if ( i > ( NUMBER_OF_LEDS / 2 ) - usLedsToLight ) { vSetLed ( i , ucR , ucG , ucB ) ; vSetLed ( NUMBER_OF_LEDS - i , ucR , ucG , ucB ) ; } else { vSetLed ( i , 0 , 0 , 0 ) ; vSetLed ( NUMBER_OF_LEDS - i , 0 , 0 , 0 ) ; } } fPrevMaxFFTMag = fMaxFFTMag - configAUDIO_MAGNITUDE_VIS_PREV_DECAY_RATE ; if ( fPrevMaxFFTMag < 0 ) { fPrevMaxFFTMag = 0 ; } }
@brief  Create magnitude visualization pattern.
@brief Create magnitude visualization pattern .
/* The real FFT does not provide symmetry so divide FFT_SIZE by 2. */ /* FFT max variables */ /* Do the FFT. */ /* Get the max FFT magnitude and its index. */ // Saturate the FFT magnitude // Current must be bigger by configAUDIO_MAGNITUDE_VIS_SWITCH_HYSTERESIS // or more in order for the new frequency to be switched to //bins[0] = configAUDIO_MAGNITUDE_VIS_TRIANG_GAIN * fTriangWeight(ufFourierFrequency,  100.0F,   90.0F); //bins[4] = configAUDIO_MAGNITUDE_VIS_TRIANG_GAIN * fTriangWeight(ufFourierFrequency, 2500.0F, 3750.0F); //bins[5] = configAUDIO_MAGNITUDE_VIS_TRIANG_GAIN * fTriangWeight(ufFourierFrequency, 6250.0F, 9750.0F); /** Set R, G and B */ // Right now we use only 3 bins to determine color but we use the whole frequency spectrum // to determine the brightness.  Is this a bad thing? Maybe people like it? // Should we use the whole frequency spectrum?  Should we only use the three bins? /* Modulate the number of LEDs that are lit based on the brightness. */ /* Set the LEDs */ /* Light the LEDs. */ /* Turn leds off. */