ReactOS  0.4.12-dev-18-gf469aca
audio_waveout.hpp
Go to the documentation of this file.
1 /* PROJECT: ReactOS sndrec32
2  * LICENSE: GPL - See COPYING in the top level directory
3  * FILE: base/applications/sndrec32/audio_waveout.hpp
4  * PURPOSE: Windows MM wave out abstraction
5  * PROGRAMMERS: Marco Pagliaricci (irc: rendar)
6  */
7 
8 #ifndef _AUDIOWAVEOUT__H_
9 #define _AUDIOWAVEOUT__H_
10 
11 #include "audio_format.hpp"
12 #include "audio_producer.hpp"
13 
15 
17 {
25 };
26 
28 {
29  friend class audio_buffer;
30 
31  private:
34 
35  protected:
38  HWAVEOUT waveout_handle;
39 
42 
43  /* Audio Playing Thread id */
45 
47  float buf_secs;
48 
49  /* The temporary buffers for the audio data outgoing to the waveout
50  device and its size, and its total number */
51 
52  /* base address for entire memory */
54 
55  /* size in bytes for the entire memory */
56  unsigned int mb_size;
57 
58  /* number of little buffers */
59  unsigned int buffers;
60 
61  /* Protected Functions */
62 
63  void init_(void);
64  void alloc_buffers_mem_(unsigned int, float);
65  void free_buffers_mem_(void);
66 
67  void init_headers_(void);
68  void prep_headers_(void);
69  void unprep_headers_(void);
70 
71  public:
72  /* Ctors */
73  audio_waveout(const audio_format &aud_fmt,
74  audio_producer &a_buf) : wave_headers(0),
75  aud_info(aud_fmt),
76  audio_buf(a_buf),
77  status(WAVEOUT_NOTREADY),
78  main_buffer(0),
79  mb_size(0),
81  {
82  /* Initializing internal wavein data */
83  init_();
84  }
85 
86  /* Dtor */
88  {
89  }
90 
91  /* Public Functions */
92 
93  void open(void);
94  void play(void);
95  void pause(void);
96  void stop(void);
97  void close(void);
98 
100  {
101  return status;
102  }
103 
104  BYTE *buf(void)
105  {
106  return main_buffer;
107  }
108 
109  unsigned int bufsz(void)
110  {
111  return mb_size;
112  }
113 
114  unsigned int samplevalue_max(void)
115  {
116  if (aud_info.bits() == 16)
117  return (unsigned int)65535;
118  else if (aud_info.bits() == 8)
119  return (unsigned int)255;
120  else
121  return 0;
122  }
123 
124  unsigned tot_samples_buf(void)
125  {
126  return aud_info.samples_in_bytes(mb_size);
127  }
128 
129  unsigned int nsample(unsigned int nsamp)
130  {
131  unsigned int svalue;
132 
133  if (aud_info.bits() == 16)
134  svalue = (unsigned int)abs(*((short *)(main_buffer + aud_info.bytes_in_samples(nsamp))));
135  else if (aud_info.bits() == 8)
136  svalue = (unsigned int)((ptrdiff_t) *(main_buffer + aud_info.bytes_in_samples(nsamp)));
137  else
138  svalue = 0;
139 
140  return svalue;
141  }
142 };
143 
145 
146 #endif /* _AUDIOWAVEOUT__H_ */
void free_buffers_mem_(void)
#define abs(i)
Definition: fconv.c:206
void stop(void)
void open(void)
void prep_headers_(void)
BYTE * buf(void)
static DWORD WINAPI playing_procedure(LPVOID)
friend class audio_buffer
#define _AUDIO_NAMESPACE_START_
Definition: audio_def.hpp:24
unsigned short int bits(void) const
audio_producer & audio_buf
WAVEFORMATEX wave_format
HWAVEOUT waveout_handle
audio_waveout(const audio_format &aud_fmt, audio_producer &a_buf)
void play(void)
void unprep_headers_(void)
unsigned int buffers
audio_waveout_status
#define _AUDIO_DEFAULT_WAVEOUTBUFFERS
Definition: audio_def.hpp:18
audio_waveout_status status
unsigned long DWORD
Definition: ntddk_ex.h:95
unsigned int mb_size
void close(void)
const audio_format & aud_info
void init_headers_(void)
WAVEHDR * wave_headers
#define WINAPI
Definition: msvc.h:20
audio_waveout_status current_status(void)
unsigned char BYTE
Definition: ntddk_ex.h:96
unsigned int samplevalue_max(void)
__kernel_ptrdiff_t ptrdiff_t
Definition: linux.h:247
unsigned tot_samples_buf(void)
void alloc_buffers_mem_(unsigned int, float)
#define _AUDIO_NAMESPACE_END_
Definition: audio_def.hpp:25
unsigned int samples_in_bytes(unsigned int bytes) const
void pause(void)
unsigned int bytes_in_samples(unsigned int samples) const
HANDLE wakeup_playthread
void init_(void)
unsigned int nsample(unsigned int nsamp)
unsigned int bufsz(void)