⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 bargraph.c

📁 dsp 5416dsk aduio音效code
💻 C
字号:
/*****************************************************************************/
/* FILENAME                                                                  */
/* 	 bargraph.c                                                              */
/*                                                                           */
/* DESCRIPTION                                                               */
/*   Configures four user LEDs as a bargraph display.                        */
/*   Different formats of display for mono audio, stereo audio or power      */
/*   for use with Fast Fourier Transform (FFT).                              */
/*                                                                           */
/* VERSION                                                                   */
/*   1.01                                                                    */
/*                                                                           */
/* AUTHOR                                                                    */
/*   Bao Xiaojing                                                            */
/*                                                                           */
/* REVISION HISTORY                                                          */
/*   VER   DATE        AUTHOR          DESCRIPTION                           */
/* ------------------------------------------------------------------------  */
/*   1.01  2008.12.06  Bao Xiaojing    Update 3 audio effects.               */
/*   1.00  2002.10.30  Richard Sikora  Initial version.                      */
/*                                                                           */
/*****************************************************************************/

#include "AudioEffectcfg.h"

#include "dsk5416.h"
#include "dsk5416_led.h"


/*****************************************************************************/
/* Reference thresholds                                                      */
/*---------------------------------------------------------------------------*/
/*                                                                           */
/* 0 dB reference is taken to be 50% output level. This allows 6dB headroom  */
/* Other thresholds are -6dB, -12dB and -18dB below the reference of 0dB.    */
/*                                                                           */
/*****************************************************************************/

#define LEVEL_0dB  0x4000
#define LEVEL_6dB  0x2000
#define LEVEL_12dB 0x1000
#define LEVEL_18dB 0x0800

/*****************************************************************************/
/* bargraph_mono()                                                           */
/*---------------------------------------------------------------------------*/
/*                                                                           */
/* Bargraph for use with a single (mono) signal.                             */
/*                                                                           */
/*****************************************************************************/

void bargraph_mono(signed int input)
{
    /* If input is negative, then convert to positive */

    if ( 0x8000 == input)  /* Special case where input = -32768 */
    {
        input = 0x7FFF;      /*  Make input +32767. There is no +32768! */
    }
    else if ( input < 0 )
    {
        input = - input;     /* Make negative values positive */
    }

    if ( input > LEVEL_0dB)
    {
        /* Large input signal. Turn on all 4 LEDs */
        DSK5416_LED_on(0);
        DSK5416_LED_on(1);
        DSK5416_LED_on(2);
        DSK5416_LED_on(3);
    }
    else if ( input > LEVEL_6dB)
    {
        /* Smaller signal. Turn on 3 LEDs */
        DSK5416_LED_off(0);
        DSK5416_LED_on(1);
        DSK5416_LED_on(2);
        DSK5416_LED_on(3);
    }
    else if ( input > LEVEL_12dB)
    {
        /* Turn on 2 LEDs */
        DSK5416_LED_off(0);
        DSK5416_LED_off(1);
        DSK5416_LED_on(2);
        DSK5416_LED_on(3);
    }
    else if ( input > LEVEL_18dB)
    {
        /* Turn on 1 LED */
        DSK5416_LED_off(0);
        DSK5416_LED_off(1);
        DSK5416_LED_off(2);
        DSK5416_LED_on(3);
    }
    else
    {
        /* Small or no input signal. Turn off all LEDs */
        DSK5416_LED_off(0);
        DSK5416_LED_off(1);
        DSK5416_LED_off(2);
        DSK5416_LED_off(3);
    }

}

/*****************************************************************************/
/* bargraph()                                                                */
/*---------------------------------------------------------------------------*/
/*                                                                           */
/* Displays greater of two inputs as a bargraph. For mono use, use the       */
/* single mono input for both the left and the right channels.               */
/*                                                                           */
/*****************************************************************************/

void bargraph(signed int left_channel, signed int right_channel)
{
    signed int input;

    /* If left channel is negative, then convert to positive */

    if ( 0x8000 == left_channel)  /* Special case where input = -32768 */
    {
        left_channel= 0x7FFF;      /*  Make input +32767. There is no +32768! */
    }
    else if ( left_channel < 0)
    {
        left_channel = - left_channel;     /* Make negative values positive */
    }

    /* If right channel is negative, then convert to positive */

    if ( 0x8000 == right_channel)  /* Special case where input = -32768 */
    {
        right_channel= 0x7FFF;      /*  Make input +32767. There is no +32768! */
    }
    else if ( right_channel < 0)
    {
        right_channel = - right_channel;     /* Make negative values positive */
    }

    /* Display the greater of the two channels */

    if ( right_channel > left_channel)
    {
        input = right_channel;
    }
    else
    {
        input = left_channel;
    }

    if ( input > LEVEL_0dB)
    {
        /* Large input signal. Turn on all 4 LEDs */
        DSK5416_LED_on(0);
        DSK5416_LED_on(1);
        DSK5416_LED_on(2);
        DSK5416_LED_on(3);
    }
    else if ( input > LEVEL_6dB)
    {
        /* Smaller signal. Turn on 3 LEDs */
        DSK5416_LED_off(0);
        DSK5416_LED_on(1);
        DSK5416_LED_on(2);
        DSK5416_LED_on(3);
    }
    else if ( input > LEVEL_12dB)
    {
        /* Turn on 2 LEDs */
        DSK5416_LED_off(0);
        DSK5416_LED_off(1);
        DSK5416_LED_on(2);
        DSK5416_LED_on(3);
    }
    else if ( input > LEVEL_18dB)
    {
        /* Turn on 1 LED */
        DSK5416_LED_off(0);
        DSK5416_LED_off(1);
        DSK5416_LED_off(2);
        DSK5416_LED_on(3);
    }
    else
    {
        /* Small or no input signal. Turn off all 4 LEDs */
        DSK5416_LED_off(0);
        DSK5416_LED_off(1);
        DSK5416_LED_off(2);
        DSK5416_LED_off(3);
    }

}

/*****************************************************************************/
/* spectrum_analyser_display()                                               */
/*---------------------------------------------------------------------------*/
/*                                                                           */
/* Each input represents the power in a particular frequency band, and       */
/* therefore can only be positive.                                           */
/*                                                                           */
/*****************************************************************************/

void spectrum_analyser_display( unsigned int input1,
                                unsigned int input2,
                                unsigned int input3,
                                unsigned int input4 )
{
    /* Display each input on a different LED */

    if ( input1 > LEVEL_0dB)
    {
        DSK5416_LED_on(3);
    }
    else
    {
        DSK5416_LED_off(3);
    }

    if ( input2 > LEVEL_0dB)
    {
        DSK5416_LED_on(2);
    }
    else
    {
        DSK5416_LED_off(2);
    }

    if ( input3 > LEVEL_0dB)
    {
        DSK5416_LED_on(1);
    }
    else
    {
        DSK5416_LED_off(1);
    }

    if ( input4 > LEVEL_0dB)
    {
        DSK5416_LED_on(0);
    }
    else
    {
        DSK5416_LED_off(0);
    }

}

/*****************************************************************************/
/* End of bargraph.c                                                         */
/*****************************************************************************/

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -