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

📄 wmxscaleaudiotests.c

📁 WM9713 audio codec driver for WinCE 5.0
💻 C
📖 第 1 页 / 共 2 页
字号:
	{
		WMTEST_SKIP();	
	}
    /*
     * Power up, enable and unmute the Mono output path.
     */
    WMTEST_CALL( WMAudioPowerUp( hDevice,WM_POWER_AUDIO_PLAYBACK ) );

    WMTEST_CALL( WMAudioEnableOutputPaths( hDevice, WM_STREAM_MONO_OUT, TRUE ) );

    WMTEST_CALL( WMAudioMuteAllOutputs( hDevice, FALSE ) );

    /*
     * Set the sample rate for the AuxDAC.
     */
    WMTEST_CALL( WMAudioSetSampleRate( hDevice,
                                       WM_STREAM_MONO_OUT,
                                       sampleRate
                                     )
               );


    /*
     * Work out the number of repeats to get our duration.
     */
    repeats = WM_TEST_REPEATS( TEST_BUFFER_DURATION,
                               sampleRate,
                               samplesPerBuffer
                             );

    /*
     * Generate a sine wave.  The parameters should work out so an exact
     * number of cycles fits in the buffer.
     */    
    WMGenerateSineWave( g_buffer,
                        samplesPerBuffer,
                        sampleRate,
                        frequency,
                        amplitude,
                        WM_WAVEGEN_MONO,
                        NULL
                        );
                        
    /*
     * Now keep pumping the sine waves at the registers.
     */
    do
    {
        for ( repeat = 0; repeat < repeats; repeat++ )
        {
            for ( currPoint = 0; currPoint < samplesPerBuffer; currPoint++ )
            {
                /*
                 * Wait for the start of a new frame.
                 * This is signified by a pulse on the SYNC line.
                 */
                while (!(v_pGPIORegs->GPIO_REG_0_31(GPLR) & GPIO_BIT_SYNC))
                    /* Wait for it to go high */;
                while (  v_pGPIORegs->GPIO_REG_0_31(GPLR) & GPIO_BIT_SYNC )
                    /* Wait for it to go low */;
                    
                /* Now write the new sample to the FIFO */
                v_pAC97Regs->MODR = g_buffer[currPoint].sampleVal;
            }
        }
    }
    while ( loopForever );

    /*
     * Mute, disable and power down the Mono output path.
     */
    WMTEST_CALL( WMAudioMuteAllOutputs( hDevice, TRUE ) );

    WMTEST_CALL( WMAudioEnableOutputPaths( hDevice, WM_STREAM_MONO_OUT, FALSE ) );

    WMTEST_CALL( WMAudioPowerDown( hDevice,WM_POWER_AUDIO_PLAYBACK ) );

#else /* WM_MONODAC */
	WMTEST_SKIP();	
#endif /* WM_MONODAC */
}
WMTEST_END

/*-----------------------------------------------------------------------------
 * Function:    WMTestVoiceDACDirect
 *
 * Plays a sound directly to the Voice DAC, hitting the controller registers
 * directly (i.e. not using DMA).
 *
 * Parameters:
 *      hDevice     handle to the device (from WMOpenDevice)
 *
 * Returns:     WM_BOOL
 *      TRUE if it passed, FALSE if it failed in a way it could detect.
 *---------------------------------------------------------------------------*/
WMTEST_START( WMTestVoiceDACDirect( WM_DEVICE_HANDLE hDevice ) )
{
#if WM_VOICE
	unsigned int                repeat = 0;
	unsigned int                repeats = 0;
	unsigned int                currPoint			= 0;
	unsigned int                samplesPerBuffer	= 
									WM_ARRAY_COUNT( g_buffer );
	WM_XSCALE_DEVICE_CONTEXT    *pDeviceContext		=
									(WM_XSCALE_DEVICE_CONTEXT *) hDevice;
	VOLATILE_GPIO_T             *v_pGPIORegs		= 
									pDeviceContext->v_pGPIORegs;

	/*
	 * The following values are put into variables so they can be
	 * altered in a debugger.
	 */
	int                         loopForever			= CONTINUAL_VOICE;
	int                         sampleRate			= TEST_SAMPLE_RATE_VOICE;
	int                         frequency			= TEST_FREQUENCY;
	int                         amplitude			= TEST_AMPLITUDE;

    
	if ( !WM_HAS_VOICE_DAC( hDevice ) )
	{
		WMTEST_SKIP();	
	}

    /*
     * Power up, enable and umute the Voice output path.
     */
    WMTEST_CALL( WMAudioPowerUp( hDevice,WM_POWER_AUDIO_PLAYBACK ) );

    WMTEST_CALL( WMAudioEnableOutputPaths( hDevice, WM_STREAM_VOICE_OUT, TRUE ) );

    WMTEST_CALL( WMAudioMuteAllOutputs( hDevice, FALSE ) );

	/*
	 * Set the sample rate for the VoiceDAC.
	 */
	WMTEST_CALL( WMAudioSetSampleRate( hDevice,
									   WM_STREAM_VOICE_OUT,
									   sampleRate
									 )
			   );

	/*
	 * Work out the number of repeats to get our duration.
	 */
	repeats = WM_TEST_REPEATS( TEST_BUFFER_DURATION,
							   sampleRate,
							   samplesPerBuffer
							 );

	/*
	 * Generate a sine wave.  The parameters should work out so an exact
	 * number of cycles fits in the buffer.
	 */    
	WMGenerateSineWave( g_buffer,
						samplesPerBuffer,
						sampleRate,
						frequency,
						amplitude,
						WM_WAVEGEN_MONO,
						NULL
						);

	/*
	 * Enable and start the Voice DAC Interface.
	 */
	WMTEST_CALL( WMAudioEnableStream( hDevice, WM_STREAM_VOICE_OUT ) );
	WMVoiceStart( hDevice );

	/*
	 * Now keep pumping the sine waves at the registers.
	 */
	do
	{
		for ( repeat = 0; repeat < repeats; repeat++ )
		{
			for ( currPoint = 0; currPoint < samplesPerBuffer; currPoint++ )
			{
                WM_STATUS status = private_fillVoiceFifo( hDevice, currPoint );
                if ( WM_ERROR( status ) )
                {
                    WM_TRACE( hDevice, ( "Timed out filling FIFO - skipping test" ) );
                    WMTEST_SKIP();
                }
			}
		}
	}
	while ( loopForever );

	/*
	 * Stop, mute, disable and power down the Voice DAC Interface.
	 */
	WMVoiceStop( hDevice );

    WMTEST_CALL( WMAudioMuteAllOutputs( hDevice, TRUE ) );

    WMTEST_CALL( WMAudioEnableOutputPaths( hDevice, WM_STREAM_VOICE_OUT, FALSE ) );

    WMTEST_CALL( WMAudioPowerDown( hDevice,WM_POWER_AUDIO_PLAYBACK ) );

#else /* WM_VOICE */
	WMTEST_SKIP();	
#endif /* WM_VOICE */
}
WMTEST_END

#if WM_AC97
/*-----------------------------------------------------------------------------
 * Function:    private_fillAC97HiFiFifo
 *
 * Fill the AC97 HiFi Fifo directly.
 *
 * Parameters:
 *      hDevice     handle to the device (from WMOpenDevice)
 *
 * Returns:     WM_STATUS
 *      WMS_SUCCESS         - succeeded
 *      WMS_DATA_TIMED_OUT  - couldn't do write
 *---------------------------------------------------------------------------*/
static WM_STATUS private_fillAC97HiFiFifo( WM_DEVICE_HANDLE hDevice,
                                           unsigned int currPoint
                                         )
{
    WM_XSCALE_DEVICE_CONTEXT	*pDeviceContext =
        (WM_XSCALE_DEVICE_CONTEXT*) hDevice;

    /*
     * Wait for the start of a new frame.
     * This is signified by a pulse on the SYNC line.
     */
    while (!(pDeviceContext->v_pGPIORegs->GPIO_REG_0_31(GPLR) & GPIO_BIT_SYNC))
        /* Wait for it to go high */;
    while (  pDeviceContext->v_pGPIORegs->GPIO_REG_0_31(GPLR) & GPIO_BIT_SYNC )
        /* Wait for it to go low */;
    
    /* Now write the new sample to the FIFO */
    pDeviceContext->v_pAC97Regs->PCDR = g_buffer[currPoint].sampleVal;

    return WMS_SUCCESS;
}
#endif /* WM_AC97 */

#if WM_I2S
/*-----------------------------------------------------------------------------
 * Function:    private_fillI2SHiFiFifo
 *
 * Fill the I2S HiFi Fifo directly.
 *
 * Parameters:
 *      hDevice     handle to the device (from WMOpenDevice)
 *
 * Returns:     WM_STATUS
 *      WMS_SUCCESS         - succeeded
 *      WMS_DATA_TIMED_OUT  - couldn't do write
 *---------------------------------------------------------------------------*/
static WM_STATUS private_fillI2SHiFiFifo( WM_DEVICE_HANDLE hDevice,
                                          unsigned int currPoint
                                        )
{
    WM_XSCALE_DEVICE_CONTEXT *pDeviceContext = (WM_XSCALE_DEVICE_CONTEXT*) hDevice;
    unsigned int             timeout = 0;

    while ( !(pDeviceContext->v_pI2SRegs->SASR0 & 0x8) && timeout < TRANSMIT_TIMEOUT )
    {
        timeout++;
    }

    if ( timeout >= TRANSMIT_TIMEOUT )
        return WMS_DATA_TIMED_OUT;

    pDeviceContext->v_pI2SRegs->SAICR |= XLLP_SAICR_TUR;
    pDeviceContext->v_pI2SRegs->SADR = g_buffer[currPoint].sampleVal;

    return WMS_SUCCESS;
}
#endif /* WM_I2S */

#if WM_VOICE
/*-----------------------------------------------------------------------------
 * Function:    private_fillVoiceFifo
 *
 * Fill the Voice (SSP2) Fifo directly.
 *
 * Parameters:
 *      hDevice     handle to the device (from WMOpenDevice)
 *
 * Returns:     WM_STATUS
 *      WMS_SUCCESS         - succeeded
 *      WMS_DATA_TIMED_OUT  - couldn't do write
 *---------------------------------------------------------------------------*/
static WM_STATUS private_fillVoiceFifo( WM_DEVICE_HANDLE hDevice,
                                        unsigned int currPoint
                                      )
{
    WM_XSCALE_DEVICE_CONTEXT *pDeviceContext = (WM_XSCALE_DEVICE_CONTEXT*) hDevice;
    unsigned int             timeout = 0;
	VOLATILE_SSP_T           *v_pSSP2Regs = pDeviceContext->v_pSSP2Regs;

    while ( !(v_pSSP2Regs->ssr & XLLP_SSSP_TNF) && timeout < TRANSMIT_TIMEOUT )
    {
        timeout++;
    }

    if ( timeout >= TRANSMIT_TIMEOUT )
        return WMS_DATA_TIMED_OUT;

    v_pSSP2Regs->ssdr = g_buffer[currPoint].sampleVal;

    return WMS_SUCCESS;
}
#endif /* WM_VOICE */

#endif  /* WM_AUDIO && WM_TESTING */

/*------------------------------ END OF FILE ---------------------------------*/

⌨️ 快捷键说明

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