📄 wmaudiotesthelpers.c
字号:
/*-----------------------------------------------------------------------------
* 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: WMAudioTestHelpers.c 2819 2006-03-27 08:03:10Z fb $
*
* This file contains helper functions for the audio tests.
*
* Warning:
* This driver is specifically written for Wolfson Codecs. It is not a
* general CODEC device driver.
*
* -----------------------------------------------------------------------------*/
/*
* Include files
*/
#include "WMCommon.h"
#include "WMDevice.h"
#include "WMControlLink.h"
#include "WMAudioPaths.h"
#include "WM97AudioDefs.h"
#include "WMAudio.h"
#include "WM8753Audio.h"
#include "Test/WMTestCommon.h"
#include "Test/WMAudioTestHelpers.h"
/*
* Only build this if we are asked to.
*/
#if WM_AUDIO && WM_TESTING
/*
* Global definitions
*/
#define TEST_VOLUME WM_AUDIO_MAX_AMPLITUDE
#define SECOND 1000
/*
* An octave.
*/
#define PITCH_A 440
#define EQUAL_TEMPERAMENT TRUE
#if EQUAL_TEMPERAMENT
/*
* In equal temperament, all semi-tones are equal (and all but the tonic
* are out of tune). Each semi-tone is the previous one multiplied by the
* 12th root of 2 (since an octave is a doubling in frequency).
*/
# define EQUAL_SEMITONE 1.05946309
# define NEXT_SEMITONE(_p) ((int)(((double)(_p))*EQUAL_SEMITONE))
# define PITCH_ASHARP NEXT_SEMITONE(PITCH_A)
# define PITCH_B NEXT_SEMITONE(PITCH_ASHARP)
# define PITCH_C NEXT_SEMITONE(PITCH_B)
# define PITCH_CSHARP NEXT_SEMITONE(PITCH_C)
# define PITCH_D NEXT_SEMITONE(PITCH_CSHARP)
# define PITCH_DSHARP NEXT_SEMITONE(PITCH_D)
# define PITCH_E NEXT_SEMITONE(PITCH_DSHARP)
# define PITCH_F NEXT_SEMITONE(PITCH_E)
# define PITCH_FSHARP NEXT_SEMITONE(PITCH_F)
# define PITCH_G NEXT_SEMITONE(PITCH_FSHARP)
# define PITCH_GSHARP NEXT_SEMITONE(PITCH_G)
#else /* EQUAL_TEMPERAMENT */
/*
* In just temperament, the notes are defined by their exact interval from
* the tonic. This means that tunes in keys other than the tonic are likely
* to sound badly out of tune, but in the key of the tonic, all intervals are
* accurate.
*/
# define PITCH_ASHARP (PITCH_A*16/15)
# define PITCH_B (PITCH_A*9/8)
# define PITCH_C (PITCH_A*6/5)
# define PITCH_CSHARP (PITCH_A*5/4)
# define PITCH_D (PITCH_A*4/3)
# define PITCH_DSHARP (PITCH_D*16/15)
# define PITCH_E (PITCH_A*3/2)
# define PITCH_F (PITCH_A*8/5)
# define PITCH_FSHARP (PITCH_A*5/3)
# define PITCH_G (PITCH_A*9/5)
# define PITCH_GSHARP (PITCH_A*15/8)
#endif /* EQUAL_TEMPERAMENT */
/*
* Up and down an octave.
*/
#define OCT_UP(_p) ((PITCH_ ## _p)*2)
#define OCT_DOWN(_p) ((PITCH_ ## _p)/2)
/*
* Private data
*/
static WM_TEST_SOUND s_testSounds[] =
{
{ PITCH_D, TEST_VOLUME, SECOND },
{ PITCH_E, TEST_VOLUME, SECOND },
{ PITCH_C, TEST_VOLUME, SECOND },
{ OCT_DOWN(C), TEST_VOLUME, SECOND },
{ OCT_DOWN(G), TEST_VOLUME, 2*SECOND }
};
static int s_nextSound = 0;
/*
* Function prototypes
*/
/*-----------------------------------------------------------------------------
* Function: WMTestAudio_GetSound
*
* Helper function for audio tests - returns the next sound to play.
* By picking our sounds from a list, we can check that no sounds are missed
* out by checking that it generates the correct tune.
*
* Parameters:
* none
*
* Returns: const WM_TEST_SOUND *
* Pointer to next sound to play.
*---------------------------------------------------------------------------*/
const WM_TEST_SOUND *WMTestAudio_GetSound()
{
const WM_TEST_SOUND *pSound = &s_testSounds[s_nextSound];
s_nextSound = (s_nextSound + 1) % WM_ARRAY_COUNT( s_testSounds );
return pSound;
}
#endif /* WM_AUDIO && WM_TESTING */
/*------------------------------ END OF FILE ---------------------------------*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -