home *** CD-ROM | disk | FTP | other *** search
/ The Net: Ultimate Internet Guide / WWLCD1.ISO / pc / directx2 / sdk / samples / dsstream / dsstream.h < prev    next >
Encoding:
C/C++ Source or Header  |  1996-05-28  |  7.6 KB  |  212 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.  
  41. #define ERR_WAVE_OPEN_FAILED    -100
  42. #define ERR_WAVE_INVALID_FORMAT -101
  43. #define ERR_CREATEDSB_FAILED    -102
  44. #define ERR_WAVE_CORRUPTED_FILE -103
  45.  
  46.  
  47. #define BORDER_SPACE_CX         10
  48. #define BORDER_SPACE_CY         10
  49. #define CONTROL_SPACE_CX        4
  50. #define CONTROL_SPACE_CY        4
  51. #define TEXT_SPACE_CY           0
  52. #define TEXT_SPACE_CX           2
  53.  
  54. #define BUTTON_CX               70
  55. #define BUTTON_CY               32
  56. #define CHECK_CX                70
  57. #define CHECK_CY                22
  58. #define BUTTON_SPACE_CY         6
  59.  
  60. #define PAN_TEXT_CX             140
  61. #define VOL_TEXT_CX             140
  62. #define FREQ_TEXT_CX            140
  63. #define PROG_TEXT_CX            140
  64.  
  65. #define PAN_TB_CX               200
  66. #define PAN_TB_CY               30
  67. #define VOL_TB_CX               200
  68. #define VOL_TB_CY               30
  69. #define FREQ_TB_CX              200
  70. #define FREQ_TB_CY              30
  71. #define PROG_TB_CX              200
  72. #define PROG_TB_CY              30
  73.  
  74. // The values for PAN may change in range...
  75.  
  76. //#define PAN_TB_MIN              0
  77. //#define PAN_TB_MAX              2000
  78. //#define PAN_TB_CENTER           1000
  79. //#define PAN_MULTIPLIER          1
  80. #define PAN_MIN                 0
  81. #define PAN_MAX                 800
  82. #define PAN_CENTER              400
  83. #define PAN_SHIFT               (-400)
  84. #define PAN_PAGESIZE            10
  85. #define PAN_DIV                 10
  86. #define PAN_MULT                10
  87.  
  88. //#define PAN_DSB_MIN           (-400)
  89. //#define PAN_DSB_MAX           400
  90. //#define PAN_DSB_CENTER        0
  91.  
  92. //#define VOL_TB_MIN              0
  93. //#define VOL_TB_MAX              1000
  94. //#define VOL_MULTIPLIER          1
  95. #define VOL_SHIFT               (-400)
  96. #define VOL_MIN                 0
  97. #define VOL_MAX                 400
  98. #define VOL_PAGESIZE            10
  99. #define VOL_DIV                 10
  100. #define VOL_MULT                10
  101. #define FREQ_MIN                441
  102. #define FREQ_MAX                4410
  103. #define FREQ_PAGESIZE           100
  104. #define FREQ_MULTIPLIER         10
  105. #define PROG_MIN                0
  106. #define PROG_MAX                10000
  107. #define PROG_MULTIPLIER         100
  108.  
  109.  
  110. /* WAVE I/O subsystem defines */
  111.  
  112. #define WAVEVERSION 1
  113.  
  114. #ifndef ER_MEM
  115. #define ER_MEM                  0xe000
  116. #endif
  117.  
  118. #ifndef ER_CANNOTOPEN
  119. #define ER_CANNOTOPEN           0xe100
  120. #endif
  121.  
  122. #ifndef ER_NOTWAVEFILE
  123. #define ER_NOTWAVEFILE          0xe101
  124. #endif
  125.  
  126. #ifndef ER_CANNOTREAD
  127. #define ER_CANNOTREAD           0xe102
  128. #endif
  129.  
  130. #ifndef ER_CORRUPTWAVEFILE
  131. #define ER_CORRUPTWAVEFILE      0xe103
  132. #endif
  133.  
  134. #ifndef ER_CANNOTWRITE
  135. #define ER_CANNOTWRITE          0xe104
  136. #endif
  137.  
  138. /* Streaming communication defines and structures */
  139.  
  140. #define WM_DSSTREAM_DONE        WM_USER + 0x100 /* Make our own app messages */
  141. #define WM_DSSTREAM_DEBUG       WM_USER + 0x101
  142. #define WM_DSSTREAM_PROGRESS    WM_USER + 0x102
  143.  
  144. #define DEBUGF_PLAYPOSITION     0x0300
  145. #define DEBUGF_WRITEPOSITION    0x0301
  146. #define DEBUGF_NEXTWRITE        0x0302
  147. #define DEBUGF_SKIP             0x0303
  148.  
  149. /*
  150.  * This structure keeps all the data that the TimeFunc callback uses in one
  151.  * place.  In this implementation, that means the global data segement.  This
  152.  * is setup so that if you wanted to put your callback in a DLL, all you'd need
  153.  * to do is pass the address of this structure as a parameter.
  154.  */
  155.  
  156. typedef struct waveinfoca_tag
  157. {
  158.     WAVEFORMATEX         *pwfx;             /* Wave Format data structure */
  159.     HMMIO                hmmio;             /* MM I/O handle for the WAVE */
  160.     MMCKINFO             mmck;              /* Multimedia RIFF chunk */
  161.     MMCKINFO             mmckInRIFF;        /* Use in opening a WAVE file */
  162.     LPDIRECTSOUNDBUFFER  lpDSBStreamBuffer; /* Points to DirectSoundBuffer */
  163.     DWORD                dwBufferSize;      /* Size of the entire buffer */
  164.     DWORD                dwNextWriteOffset; /* Offset to next buffer segment */
  165.     DWORD                dwProgress;        /* Used with above to show prog. */
  166.     DWORD                dwBytesRemaining;  /* Bytes 'til timer shutdown */
  167.     BOOL                 bDonePlaying;      /* Signals early abort to timer */
  168.     BOOL                 bLoopFile;         /* Should we loop playback? */
  169.     BOOL                 bFoundEnd;         /* Timer found file end */
  170. } WAVEINFOCA, *LPWAVEINFOCA;
  171.  
  172. /* Function declarations */
  173.  
  174. LRESULT CALLBACK MainWindowProc( HWND, unsigned, WPARAM, LPARAM );
  175. BOOL CALLBACK DLG_About( HWND, UINT, WPARAM, LPARAM );
  176. void CALLBACK TimeFunc( UINT, UINT, DWORD, DWORD, DWORD );
  177. BOOL CALLBACK DSEnumDlgProc( HWND, UINT, WPARAM, LPARAM );
  178. BOOL CALLBACK DSEnumProc( LPGUID, LPSTR, LPSTR, LPVOID );
  179.  
  180. void ErrorMessageBox( UINT, DWORD );
  181. void HandlePanScroll( int, int );
  182. void HandleVolScroll( int, int );
  183. void HandleFreqScroll( int, int );
  184. void ResetWavePlayer( void );
  185. void UpdateFromControls( void );
  186.  
  187. int CreateChildren( RECT );
  188. int HandleCommDlgError( DWORD );
  189. int StreamBufferSetup( void );
  190.  
  191. BOOL DoDSoundEnumerate( LPGUID );
  192.  
  193. int WaveOpenFile(char *, HMMIO *, WAVEFORMATEX **, MMCKINFO *);
  194. int WaveStartDataRead(HMMIO *, MMCKINFO *, MMCKINFO *);
  195. int WaveReadFile(HMMIO, UINT, BYTE *, MMCKINFO *, UINT *);
  196. int WaveCloseReadFile(HMMIO *, WAVEFORMATEX **);
  197.  
  198. int WaveCreateFile(char *, HMMIO *, WAVEFORMATEX *, MMCKINFO *, MMCKINFO *);
  199. int WaveStartDataWrite(HMMIO *, MMCKINFO *, MMIOINFO *);
  200. int WaveWriteFile(HMMIO, UINT, BYTE *, MMCKINFO *, UINT *, MMIOINFO *);
  201. int WaveCloseWriteFile(HMMIO *, MMCKINFO *, MMCKINFO *, MMIOINFO *, DWORD);
  202.  
  203. int WaveLoadFile(char *, UINT *, DWORD *, WAVEFORMATEX **, BYTE **);
  204. int WaveSaveFile(char *, UINT, DWORD, WAVEFORMATEX *, BYTE *);
  205.  
  206. int WaveCopyUselessChunks(HMMIO *, MMCKINFO *, MMCKINFO *, HMMIO *,
  207.                                 MMCKINFO *, MMCKINFO *);
  208. BOOL riffCopyChunk(HMMIO, HMMIO, const LPMMCKINFO);
  209.  
  210. #endif /* __DSSTREAM_INCLUDED__ */
  211.  
  212.