Create Project for repo.or.cz
[vp.git] / test / dsp_test.cpp
blob9a5537123491401e38fb0fd70321950cfa88de8b
1 /*******************************************************************************
2 * File Name : test/dsp_test.cpp
3 *
4 * Author : Henry He
5 * Created Time : Fri 23 Oct 2009 10:49:00 AM CST
6 * Description :
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 ******************************************************************************/
35 #if 0
36 static UINT32 m_unFrameCnt;
37 static UINT32 m_unFramesLength;
38 #endif
41 // Audio buffer
42 static UINT8 m_aucAudioBuffer [8000 * DSP_TEST_TIME_SECS];
43 static volatile UINT8 *m_pucAudioBuffer;
44 static volatile UINT32 m_unAudioCntLeft;
47 /******************************************************************************
48 * Desc : Functions
49 ******************************************************************************/
50 void OnAudioRead (void *pvParam, void *pvBuf, UINT32 unLen)
52 HLH_Audio *pzhaAudioDev;
54 ASSERT (pvParam != NULL);
56 #if 0
57 m_unFrameCnt++;
58 m_unFramesLength += unLen;
59 #endif
61 pzhaAudioDev = (HLH_Audio *) pvParam;
63 #if 0
64 pzhaAudioDev->Write (pvBuf, unLen);
65 #else
66 if ( m_unAudioCntLeft > 0 ) {
67 UINT32 unCopyLen;
68 unCopyLen = m_unAudioCntLeft >= unLen ? unLen : m_unAudioCntLeft;
69 memcpy ((void*)m_pucAudioBuffer, pvBuf, unCopyLen);
70 m_pucAudioBuffer += unCopyLen;
71 m_unAudioCntLeft -= unCopyLen;
73 #endif
80 /******************************************************************************
81 * Func : main
82 * Desc :
83 * Args :
84 * Outs :
85 ******************************************************************************/
86 int main ()
88 int nRetVal;
89 HLH_Audio zhaAudioDev;
91 #if 0
92 HLH_Time m_zhtStartTime;
93 HLH_Time m_zhtEndTime;
95 UINT32 m_unSeconds;
97 m_unFrameCnt = 0;
98 m_unFramesLength = 0;
99 m_zhtStartTime = HLH_Time::GetCurrentTime ();
100 #endif
102 #if 1
103 int vol;
104 int mixer_fd;
106 mixer_fd = open ("/dev/mixer", O_RDWR);
107 if (mixer_fd < 0) {
108 Printf ("can't open mixer\n");
109 goto failed;
112 nRetVal = ioctl (mixer_fd, SOUND_MIXER_READ_MIC, &vol);
113 if (nRetVal == -1) {
114 Printf ("can't get mic volumn");
115 goto failed;
117 Printf ("volume = %d\n", vol);
119 vol = 80;
120 nRetVal = ioctl (mixer_fd, SOUND_MIXER_WRITE_MIC, &vol);
121 if (nRetVal == -1) {
122 Printf ("can't set mic volumn\n");
123 goto failed;
125 Printf ("set volumn to %d\n", vol);
126 #endif
128 m_pucAudioBuffer = m_aucAudioBuffer;
129 m_unAudioCntLeft = sizeof(m_aucAudioBuffer);
131 nRetVal = zhaAudioDev.Create (OnAudioRead, &zhaAudioDev, AFMT_U8, 8000, 1, 8, 16) ;
133 if (nRetVal < 0) {
134 goto failed;
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) );
146 #if 0
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);
153 #endif
155 zhaAudioDev.Destroy ();
157 return 0;
159 failed:
160 return -1;
162 } /* ---------- end of function main ---------- */