1 /*---------------------------------------------------------------------------*
2   Project:  TwlSDK - SPI - demos - mic-2
3   File:     main.c
4 
5   Copyright 2003-2008 Nintendo. All rights reserved.
6 
7   These coded instructions, statements, and computer programs contain
8   proprietary information of Nintendo of America Inc. and/or Nintendo
9   Company Ltd., and are protected by Federal copyright law. They may
10   not be disclosed to third parties or copied or duplicated in any form,
11   in whole or in part, without the prior written consent of Nintendo.
12 
13   $Date:: 2008-12-22#$
14   $Rev: 9714 $
15   $Author: okubata_ryoma $
16  *---------------------------------------------------------------------------*/
17 
18 /*---------------------------------------------------------------------------*
19     A sample that controls mic sampling status.
20 
21     USAGE:
22         UP, DOWN   : Control sampling span
23         LEFT, RIGHT: Control sampling bit range (8-bit or 12-bit)
24         A: Start / stop sampling (toggle)
25         B: Force-stop (Stop and ignore rest of data)
26 
27     HOWTO:
28         1. Initialize memory allocation system to get 32-byte aligned buffer.
29         2. Initialize MIC library.
30         3. When sampling is stopped, you can change status
31            and start auto sampling.
32            Debug-output is sampling data for mic2wav.exe tool.
33         4. Debug-output log can make its waveform files with mic2wav.exe tool.
34            > $(NITROSDK_ROOT)/tools/bin/mic2wav [logfile] [,directory]
35            Each sampling data (separated by A-button) creates a waveform file
36            in '[directory]/%08X.wav'.
37 
38     NOTE:
39         1. The speed of debug-output is later than sampling.
40            When you stop sampling, wait until all data is printed.
41 
42  *---------------------------------------------------------------------------*/
43 
44 #include    <nitro.h>
45 #include    <nitro/spi/common/pm_common.h>
46 #include    <nitro/spi/ARM9/pm.h>
47 
48 
49 /*---------------------------------------------------------------------------*
50     Constant Definitions
51  *---------------------------------------------------------------------------*/
52 #define     KEY_REPEAT_START    25     // Number of frames until key repeat starts
53 #define     KEY_REPEAT_SPAN     10     // Number of frames between key repeats
54 #define     TEST_BUFFER_SIZE    ( 1024 * 1024 ) // 1M
55 
56 
57 /*---------------------------------------------------------------------------*
58     Structure Definitions
59  *---------------------------------------------------------------------------*/
60 // Key input data
61 typedef struct KeyInformation
62 {
63     u16     cnt;                       // Unprocessed input value
64     u16     trg;                       // Push trigger input
65     u16     up;                        // Release trigger input
66     u16     rep;                       // Press and hold repeat input
67 
68 }
69 KeyInformation;
70 
71 /*---------------------------------------------------------------------------*
72     Internal Function Definitions
73  *---------------------------------------------------------------------------*/
74 static void InitializeAllocateSystem(void);
75 static void Init3D(void);
76 static void Draw3D(void);
77 static void DrawLine(s16 sx, s16 sy, s16 ex, s16 ey);
78 static void VBlankIntr(void);
79 static void KeyRead(KeyInformation * pKey);
80 static void SetDrawData(void *address, MICSamplingType type);
81 static void PrintfVariableData(void);
82 
83 /*---------------------------------------------------------------------------*
84     Internal Variable Definitions
85  *---------------------------------------------------------------------------*/
86 static KeyInformation gKey;
87 static MICAutoParam gMicAutoParam;
88 static u8 *gMicData;
89 static u8 gDrawData[192];
90 
91 
92 /* This differs from mic-1 in that there is a debug output of data and it is always "one-shot" recording
93    */
94 
95 /* Variables for waveform output */
96 static volatile BOOL g_sample_busy = FALSE;
97 static const void *g_record_smps = NULL;
98 
99 static void StartSampling(void);
100 static void OnSampleDone(MICResult result, void *arg);
101 static void OutputSampleWave(void *dat, MICSamplingType type);
102 static void StopSamplingOutput(void);
103 
104 /* Begin sampling */
StartSampling(void)105 static void StartSampling(void)
106 {
107     gMicAutoParam.buffer = (void *)gMicData;
108     gMicAutoParam.size = TEST_BUFFER_SIZE;
109     gMicAutoParam.loop_enable = FALSE;
110     gMicAutoParam.full_callback = OnSampleDone;
111     g_sample_busy = TRUE;
112     g_record_smps = gMicData;
113     PrintfVariableData();
114     (void)MIC_StartAutoSampling(&gMicAutoParam);
115 }
116 
117 /* End sampling output */
StopSamplingOutput(void)118 static void StopSamplingOutput(void)
119 {
120     OS_PutString("$end\n");
121     OS_PutString("\n");
122     g_record_smps = NULL;
123 }
124 
125 /* Sampling completion notification, or waveform output process at stop */
OnSampleDone(MICResult result,void * arg)126 static void OnSampleDone(MICResult result, void *arg)
127 {
128     (void)result;
129     (void)arg;
130     if (g_sample_busy)
131     {
132         g_sample_busy = FALSE;
133     }
134 }
135 
136 /* Waveform sampling log output*/
OutputSampleWave(void * dat,MICSamplingType type)137 static void OutputSampleWave(void *dat, MICSamplingType type)
138 {
139     /* Up to 2 lines at once with 16-sample units.
140        If you output more than this amount, the log may contain omissions. */
141     enum
142     { smps_per_line = 16, max_line_per_frame = 2 };
143     if (!g_record_smps || !dat)
144         return;
145 
146     DC_InvalidateRange((void *)g_record_smps, (u32)((u8 *)dat - (u8 *)g_record_smps));
147     switch (type)
148     {
149     case MIC_SAMPLING_TYPE_8BIT:
150         {
151             typedef u8 SMP;
152             /* The following is identical to MIC_SAMPLING_TYPE_12BIT */
153             char    buf[1 + (sizeof(SMP) * 2 + 1) * smps_per_line + 1 + 1], *s;
154             const SMP *from = (const SMP *)g_record_smps;
155             const SMP *to = (const SMP *)dat;
156             int     lines = 0;
157             while ((lines < max_line_per_frame) && (from + smps_per_line <= to))
158             {
159                 int     i, j;
160                 s = buf;
161                 *s++ = '|';
162                 for (i = 0; i < smps_per_line; ++i)
163                 {
164                     u32     unit = from[i];
165                     for (j = sizeof(SMP) * 8; (j -= 4) >= 0;)
166                     {
167                         u32     c = (u32)((unit >> j) & 0x0F);
168                         c += (u32)((c < 10) ? ('0' - 0) : ('A' - 10));
169                         MI_WriteByte(s++, (u8)c);
170                     }
171                     MI_WriteByte(s++, (u8)',');
172                 }
173                 MI_WriteByte(s++, (u8)'\n');
174                 MI_WriteByte(s++, (u8)'\0');
175                 OS_PutString(buf);
176                 from += smps_per_line;
177                 ++lines;
178             }
179             g_record_smps = from;
180 
181         }
182         break;
183     case MIC_SAMPLING_TYPE_12BIT:
184         {
185             typedef u16 SMP;
186             /* The following is identical to MIC_SAMPLING_TYPE_8BIT */
187             char    buf[1 + (sizeof(SMP) * 2 + 1) * smps_per_line + 1 + 1], *s;
188             const SMP *from = (const SMP *)g_record_smps;
189             const SMP *to = (const SMP *)dat;
190             int     lines = 0;
191             while ((lines < max_line_per_frame) && (from + smps_per_line <= to))
192             {
193                 int     i, j;
194                 s = buf;
195                 *s++ = '|';
196                 for (i = 0; i < smps_per_line; ++i)
197                 {
198                     u32     unit = from[i];
199                     for (j = sizeof(SMP) * 8; (j -= 4) >= 0;)
200                     {
201                         u32     c = (u32)((unit >> j) & 0x0F);
202                         c += (u32)((c < 10) ? ('0' - 0) : ('A' - 10));
203                         MI_WriteByte(s++, (u8)c);
204                     }
205                     MI_WriteByte(s++, (u8)',');
206                 }
207                 MI_WriteByte(s++, (u8)'\n');
208                 MI_WriteByte(s++, (u8)'\0');
209                 OS_PutString(buf);
210                 from += smps_per_line;
211                 ++lines;
212             }
213             g_record_smps = from;
214 
215         }
216         break;
217     }
218 
219     /* Also output remaining data after stopping sampling */
220     if (!g_sample_busy && g_record_smps)
221     {
222         if ((u8 *)g_record_smps + smps_per_line * 2 >= (u8 *)dat)
223         {
224             StopSamplingOutput();
225         }
226     }
227 
228 }
229 
230 
231 /*---------------------------------------------------------------------------*
232   Name:         NitroMain
233 
234   Description:  Initialization and main loop.
235 
236   Arguments:    None.
237 
238   Returns:      None.
239  *---------------------------------------------------------------------------*/
NitroMain(void)240 void NitroMain(void)
241 {
242     // Various types of initialization
243     OS_Init();
244     FX_Init();
245     GX_Init();
246     GX_DispOff();
247     GXS_DispOff();
248 
249     // Initializes display settings
250     GX_SetBankForLCDC(GX_VRAM_LCDC_ALL);
251     MI_CpuClearFast((void *)HW_LCDC_VRAM, HW_LCDC_VRAM_SIZE);
252     (void)GX_DisableBankForLCDC();
253     MI_CpuFillFast((void *)HW_OAM, 192, HW_OAM_SIZE);
254     MI_CpuClearFast((void *)HW_PLTT, HW_PLTT_SIZE);
255     MI_CpuFillFast((void *)HW_DB_OAM, 192, HW_DB_OAM_SIZE);
256     MI_CpuClearFast((void *)HW_DB_PLTT, HW_DB_PLTT_SIZE);
257 
258     // 3D-related initialization
259     Init3D();
260 
261     // Interrupt settings
262     OS_SetIrqFunction(OS_IE_V_BLANK, VBlankIntr);
263     (void)OS_EnableIrqMask(OS_IE_V_BLANK);
264     (void)OS_EnableIrq();
265     (void)OS_EnableInterrupts();
266     (void)GX_VBlankIntr(TRUE);
267 
268     //****************************************************************
269     // Initialize MIC.
270     InitializeAllocateSystem();
271     // Because the memory allocated with OS_Alloc is 32-byte aligned, other memory is not destroyed even if the cache is manipulated
272     //
273     gMicData = (u8 *)OS_Alloc(TEST_BUFFER_SIZE);
274     gMicAutoParam.type = MIC_SAMPLING_TYPE_12BIT;
275     gMicAutoParam.rate = MIC_SAMPLING_RATE_11K;
276     MIC_Init();
277 
278 #ifdef  SDK_TS
279     // Initialize PMIC
280     PM_Init();
281     // AMP on
282     (void)PM_SetAmp(PM_AMP_ON);
283 #if defined(SDK_TS_VERSION) && ( SDK_TS_VERSION >= 100 )
284     // Adjust AMP gain
285     (void)PM_SetAmpGain(PM_AMPGAIN_80);
286 #endif
287 #if defined(SDK_TS_VERSION) && ( SDK_TS_VERSION == 100 )
288     // Turn off LCD backlight to deal with noise
289     (void)PM_SetBackLight(PM_LCD_ALL, PM_BACKLIGHT_OFF);
290 #endif
291 #endif
292 
293     //****************************************************************
294 
295     // Initialize internal variables
296     {
297         s32     i;
298         for (i = 0; i < 192; i++)
299         {
300             gDrawData[i] = 0x80;
301         }
302     }
303 
304     // LCD display start
305     GX_DispOn();
306     GXS_DispOn();
307 
308     // Start message output
309     OS_Printf("#ARM9: MIC demo started.\n");
310     OS_Printf("#   up/down    -> change sampling span\n");
311     OS_Printf("#   left/right -> change bit range\n");
312     OS_Printf("#   A          -> start / stop\n");
313     OS_Printf("#   B          -> force-stop\n");
314     OS_Printf("#   select     -> terminate\n");
315 
316     // Empty call for getting key input data (strategy for pressing A button in the IPL)
317     KeyRead(&gKey);
318 
319     // Main loop
320     while (TRUE)
321     {
322         // Get key input data
323         KeyRead(&gKey);
324 
325         // Start if A button is pressed; stop if A button is pressed again
326         if ((gKey.trg & PAD_BUTTON_A) != 0)
327         {
328             if (!g_sample_busy)
329             {
330                 StartSampling();
331             }
332             else
333             {
334                 (void)MIC_StopAutoSampling();
335                 OnSampleDone(MIC_RESULT_SUCCESS, &gMicAutoParam);
336             }
337         }
338         // If B button is pressed, stop and ignore remaining data
339         if ((gKey.trg & PAD_BUTTON_B) != 0)
340         {
341             if (g_sample_busy)
342             {
343                 (void)MIC_StopAutoSampling();
344                 OnSampleDone(MIC_RESULT_SUCCESS, &gMicAutoParam);
345             }
346             if (g_record_smps)
347             {
348                 StopSamplingOutput();
349             }
350         }
351         // Program ended when SELECT button is pressed
352         if ((gKey.trg & PAD_BUTTON_SELECT) != 0)
353         {
354             OS_Exit(0);
355         }
356 
357         // If sampling output is not in progress, change the variable parameters
358         if (!g_record_smps)
359         {
360             // Change sampling type (bit width)
361             if ((gKey.trg | gKey.rep) & (PAD_KEY_LEFT | PAD_KEY_RIGHT))
362             {
363                 //****************************************************************
364                 if (gMicAutoParam.type == MIC_SAMPLING_TYPE_8BIT)
365                 {
366                     gMicAutoParam.type = MIC_SAMPLING_TYPE_12BIT;
367                 }
368                 else
369                 {
370                     gMicAutoParam.type = MIC_SAMPLING_TYPE_8BIT;
371                 }
372                 //****************************************************************
373                 if (!g_record_smps)
374                     PrintfVariableData();
375             }
376             // Change sampling rate
377             if ((gKey.trg | gKey.rep) & PAD_KEY_UP)
378             {
379                 //****************************************************************
380                 switch (gMicAutoParam.rate)
381                 {
382                 case MIC_SAMPLING_RATE_8K:
383                     gMicAutoParam.rate = MIC_SAMPLING_RATE_11K;
384                     break;
385                 case MIC_SAMPLING_RATE_11K:
386                     gMicAutoParam.rate = MIC_SAMPLING_RATE_16K;
387                     break;
388                 case MIC_SAMPLING_RATE_16K:
389                     gMicAutoParam.rate = MIC_SAMPLING_RATE_22K;
390                     break;
391                 case MIC_SAMPLING_RATE_22K:
392                     gMicAutoParam.rate = MIC_SAMPLING_RATE_32K;
393                     break;
394                 case MIC_SAMPLING_RATE_32K:
395                     gMicAutoParam.rate = MIC_SAMPLING_RATE_8K;
396                     break;
397                 }
398                 //****************************************************************
399                 if (!g_record_smps)
400                     PrintfVariableData();
401             }
402             if ((gKey.trg | gKey.rep) & PAD_KEY_DOWN)
403             {
404                 //****************************************************************
405                 switch (gMicAutoParam.rate)
406                 {
407                 case MIC_SAMPLING_RATE_8K:
408                     gMicAutoParam.rate = MIC_SAMPLING_RATE_32K;
409                     break;
410                 case MIC_SAMPLING_RATE_11K:
411                     gMicAutoParam.rate = MIC_SAMPLING_RATE_8K;
412                     break;
413                 case MIC_SAMPLING_RATE_16K:
414                     gMicAutoParam.rate = MIC_SAMPLING_RATE_11K;
415                     break;
416                 case MIC_SAMPLING_RATE_22K:
417                     gMicAutoParam.rate = MIC_SAMPLING_RATE_16K;
418                     break;
419                 case MIC_SAMPLING_RATE_32K:
420                     gMicAutoParam.rate = MIC_SAMPLING_RATE_22K;
421                     break;
422                 }
423                 //****************************************************************
424                 if (!g_record_smps)
425                     PrintfVariableData();
426             }
427         }
428 
429         // Log output of waveform
430         OutputSampleWave(MIC_GetLastSamplingAddress(), gMicAutoParam.type);
431 
432         // Render waveform
433         if (g_sample_busy)
434         {
435             SetDrawData(MIC_GetLastSamplingAddress(), gMicAutoParam.type);
436             Draw3D();
437         }
438 
439         // Waiting for the V-Blank
440         OS_WaitVBlankIntr();
441     }
442 }
443 
444 /*---------------------------------------------------------------------------*
445   Name:         InitializeAllocateSystem
446 
447   Description:  Initializes the memory allocation system within the main memory arena.
448 
449   Arguments:    None.
450 
451   Returns:      None.
452  *---------------------------------------------------------------------------*/
InitializeAllocateSystem(void)453 static void InitializeAllocateSystem(void)
454 {
455     void   *tempLo;
456     OSHeapHandle hh;
457 
458     // Based on the premise that OS_Init has been already called
459     tempLo = OS_InitAlloc(OS_ARENA_MAIN, OS_GetMainArenaLo(), OS_GetMainArenaHi(), 1);
460     OS_SetArenaLo(OS_ARENA_MAIN, tempLo);
461     hh = OS_CreateHeap(OS_ARENA_MAIN, OS_GetMainArenaLo(), OS_GetMainArenaHi());
462     if (hh < 0)
463     {
464         OS_Panic("ARM9: Fail to create heap...\n");
465     }
466     hh = OS_SetCurrentHeap(OS_ARENA_MAIN, hh);
467 }
468 
469 /*---------------------------------------------------------------------------*
470   Name:         Init3D
471 
472   Description:  Initialization for 3D display.
473 
474   Arguments:    None.
475 
476   Returns:      None.
477  *---------------------------------------------------------------------------*/
Init3D(void)478 static void Init3D(void)
479 {
480     G3X_Init();
481     G3X_InitMtxStack();
482     G3_SwapBuffers(GX_SORTMODE_AUTO, GX_BUFFERMODE_W);
483     GX_SetGraphicsMode(GX_DISPMODE_GRAPHICS, GX_BGMODE_0, GX_BG0_AS_3D);
484     GX_SetVisiblePlane(GX_PLANEMASK_BG0);
485     G2_SetBG0Priority(0);
486     G3X_SetShading(GX_SHADING_TOON);
487     G3X_AlphaTest(FALSE, 0);
488     G3X_AlphaBlend(TRUE);
489     G3X_AntiAlias(TRUE);
490     G3X_EdgeMarking(FALSE);
491     G3X_SetFog(FALSE, (GXFogBlend)0, (GXFogSlope)0, 0);
492     G3X_SetClearColor(0, 0, 0x7fff, 63, FALSE);
493     G3_ViewPort(0, 0, 255, 191);
494 }
495 
496 /*---------------------------------------------------------------------------*
497   Name:         Draw3D
498 
499   Description:  Displays waveforms in 3D.
500 
501   Arguments:    None.
502 
503   Returns:      None.
504  *---------------------------------------------------------------------------*/
Draw3D(void)505 static void Draw3D(void)
506 {
507     G3X_Reset();
508 
509     G3_MtxMode(GX_MTXMODE_PROJECTION);
510     G3_Identity();
511     G3_MtxMode(GX_MTXMODE_POSITION_VECTOR);
512     G3_Identity();
513 
514     G3_PolygonAttr(GX_LIGHTMASK_NONE, GX_POLYGONMODE_MODULATE, GX_CULL_NONE, 0, 31, 0);
515 
516     if (g_sample_busy)
517     {
518         s32     i;
519 
520         for (i = 0; i < 191; i++)
521         {
522             DrawLine((s16)(gDrawData[i]), (s16)i, (s16)(gDrawData[i + 1]), (s16)(i + 1));
523         }
524     }
525 
526     G3_SwapBuffers(GX_SORTMODE_AUTO, GX_BUFFERMODE_W);
527 }
528 
529 /*---------------------------------------------------------------------------*
530   Name:         DrawLine
531 
532   Description:  Renders lines with triangular polygons.
533 
534   Arguments:    sx: X-coordinate of line's starting point
535                 sy: Y-coordinate of line's starting point
536                 ex: X-coordinate of line's ending point
537                 ey: Y-coordinate of line's ending point
538 
539   Returns:      None.
540  *---------------------------------------------------------------------------*/
DrawLine(s16 sx,s16 sy,s16 ex,s16 ey)541 static void DrawLine(s16 sx, s16 sy, s16 ex, s16 ey)
542 {
543     fx16    fsx, fsy, fex, fey;
544 
545     fsx = (fx16)(((sx - 128) * 0x1000) / 128);
546     fsy = (fx16)(((96 - sy) * 0x1000) / 96);
547     fex = (fx16)(((ex - 128) * 0x1000) / 128);
548     fey = (fx16)(((96 - ey) * 0x1000) / 96);
549 
550     G3_Begin(GX_BEGIN_TRIANGLES);
551     {
552         G3_Color(GX_RGB(31, 31, 31));
553         G3_Vtx(fsx, fsy, 0);
554         G3_Color(GX_RGB(31, 31, 31));
555         G3_Vtx(fex, fey, 0);
556         G3_Color(GX_RGB(31, 31, 31));
557         G3_Vtx(fsx, fsy, 1);
558     }
559     G3_End();
560 }
561 
562 /*---------------------------------------------------------------------------*
563   Name:         VBlankIntr
564 
565   Description:  V-Blank interrupt vector.
566 
567   Arguments:    None.
568 
569   Returns:      None.
570  *---------------------------------------------------------------------------*/
VBlankIntr(void)571 static void VBlankIntr(void)
572 {
573     // Sets the IRQ check flag
574     OS_SetIrqCheckFlag(OS_IE_V_BLANK);
575 }
576 
577 /*---------------------------------------------------------------------------*
578   Name:         KeyRead
579 
580   Description:  Edits key input data.
581                 Detects press trigger, release trigger, and press-and-hold repeat.
582 
583   Arguments:    pKey: Structure that holds key input data to be edited
584 
585   Returns:      None.
586  *---------------------------------------------------------------------------*/
KeyRead(KeyInformation * pKey)587 static void KeyRead(KeyInformation * pKey)
588 {
589     static u16 repeat_count[12];
590     int     i;
591     u16     r;
592 
593     r = PAD_Read();
594     pKey->trg = 0x0000;
595     pKey->up = 0x0000;
596     pKey->rep = 0x0000;
597 
598     for (i = 0; i < 12; i++)
599     {
600         if (r & (0x0001 << i))
601         {
602             if (!(pKey->cnt & (0x0001 << i)))
603             {
604                 pKey->trg |= (0x0001 << i);     // Press trigger
605                 repeat_count[i] = 1;
606             }
607             else
608             {
609                 if (repeat_count[i] > KEY_REPEAT_START)
610                 {
611                     pKey->rep |= (0x0001 << i); // Press-and-hold repeat
612                     repeat_count[i] = KEY_REPEAT_START - KEY_REPEAT_SPAN;
613                 }
614                 else
615                 {
616                     repeat_count[i]++;
617                 }
618             }
619         }
620         else
621         {
622             if (pKey->cnt & (0x0001 << i))
623             {
624                 pKey->up |= (0x0001 << i);      // Release trigger
625             }
626         }
627     }
628     pKey->cnt = r;                     // Unprocessed key input
629 }
630 
631 /*---------------------------------------------------------------------------*
632   Name:         SetDrawData
633 
634   Description:  Stores the current newest sampled data in the buffer that puts it on the display.
635 
636 
637   Arguments:    address: Location in main memory where the most recent sampling data is stored by the components
638 
639                 type: Sampling type (bit width)
640 
641   Returns:      None.
642  *---------------------------------------------------------------------------*/
SetDrawData(void * address,MICSamplingType type)643 static void SetDrawData(void *address, MICSamplingType type)
644 {
645     s32     i;
646 
647     if (!address)
648         return;
649 
650     if (type == MIC_SAMPLING_TYPE_8BIT)
651     {
652         u8     *p;
653 
654         p = (u8 *)((u32)address - 191);
655         if (p < gMicData)
656         {
657             p = (u8 *)((u32)p + TEST_BUFFER_SIZE);
658         }
659         DC_InvalidateRange((void *)((u32)p & 0xffffffe0), 32);
660         for (i = 0; i < 192; i++)
661         {
662             gDrawData[i] = *p;
663             p++;
664             if ((u32)p >= (u32)(gMicData + TEST_BUFFER_SIZE))
665             {
666                 p -= TEST_BUFFER_SIZE;
667             }
668             if (((u32)p % 32) == 0)
669             {
670                 DC_InvalidateRange(p, 32);
671             }
672         }
673     }
674 
675     if (type == MIC_SAMPLING_TYPE_12BIT)
676     {
677         u16    *p;
678 
679         p = (u16 *)((u32)address - 382);
680         if ((u32)p < (u32)gMicData)
681         {
682             p = (u16 *)((u32)p + TEST_BUFFER_SIZE);
683         }
684         DC_InvalidateRange((void *)((u32)p & 0xffffffe0), 32);
685         for (i = 0; i < 192; i++)
686         {
687             gDrawData[i] = (u8)((*p >> 8) & 0x00ff);
688             p++;
689             if ((u32)p >= (u32)(gMicData + TEST_BUFFER_SIZE))
690             {
691                 p = (u16 *)((u32)p - TEST_BUFFER_SIZE);
692             }
693             if (((u32)p % 32) == 0)
694             {
695                 DC_InvalidateRange(p, 32);
696             }
697         }
698     }
699 }
700 
701 /*---------------------------------------------------------------------------*
702   Name:         PrintfVariableData
703 
704   Description:  Print-output the variable sampling settings.
705 
706   Arguments:    None.
707 
708   Returns:      None.
709  *---------------------------------------------------------------------------*/
PrintfVariableData(void)710 static void PrintfVariableData(void)
711 {
712     s32     range = 0;
713     s32     rate = 0;
714 
715     switch (gMicAutoParam.type)
716     {
717     case MIC_SAMPLING_TYPE_8BIT:
718         range = 8;
719         break;
720     case MIC_SAMPLING_TYPE_12BIT:
721         range = 16;
722         break;
723     }
724 
725     switch (gMicAutoParam.rate)
726     {
727     case MIC_SAMPLING_RATE_8K:
728         rate = 8000;
729         break;
730     case MIC_SAMPLING_RATE_11K:
731         rate = 11025;
732         break;
733     case MIC_SAMPLING_RATE_16K:
734         rate = 16000;
735         break;
736     case MIC_SAMPLING_RATE_22K:
737         rate = 22050;
738         break;
739     case MIC_SAMPLING_RATE_32K:
740         rate = 32000;
741         break;
742     }
743 
744     OS_Printf("$rate=%d\n$bits=%d\n", rate, range);
745 }
746 
747 /*---------------------------------------------------------------------------*
748   End of file
749  *---------------------------------------------------------------------------*/
750