ReactOS 0.4.15-dev-7958-gcd0bb1a
audio_membuffer Class Reference

#include <audio_membuffer.hpp>

Inheritance diagram for audio_membuffer:
Collaboration diagram for audio_membuffer:

Public Member Functions

 audio_membuffer (void)
 
 audio_membuffer (audio_format aud_fmt)
 
 audio_membuffer (audio_format aud_fmt, unsigned int seconds)
 
 audio_membuffer (audio_format aud_fmt, float seconds)
 
 audio_membuffer (unsigned int bytes)
 
virtual ~audio_membuffer (void)
 
unsigned int mem_size (void) const
 
unsigned int bytes_recorded (void) const
 
unsigned int seconds_total (void) const
 
unsigned int seconds_recorded (void) const
 
float fseconds_total (void) const
 
float fseconds_recorded (void) const
 
unsigned int total_samples (void) const
 
unsigned int samples_received (void) const
 
BYTEaudio_buffer (void) const
 
void clear (void)
 
audio_formataudinfo (void)
 
void reset (void)
 
void truncate (void)
 
void alloc_bytes (unsigned int)
 
void alloc_seconds (unsigned int)
 
void alloc_seconds (float)
 
void resize_bytes (unsigned int)
 
void resize_seconds (unsigned int)
 
void resize_seconds (float)
 
void audio_receive (unsigned char *, unsigned int)
 
unsigned int read (BYTE *, unsigned int)
 
bool finished (void)
 
- Public Member Functions inherited from audio_receiver
 audio_receiver (void)
 
virtual ~audio_receiver (void)
 
virtual void audio_receive (unsigned char *, unsigned int)=0
 
void set_b_received (unsigned int r)
 
- Public Member Functions inherited from audio_producer
 audio_producer ()
 
virtual ~audio_producer (void)
 
virtual unsigned int read (BYTE *, unsigned int)=0
 
virtual bool finished (void)=0
 
unsigned int bytes_played (void) const
 
void set_position (unsigned int pos)
 
void set_position_start (void)
 
void forward (unsigned int bytes)
 
void backward (unsigned int bytes)
 

Public Attributes

void(* audio_arrival )(unsigned int)
 
void(* buffer_resized )(unsigned int)
 
- Public Attributes inherited from audio_producer
void(* play_finished )(void)
 

Protected Member Functions

void alloc_mem_ (unsigned int)
 
void free_mem_ (void)
 
void resize_mem_ (unsigned int)
 
void truncate_ (void)
 

Protected Attributes

BYTEaudio_data
 
audio_format aud_info
 
unsigned int buf_size
 
unsigned int init_size
 
- Protected Attributes inherited from audio_receiver
unsigned int bytes_received
 
- Protected Attributes inherited from audio_producer
unsigned int bytes_played_
 

Detailed Description

Definition at line 17 of file audio_membuffer.hpp.

Constructor & Destructor Documentation

◆ audio_membuffer() [1/5]

audio_membuffer::audio_membuffer ( void  )
inline

Definition at line 41 of file audio_membuffer.hpp.

41 : audio_data(0),
43 buf_size(0),
44 init_size(0)
45 {
46 /* Allocs memory for at least 1 or some seconds of recording */
47 init_size = (unsigned int)((float)aud_info.byte_rate() * _AUDIO_DEFAULT_BUFSECS);
49 }
#define _AUDIO_DEFAULT_FORMAT
Definition: audio_def.hpp:13
#define _AUDIO_DEFAULT_BUFSECS
Definition: audio_def.hpp:21
unsigned int byte_rate(void) const
unsigned int buf_size
void alloc_mem_(unsigned int)
unsigned int init_size
audio_format aud_info
unsigned int(__cdecl typeof(jpeg_read_scanlines))(struct jpeg_decompress_struct *
Definition: typeof.h:31

◆ audio_membuffer() [2/5]

audio_membuffer::audio_membuffer ( audio_format  aud_fmt)
inline

Definition at line 51 of file audio_membuffer.hpp.

51 : audio_data(0),
52 aud_info(aud_fmt),
53 buf_size(0),
54 init_size(0)
55 {
56 /* Allocs memory for at least 1 or some seconds of recording */
57 init_size = (unsigned int)((float)aud_info.byte_rate() * _AUDIO_DEFAULT_BUFSECS);
59 }

◆ audio_membuffer() [3/5]

audio_membuffer::audio_membuffer ( audio_format  aud_fmt,
unsigned int  seconds 
)
inline

Definition at line 61 of file audio_membuffer.hpp.

61 : audio_data(0),
62 aud_info(aud_fmt),
63 buf_size(0),
64 init_size(0)
65 {
66 /* Allocs memory for audio recording the specified number of seconds */
67 init_size = aud_info.byte_rate() * seconds;
69 }

◆ audio_membuffer() [4/5]

audio_membuffer::audio_membuffer ( audio_format  aud_fmt,
float  seconds 
)
inline

Definition at line 71 of file audio_membuffer.hpp.

71 : audio_data(0),
72 aud_info(aud_fmt),
73 buf_size(0),
74 init_size(0)
75 {
76 /* Allocs memory for audio recording the specified number of seconds */
77 init_size = (unsigned int)((float)aud_info.byte_rate() * seconds <= 0 ? 1 : seconds);
79 }

◆ audio_membuffer() [5/5]

audio_membuffer::audio_membuffer ( unsigned int  bytes)
inline

Definition at line 81 of file audio_membuffer.hpp.

81 : audio_data(0),
83 buf_size(0),
84 init_size(0)
85 {
86 /* Allocs memory for the specified bytes */
89 }
static unsigned char bytes[4]
Definition: adnsresfilter.c:74

◆ ~audio_membuffer()

virtual audio_membuffer::~audio_membuffer ( void  )
inlinevirtual

Definition at line 92 of file audio_membuffer.hpp.

93 {
94 /* Frees memory and reset values */
95 clear();
96 }

Member Function Documentation

◆ alloc_bytes()

void audio_membuffer::alloc_bytes ( unsigned int  bytes)

Definition at line 126 of file audio_membuffer.cpp.

127{
129}

◆ alloc_mem_()

_AUDIO_NAMESPACE_START_ void audio_membuffer::alloc_mem_ ( unsigned int  bytes)
protected

Definition at line 16 of file audio_membuffer.cpp.

17{
18 /* Some checking */
19 if (bytes == 0)
20 return;
21
22 /* Checks previously alloc'd memory and frees it */
23 if (audio_data)
24 delete[] audio_data;
25
26 /* Allocs new memory and zeros it */
27 audio_data = new BYTE[bytes];
28 memset(audio_data, 0, bytes * sizeof(BYTE));
29
30 /* Sets the correct buffer size */
33}
#define memset(x, y, z)
Definition: compat.h:39
unsigned char BYTE
Definition: xxhash.c:193

Referenced by alloc_bytes(), alloc_seconds(), audio_membuffer(), audio_receive(), and reset().

◆ alloc_seconds() [1/2]

void audio_membuffer::alloc_seconds ( float  secs)

Definition at line 138 of file audio_membuffer.cpp.

139{
140 alloc_mem_((unsigned int)((float)aud_info.byte_rate() * secs));
141}

◆ alloc_seconds() [2/2]

void audio_membuffer::alloc_seconds ( unsigned int  secs)

Definition at line 132 of file audio_membuffer.cpp.

133{
134 alloc_mem_(aud_info.byte_rate() * secs);
135}

◆ audinfo()

audio_format & audio_membuffer::audinfo ( void  )
inline

Definition at line 155 of file audio_membuffer.hpp.

156 {
157 return aud_info;
158 }

◆ audio_buffer()

BYTE * audio_membuffer::audio_buffer ( void  ) const
inline

Definition at line 147 of file audio_membuffer.hpp.

148 {
149 return audio_data;
150 }

◆ audio_receive()

void audio_membuffer::audio_receive ( unsigned char data,
unsigned int  size 
)
virtual

Implements audio_receiver.

Definition at line 164 of file audio_membuffer.cpp.

165{
166 /* If there isn't a buffer, allocs memory for it of size*2, and copies audio data arrival */
167 if ((audio_data == 0) || (buf_size == 0))
168 {
169 alloc_mem_(size * 2);
171 return;
172 }
173
174 /* If buffer's free memory is < of `size', we have to realloc buffer memory
175 of buf_size*2, while free memory is enough to contain `size' bytes.
176 In this case free memory is represented by `buf_size - bytes_recorded' */
177 unsigned int tot_mem = buf_size, free_mem = buf_size - bytes_received;
178 if (free_mem < size)
179 {
180 /* Calcs new buffer size */
181 /* TODO: flags for other behaviour? */
182 while (free_mem < size)
183 {
184 tot_mem *= 2;
185 free_mem = tot_mem - bytes_received;
186 }
187
188 /* Resize buffer memory */
189 resize_mem_(tot_mem);
190 }
191
192 /* Now we have enough free space in the buffer, so let's copy audio data arrivals */
194
195 if (audio_arrival)
197}
unsigned int samples_in_bytes(unsigned int bytes) const
void resize_mem_(unsigned int)
void(* audio_arrival)(unsigned int)
unsigned int bytes_received
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: gl.h:1950
GLsizeiptr size
Definition: glext.h:5919
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878

◆ bytes_recorded()

unsigned int audio_membuffer::bytes_recorded ( void  ) const
inline

Definition at line 107 of file audio_membuffer.hpp.

108 {
109 return bytes_received;
110 }

◆ clear()

void audio_membuffer::clear ( void  )

Definition at line 110 of file audio_membuffer.cpp.

111{
112 free_mem_();
113 bytes_received = 0;
114}
void free_mem_(void)

Referenced by reset(), and ~audio_membuffer().

◆ finished()

bool audio_membuffer::finished ( void  )
virtual

Implements audio_producer.

Definition at line 228 of file audio_membuffer.cpp.

229{
231 return false;
232 else
233 return true;
234}
unsigned int bytes_played_

◆ free_mem_()

void audio_membuffer::free_mem_ ( void  )
protected

Definition at line 36 of file audio_membuffer.cpp.

37{
38 if (audio_data)
39 delete[] audio_data;
40
41 buf_size = 0;
42 audio_data = 0;
43}

Referenced by clear().

◆ fseconds_recorded()

float audio_membuffer::fseconds_recorded ( void  ) const
inline

Definition at line 131 of file audio_membuffer.hpp.

132 {
133 return (float)((float)bytes_received / (float)aud_info.byte_rate());
134 }
static float(__cdecl *square_half_float)(float x

◆ fseconds_total()

float audio_membuffer::fseconds_total ( void  ) const
inline

Definition at line 125 of file audio_membuffer.hpp.

126 {
127 return (float)((float) buf_size / (float)aud_info.byte_rate());
128 }

Referenced by total_samples().

◆ mem_size()

unsigned int audio_membuffer::mem_size ( void  ) const
inline

Definition at line 101 of file audio_membuffer.hpp.

102 {
103 return buf_size;
104 }

◆ read()

unsigned int audio_membuffer::read ( BYTE out_buf,
unsigned int  bytes 
)
virtual

Implements audio_producer.

Definition at line 200 of file audio_membuffer.cpp.

201{
202 /* Some checking */
203 if (!audio_data)
204 return 0;
205
207 return 0;
208
209 unsigned int to_play = bytes_received - bytes_played_;
210 unsigned int to_copy = bytes > to_play ? to_play : bytes;
211
212 /* Copies the audio data out */
213 if ((out_buf) && (to_copy) && (audio_data))
214 memcpy(out_buf, audio_data + bytes_played_, to_copy);
215
216 /* Increments the number of total bytes played (audio data gone out from
217 the `audio_producer' object) */
218 bytes_played_ += to_copy;
219
220 if (audio_arrival)
222
223 /* Returns the exact size of audio data produced */
224 return to_copy;
225}

◆ reset()

void audio_membuffer::reset ( void  )

Definition at line 117 of file audio_membuffer.cpp.

118{
119 /* Frees memory and reset to initial state */
120 clear();
121 /* Alloc memory of size specified at the constructor */
123}

◆ resize_bytes()

void audio_membuffer::resize_bytes ( unsigned int  bytes)

Definition at line 144 of file audio_membuffer.cpp.

145{
147}

◆ resize_mem_()

void audio_membuffer::resize_mem_ ( unsigned int  new_size)
protected

Definition at line 46 of file audio_membuffer.cpp.

47{
48 if (new_size == 0)
49 return;
50
51 /* The new_size, cannot be <= of the `bytes_received' member value of the
52 parent class `audio_receiver'. We cannot touch received audio data,
53 so we have to alloc at least bytes_received+1 bytes. But we can truncate
54 unused memory, so `new_size' can be < of `buf_size' */
55 if (new_size <= bytes_received)
56 return;
57
58 BYTE * new_mem;
59
60 /* Allocs new memory and zeros it */
61 new_mem = new BYTE[new_size];
62 memset(new_mem, 0, new_size * sizeof(BYTE));
63
64 if (audio_data)
65 {
66 /* Copies received audio data, and discard unused memory */
68 /* Frees old memory */
69 delete[] audio_data;
70 /* Commit new memory */
71 audio_data = new_mem;
72 buf_size = new_size;
73 } else {
74 audio_data = new_mem;
75 buf_size = new_size;
76 }
77
79 buffer_resized(new_size);
80}
void(* buffer_resized)(unsigned int)

Referenced by audio_receive(), resize_bytes(), and resize_seconds().

◆ resize_seconds() [1/2]

void audio_membuffer::resize_seconds ( float  secs)

Definition at line 156 of file audio_membuffer.cpp.

157{
158 resize_mem_((unsigned int)((float)aud_info.byte_rate() * secs));
159}

◆ resize_seconds() [2/2]

void audio_membuffer::resize_seconds ( unsigned int  secs)

Definition at line 150 of file audio_membuffer.cpp.

151{
153}

◆ samples_received()

unsigned int audio_membuffer::samples_received ( void  ) const
inline

Definition at line 141 of file audio_membuffer.hpp.

142 {
144 }

◆ seconds_recorded()

unsigned int audio_membuffer::seconds_recorded ( void  ) const
inline

Definition at line 119 of file audio_membuffer.hpp.

120 {
122 }

◆ seconds_total()

unsigned int audio_membuffer::seconds_total ( void  ) const
inline

Definition at line 113 of file audio_membuffer.hpp.

114 {
115 return buf_size / aud_info.byte_rate();
116 }

◆ total_samples()

unsigned int audio_membuffer::total_samples ( void  ) const
inline

Definition at line 136 of file audio_membuffer.hpp.

137 {
139 }
unsigned int samples_in_seconds(float seconds) const
float fseconds_total(void) const

◆ truncate()

void audio_membuffer::truncate ( void  )
inline

Definition at line 166 of file audio_membuffer.hpp.

167 {
168 truncate_();
169 } /* TODO: fare truncate N bytes */
void truncate_(void)

◆ truncate_()

void audio_membuffer::truncate_ ( void  )
protected

Definition at line 83 of file audio_membuffer.cpp.

84{
85 /* If `buf_size' is already = to the `bytes_received' of audio data,
86 then this operation is useless; simply return */
88 return;
89
90 if (audio_data)
91 {
92 /* Allocs a new buffer */
93 BYTE * newbuf = new BYTE[bytes_received];
94 /* Copies audio data */
96 /* Frees old memory */
97 delete[] audio_data;
98 /* Commit the new buffer */
99 audio_data = newbuf;
101
102 /* Buffer truncation successful. Now the buffer size is exactly big
103 as much audio data was received */
104 }
105}

Referenced by truncate().

Member Data Documentation

◆ aud_info

◆ audio_arrival

void(* audio_membuffer::audio_arrival) (unsigned int)

Definition at line 37 of file audio_membuffer.hpp.

Referenced by audio_receive(), and read().

◆ audio_data

BYTE* audio_membuffer::audio_data
protected

◆ buf_size

unsigned int audio_membuffer::buf_size
protected

◆ buffer_resized

void(* audio_membuffer::buffer_resized) (unsigned int)

Definition at line 38 of file audio_membuffer.hpp.

Referenced by resize_mem_().

◆ init_size

unsigned int audio_membuffer::init_size
protected

Definition at line 23 of file audio_membuffer.hpp.

Referenced by alloc_mem_(), audio_membuffer(), and reset().


The documentation for this class was generated from the following files: