sprint 1-alpha
|
00001 /*==========================================================================; 00002 * 00003 * Copyright (C) ©1994-1999 Paolo Medici Software. All Rights Reserved. 00004 * 00005 * File: PmSound.h 00006 * Content: Common gate to DirectSound 6 00007 * 00008 ****************************************************************************/ 00009 00010 #ifndef PM_SOUND 00011 #define PM_SOUND 00012 00013 #include <mmsystem.h> 00014 #include <dsound.h> 00015 #include <dxcp.h> 00016 00017 #ifdef __cplusplus 00018 00019 // =========================== AREA C++ ======================= 00020 00021 #define AUDIOSTREAMEVENTS 2 00022 00023 // Notify Overloading System 00024 #define AN_PLAY 1 00025 #define AN_STOP 2 00026 #define AN_END 3 // Fine Canzone 00027 00028 // Controlla il volume 00029 #define ASF_CTRLVOLUME 0x00000001 00030 #define ASF_CTRLPAN 0x00000002 00031 #define ASF_CTRLFREQ 0x00000004 00032 00033 // Deve Playare più di un file 00034 #define ASF_MULTIPLE 0x00000100 00035 00036 class AudioStream { 00037 private: 00038 LPDIRECTSOUNDNOTIFY lpdsNotify; 00039 DSBPOSITIONNOTIFY rgdsbpn[AUDIOSTREAMEVENTS]; 00040 DWORD dwFileStartPos; 00041 protected: 00042 DWORD dwFlags; 00043 LPDIRECTSOUNDBUFFER lpdsb; 00044 UINT cbDataSize; 00045 UINT cbBufferSize; // 2 secondi 00046 DWORD dwStopNextTime; 00047 LONG lVolume; 00048 public: 00049 UINT uCountDown; 00050 HANDLE hfile; 00051 BOOL m_bPlaying; // Whether sound is playing 00052 HANDLE rghEvent[AUDIOSTREAMEVENTS]; 00053 00054 HRESULT CreateFromHandle(); 00055 HRESULT CreateFromFile(LPCSTR lpszFile); 00056 VOID SetOptions( LONG lFrequency, LONG lPan, LONG lVolume ); 00057 // Il volume è in valore assoluto questa volta. 00058 // va da 0 (silence) a 10000 (max) 00059 VOID SetVolume(LONG lVolume); 00060 VOID SetPan(LONG lPan); 00061 HRESULT Play( BOOL bLooped = FALSE ); 00062 HRESULT Stop(); 00063 void Rewind(); 00064 void Release(); 00065 BOOL CheckForNotificationSignal(); 00066 void HandleNotificationSignal(); 00067 BOOL StreamToBuffer(DWORD dwPos); 00068 BOOL Init(DWORD dwFlag=0); 00069 void Done(); 00070 00071 // Overloading... 00072 virtual void Notify(DWORD); 00073 }; 00074 00075 class AudioThread { 00076 protected: 00077 HANDLE hAudioThread; 00078 DWORD dwAudioThreadId; 00079 HANDLE CloseEvent; 00080 AudioStream *pas; 00081 public: 00082 AudioThread(); 00083 ~AudioThread(); 00084 // Unused 00085 void Initialize(); 00086 00087 void HandleStream(AudioStream &as); 00088 00089 void UnlinkStream(AudioStream &as); 00090 00091 void CloseStream(BOOL bSelfRefreshing=TRUE); 00092 00093 friend DWORD WINAPI AudioThreadFunc(AudioThread *); 00094 }; 00095 00096 // =========================== AREA C++ (fine) ================== 00097 00098 extern "C" { 00099 #endif 00100 00101 #include <pshpack1.h> 00102 00103 #define PCM_ID 'xMCP' 00104 00105 // valori per wVersion 00106 00107 // PCM_UNCOMPRESSED DATA: 00108 #define PCM_VERSION 0x0101 00109 00110 #define FLAG_STEREO 0x0001 // 00111 #define FLAG_HIBIT 0x0002 // 16 bit 00112 00113 // i Dati che seguono l'header contengono il tag per il WAVEFORMATEX 00114 // dati da passare al ACM Converter in loading... 00115 #define FLAG_WAVEFORMATEX 0x8000 00116 00117 typedef struct IDirectPCM { 00118 WORD wFlag; 00119 WORD wReserved; 00120 DWORD dwSize; 00121 // frequenza di campionamento 00122 DWORD dwFreq; // supporto per frequenze sul 96KHz!!!! 00123 } PCMHEAD, *LPPCMHEAD; 00124 00125 #include <poppack.h> 00126 00127 extern LPDIRECTSOUND lpds; 00128 extern DSBUFFERDESC dsbdesc; 00129 extern LPDIRECTSOUNDBUFFER lpdsbPrimary; 00130 00131 extern BOOL InitDSoundEx(HWND hwnd, 00132 GUID *pguid, 00133 LPWAVEFORMATEX pwfx, 00134 BOOL bForceSecondary); 00135 00136 extern BOOL InitDSound(HWND hwnd, 00137 LPWAVEFORMATEX pwfx); 00138 00139 extern void CreateWaveEx(LPWAVEFORMATEX, DWORD, BOOL, BOOL); 00140 extern void CreateWave(LPWAVEFORMATEX pwfx, LPPCMHEAD pcm); 00141 extern void DSExit(void); 00142 00143 #define DSBCAPS_FASTPLAY DSBCAPS_STATIC 00144 #define DSBCAPS_STANDARD (DSBCAPS_STATIC | DSBCAPS_CTRLVOLUME) 00145 #define DSBCAPS_MODULATE (DSBCAPS_STATIC | DSBCAPS_CTRLFREQUENCY | DSBCAPS_CTRLPAN | DSBCAPS_CTRLVOLUME) 00146 00147 // Crea un buffer sonoro da un file pcw 00148 extern LPDIRECTSOUNDBUFFER CreateSoundBuffer(LPCSTR flnm,DWORD dwFlag); 00149 extern LPDIRECTSOUNDBUFFER CreateSoundBufferFromHandle(HANDLE, DWORD dwFlag); 00150 00151 extern LPDIRECTSOUNDBUFFER CreateEmptySoundBuffer(LPPCMHEAD lpPcm, DWORD dwFlag); 00152 00153 extern LPDIRECTSOUNDBUFFER CreateFullSoundBuffer(LPPCMHEAD lpPcm, 00154 LPVOID lpData, DWORD dwFlag); 00155 00156 HRESULT WaitStopSound(LPDIRECTSOUNDBUFFER lpdsb); 00157 00158 // I pack di strumenti sono normali pack 00159 UINT LoadSoundPack(LPCSTR lpszFilename, 00160 LPDIRECTSOUNDBUFFER *lpdsbList, 00161 UINT lSize, 00162 DWORD dwFlag); 00163 00164 // ==================== PMMODULE ================================= 00165 00166 typedef struct _MODULEDESC FAR *LPMODULEDESC; 00167 00168 typedef struct _MODULEDESC { 00169 DWORD dwSize; 00170 char name[64]; 00171 DWORD dwType; 00172 DWORD dwStatus; 00173 DWORD dwCaps; 00174 00175 DWORD dwOrders; 00176 DWORD dwPatterns; 00177 DWORD dwInstruments; 00178 DWORD dwSamples; 00179 DWORD dwChannels; 00180 } MODULEDESC; 00181 00182 00183 typedef struct _MODULESTATUS FAR *LPMODULESTATUS; 00184 00185 typedef struct _MODULESTATUS { 00186 DWORD dwSize; 00187 00188 DWORD dwStatus; 00189 DWORD dwTime; 00190 00191 DWORD dwOrder; 00192 DWORD dwPattern; 00193 DWORD dwSpeed; 00194 DWORD dwBPM; 00195 DWORD dwRow; 00196 00197 00198 } MODULESTATUS; 00199 00200 struct IMusicModule; 00201 00202 typedef struct IMusicModule FAR *LPMUSICMODULE; 00203 00204 #if defined( _WIN32 ) && !defined( _NO_COM ) 00205 #undef INTERFACE 00206 #define INTERFACE IMusicModule 00207 DECLARE_INTERFACE( IMusicModule) 00208 { 00209 /*** IUnknown0 methods **/ 00210 STDMETHOD_(ULONG,AddRef) (THIS) PURE; 00211 STDMETHOD_(ULONG,Release) (THIS) PURE; 00212 /*** IMusicModule methods ***/ 00213 STDMETHOD(GetCaps)(THIS_ LPMODULEDESC) PURE; 00214 STDMETHOD(GetStatus)(THIS_ LPMODULESTATUS) PURE; 00215 STDMETHOD(Play)(THIS) PURE; 00216 STDMETHOD(SetPosition)(THIS_ DWORD) PURE; 00217 STDMETHOD(GetPosition)(THIS_ LPDWORD) PURE; 00218 STDMETHOD(Stop)(THIS) PURE; 00219 STDMETHOD(NotifyStatus)(THIS) PURE; 00220 00221 STDMETHOD(SetPanSeperation)(THIS_ FLOAT) PURE; 00222 00223 STDMETHOD(GetSample)(THIS_ DWORD sampno, LPVOID) PURE; 00224 }; 00225 #endif 00226 00227 struct IPMMusic; 00228 00229 typedef struct IPMMusic FAR *LPPMMUSIC; 00230 00231 #if defined( _WIN32 ) && !defined( _NO_COM ) 00232 #undef INTERFACE 00233 #define INTERFACE IPMMusic 00234 DECLARE_INTERFACE( IPMMusic) 00235 { 00236 /*** IUnknown0 methods **/ 00237 STDMETHOD_(ULONG,AddRef) (THIS) PURE; 00238 STDMETHOD_(ULONG,Release) (THIS) PURE; 00239 /*** IPMMusic methods ***/ 00240 STDMETHOD(SetInterface)(THIS_ LPDIRECTSOUND lpdds) PURE; 00241 STDMETHOD(GetCaps)(THIS) PURE; 00242 STDMETHOD(EnumMixer)(THIS) PURE; 00243 STDMETHOD(SetMixer)(THIS_ DWORD) PURE; 00244 STDMETHOD(GetMixer)(THIS_ DWORD) PURE; 00245 STDMETHOD(StopAllSong) (THIS) PURE; 00246 00247 STDMETHOD(LoadSong)(THIS_ LPCSTR lpszFile, LPMUSICMODULE FAR *ppModule) PURE; 00248 STDMETHOD(LoadSongMemory)(THIS_ LPVOID lpData, DWORD dwSize, LPMUSICMODULE FAR *ppModule) PURE; 00249 }; 00250 #endif 00251 00252 // ==================== MGR ====================================== 00253 extern BOOL WritePCMFile(LPCSTR file, LPPCMHEAD lpPcm, LPBYTE src); 00254 00255 extern DWORD WritePCMFileEx(HANDLE hfile, LPPCMHEAD lpPcm, LPBYTE src); 00256 00257 extern BOOL WriteSoundModule(LPCSTR lpszFilename, LPVOID lpDst); 00258 00259 // ==================== GESTIONE FILE WAVE ==================== 00260 void CreatePCMHeader(LPPCMHEAD lpPcmDst, LPPCMWAVEFORMAT lpPcmSrc); 00261 void AcquireWaveHeader(LPCSTR file, PCMHEAD *ppcm); 00262 LPBYTE ReadWaveFile(LPCSTR file, PCMHEAD *ppcm); 00263 00264 // ==================== SPECIAL FX =========================== 00265 00266 typedef struct IndirectFadeParam{ 00267 LPDIRECTSOUNDBUFFER lpdsb; 00268 UINT fadetime; 00269 } FADEPARAM, *LPFADEPARAM; 00270 00271 HANDLE museFadeOut(LPDIRECTSOUNDBUFFER lpdsb, UINT fadetime); 00272 HANDLE museFadeIn(LPDIRECTSOUNDBUFFER lpdsb, UINT fadetime); 00273 00274 typedef int (FAR WINAPI * LPWAKEUPPROC) (LPARAM); 00275 00276 BOOL museWakeUpProc(HANDLE hEvent, LPWAKEUPPROC lpProc, LPARAM lparam); 00277 00278 DWORD WINAPI AudioFadeOut(LPFADEPARAM p); 00279 DWORD WINAPI AudioFadeIn(LPFADEPARAM p); 00280 00281 // ==================== DSOUND EMULAZIONE ====================== 00282 00283 // E' possibile creare un DirectSound completamente via software 00284 // per usare o il WaveOut, o il PCSpeaker, o Dummy, 00285 // che non fà niente... 00286 00287 #define DSCLASS_DUMMY 0 00288 #define DSCLASS_WAVEEMUL 1 00289 #define DSCLASS_PCSPEACKER 2 00290 00291 HRESULT WINAPI EmulDirectSoundCreate(DWORD dwClass, 00292 LPDIRECTSOUND * ppDS); 00293 00294 extern GUID CLSID_EmulDirectSound; 00295 00296 #ifdef __cplusplus 00297 } 00298 #endif 00299 00300 #endif 00301 00302 // #pragma comment(lib, "dsound.lib")