home *** CD-ROM | disk | FTP | other *** search
/ NEXT Generation 27 / NEXT27.iso / pc / demos / emperor / dx3.exe / SDK / SAMPLES / DSSTREAM / DSSTREAM.H < prev    next >
C/C++ Source or Header  |  1996-08-28  |  8KB  |  213 lines

  1. /*==========================================================================
  2.  *
  3.  *  Copyright (C) 1995-1996 Microsoft Corporation. All Rights Reserved.
  4.  *
  5.  *  File:               DSStream.h
  6.  *  Content:    DirectSound Stream Sample Application Header
  7.  *
  8.  ***************************************************************************/
  9. #ifndef __DSSTREAM_INCLUDED__
  10. #define __DSSTREAM_INCLUDED__
  11.  
  12. #include <dsound.h>
  13. #include "resource.h"
  14. #include "debug.h"
  15.  
  16. /* WARNING -- Be careful about changing NUM_BUFFER_SEGMENTS -- it should be at
  17.  * least 3, or there will probably not be enough time for the interrupt to do
  18.  * its thing before the player catches up to it.  Also, PLAYBACK_TIMER_PERIOD
  19.  * is set at 200 milliseconds because we are OVERSAMPLING by a factor of four.
  20.  * This is so we can shift the frequency on the fly and still keep up with the
  21.  * play cursor.  The timer routine will only fill when necessary.  Experiments
  22.  * have shown that the timer still operates well when interrupted every 50ms
  23.  * (and possibly even more often than that).  If you do not require real-time
  24.  * frequency changes, you reduce the OVERSAMPLE as well as the TIMER_PERIOD.
  25.  * However, note that since a buffer segment is only an approximation of the
  26.  * number of bytes played per interrupt, it's a good idea to interupt a bit more
  27.  * often than the TIMER_PERIOD, just to make sure the timer isn't falling behind
  28.  * the player.  If your frequency is fixed, the call to initialize the timer
  29.  * event could be changed to first calculate something like (TIMER_PERIOD * .8).
  30.  * This should ensure that the buffer is well maintained and system performance
  31.  * is maximized.
  32.  */
  33.  
  34. #define NUM_BUFFER_SEGMENTS     6
  35. #define PLAYBACK_TIMER_PERIOD   200
  36. #define PLAYBACK_OVERSAMPLE     4
  37. #define PLAYBACK_TIMER_ACCURACY 10
  38.  
  39. #define DSSTREAM_STOPF_NOREOPEN 0x0001
  40. #define DSSTREAM_STOPF_NOEXIT   0x0002  // Prevent the stop code from calling exit
  41.  
  42. #define ERR_WAVE_OPEN_FAILED    -100
  43. #define ERR_WAVE_INVALID_FORMAT -101
  44. #define ERR_CREATEDSB_FAILED    -102
  45. #define ERR_WAVE_CORRUPTED_FILE -103
  46.  
  47.  
  48. #define BORDER_SPACE_CX         10
  49. #define BORDER_SPACE_CY         10
  50. #define CONTROL_SPACE_CX        4
  51. #define CONTROL_SPACE_CY        4
  52. #define TEXT_SPACE_CY           0
  53. #define TEXT_SPACE_CX           2
  54.  
  55. #define BUTTON_CX               70
  56. #define BUTTON_CY               32
  57. #define CHECK_CX                70
  58. #define CHECK_CY                22
  59. #define BUTTON_SPACE_CY         6
  60.  
  61. #define PAN_TEXT_CX             140
  62. #define VOL_TEXT_CX             140
  63. #define FREQ_TEXT_CX            140
  64. #define PROG_TEXT_CX            140
  65.  
  66. #define PAN_TB_CX               200
  67. #define PAN_TB_CY               30
  68. #define VOL_TB_CX               200
  69. #define VOL_TB_CY               30
  70. #define FREQ_TB_CX              200
  71. #define FREQ_TB_CY              30
  72. #define PROG_TB_CX              200
  73. #define PROG_TB_CY              30
  74.  
  75. // The values for PAN may change in range...
  76.  
  77. //#define PAN_TB_MIN              0
  78. //#define PAN_TB_MAX              2000
  79. //#define PAN_TB_CENTER           1000
  80. //#define PAN_MULTIPLIER          1
  81. #define PAN_MIN                 0
  82. #define PAN_MAX                 800
  83. #define PAN_CENTER              400
  84. #define PAN_SHIFT               (-400)
  85. #define PAN_PAGESIZE            10
  86. #define PAN_DIV                 10
  87. #define PAN_MULT                10
  88.  
  89. //#define PAN_DSB_MIN           (-400)
  90. //#define PAN_DSB_MAX           400
  91. //#define PAN_DSB_CENTER        0
  92.  
  93. //#define VOL_TB_MIN              0
  94. //#define VOL_TB_MAX              1000
  95. //#define VOL_MULTIPLIER          1
  96. #define VOL_SHIFT               (-400)
  97. #define VOL_MIN                 0
  98. #define VOL_MAX                 400
  99. #define VOL_PAGESIZE            10
  100. #define VOL_DIV                 10
  101. #define VOL_MULT                10
  102. #define FREQ_MIN                441
  103. #define FREQ_MAX                4410
  104. #define FREQ_PAGESIZE           100
  105. #define FREQ_MULTIPLIER         10
  106. #define PROG_MIN                0
  107. #define PROG_MAX                10000
  108. #define PROG_MULTIPLIER         100
  109.  
  110.  
  111. /* WAVE I/O subsystem defines */
  112.  
  113. #define WAVEVERSION 1
  114.  
  115. #ifndef ER_MEM
  116. #define ER_MEM                  0xe000
  117. #endif
  118.  
  119. #ifndef ER_CANNOTOPEN
  120. #define ER_CANNOTOPEN           0xe100
  121. #endif
  122.  
  123. #ifndef ER_NOTWAVEFILE
  124. #define ER_NOTWAVEFILE          0xe101
  125. #endif
  126.  
  127. #ifndef ER_CANNOTREAD
  128. #define ER_CANNOTREAD           0xe102
  129. #endif
  130.  
  131. #ifndef ER_CORRUPTWAVEFILE
  132. #define ER_CORRUPTWAVEFILE      0xe103
  133. #endif
  134.  
  135. #ifndef ER_CANNOTWRITE
  136. #define ER_CANNOTWRITE          0xe104
  137. #endif
  138.  
  139. /* Streaming communication defines and structures */
  140.  
  141. #define WM_DSSTREAM_DONE        WM_USER + 0x100 /* Make our own app messages */
  142. #define WM_DSSTREAM_DEBUG       WM_USER + 0x101
  143. #define WM_DSSTREAM_PROGRESS    WM_USER + 0x102
  144.  
  145. #define DEBUGF_PLAYPOSITION     0x0300
  146. #define DEBUGF_WRITEPOSITION    0x0301
  147. #define DEBUGF_NEXTWRITE        0x0302
  148. #define DEBUGF_SKIP             0x0303
  149.  
  150. /*
  151.  * This structure keeps all the data that the TimeFunc callback uses in one
  152.  * place.  In this implementation, that means the global data segement.  This
  153.  * is setup so that if you wanted to put your callback in a DLL, all you'd need
  154.  * to do is pass the address of this structure as a parameter.
  155.  */
  156.  
  157. typedef struct waveinfoca_tag
  158. {
  159.     WAVEFORMATEX         *pwfx;             /* Wave Format data structure */
  160.     HMMIO                hmmio;             /* MM I/O handle for the WAVE */
  161.     MMCKINFO             mmck;              /* Multimedia RIFF chunk */
  162.     MMCKINFO             mmckInRIFF;        /* Use in opening a WAVE file */
  163.     LPDIRECTSOUNDBUFFER  lpDSBStreamBuffer; /* Points to DirectSoundBuffer */
  164.     DWORD                dwBufferSize;      /* Size of the entire buffer */
  165.     DWORD                dwNextWriteOffset; /* Offset to next buffer segment */
  166.     DWORD                dwProgress;        /* Used with above to show prog. */
  167.     DWORD                dwBytesRemaining;  /* Bytes 'til timer shutdown */
  168.     BOOL                 bDonePlaying;      /* Signals early abort to timer */
  169.     BOOL                 bLoopFile;         /* Should we loop playback? */
  170.     BOOL                 bFoundEnd;         /* Timer found file end */
  171. } WAVEINFOCA, *LPWAVEINFOCA;
  172.  
  173. /* Function declarations */
  174.  
  175. LRESULT CALLBACK MainWindowProc( HWND, unsigned, WPARAM, LPARAM );
  176. BOOL CALLBACK DLG_About( HWND, UINT, WPARAM, LPARAM );
  177. void CALLBACK TimeFunc( UINT, UINT, DWORD, DWORD, DWORD );
  178. BOOL CALLBACK DSEnumDlgProc( HWND, UINT, WPARAM, LPARAM );
  179. BOOL CALLBACK DSEnumProc( LPGUID, LPSTR, LPSTR, LPVOID );
  180.  
  181. void ErrorMessageBox( UINT, DWORD );
  182. void HandlePanScroll( int, int );
  183. void HandleVolScroll( int, int );
  184. void HandleFreqScroll( int, int );
  185. void ResetWavePlayer( void );
  186. void UpdateFromControls( void );
  187.  
  188. int CreateChildren( RECT );
  189. int HandleCommDlgError( DWORD );
  190. int StreamBufferSetup( void );
  191.  
  192. BOOL DoDSoundEnumerate( LPGUID );
  193.  
  194. int WaveOpenFile(char *, HMMIO *, WAVEFORMATEX **, MMCKINFO *);
  195. int WaveStartDataRead(HMMIO *, MMCKINFO *, MMCKINFO *);
  196. int WaveReadFile(HMMIO, UINT, BYTE *, MMCKINFO *, UINT *);
  197. int WaveCloseReadFile(HMMIO *, WAVEFORMATEX **);
  198.  
  199. int WaveCreateFile(char *, HMMIO *, WAVEFORMATEX *, MMCKINFO *, MMCKINFO *);
  200. int WaveStartDataWrite(HMMIO *, MMCKINFO *, MMIOINFO *);
  201. int WaveWriteFile(HMMIO, UINT, BYTE *, MMCKINFO *, UINT *, MMIOINFO *);
  202. int WaveCloseWriteFile(HMMIO *, MMCKINFO *, MMCKINFO *, MMIOINFO *, DWORD);
  203.  
  204. int WaveLoadFile(char *, UINT *, DWORD *, WAVEFORMATEX **, BYTE **);
  205. int WaveSaveFile(char *, UINT, DWORD, WAVEFORMATEX *, BYTE *);
  206.  
  207. int WaveCopyUselessChunks(HMMIO *, MMCKINFO *, MMCKINFO *, HMMIO *,
  208.                                 MMCKINFO *, MMCKINFO *);
  209. BOOL riffCopyChunk(HMMIO, HMMIO, const LPMMCKINFO);
  210.  
  211. #endif /* __DSSTREAM_INCLUDED__ */
  212.  
  213.