home *** CD-ROM | disk | FTP | other *** search
/ ftp.whtech.com / ftp.whtech.com.7z / ftp.whtech.com / emulators / v9t9 / linux / sources / V9t9 / source / sound.h < prev    next >
Encoding:
C/C++ Source or Header  |  2006-10-19  |  4.4 KB  |  178 lines

  1.  
  2. /*
  3.  
  4.  
  5.  
  6. */
  7.  
  8. #ifndef __SOUND_H__
  9. #define __SOUND_H__
  10.  
  11. #include "centry.h"
  12.  
  13. #define PLAYABLE (FE_SOUND|FE_PLAYSOUND)
  14. #define PLAYSOUND ((features&PLAYABLE)==PLAYABLE)
  15.  
  16. #define DOSOUND(x,y) do { \
  17.     vmModule *ptr = vmSound; \
  18.     while (ptr) {\
  19.         if ((ptr->runtimeflags & vmRTInUse) && (ptr->m.sound->x)) \
  20.                 ptr->m.sound->x y; \
  21.         ptr = ptr->next; \
  22.     } \
  23.     } while (0)
  24.  
  25. #define DOSOUNDUPDATE(w) DOSOUND(update, (w))
  26.  
  27. #define DOSOUNDFLUSH() DOSOUND(flush, ())
  28.  
  29. #define DOSOUNDPLAY(kind,data,size,hz) DOSOUND(play, (kind, data, size, hz))
  30.  
  31. #define SOUNDUPDATE(w) do { \
  32.     if (features&FE_PLAYSOUND) DOSOUNDUPDATE(w); \
  33.     } while (0)
  34.  
  35. #define SOUNDFLUSH() DOSOUNDFLUSH()
  36.  
  37. #define SOUNDPLAY(kind,data,size,hz) do { \
  38.     if (features&FE_PLAYSOUND) DOSOUNDPLAY(kind,data,size,hz); \
  39.     } while (0)
  40.  
  41. #define SPEECHPLAY(kind,data,size,hz) do { \
  42.     if (features&FE_PLAYSPEECH) DOSOUNDPLAY(kind,data,size,hz); \
  43.     } while (0)
  44.  
  45. /*    This struct is defined in sound.c through writes
  46.     to the sound port.  
  47.     
  48.     'period' and 'hertz' are related; 'period' is a number 0 through 0x3ff
  49.     which was decoded from writes to the port and 'hertz' is the frequency
  50.     of the tone that represents.
  51.     
  52.     'volume' is really attenuation -- 0 is loudest, 0xf is silent or off. 
  53.     
  54.     'stype' describes the characteristics of the noise channel (voices[3]);
  55.     this is directly from the sound port (0-7).  stype >= 4 is white noise,
  56.     else periodic.  The sound module defines 'period' and 'hertz' based on
  57.     whether the stype represents a fixed-frequency sound or one that is
  58.     derived from the frequency of channel 2.
  59. */
  60.  
  61. /* These are used as an index into the operation[] field */
  62. enum
  63. {
  64.     OPERATION_FREQUENCY_LO = 0,        /* low 4 bits [1vv0yyyy] */
  65.     OPERATION_CONTROL = 0,            /* for noise  [11100xyy] */
  66.     OPERATION_FREQUENCY_HI = 1,        /* hi 6 bits  [00yyyyyy] */
  67.     OPERATION_ATTENUATION = 2        /* low 4 bits [1vv1yyyy] */
  68. };
  69.  
  70. typedef struct voiceinfo
  71. {
  72.     u8    operation[3];    // operation bytes
  73.     
  74.     u8    volume;            // volume, 0 == off, 0xf == loudest
  75.     u16    period, hertz;    // calculated from OPERATION_FREQUENCY_xxx
  76. }    voiceinfo;
  77.  
  78. enum
  79. {
  80.     VOICE_TONE_0, VOICE_TONE_1, VOICE_TONE_2, VOICE_NOISE
  81. };
  82.  
  83. extern voiceinfo sound_voices[4];
  84.  
  85. #define OPERATION_TO_VOICE(o) \
  86.         ( ((o) & 0x60) >> 5)
  87.  
  88. /*
  89.  *    Masks for the OPERATION_CONTROL byte for VOICE_NOISE
  90.  */
  91. enum
  92. {
  93.     NOISE_PERIODIC = 0,
  94.     NOISE_WHITE = 0x4
  95. };
  96.  
  97. enum
  98. {
  99.     NOISE_PERIOD_FIXED_0,
  100.     NOISE_PERIOD_FIXED_1,
  101.     NOISE_PERIOD_FIXED_2,
  102.     NOISE_PERIOD_VARIABLE
  103. };
  104.  
  105. #define OPERATION_TO_PERIOD(v)    \
  106.         ( ((v)->operation[OPERATION_FREQUENCY_LO] & 0xf) | \
  107.         ( ((v)->operation[OPERATION_FREQUENCY_HI] & 0x3f) << 4 ) )
  108.  
  109. #define PERIOD_TO_HERTZ(p)        \
  110.         ((p) > 1 ? (111860 / (p)) : (55930))
  111.  
  112. #define OPERATION_TO_NOISE_TYPE(v)  \
  113.         ( (v)->operation[OPERATION_CONTROL] & 0x4 )
  114.  
  115. #define OPERATION_TO_NOISE_PERIOD(v)  \
  116.         ( (v)->operation[OPERATION_CONTROL] & 0x3 )
  117.  
  118. #define OPERATION_TO_ATTENUATION(v) \
  119.         ( (v)->operation[OPERATION_ATTENUATION] & 0xf )
  120.  
  121. #define OPERATION_TO_VOLUME(v) \
  122.         ( 0xf - OPERATION_TO_ATTENUATION(v) )
  123.  
  124. /*    Audio gate info. */
  125.  
  126. typedef struct
  127. {
  128.     u32 base_time, last_time;        /* base time for making noise, 
  129.                                         last time gate accessed */
  130.     u32 length;                        /* how long to trigger */
  131.     u32 hertz;                        /* reference for length */
  132.     u8 latch;                        /* last bit was on or off? */
  133.     u8 play;                        /* is gate on or off? */
  134. }    AudioGate;
  135.  
  136. extern AudioGate audiogate;
  137.  
  138. /*****************************************************/
  139.  
  140. /*    Playback options    */
  141. extern    int        sndplayhz;        /* playback rate */
  142. extern    int        sndplaybits;    /* word size for sound */
  143.  
  144. extern    void    sound_mmio_write(u8 val);        /* to the I/O port */
  145.  
  146. extern    void    sound_init(void);
  147.  
  148. extern    int        sound_restart(void);
  149. extern    void    sound_restop(void);
  150. extern    int        sound_enable(void);
  151. extern    void    sound_disable(void);
  152.  
  153.  
  154. /******************/
  155.  
  156. /*    Cassette routines  */
  157.  
  158. /*    "Time passed" is measured in 9901 timer ticks, the maximum
  159.     being 46875 Hz, and set with cassette_set_timer() when the clock rate
  160.     changes.  The actual cassette routines will not set the timer this high,
  161.     only about ~1390 Hz.  If a wave file is used for input, the actual input
  162.     will be smoothed to fit the timer rate.  If a data file is used, it is
  163.     assumed to be exactly the cassette's data rate.
  164.  
  165.     The cassette is constantly running once the motor is started, so it is
  166.     possible to lose data.  This is why cassette_read returns only one bit.
  167. */
  168.  
  169. void    cassette_set_timer(u16 hz);
  170. void    cassette_set_motor(int csx, u8 onoff);
  171. void    cassette_write(u8 onoff, u32 timepassed);
  172. u8        cassette_read(void);
  173.  
  174.  
  175. #include "cexit.h"
  176.  
  177. #endif
  178.