Exemplo n.º 1
0
//*****************************************************************************
//
//! Initializes the sound output.
//!
//! This function prepares the sound driver to play songs or sound effects.  It
//! must be called before any other sound function.  The sound driver uses
//! uDMA and the caller must ensure that the uDMA peripheral is enabled and
//! its control table configured prior to making this call.
//!
//! \return None
//
//*****************************************************************************
void
SoundInit(void)
{
    //
    // Set the current active buffer to zero.
    //
    g_ulPlaying = 0;

    //
    // Enable and reset the peripheral.
    //
    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_I2S0);

    //
    // Select alternate functions for all of the I2S pins.
    //
    ROM_SysCtlPeripheralEnable(I2S0_SCLKTX_PERIPH);
    GPIOPinTypeI2S(I2S0_SCLKTX_PORT, I2S0_SCLKTX_PIN);

    ROM_SysCtlPeripheralEnable(I2S0_LRCTX_PERIPH);
    GPIOPinTypeI2S(I2S0_LRCTX_PORT, I2S0_LRCTX_PIN);

    ROM_SysCtlPeripheralEnable(I2S0_SDATX_PERIPH);
    GPIOPinTypeI2S(I2S0_SDATX_PORT, I2S0_SDATX_PIN);

    ROM_SysCtlPeripheralEnable(I2S0_MCLKTX_PERIPH);
    GPIOPinTypeI2S(I2S0_MCLKTX_PORT, I2S0_MCLKTX_PIN);

    //
    // Initialize the DAC.
    //
    WM8510Init();

    //
    // Set the intial volume level
    //
    WM8510VolumeSet(g_ucVolume);

    //
    // Set the FIFO trigger limit
    //
    I2STxFIFOLimitSet(I2S0_BASE, 4);

    //
    // Clear out all pending interrupts.
    //
    I2SIntClear(I2S0_BASE, I2S_INT_TXERR | I2S_INT_TXREQ );

    //
    // Enable the I2S interrupt on the NVIC
    //
    ROM_IntEnable(INT_I2S0);

    //
    // Disable all uDMA attributes.
    //
    ROM_uDMAChannelAttributeDisable(UDMA_CHANNEL_I2S0TX, UDMA_ATTR_ALL);
}
Exemplo n.º 2
0
int main(void)
{
	long address = 0;
	int record = 0;
	int selector_efecto = 0;
    ///tremolo2
	double trem_triangular = -0.5;
	int trem_subida = 1;
	///tremolo2
	///wahwah
	double wah_triangular = 500;
	int wah_subida = 1;
    double last_wah_wah_yb, last_wah_wah_yh, last_wah_wah_yl;
    int first_time_wah_wah_function = 1;
	///wahwah
    ///phaser
	double phaser_triangular = 500;
    int phaser_subida = 1;
    int first_time_phaser_function = 1;
    double last_phaser_yb, last_phaser_yh, last_phaser_yl;
    //Phaser
	/* Configure Oscillator to operate the device at 40MHz.
	 * Fosc= Fin*M/(N1*N2), Fcy=Fosc/2
	 * Fosc= 700Mhz for 7.37M input clock */

	PLLFBD=41;				/* M=39	*/
	CLKDIVbits.PLLPOST=0;		/* N1=2	*/
	CLKDIVbits.PLLPRE=0;		/* N2=2	*/
	OSCTUN=0;

	__builtin_write_OSCCONH(0x01);		/*	Initiate Clock Switch to FRC with PLL*/
	__builtin_write_OSCCONL(0x01);
	while (OSCCONbits.COSC != 0b01);	/*	Wait for Clock switch to occur	*/
	while(!OSCCONbits.LOCK);

	/* Intialize the board and the drivers	*/
	SASKInit();
	WM8510Init(codecHandle,codecBuffer);

	/* Start Audio input and output function	*/
	WM8510Start(codecHandle);

	/* Configure codec for 8K operation	*/
	WM8510SampleRate8KConfig(codecHandle);

	/* Main processing loop. Executed for every input and
	 * output frame	*/

	while(1) {
        /*Obtain Audio Samples	*/
        while(WM8510IsReadBusy(codecHandle));
        WM8510Read(codecHandle,samples,FRAME_SIZE);

        G711Lin2Ulaw(samples,encodedSamples,FRAME_SIZE);

        /* Decode the samples	*/
        G711Ulaw2Lin (encodedSamples,decodedSamples, FRAME_SIZE);

        /* Wait till the codec is available for a new  frame	*/
        while(WM8510IsWriteBusy(codecHandle));

        switch(selector_efecto) {
            case 0:
                // prenden los leds
                RED_LED=SASK_LED_OFF;
                YELLOW_LED=SASK_LED_OFF;
                GREEN_LED=SASK_LED_OFF;
                // se activa el clean
                break;

            case 1:
                // prenden los leds
                RED_LED=SASK_LED_OFF;
                YELLOW_LED=SASK_LED_OFF;
                GREEN_LED=SASK_LED_ON;
                // Se activa el efecto de tremolo
                tremolo_effect(decodedSamples);
                break;

            case 2:
                // prenden los leds
                RED_LED=SASK_LED_OFF;
                YELLOW_LED=SASK_LED_ON;
                GREEN_LED=SASK_LED_OFF;
                // Se activa el efecto de tremolo2
                 trem_triangular = tremolo_effect2(trem_triangular, &trem_subida, decodedSamples);
                break;
            case 3:
                // prenden los leds
                RED_LED=SASK_LED_OFF;
                YELLOW_LED=SASK_LED_ON;
                GREEN_LED=SASK_LED_ON;
                // Se activa el efecto de fuzz
                fuzz_effect(decodedSamples);
                break;
            case 4:
                // prenden los leds
                RED_LED=SASK_LED_ON;
                YELLOW_LED=SASK_LED_OFF;
                GREEN_LED=SASK_LED_OFF;
                // Se activa el efecto de wah wah
                wah_triangular = wah_wah_effect(wah_triangular, &wah_subida, decodedSamples, &last_wah_wah_yb, &last_wah_wah_yh, &last_wah_wah_yl, &first_time_wah_wah_function);
                break;
            case 5:
                // prenden los leds
                RED_LED=SASK_LED_ON;
                YELLOW_LED=SASK_LED_OFF;
                GREEN_LED=SASK_LED_ON;
		        phaser_triangular = phaser_effect(phaser_triangular, &phaser_subida, decodedSamples, &last_phaser_yb, &last_phaser_yh, &last_phaser_yl, &first_time_phaser_function);
                                
// Se activa el efecto de wah wah
                break;
            case 6:
                // prenden los leds
                RED_LED=SASK_LED_ON;
                YELLOW_LED=SASK_LED_ON;
                GREEN_LED=SASK_LED_OFF;
                // Se activa el efecto de wah wah
                break;
            case 7:
                // prenden los leds
                RED_LED=SASK_LED_ON;
                YELLOW_LED=SASK_LED_ON;
                GREEN_LED=SASK_LED_ON;
                // Se activa el efecto de wah wah
                break;
            default:
                break;

        }
        /* Write the frame to the output	*/
        WM8510Write (codecHandle,decodedSamples,FRAME_SIZE);

        if(CheckSwitchS1()){
            selector_efecto--;
        }

        if(CheckSwitchS2()){
            selector_efecto++;
        }
        // rango de 0-7 para selector de efectos
        if (selector_efecto < 0 ) {
            selector_efecto = 7;
        }
        if (selector_efecto > 7  ) {
            selector_efecto = 0;
        }
	}
}