home *** CD-ROM | disk | FTP | other *** search
/ Vectronix 2 / VECTRONIX2.iso / FILES_01 / DIGI_104.LZH / DIGITAPE.104 / MODULE.PRG / EXAMPLE / HALL.C < prev    next >
C/C++ Source or Header  |  1993-07-07  |  6KB  |  236 lines

  1. /* Beispiel Source für DigiTape Modul */
  2.  
  3.  
  4. #include "\dt_modul\dt_local.h" /* UP-Anbindung */
  5. #include "\dt_modul\dt_defin.h" /* Globale Definitionen */
  6.  
  7. #include "hall.d"     /* DSP-Programm */
  8. #include "hall.dh"     /* defines DSP Programm */
  9.  
  10. #include "hall.h"                  /* Defines Resource-File */
  11. #include "hall.r"                  /* Dump Resource-File */
  12.  
  13. #define ECHO_BUFF_SIZE 0x1e00  /* max. 0x1e00 */
  14. #define NR_REFLECT 10
  15.  
  16. typedef struct
  17. {
  18.     Modul_header mh;
  19.     Modul_globals mg;
  20.  
  21.     int rev_index;        /* Index des akt. Paremetersatzes */
  22.     int    dsp_deltab;     /* abwechselnd delay/pegel/... */
  23.     int dsp_feedback; /* pegel */
  24.     int dsp_eptr;            /* Zeiger für Ringbuffer */
  25.     long buff_adr;         /* Datenbereich */
  26. } Rev_globals;
  27.  
  28. static Rsc_info rsc_reverb=
  29. {
  30.     FORM1, TEXT, SOLO, UNLOCK_M, L_BUTT_M, V_M, VS_M, P_M, PS_M
  31. };
  32.  
  33. static Module_info dtm_reverb=
  34. {
  35.     0,
  36.     0, 0, 0, ECHO_BUFF_SIZE,    /* x6 x8 x15 xbuff */
  37.     2, 2*NR_REFLECT, 0, 0,        /* y6 y8 y15 ybuff */
  38.     "Example reverb modul"
  39. };
  40.  
  41.  
  42. /* Aufbau deltab: long Reflektorabstand in cm
  43.                                     (max. ECHO_BUFF_SIZE beachten!)
  44.                                     long Pegel für diesen Reflektor
  45.                                     ( 1.0 entspricht 1000 )          */
  46. char *texte[]={"Theater", "Club", "Nature", "Chamber", 0L};
  47.  
  48. /* Laengste Verzoegerung zuerst */
  49. int deltab[][NR_REFLECT]=
  50. {
  51. {2300, 2150, 2000, 1300, 1200, 1100, 1000, 600, 550, 500},
  52. { 250,  270,  300,  400,  450,  500,  550, 150, 175, 200},
  53.  
  54. {1500, 1400, 1300, 1000, 900, 600, 500, 400, 300, 200},
  55. { 200,  200,  200,  100, 100, 200, 350, 500, 400, 300},
  56.  
  57. {3400, 3200, 3000, 2800, 2600, 2400, 2200, 600, 550, 500},
  58. { 140,  160,  180,  200,  220,  240,  260, 500, 500, 500},
  59.  
  60. {1139,  912,  526,  491,  447,  187,  159,  132,  99,   70},
  61. { 200,  200,  600,  550,  500,  600,  800,  700,  700, 800}
  62. };
  63.  
  64. /*++++++++++++++++++++++++++++++++++++++++++++++++++++++
  65.     Klick auf Button abfragen
  66. ++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
  67. int    check_reverb_buttons( int button, Rev_globals *glob );
  68.  
  69. /*+++++++++++++++++++++++++++++++++++++++++++++++++++++
  70.     Slot-Lautstärke L/R und Echo setzen
  71.     +++++++++++++++++++++++++++++++++++++++++++++++++++++*/
  72. void init_reverb_volumes( Rev_globals *glob );
  73.  
  74. /*++++++++++++++++++++++++++++++++++++++++++++++++++++++
  75.     Reverb-Auswahl bearbeiten
  76. ++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
  77. void    do_reverb_type( Rev_globals *glob );
  78.  
  79. /*++++++++++++++++++++++++++++++++++++++++++++*
  80.  * Delaytabelle entsprechend Abtastfrequenz
  81.  * umrechnen und an DSP schicken
  82.  *++++++++++++++++++++++++++++++++++++++++++++*/
  83. void load_deltab( Rev_globals *glob );
  84.  
  85. /*+++++++++++++++++++++++++++++++++++++++++++
  86.     Echo-Modul
  87.     bei LOAD_DSP: dsp-Quelladresse in x
  88.                                 dsp-Zieladresse in y
  89.                                 dsp-Buffer-Address in param
  90. +++++++++++++++++++++++++++++++++++++++++++++*/
  91. long cdecl do_module_reverb( int module_action, Rev_globals *glob,
  92.                                                      int x, int y, int param )
  93.  
  94. {
  95.     int button;
  96.  
  97.     switch ( module_action )
  98.     {
  99.         case MOD_GET_VERSION:
  100.         return DTM_VERSION;
  101.  
  102.         case MOD_RSC_INIT:
  103.             dtm_init(    &dtm_reverb, HALL, &rsc_reverb );
  104.         return DTM_VERSION;
  105.  
  106.         case MOD_INIT:
  107.             /* Feedback Poti */
  108.             dtm_init_poti( glob, 0, H_POTI, AMPL_M, AMPLS_M, 0);
  109.  
  110.             glob->rev_index = 0;
  111.          break;
  112.  
  113.         case MOD_LOAD_DSP:
  114.             /* dsp-Datenbereich */
  115.             glob->buff_adr = (long)param;
  116.             glob->dsp_deltab = dm_defvar( 'Y', 8, 2*NR_REFLECT ); /* Delay/Ampl abwechs. */
  117.             glob->dsp_feedback = dm_defvar( 'Y', 6, 1 );
  118.             glob->dsp_eptr = dm_defvar( 'Y', 6, 1 ); /* ptr auf Ringpuffer */
  119.  
  120.             dm_load(    MODUL_HALL,
  121.                                 HALL_QUELLE, x, HALL_ZIEL, y,
  122.                                 HALL_DELTAB, glob->dsp_deltab,
  123.                                 HALL_FBACK, glob->dsp_feedback,
  124.                                 HALL_EPTR, glob->dsp_eptr,
  125.                                 HALL_ESIZE, ECHO_BUFF_SIZE-1,
  126.                                 HALL_EZAHL, NR_REFLECT, -1 );
  127.  
  128.             /* Delaytabelle */
  129.             load_deltab(glob);
  130.  
  131.             /* Puffer-Anfangsadresse */
  132.             dm_setvar( 'Y', glob->dsp_eptr, &glob->buff_adr, 1 );
  133.         break;
  134.  
  135.         case MOD_CLR_MEMORY:
  136.             dsp_setblock( 'X', (int)glob->buff_adr, 0L, ECHO_BUFF_SIZE );
  137.         break;
  138.  
  139.         case MOD_OUT_VOLS: /* gleich nach Aufruf */
  140.             /* Volumes und Echo setzen */
  141.             init_reverb_volumes( glob );
  142.         break;
  143.  
  144.         case MOD_LBUTTONDOWN:
  145.           button = object_find( glob->mh.object_ptr, 0, 10, x, y );
  146.  
  147.             if ( check_reverb_buttons( button, glob ) )
  148.                 return TRUE;
  149.         break;
  150.  
  151.         case MOD_DRAW:
  152.             DialogPrintf( glob->mh.hdialog, SELECHO, texte[glob->rev_index] );
  153.         break;
  154.  
  155.         case MOD_SLIDER_MOVED:
  156.             switch ( x )
  157.             {
  158.                 case 0:
  159.                     /* Echo feedback setzen */
  160.                     dm_setvar( 'Y', glob->dsp_feedback, log_tab_entry(y), 1 );
  161.                 break;
  162.                 default:
  163.                     return FALSE;
  164.             }
  165.         return TRUE;
  166.     }
  167.  
  168.     return FALSE;
  169. }
  170.  
  171. /*++++++++++++++++++++++++++++++++++++++++++++++++++++++
  172.     Klick auf Button abfragen
  173. ++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
  174. int    check_reverb_buttons( int button, Rev_globals *glob )
  175.  
  176. {
  177.     switch ( button )
  178.     {
  179.         case SELECHO:
  180.             do_reverb_type( glob );
  181.         break;
  182.  
  183.         default:
  184.             return FALSE;
  185.     }
  186.  
  187.     draw_object( glob->mh.object_ptr, button );
  188.     return TRUE;
  189. }
  190.  
  191. /*+++++++++++++++++++++++++++++++++++++++++++++++++++++
  192.     Slot-Lautstärke L/R und Echo setzen
  193.     +++++++++++++++++++++++++++++++++++++++++++++++++++++*/
  194. void init_reverb_volumes( Rev_globals *glob )
  195.  
  196. {
  197.     /* Echo feedback setzen */
  198.     dm_setvar( 'Y', glob->dsp_feedback,
  199.                             log_tab_entry(glob->mg.potis[0].position), 1 );
  200. }
  201.  
  202. /*++++++++++++++++++++++++++++++++++++++++++++*
  203.  * Delaytabelle entsprechend Abtastfrequenz
  204.  * umrechnen und an DSP schicken
  205.  *++++++++++++++++++++++++++++++++++++++++++++*/
  206. void load_deltab( Rev_globals *glob )
  207. {
  208.     long loc_deltab[2*NR_REFLECT];
  209.     int  *deltab_ptr;
  210.     int i;
  211.  
  212.     deltab_ptr=deltab[glob->rev_index*2];
  213.  
  214.     for (i=0; i<2*NR_REFLECT; )
  215.     {
  216.         loc_deltab[i++] = ECHO_BUFF_SIZE -
  217.                                             (long)*deltab_ptr * glob->mh.sys->Hz / 33000L;
  218.         loc_deltab[i++] = 8388L * *(deltab_ptr++ + NR_REFLECT);
  219.     }    
  220.     dm_setvar( 'Y', glob->dsp_deltab, loc_deltab, 2*NR_REFLECT);
  221. }
  222.  
  223.  
  224. /*++++++++++++++++++++++++++++++++++++++++++++++++++++++
  225.     Reverb-Auswahl bearbeiten
  226. ++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
  227. void    do_reverb_type( Rev_globals *glob )
  228.  
  229. {
  230.     if ( texte[++(glob->rev_index)] == 0L )
  231.         glob->rev_index = 0;
  232.  
  233.     load_deltab(glob);
  234.     DialogPrintf( glob->mh.hdialog, SELECHO, texte[glob->rev_index] );
  235. }
  236.