room101/WIN32/DSUTIL.H

142 lines
4.7 KiB
C

#ifndef __DSUTIL_H
#define __DSUTIL_H
/*==========================================================================
*
* Copyright (C) 1995 Microsoft Corporation. All Rights Reserved.
*
* File: dsutil.cpp
* Content: Routines for dealing with sounds from resources
*
*
***************************************************************************/
#ifdef __cplusplus
extern "C" {
#endif
#include <dsound.h>
typedef struct
{
char* memory;
WAVEFORMATEX* header;
BYTE* data; // pointer into wave resource (for restore)
DWORD size; // size of wave data (for restore)
int iAlloc; // number of buffers.
int iCurrent; // current buffer
IDirectSoundBuffer* Buffers[1]; // list of buffers
} SNDOBJ;
#define _HSNDOBJ_DEFINED
IDirectSoundBuffer* DSLoadSoundBuffer(IDirectSound*, SNDOBJ*);
BOOL DSReloadSoundBuffer(IDirectSoundBuffer*, SNDOBJ*);
///////////////////////////////////////////////////////////////////////////////
//
// HSNDOBJ Handle to a SNDOBJ object.
//
// SNDOBJs are implemented in dsutil as an example layer built on top
// of DirectSound.
//
// A SNDOBJ is generally used to manage individual
// sounds which need to be played multiple times concurrently. A
// SNDOBJ represents a queue of IDirectSoundBuffer objects which
// all refer to the same buffer memory.
//
// A SNDOBJ also automatically reloads the sound resource when
// DirectSound returns a DSERR_BUFFERLOST
//
///////////////////////////////////////////////////////////////////////////////
#ifndef _HSNDOBJ_DEFINED
DECLARE_HANDLE32(HSNDOBJ);
#endif
///////////////////////////////////////////////////////////////////////////////
//
// SndObjCreate Loads a SNDOBJ from a Win32 resource in
// the current application.
//
// Params:
// pDS -- Pointer to an IDirectSound that will be used to create
// the SNDOBJ.
//
// lpName -- Name of WAV resource to load the data from. Can be a
// resource id specified using the MAKEINTRESOURCE macro.
//
// iConcurrent -- Integer representing the number of concurrent playbacks of
// to plan for. Attempts to play more than this number will
// succeed but will restart the least recently played buffer
// even if it is not finished playing yet.
//
// Returns an HSNDOBJ or NULL on error.
//
// NOTES:
// SNDOBJs automatically restore and reload themselves as required.
//
///////////////////////////////////////////////////////////////////////////////
SNDOBJ* SndObjCreate(IDirectSound *pDS, LPCTSTR lpName, int iConcurrent);
///////////////////////////////////////////////////////////////////////////////
//
// SndObjDestroy Frees a SNDOBJ and releases all of its buffers.
//
// Params:
// hSO -- Handle to a SNDOBJ to free.
//
///////////////////////////////////////////////////////////////////////////////
void SndObjDestroy(SNDOBJ* hSO);
///////////////////////////////////////////////////////////////////////////////
//
// SndObjPlay Plays a buffer in a SNDOBJ.
//
// Params:
// hSO -- Handle to a SNDOBJ to play a buffer from.
//
// dwPlayFlags -- Flags to pass to IDirectSoundBuffer::Play. It is not
// legal to play an SndObj which has more than one buffer
// with the DSBPLAY_LOOPING flag. Pass 0 to stop playback.
//
///////////////////////////////////////////////////////////////////////////////
BOOL SndObjPlay(SNDOBJ* hSO, DWORD dwPlayFlags);
///////////////////////////////////////////////////////////////////////////////
//
// SndObjStop Stops one or more buffers in a SNDOBJ.
//
// Params:
// hSO -- Handle to a SNDOBJ to play a buffer from.
//
///////////////////////////////////////////////////////////////////////////////
BOOL SndObjStop(SNDOBJ* hSO);
///////////////////////////////////////////////////////////////////////////////
//
// SndObjGetFreeBuffer returns one of the cloned buffers that is
// not currently playing
//
// Params:
// hSO -- Handle to a SNDOBJ
//
// NOTES:
// This function is provided so that callers can set things like pan etc
// before playing the buffer.
//
// EXAMPLE:
// ...
//
///////////////////////////////////////////////////////////////////////////////
IDirectSoundBuffer* SndObjGetFreeBuffer(SNDOBJ* hSO);
BOOL DSFillSoundBuffer(IDirectSoundBuffer*, SNDOBJ*);
BOOL DSParseWaveResource(void*, WAVEFORMATEX**, BYTE**, DWORD*);
#ifdef __cplusplus
}
#endif
#endif