home *** CD-ROM | disk | FTP | other *** search
/ Learn 3D Graphics Programming on the PC / Learn_3D_Graphics_Programming_on_the_PC_Ferraro.iso / rwwin / wavemix.tx_ / wavemix.bin
Text File  |  1995-11-14  |  20KB  |  589 lines

  1. The wavemix DLL is a utility that allows multiple wav files to be played
  2. simultaneously. It is designed to be as simple to use as possilbe but still
  3. have the power to do what is required by games.  The DLL supports 8 channels
  4. of simultaneous wave play, the ability to queue up waves along the same
  5. channel and wave completion notification.
  6.  
  7. The wavemix DLL currently supports 11.025 Khz, 22.05 Khz and 44.1 Khz 8-bit Mono and Stereo.
  8. Wave conversion from the file format is done automatically to the output sampling rate
  9. when the file is opened.  The default sampling rate is set in wavemix.ini.  See wavemix.ini for
  10. details.  16 bit files are converted to 8-bit when the wave is loaded.
  11.  
  12. The API consists of the following functions:
  13.  
  14. HANDLE WINAPI WaveMixInit(void);
  15. HANDLE WINAPI WaveMixConfigureInit(LPMIXCONFIG lpConfig);
  16. HANDLE WINAPI WaveMixActivate(HANDLE hMixSession, BOOL fActivate);
  17. LPMIXWAVE WINAPI WaveMixOpenWave(HANDLE hMixSession, LPSTR szWaveFilename, HINSTANCE hInst, DWORD dwFlags);
  18. UINT WINAPI WaveMixOpenChannel(HANDLE hMixSession, int iChannel, DWORD dwFlags);
  19. UINT WINAPI WaveMixPlay(LPMIXPLAYPARAMS lpMixPlayParams);
  20. UINT WINAPI WaveMixFlushChannel(HANDLE hMixSession, int iChannel, DWORD dwFlags);
  21. UINT WINAPI WaveMixCloseChannel(HANDLE hMixSession, int iChannel, DWORD dwFlags);
  22. UINT WINAPI WaveMixFreeWave(LPMIXWAVE lpMixWave);
  23. UINT WINAPI WaveMixCloseSession(HANDLE hMixSession);
  24. void WINAPI WaveMixPump(void);
  25. WORD WINAPI WaveMixGetInfo(LPWAVEMIXINFO lpWaveMixInfo);
  26.  
  27. In order to play a file a program must: 
  28. 1. Initialize the DLL with WaveMixInit() or WaveMixConfigureInit()
  29. 2. Open a wave file with WaveMixOpenFile()
  30. 3. Open a channel with WaveMixOpenChannel()
  31. 4. Call WaveMixActivate(TRUE) to tell wavemix.dll to actually get the wave output device (see note 1 below)
  32. 5. Play the file using WaveMixPlay()
  33.  
  34. A given channel can be silenced by calling WaveMixFlushChannel() at any time.
  35.  
  36. When the program is done with playing sounds it should
  37.  
  38. 1. Close the open channels using WaveMixCloseChannel()
  39. 2. Free the memmory for the waves using WaveMixFreeWave()
  40. 3. End the session with WaveMixCloseSession()
  41.  
  42. Note 1:
  43. An appliction should call WaveMixActivate(FALSE) when it loses the focus so that
  44. the waveform device can be freed for other applications.  When focus is regained
  45. the application can call WaveMixActivate(TRUE);
  46.  
  47. Note 2:
  48. An application that does not release the processor can cause the sound to "skip"
  49. To avoid this it can call WaveMixPump() frequently.
  50.  
  51. Note 3:
  52. Setting ShowDevices=1 in wavemix.ini enables error message box support in wavemix.dll.
  53. This is especially useful if WaveMixOpenWave fails.
  54.  
  55. -------------------------------------------------------------------------------
  56.  
  57. WORD WINAPI WaveMixGetInfo(LPWAVEMIXINFO lpWaveMixInfo);
  58.  
  59. parameters
  60.  
  61. lpMixWaveMixInfo
  62.  
  63.     a pointer to a WAVEMIXINFO structure that will get filled in by the WaveMix DLL:
  64.  
  65.     typedef struct
  66.     {
  67.         WORD wSize;
  68.         BYTE bVersionMajor;
  69.         BYTE bVersionMinor;
  70.         char szDate[12]; /* Mmm dd yyyy */
  71.         DWORD dwFormats; /* see waveOutGetDevCaps (wavemix requires synchronous device) */
  72.     }
  73.     WAVEMIXINFO, *PWAVEMIXINFO, FAR * LPWAVEMIXINFO;
  74.  
  75.     wSize: should be set to sizeof(WAVEMIXINFO) before calling WaveMixGetInfo.
  76.  
  77.     bVersionMajor: the major version of the DLL.
  78.  
  79.     bVersionMinor: the minor version of the DLL.
  80.  
  81.     szDate: The compilation date of the DLL, Null terminated string in form Mmm dd yyyy
  82.             where Mmm is one of the following:  "Jan","Feb","Mar","Apr","May","Jun","Jul","Aug",
  83.             "Sep","Oct","Nov","Dec".
  84.  
  85.     dwFormats: Specifies which standard formats are supported. The supported formats are specified
  86.                with a logical OR of the flags listed in WAVEOUTCAPS documentation:
  87.  
  88.                for version 1.0: the following wave formats are supported:
  89.  
  90.                     WAVE_FORMAT_1M08  /* 11.025 kHz, Mono,   8-bit  */
  91.                     WAVE_FORMAT_1S08  /* 11.025 kHz, Stereo, 8-bit  */
  92.                     WAVE_FORMAT_1M16  /* 11.025 kHz, Mono,   16-bit */
  93.                     WAVE_FORMAT_1S16  /* 11.025 kHz, Stereo, 16-bit */
  94.                     WAVE_FORMAT_2M08  /* 22.05  kHz, Mono,   8-bit  */
  95.                     WAVE_FORMAT_2S08  /* 22.05  kHz, Stereo, 8-bit  */
  96.                     WAVE_FORMAT_2M16  /* 22.05  kHz, Mono,   16-bit */
  97.                     WAVE_FORMAT_2S16  /* 22.05  kHz, Stereo, 16-bit */
  98.                     WAVE_FORMAT_4M08  /* 44.1   kHz, Mono,   8-bit  */
  99.                     WAVE_FORMAT_4S08  /* 44.1   kHz, Stereo, 8-bit  */
  100.                     WAVE_FORMAT_4M16  /* 44.1   kHz, Mono,   16-bit */
  101.                     WAVE_FORMAT_4S16  /* 44.1   kHz, Stereo, 16-bit */
  102.  
  103.                 this is done by converting the wave format of the input wave to the current
  104.                 output format when the wave is opened.
  105.  
  106. return value
  107.  
  108. zero will be returned if the size fields match and the structure will be filled in.
  109.  
  110. if the size fields do not match the DLL will return the size that it expected.  None of the fields
  111. in the structure will be filled in.
  112.  
  113. -------------------------------------------------------------------------------
  114.  
  115. HANDLE WINAPI WaveMixInit(void);
  116.  
  117. This function should be called before any of the other functions.  It will return
  118. a handle that should be used for subsequent API calls.  This function will conifgure
  119. the DLL using default parameters and parameters specified in wavemix.ini
  120.  
  121. Note: WaveMixConfigureInit is a replacement for this function it provides application
  122.  
  123. Parameters
  124.  
  125. none
  126.  
  127. Return Value
  128.  
  129. NULL will be returned if an error occurs
  130.  
  131. -------------------------------------------------------------------------------
  132.  
  133. HANDLE WINAPI WaveMixConfigureInit(LPMIXCONFIG lpConfig);
  134.  
  135. Applications that require more control over the DLL should call this function instead
  136. of WaveMixInit().  It allows the application to specify if the DLL should support
  137. stereo output and allows the application to specify the sampling rate.  It is likely
  138. that more parameters will be specified in the future.
  139.  
  140. Note: This function is a replacement to WaveMixInit(), only one of them should be called.
  141.  
  142. Parameters
  143.  
  144. lpConfig
  145.  
  146.     a pointer to a MIXCONFIG structure:
  147.  
  148.     #define WMIX_CONFIG_CHANNELS 0x1
  149.     #define WMIX_CONFIG_SAMPLINGRATE 0x2
  150.     typedef struct
  151.     {
  152.         WORD wSize;
  153.         DWORD dwFlags;
  154.         WORD wChannels;  /* 1 = MONO, 2 = STEREO */
  155.         WORD wSamplingRate; /* 11,22,44  (11=11025, 22=22050, 44=44100 Hz) */
  156.     }
  157.     MIXCONFIG, *PMIXCONFIG, FAR * LPMIXCONFIG;
  158.  
  159.     wSize: should be set to sizeof(MIXCONFIG)
  160.  
  161.     dwFlags: this parameter is the bitwise OR of the parameters the application
  162.              wishes to specify.
  163.  
  164.     wChannels: The number of output channels to use 1 = MONO, 2 = STEREO
  165.              you must bitwise or dwFlags with WMIX_CONFIG_CHANNELS when you
  166.              set this parameter
  167.  
  168.     wSamplingRate: the output sampling rate you want to play at.  This parameter
  169.             can be set to 11, 22, or 44.  You must also bitwise OR dwFlags with
  170.             WMIX_CONFIG_SAMPLINGRATE.
  171.  
  172.             Note: It is a good idea not to set this parameter.  That will permit
  173.             wavemix to use the value that has been specified in wavemix.ini
  174.  
  175. Return Value
  176.  
  177. NULL will be returned if an error occurs
  178.  
  179. -------------------------------------------------------------------------------
  180.  
  181. UINT WINAPI WaveMixActivate(HANDLE hMixSession, BOOL fActivate);
  182.  
  183. This function should be called when an application loses the focus or otherwise
  184. becomes inactive.  This will permit other applications to aquire the wave output
  185. device. Calling this function keeps all the channels open.
  186.  
  187. Note:
  188.  
  189. 1. The wavemix DLL will keep sounds that were queued while the application was
  190. active in the queue.  When wavemix play is subsequently reactivated the sounds will
  191. continue from where they were.  (there will be a small amount of data loss equivalent
  192. to the amount of data that was buffered in the wave driver).  
  193.  
  194. 2. Calls to WaveMixPlay that are made while the application is not active will not be queued.
  195.  
  196. 3. The Application can call WaveMixFlush if it does not wish the data to be pending while
  197. it is inactive.
  198.  
  199. Parameters
  200.  
  201. HANDLE hMixSession
  202.  
  203. handle that was returned by WaveMixInit()
  204.  
  205. BOOL fActivate
  206.  
  207.     TRUE:  The application is being activated and wishes to regain the wave output
  208.            device
  209.     FALSE: The application is not active and wishes to be a good Windows Citizen and
  210.            allow other applications to use the wave output device.  This call will
  211.            cause all the channels to be flushed.
  212.  
  213. Return Value
  214.  
  215. Returns zero if the function was successful. Otherwise, it returns an error
  216. number. Possible error returns are:
  217.  
  218. MMSYSERR_ALLOCATED
  219.  
  220. Specified resource is already allocated to a process. try again later.
  221.  
  222. MMSYSERR_NOMEM
  223.  
  224. Unable to allocate or lock memory.
  225.  
  226. MMSYSERR_ERROR
  227.  
  228. an internal error
  229.  
  230. -------------------------------------------------------------------------------
  231.  
  232. LPMIXWAVE WINAPI WaveMixOpenWave(HANDLE hMixSession, LPSTR szWaveFilename,
  233.                                  HINSTANCE hInst, DWORD dwFlags);
  234.  
  235. Parameters
  236.  
  237. HANDLE hMixSession
  238.  
  239. handle that was returned by WaveMixInit()
  240.  
  241. LPSTR  szWaveFileName
  242.  
  243. szWaveFileName can be the name of a wave file to open, or the name of a WAVE resource
  244. to open, or an integer ID of a WAVE resource to open.  See the dwFlags parameter for
  245. details
  246.  
  247. HINSTANCE hInst
  248.  
  249. Identifies the instance of the module whose executable file contains the resource.
  250. See the dwFlags parameter for details.
  251.  
  252. DWORD dwFlags
  253.  
  254.     WMIX_FILE: if this bit is set then szWaveFileName specifies a far pointer to a
  255.                string containing the filename of the file to open.  hInst is ignored.
  256.  
  257.                The MS-DOS filename should not be longer than 128 bytes, including the
  258.                terminating NULL.
  259.  
  260.                Currently the DLL will only permit 11Khz 8-bit mono files to be opened.
  261.  
  262.                This flag should not be set with WMIX_RESOURCE    
  263.  
  264.     WMIX_RESOURCE:  if this bit is set then szWaveFileName specifies a WAVE resource
  265.                to be opened in hInst.
  266.  
  267.                If the high-order word of the szWaveFileName is zero, the low-order word
  268.                specifies the integer identifier of the name or type of the given resource.
  269.                Otherwise, the parameter is a long pointers to a null-terminated string. If
  270.                the first character of the string is a pound sign (#), the remaining
  271.                characters represent a decimal number that specifies the integer identifier
  272.                of the resource's name or type. For example, the string #258 represents the
  273.                integer ID 258. 
  274.  
  275.                To embed a wave file in a resource use the following format in your .rc file:
  276.                
  277.                GameSound WAVE gamesnd.wav
  278.  
  279.                Note: to reduce the amount of memory required for the resources used by an
  280.                application, the application should refer to the resources by integer
  281.                identifier instead of by name.
  282.  
  283.     WMIX_MEMORY: if this bit is set then szWaveFileName is expected to be a far pointer to
  284.                a MMIOINFO struct (see multimedia mmioOpen and MMIOINFO documentation). The
  285.                parameters should be filled in similar to:
  286.  
  287.                     mmioInfo.pchBuffer=lp;                 // pointer to the memory file
  288.                     mmioInfo.cchBuffer=GlobalSize(hMem); // size of buffer
  289.                     mmioInfo.fccIOProc=FOURCC_MEM;         // files I/O procedure
  290.  
  291.                all other fields should be 0.  WaveMixOpenWave will pass this pointer to
  292.                mmioOpen in the following manner:
  293.  
  294.                hmmio = mmioOpen(NULL, (MMIOINFO FAR* )szWaveFilename, MMIO_READ)))
  295.  
  296.                it will then read the data from hmmio, and convert it for internal use.  The 
  297.                original memory will not be modified.
  298.  
  299. Return Value
  300.  
  301. NULL will be returned if the dll was unable to open the file or resource.
  302.  
  303. -------------------------------------------------------------------------------
  304.  
  305. UINT WINAPI WaveMixOpenChannel(HANDLE hMixSession, int iChannel, DWORD dwFlags);
  306.  
  307. Parameters
  308.  
  309. HANDLE hMixSession
  310.  
  311. handle that was returned by WaveMixInit()
  312.  
  313. int iChannel
  314.  
  315. Specifies a number which indicates which channel should be opened.  Currently 
  316. the DLL supports channels 0 though 7.
  317.  
  318. It is not necessary to open or close them in any particular order.
  319.  
  320. DWORD dwFlags
  321.     WMIX_OPENSINGLE: iChannel specifies the single channel to be opened.
  322.     WMIX_ALL:    all the available channels will be opened. iChannel is ignored.
  323.     WMIX_OPENCOUNT: iChannel specifies the number of channels to open.  
  324.                eg. if iChannel==4 then channels 0 through 3 will be opend.
  325.  
  326.  
  327. Return Value
  328.  
  329. Returns zero if the function was successful. Otherwise, it returns an error
  330. number. Possible error returns are:
  331.  
  332. MMSYSERR_INVALHANDLE
  333.  
  334. if an invalid channel (ie > 7) was specified
  335.  
  336. MMSYSERR_BADDEVICEID
  337.  
  338. Specified device ID is out of range.
  339.  
  340. MMSYSERR_ALLOCATED
  341.  
  342. Specified resource is already allocated.
  343. Or the channel has already been opened.
  344.  
  345. MMSYSERR_NOMEM
  346.  
  347. Unable to allocate or lock memory.
  348.  
  349. WAVERR_BADFORMAT
  350.  
  351. Attempted to open with an unsupported wave format.
  352.  
  353. WAVERR_SYNC
  354.  
  355. Attempted to open a synchronous driver without specifying the WAVE_ALLOWSYNC flag.
  356.  
  357. MMSYSERR_ERROR
  358.  
  359. an internal error
  360.  
  361. -------------------------------------------------------------------------------
  362.  
  363. UINT WINAPI WaveMixPlay(LPMIXPLAYPARAMS lpMixPlayParams);
  364.  
  365. parameters
  366.  
  367. lpMixPlayParams
  368.  
  369.     a pointer to a MIXPLAYPARAMS structure:
  370.  
  371.     typedef struct
  372.     {
  373.         WORD wSize;
  374.         HANDLE hMixSession;
  375.         int iChannel;
  376.         LPMIXWAVE lpMixWave;
  377.         HWND hWndNotify;
  378.         DWORD dwFlags;
  379.         WORD wLoops;  /* 0xFFFF means loop forever */
  380.     }
  381.     MIXPLAYPARAMS, * PMIXPLAYPARAM, FAR * LPMIXPLAYPARAMS;
  382.  
  383.     wSize: should be set to sizeof(MIXPLAYPARAMS)
  384.  
  385.     hMixSession: the handle that was returned by WaveMixInit()
  386.  
  387.     iChannel: the channel on which the wave should be played.
  388.  
  389.     lpMixWave: a wave which was opened using WaveMixOpenWave()
  390.  
  391.     hWndNotify: a window handle to receive the MM_WOM_DONE message
  392.         when the wave completes.  If this value is set to NULL then
  393.         the message will not be posted.
  394.  
  395.     dwFlags: WMIX_QUEUEWAVE: the wave will be placed on the specified channel
  396.                              and played after all waves which are currently
  397.                              waiting to play on that channel.
  398.              WMIX_CLEARQUEUE:this wave will preempt all waves currently playing
  399.                               on the specified channel.  Notification messages
  400.                              will not be sent for any waves that get dumped.
  401.                              This message should not be combined with WMIX_QUEUEWAVE
  402.              WMIX_HIGHPRIORITY: Play this way immediately.  This flag will interrupt
  403.                              the data buffered in the wave driver and remix the sound.
  404.                              If this flag is not set you could experience up to a half
  405.                              second delay before sound is played.
  406.  
  407.                              Note: if WMIX_QUEUEWAVE is set with this flag then a sound
  408.                              playing on the channel will not be prempted, but it will
  409.                              begin immediately after the previous sound finishes.  If no
  410.                              sound is currently playing on this channel then a remix will
  411.                              occur.
  412.                              
  413.              WMIX_USELRUCHANNEL: the wave should be played on any available channel
  414.                              or played on the channel that was least recently used.
  415.                              This flag should be combined with WMIX_QUEUEWAVE or
  416.                              WMIX_CLEARQUEUE.
  417.  
  418.             WMIX_WAIT:         setting this flag cause waveMixPlay to put the play information on
  419.                              a "waiting list" to play.  when waveMixPlay is called without this
  420.                              flag set it will process the calls in the order they were received.
  421.                              This is useful if you want to play multiple sounds simultaneously.
  422.  
  423.                              Note 1: This flag is not a 'pause'.  Waves that are playing will continue
  424.                              to play regardless of how many files are on the wait list.
  425.  
  426.                              Note 2: Since the waves that are submitted with this flag set are not
  427.                              checked until waveMixPlay is called without the flag set you should
  428.                              be careful about using other API calls before playing the sounds.
  429.                              eg. WaveMixFlushChannel and WaveMixCloseChannel do not process the
  430.                              wait list.
  431.  
  432.     wLoops: The number of times the wave should be repeated.  If dwLoops is set to 
  433.             0xFFFF the wave will loop until the channel it is on is flushed, preempted,
  434.             or closed.
  435.  
  436. Return Value
  437.  
  438. Returns zero if the function was successful. Otherwise, it returns an error
  439. number. Possible error returns are:
  440.  
  441. MMSYSERR_INVALHANDLE
  442.  
  443. The specified channel has not been opened or invalid lpMixWave was passed in
  444.  
  445. MMSYSERR_NOMEM
  446.  
  447. The dll has run out of internal memory to queue up waves.  Wait until some 
  448. sounds complete and then try again.
  449.  
  450. -------------------------------------------------------------------------------
  451.  
  452. UINT WINAPI WaveMixFlushChannel(HANDLE hMixSession, int iChannel, DWORD dwFlags);
  453.  
  454. This function will empty the queue of any waves waiting to play on this channel.
  455. This function can be called to stop a wave that is playing on the channel without
  456. affecting any of the other channels.
  457.  
  458. Parameters
  459.  
  460. HANDLE hMixSession
  461.  
  462. The handle that was returned by WaveMixInit()
  463.  
  464. int iChannel
  465.  
  466. an integer which specifies a previously opened channel
  467.  
  468. DWORD dwFlags
  469.                                                      
  470.     WMIX_ALL: causes all the channels to be flushed. iChannel is ignored.
  471.     WMIX_NOREMIX: prevents WaveMixFlushChannel from causing the data to be
  472.                   immediately remixed.  This is useful if you want to flush
  473.                   more than one channel, or if you will be calling WaveMixPlay
  474.                   with a HIPRIORITY wave following WaveMixFlushChannel
  475.  
  476. Return Value
  477.  
  478. Returns zero if the function was successful. Otherwise, it returns an error
  479. number. Possible error returns are:
  480.  
  481. MMSYSERR_INVALHANDLE
  482.  
  483. The specified channel was not open
  484.  
  485. MMSYSERR_INVALPARAM
  486.  
  487. One of the parameters passed to the function is not valid
  488.  
  489. -------------------------------------------------------------------------------
  490.  
  491. UINT WINAPI WaveMixCloseChannel(HANDLE hMixSession, int iChannel, DWORD dwFlags);
  492.  
  493. This function will flush and close the specified channel.
  494.  
  495. Parameters
  496.  
  497. HANDLE hMixSession
  498.  
  499. The handle that was returned by WaveMixInit()
  500.  
  501. int iChannel
  502.  
  503. an integer which specifies a previously opened channel
  504.  
  505. DWORD dwFlags
  506.                                                      
  507.     WMIX_ALL: causes all the channels to be flushed. iChannel is ignored.
  508.  
  509. Return Value
  510.  
  511. Returns zero if the function was successful. Otherwise, it returns an error
  512. number. Possible error returns are:
  513.  
  514. MMSYSERR_INVALHANDLE
  515.  
  516. The specified channel was not open
  517.  
  518. -------------------------------------------------------------------------------
  519.  
  520. UINT WINAPI WaveMixFreeWave(HANDLE hMixSession, LPMIXWAVE lpMixWave);
  521.  
  522. Parameters
  523.  
  524. HANDLE hMixSession
  525.  
  526. The handle that was returned by WaveMixInit()
  527.  
  528. lpMixWave
  529.  
  530. A pointer that was created by WaveMixOpenWave()
  531.  
  532. Return Value
  533.  
  534. Returns zero if the function was successful. Otherwise, it returns an error
  535. number. Possible error returns are:
  536.  
  537. MMSYSERR_INVALHANDLE
  538.  
  539. The given pointer was not valid
  540.  
  541. -------------------------------------------------------------------------------
  542. UINT WINAPI WaveMixCloseSession(HANDLE hMixSession);
  543.  
  544. This function pairs up with WaveMixInit().  It should be called before the 
  545. application terminates.
  546.  
  547. Parameters
  548.  
  549. HANDLE hMixSession
  550.  
  551. The handle that was returned by WaveMixInit()
  552.  
  553. Return Value
  554.  
  555. Returns zero if the function was successful. Otherwise, it returns an error
  556. number. Possible error returns are:
  557.  
  558. MMSYSERR_INVALHANDLE
  559.  
  560. The given handle was not a valid session
  561.  
  562. -------------------------------------------------------------------------------
  563.  
  564. void WINAPI WaveMixPump(void);
  565.  
  566. Calling this function causes the WaveMix DLL to mix the next slice of wave data
  567. and submit it to the wave drivers.  This function can be called if the application
  568. does a lot of processing and fails to allow messages to reach the WaveMix DLL in 
  569. time to avoid drying up the wave queue.
  570.  
  571. Parameters
  572.  
  573. none
  574.  
  575. Return Value
  576.  
  577. none
  578.  
  579. -------------------------------------------------------------------------------
  580.  
  581.  
  582.  
  583.  
  584.  
  585.  
  586.  
  587.  
  588.  
  589.