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

📄 wmxscaleaudiotests.c

📁 WM9713 audio codec driver for WinCE 5.0
💻 C
📖 第 1 页 / 共 2 页
字号:
/*-----------------------------------------------------------------------------
 * Copyright (c) Wolfson Microelectronics plc.  All rights reserved.
 *
 * This software as well as any related documentation is furnished under 
 * license and may only be used or copied in accordance with the terms of the 
 * license. The information in this file is furnished for informational use 
 * only, is subject to change without notice, and should not be construed as 
 * a commitment by Wolfson Microelectronics plc. Wolfson Microelectronics plc
 * assumes no responsibility or liability for any errors or inaccuracies that
 * may appear in this document or any software that may be provided in
 * association with this document. 
 *
 * Except as permitted by such license, no part of this document may be 
 * reproduced, stored in a retrieval system, or transmitted in any form or by 
 * any means without the express written consent of Wolfson Microelectronics plc. 
 *
 * $Id: WM97xxTest.c 611 2004-09-28 13:55:23Z ib $
 *
 * This file contains platform-specific audio tests for the Wolfson codecs on 
 * Intel's XScale platforms.
 *
 * Warning:
 *  This driver is specifically written for Wolfson Codecs. It is not a 
 *  general CODEC device driver.
 *
 * -----------------------------------------------------------------------------*/

/*
 * Include files
 */
#include "WMCommon.h"
#include "WMWaveGen.h"
#include "WMACLink.h"
#include "WMAudio.h"
#include "WMPlatform_Raw.h"
#include "WMPlatformDeviceContext.h"
#include "WMRegisterDefs.h"
#include "WMAudioDefs.h"
#include "WMVoice.h"
#include "WMPlatformDebug.h"
#include "WMDevice.h"
#include "WMAudioPaths.h"
#include "Test/WMTestCommon.h"
#include "Test/WMTestHelpers.h"
#include "Test/WMPlatformTests.h"
#include "Test/WMAudioTestHelpers.h"

/*
 * Only build this if we are asked to.
 */
#if WM_AUDIO && WM_TESTING

/*
 * Global definitions
 */
#define TEST_SAMPLE_RATE_HIFI   48000
#define TEST_SAMPLE_RATE_MONO   48000
#define TEST_SAMPLE_RATE_VOICE  8000
#define TEST_BUFFER_SIZE        256
#define TEST_BUFFER_DURATION    2000    /* in ms */

/*
 * The frequency is worked out carefully so that we fill the
 * buffer with a sequence of sine waves that will loop correctly
 * from the end point of the buffer to the start point of the buffer.
 */
#define TEST_FREQUENCY          (sampleRate*2/samplesPerBuffer)
#define TEST_AMPLITUDE          32768   /* 0dBFS */

#define TRANSMIT_TIMEOUT        1000

/*
 * Define these to TRUE to run the tests forever.
 */
#define CONTINUAL_HIFI          FALSE
#define CONTINUAL_MONO          FALSE
#define CONTINUAL_VOICE         FALSE

/*
 * Private data
 */

WM_AUDIO_STEREO_SAMPLE          g_buffer[TEST_BUFFER_SIZE];

/*
 * Function prototypes
 */
#if WM_AC97
static WM_STATUS private_fillAC97HiFiFifo( WM_DEVICE_HANDLE hDevice,
                                           unsigned int currPoint
                                         );
#endif /* WM_AC97 */
#if WM_I2S
static WM_STATUS private_fillI2SHiFiFifo( WM_DEVICE_HANDLE hDevice,
                                          unsigned int currPoint
                                       );
#endif /* WM_I2S */
#if WM_VOICE
static WM_STATUS private_fillVoiceFifo( WM_DEVICE_HANDLE hDevice,
                                        unsigned int currPoint
                                      );
#endif /* WM_VOICE */

typedef WM_STATUS (*fillFifoFn) ( WM_DEVICE_HANDLE hDevice,
                                  unsigned int currPoint
                                );


/*-----------------------------------------------------------------------------
 * Function:    WMTestPlatformAudio
 *
 * Wolfson platform audio tests - plays sound via the various DACs hitting the 
 * platform registers directly.
 *
 * 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( WMTestPlatformAudio( WM_DEVICE_HANDLE hDevice ) )
{
    savedRegister   savedRegs[MAX_REGISTER_COUNT];
    WM_REGVAL       savedPowerReg[ MAX_GLOBAL_POWER_REGS ];
    WM_POWERFLAG    savedPowerRequirements[ WM_MAX_DRIVERS ];
    WM_POWERFLAG    savedWmPower = 0;
    
	/* Save our state */
	WMTEST_RUN( WMTest_SaveState( hDevice, 
								  savedRegs,
								  savedPowerReg,
								  savedPowerRequirements,
								  &savedWmPower ) );
    
    /*
     * Now run the tests
     *  - first hitting the hardware directly.
     */
	WMTEST_RUN( WMTestHiFiDACDirect( hDevice ) );
	WMTEST_RUN( WMTestMonoDACDirect( hDevice ) );
    WMTEST_RUN( WMTestVoiceDACDirect( hDevice ) );

#if WM_AUDIO_STREAM
    /*
     * - now using the DMA.
     */
    WMTEST_RUN( WMTestHiFiDACDMADirect( hDevice ) );
	WMTEST_RUN( WMTestMonoDACDMADirect( hDevice ) );
	WMTEST_RUN( WMTestVoiceDACDMADirect( hDevice ) );
#endif /* WM_AUDIO_STREAM */

	/* And set things back again. */
	WMTEST_RUN( WMTest_RestoreState( hDevice, 
									 savedRegs,
									 savedPowerReg,
									 savedPowerRequirements,
									 &savedWmPower ) );
}
WMTEST_END

/*-----------------------------------------------------------------------------
 * Function:    WMTestHiFiDACDirect
 *
 * Plays a sound directly to the HIFI 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( WMTestHiFiDACDirect( WM_DEVICE_HANDLE hDevice ) )
{
    unsigned int                repeat;
    unsigned int                repeats;
    fillFifoFn                  fnFillFifo;
    unsigned int                currPoint			= 0;
    unsigned int                samplesPerBuffer	= WM_ARRAY_COUNT( g_buffer );

    /* The following values are put into variables so they can be
     * altered in a debugger. */
    int                         loopForever			= CONTINUAL_HIFI;
    int                         sampleRate			= TEST_SAMPLE_RATE_HIFI;
    int                         frequency			= TEST_FREQUENCY;
    int                         amplitude			= TEST_AMPLITUDE;
        
    /*
     * Power up, enable and unmute the HiFi output path.
     */
    WMTEST_CALL( WMAudioPowerUp( hDevice,WM_POWER_AUDIO_PLAYBACK ) );

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

    WMTEST_CALL( WMAudioMuteAllOutputs( hDevice, FALSE ) );

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

    /*
     * Work out the number of repeats to get our duration.
     * One buffer contains WMAUDIO_MAX_BUFFER_SIZE bytes.
     */
    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_LEFT,
                        NULL
                        );
    WMGenerateSineWave( g_buffer,
                        samplesPerBuffer,
                        sampleRate,
                        frequency * 2,
                        amplitude,
                        WM_WAVEGEN_RIGHT,
                        NULL
                        );

#if WM_I2S
    if ( WM_IS_I2S( hDevice ) )
    {
        fnFillFifo = private_fillI2SHiFiFifo;
    }
#endif
#if WM_AC97
    if ( WM_IS_AC97( hDevice ) )
    {
        fnFillFifo = private_fillAC97HiFiFifo;
    }
#endif
                        
    /*
     * 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 = fnFillFifo( hDevice, currPoint );
                if ( WM_ERROR( status ) )
                {
                    WM_TRACE( hDevice, ( "Timed out filling FIFO - skipping test" ) );
                    WMTEST_SKIP();
                }
            }
        }
    }
    while ( loopForever );

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

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

    WMTEST_CALL( WMAudioPowerDown( hDevice,WM_POWER_AUDIO_PLAYBACK ) );
}
WMTEST_END

/*-----------------------------------------------------------------------------
 * Function:    WMTestMonoDACDirect
 *
 * Plays a sound directly to the Mono 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( WMTestMonoDACDirect( WM_DEVICE_HANDLE hDevice ) )
{
#if WM_MONODAC
    unsigned int                repeat;
    unsigned int                repeats;
    unsigned int                currPoint			= 0;
    unsigned int                samplesPerBuffer	= 
									WM_ARRAY_COUNT( g_buffer );
    WM_XSCALE_DEVICE_CONTEXT    *pDeviceContext		=
									(WM_XSCALE_DEVICE_CONTEXT *) hDevice;
    VOLATILE_AC97_T             *v_pAC97Regs		= 
									pDeviceContext->v_pAC97Regs;
    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_MONO;
    int                         sampleRate			= TEST_SAMPLE_RATE_MONO;
    int                         frequency			= TEST_FREQUENCY * 2;
    int                         amplitude			= TEST_AMPLITUDE;

	if ( !WM_HAS_MONO_DAC( hDevice ) )

⌨️ 快捷键说明

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