Gray C++ Libraries  0.0.2
A set of C++ libraries for MSVC, GNU on Windows, WinCE, Linux
cSoundBase.h
Go to the documentation of this file.
1 //
4 //
5 
6 #ifndef _INC_cSoundBase_H
7 #define _INC_cSoundBase_H
8 #ifndef NO_PRAGMA_ONCE
9 #pragma once
10 #endif
11 
12 #include "../GrayLibBase.h"
14 
15 #ifdef _WIN32
16 #include <mmsystem.h> // WAVEFORMATEX
17 #else
18 struct tWAVEFORMATEX;
19 #endif
20 
21 namespace GrayLib
22 {
23 #ifdef UNDER_CE
24 #define _GTNSND(_x) _x
25 #else
26 #define _GTNSND _GTN
27 #endif
28 
29  typedef WORD SOUND_VOL_t;
30  typedef DWORD SOUND_VOL2_t;
31  class cWaveFormatEx;
32 
33  MIDL_INTERFACE("0C3E2E71-B93C-11d2-AAD0-006007654234") ISoundObject : public IUnknown
34  {
37  IGNORE_WARN_INTERFACE(ISoundObject);
38  virtual size_t get_WaveDataLength() = 0;
39  virtual const void* get_WaveData() = 0;
40  virtual const cWaveFormatEx* get_WaveFormat() = 0;
41  };
42 
43  struct GRAYLIB_LINK cSoundBase // static
44  {
48  static const SOUND_VOL_t k_VOL_MIN = 0;
49  static const SOUND_VOL_t k_VOL_MAX = 0xFFFF;
50 
51  static LONG GRAYCALL FToDecibelI(float v);
52  static float GRAYCALL DecibelItoF(LONG d);
53 
54  static inline float GRAYCALL VolToF(SOUND_VOL_t v) noexcept
55  {
58  return ((float)(v - k_VOL_MIN)) / (k_VOL_MAX - k_VOL_MIN);
59  }
60  static inline SOUND_VOL_t GRAYCALL FToVol(float v) noexcept
61  {
64  return k_VOL_MIN + (SOUND_VOL_t)((k_VOL_MAX - k_VOL_MIN) * v);
65  }
66 
68  {
69  return FToDecibelI(VolToF(v));
70  }
72  {
73  return FToVol(DecibelItoF(d));
74  }
75 
76 #ifdef _WIN32
77  static inline HRESULT GetHResultFrom(MMRESULT mmRes) noexcept
78  {
80  if (mmRes == MMSYSERR_NOERROR) // 0
81  return S_OK;
82  return HResult::Make(FACILITY_MMSYS, (WORD)mmRes);
83  }
84 #endif
85  };
86 };
87 
88 #endif // _INC_cSoundBase_H
#define IGNORE_WARN_INTERFACE(c)
Definition: GrayCore.h:79
#define GRAYCALL
declare calling convention for static functions so everyone knows the arg passing scheme....
Definition: GrayCore.h:36
#define GRAYLIB_LINK
Definition: GrayLibBase.h:35
INT32 HRESULT
_WIN32 style error codes. INT32
Definition: SysTypes.h:465
Definition: cWaveFormat.h:73
static HRESULT Make(FACILITY_TYPE eFacility, WORD wCode) noexcept
Definition: HResult.h:186
Definition: IUnknown.h:68
Definition: cMesh.h:22
WORD SOUND_VOL_t
Mono Attenuation of the audio. linear perception 0 to k_VOL_MAX(0xffff). NOT decibels.
Definition: cSoundBase.h:29
DWORD SOUND_VOL2_t
Stereo linear perceived volume. LOWORD(left) HIWORD(right)
Definition: cSoundBase.h:30
MIDL_INTERFACE("0C3E2E71-B93C-11d2-AAD0-006007654304") IScriptableObj
@ FACILITY_MMSYS
Facility for _WIN32 MMSYSTEM MMRESULT error codes. MMSYSERR_BASE.
Definition: HResult.h:57
wrap WAVEFORMATEX
Definition: cSoundBase.h:44
static float GRAYCALL VolToF(SOUND_VOL_t v) noexcept
Definition: cSoundBase.h:54
static SOUND_VOL_t GRAYCALL FToVol(float v) noexcept
Definition: cSoundBase.h:60
static LONG GRAYCALL VolToDecibelI(SOUND_VOL_t v)
Definition: cSoundBase.h:67
static SOUND_VOL_t GRAYCALL DecibelItoVol(LONG d)
Definition: cSoundBase.h:71
Definition: cWaveFormat.h:53