ezplay.c
Upload User: hbbaokai
Upload Date: 2009-07-13
Package Size: 328k
Code Size: 5k
Category:

VOIP program

Development Platform:

Visual C++

  1. /*************************************************************************/
  2. /*                                                                       */
  3. /*                            LD-CELP  G.728                             */
  4. /*                                                                       */
  5. /*    Low-Delay Code Excitation Linear Prediction speech compression.    */
  6. /*                                                                       */
  7. /*                 Copyright: Analog Devices, Inc., 1993                 */
  8. /*                                                                       */
  9. /*                         Author: Alex Zatsman.                         */
  10. /*                                                                       */
  11. /*  This program was written mostly for testing  Analog Devices' g21k C  */
  12. /*  compiler for the  ADSP21000 architecture  family. While the program  */
  13. /*  works  on  Sparc and ADSP21020, it  has  NOT  been  tested with the  */
  14. /*  official test data from CCITT/ITU.                                   */
  15. /*                                                                       */
  16. /*  The program  is   distributed as  is,  WITHOUT ANY WARRANTY, EITHER  */
  17. /*  EXPLICIT OR IMPLIED.                                                 */
  18. /*                                                                       */
  19. /*************************************************************************/
  20. /* Play back for ez-lab */
  21. #include <signal.h>
  22. #include <macros.h>
  23. #include <def21020.h>
  24. #include "21kflags.h"
  25. #include "common.h"
  26. #include "parm.h"
  27. volatile int button_pushed;
  28. extern void initx_in();
  29. extern void initx_out();
  30. void irq2_handler(int);
  31. void record();
  32. void wait_for_button();
  33. void light_on(int);
  34. void light_off(int);
  35. extern void encoder();
  36. extern void init_encoder();
  37. extern void decoder();
  38. extern void init_decoder();
  39. void main ()
  40. {
  41.     interrupt(SIG_IRQ2, irq2_handler);
  42.     mode2.b.irq2_edge   = 1;
  43.     mode2.b.flg1_output = 1;
  44.     mode2.b.flg2_output = 1;
  45.     mode2.b.flg3_output = 1;
  46.     light_on(1);
  47.     light_off(2);
  48.     light_off(3);
  49.     wait_for_button();
  50.     light_off(1);
  51.     light_on(3);
  52.     initx_in();
  53.     encoder();
  54.     light_off(3);
  55.     while(1) {
  56. light_on(2);
  57. wait_for_button();
  58. light_off(2);
  59. initx_out();
  60. decoder();
  61.     }
  62. }
  63. void wait_for_button()
  64. {
  65.     button_pushed = 0;
  66.     imask.b.irq3i = 0;
  67.     imask.b.sft0i = 0;
  68.     while(!button_pushed);
  69. }
  70. void irq2_handler(int x)
  71. {
  72.     extern int volatile encoder_done;
  73.     extern int volatile decoder_done;
  74.     encoder_done  = 1;
  75.     decoder_done  = 1;
  76.     button_pushed = 1;
  77. }
  78. void light_on(int n)
  79. {
  80.     switch(n) {
  81.       case 1: astat.b.flg1_value = 1; break;
  82.       case 2: astat.b.flg2_value = 1; break;
  83.       case 3: astat.b.flg3_value = 1; break;
  84.       default:
  85. astat.b.flg1_value = 1;
  86. astat.b.flg2_value = 1;
  87. astat.b.flg3_value = 1;
  88.     }
  89. }
  90. void light_off(int n)
  91. {
  92.     switch(n) {
  93.       case 1: astat.b.flg1_value = 0; break;
  94.       case 2: astat.b.flg2_value = 0; break;
  95.       case 3: astat.b.flg3_value = 0; break;
  96.       default:
  97. astat.b.flg1_value = 0;
  98. astat.b.flg2_value = 0;
  99. astat.b.flg3_value = 0;
  100.     }
  101. }
  102. /******************************** Storing and Retrieving Indices. *******/
  103. #define NUMX 25000
  104. int ix_in  = 0;
  105. int ix_out = 0;
  106. int index_data[NUMX];
  107.    /* scratch volatile to make sure that asm's are not moved */
  108. volatile int pm scratch;
  109. void initx_out() 
  110. {
  111.     ix_out = 0;
  112. }
  113. void initx_in() 
  114. {
  115.     ix_in  = 0;
  116. }
  117. void
  118. put_index(int x)
  119. {
  120.     int wnum,fnum;
  121.     wnum = ix_in>>2;
  122.     if (wnum<NUMX) {
  123. fnum = ix_in&3;
  124. if (fnum) {
  125.     int new, old = index_data[wnum];
  126.     scratch=old;
  127.     asm volatile ("px=pm(_scratch);");
  128.     new = old | x<<(fnum*10-8);
  129.     asm volatile ("px2=%0;" : : "d" (new));
  130. }
  131. else {
  132.     /* this clobbers the rest 30 bits, but since the index is */
  133.     /* always written sequentially, this should not matter much */
  134.     int 
  135. x1 = x<<8 & 0xff00,
  136. x2 = (x>>8)&3;
  137.     asm volatile ("px1=%0;" : : "d" (x1));
  138.     asm volatile ("px2=%0;" : : "d" (x2));
  139. }
  140. asm volatile ("pm(_scratch)=px;");
  141. index_data[wnum] = scratch;
  142. ix_in++;
  143.     }
  144.     else {
  145. extern int volatile encoder_done;
  146. encoder_done=1;
  147.     }
  148. }
  149. int get_index()
  150. {
  151.     int wnum, fnum, result;
  152.     wnum = ix_out>>2;
  153.     if (ix_out < ix_in && wnum < NUMX) {
  154. fnum = ix_out&3;
  155. if (fnum) {
  156.     result  = (index_data[wnum]>>(fnum*10-8))& 0x3ff;
  157. } else {
  158.     int x1,x2;
  159.     scratch=index_data[wnum];
  160.     asm volatile ("px=pm(_scratch);");
  161.     asm volatile ("%0=px1;" : "=d" (x1));
  162.     asm volatile ("%0=px2;" : "=d" (x2));
  163.     result = ((x2&3)<<8) | (x1>>8);
  164. }
  165. ix_out++;
  166. return result;
  167.     }
  168.     else {
  169. extern int decoder_done;
  170. decoder_done=1;
  171. return 0;
  172.     }
  173. }