1 /*******************************************************************************
2 * File Name : test/dsp_test.cpp
5 * Created Time : Fri 23 Oct 2009 10:49:00 AM CST
7 ******************************************************************************/
10 /*******************************************************************************
11 * Desc : Includes Files
12 ******************************************************************************/
13 #include "src/common.h"
14 #include <sys/soundcard.h>
17 /*******************************************************************************
18 * Desc : Macro Definations
19 ******************************************************************************/
20 #define DSP_TEST_TIME_SECS 10
22 /*******************************************************************************
23 * Desc : Type Definations
24 ******************************************************************************/
27 /*******************************************************************************
28 * Desc : Global Variables
29 ******************************************************************************/
32 /*******************************************************************************
33 * Desc : File Variables
34 ******************************************************************************/
36 static UINT32 m_unFrameCnt
;
37 static UINT32 m_unFramesLength
;
42 static UINT8 m_aucAudioBuffer
[8000 * DSP_TEST_TIME_SECS
];
43 static volatile UINT8
*m_pucAudioBuffer
;
44 static volatile UINT32 m_unAudioCntLeft
;
47 /******************************************************************************
49 ******************************************************************************/
50 void OnAudioRead (void *pvParam
, void *pvBuf
, UINT32 unLen
)
52 HLH_Audio
*pzhaAudioDev
;
54 ASSERT (pvParam
!= NULL
);
58 m_unFramesLength
+= unLen
;
61 pzhaAudioDev
= (HLH_Audio
*) pvParam
;
64 pzhaAudioDev
->Write (pvBuf
, unLen
);
66 if ( m_unAudioCntLeft
> 0 ) {
68 unCopyLen
= m_unAudioCntLeft
>= unLen
? unLen
: m_unAudioCntLeft
;
69 memcpy ((void*)m_pucAudioBuffer
, pvBuf
, unCopyLen
);
70 m_pucAudioBuffer
+= unCopyLen
;
71 m_unAudioCntLeft
-= unCopyLen
;
80 /******************************************************************************
85 ******************************************************************************/
89 HLH_Audio zhaAudioDev
;
92 HLH_Time m_zhtStartTime
;
93 HLH_Time m_zhtEndTime
;
99 m_zhtStartTime
= HLH_Time::GetCurrentTime ();
106 mixer_fd
= open ("/dev/mixer", O_RDWR
);
108 Printf ("can't open mixer\n");
112 nRetVal
= ioctl (mixer_fd
, SOUND_MIXER_READ_MIC
, &vol
);
114 Printf ("can't get mic volumn");
117 Printf ("volume = %d\n", vol
);
120 nRetVal
= ioctl (mixer_fd
, SOUND_MIXER_WRITE_MIC
, &vol
);
122 Printf ("can't set mic volumn\n");
125 Printf ("set volumn to %d\n", vol
);
128 m_pucAudioBuffer
= m_aucAudioBuffer
;
129 m_unAudioCntLeft
= sizeof(m_aucAudioBuffer
);
131 nRetVal
= zhaAudioDev
.Create (OnAudioRead
, &zhaAudioDev
, AFMT_U8
, 8000, 1, 8, 16) ;
137 Printf ("Start to record (%ds)\n", DSP_TEST_TIME_SECS
);
138 while ( m_unAudioCntLeft
!= 0 ) {
139 HLH_Time::Wait (HLH_Time(1, 0));
142 Printf ("Playback\n");
143 zhaAudioDev
.Write ( m_aucAudioBuffer
, sizeof(m_aucAudioBuffer
) );
147 m_zhtEndTime
= HLH_Time::GetCurrentTime ();
149 m_unSeconds
= m_zhtEndTime
.GetSeconds () - m_zhtStartTime
.GetSeconds ();
150 Printf ("Time = %u, Frames = %u, Frames Length = %u\n",
151 m_unSeconds
, m_unFrameCnt
, m_unFramesLength
);
152 Printf ("FPS = %u fps, BPS = %u Bps", m_unFrameCnt
/m_unSeconds
, m_unFramesLength
/m_unSeconds
);
155 zhaAudioDev
.Destroy ();
162 } /* ---------- end of function main ---------- */