ReactOS 0.4.15-dev-7942-gd23573b
audio_membuffer.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_membuffer.hpp
4 * PURPOSE: Allocs audio buffer
5 * PROGRAMMERS: Marco Pagliaricci (irc: rendar)
6 */
7
8#ifndef _AUDIOMEMBUFFER__H_
9#define _AUDIOMEMBUFFER__H_
10
11#include "audio_receiver.hpp"
12#include "audio_format.hpp"
13#include "audio_producer.hpp"
14
16
18{
19 protected:
22 unsigned int buf_size;
23 unsigned int init_size;
24
25 /* Protected Functions */
26
27 /* allocs N bytes for the audio buffer */
28 void alloc_mem_(unsigned int);
29 /* frees memory */
30 void free_mem_(void);
31 /* resizes memory, and copies old audio data to new-size memory */
32 void resize_mem_(unsigned int);
33 /* truncates and discards unused memory. `buf_size' will be the same as `bytes_received' */
34 void truncate_(void);
35
36 public:
37 void (* audio_arrival)(unsigned int);
38 void (* buffer_resized)(unsigned int);
39
40 /* Ctors */
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 }
50
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 }
60
61 audio_membuffer(audio_format aud_fmt, unsigned int seconds) : 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 }
70
71 audio_membuffer(audio_format aud_fmt, float seconds) : 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 }
80
81 audio_membuffer(unsigned int bytes) : audio_data(0),
83 buf_size(0),
84 init_size(0)
85 {
86 /* Allocs memory for the specified bytes */
89 }
90
91 /* Dtor */
92 virtual ~audio_membuffer(void)
93 {
94 /* Frees memory and reset values */
95 clear();
96 }
97
98 /* Public functions */
99
100 /* returns the audio buffer size in bytes */
101 unsigned int mem_size(void) const
102 {
103 return buf_size;
104 }
105
106 /* returns how many audio data has been received, in bytes */
107 unsigned int bytes_recorded(void) const
108 {
109 return bytes_received;
110 }
111
112 /* returns the integer number of seconds that the buffer can record */
113 unsigned int seconds_total(void) const
114 {
115 return buf_size / aud_info.byte_rate();
116 }
117
118 /* returns the integer number of seconds that the buffer can record */
119 unsigned int seconds_recorded(void) const
120 {
122 }
123
124 /* returns the float number of seconds that the buffer can record */
125 float fseconds_total(void) const
126 {
127 return (float)((float) buf_size / (float)aud_info.byte_rate());
128 }
129
130 /* returns the float number of seconds that has been recorded */
131 float fseconds_recorded(void) const
132 {
133 return (float)((float)bytes_received / (float)aud_info.byte_rate());
134 }
135
136 unsigned int total_samples(void) const
137 {
139 }
140
141 unsigned int samples_received(void) const
142 {
144 }
145
146 /* returns a pointer to the audio buffer */
147 BYTE * audio_buffer(void) const
148 {
149 return audio_data;
150 }
151
152 /* frees memory and resets values */
153 void clear(void);
154
156 {
157 return aud_info;
158 }
159
160 /* discard audio data, resets values, but, instead of clear() which
161 frees memory, reset the memory to the initial size, ready for
162 receiving "new" audio data. */
163 void reset(void);
164
165 /* truncates and discards unused memory. `buf_size' will be the same as `bytes_received' */
166 void truncate(void)
167 {
168 truncate_();
169 } /* TODO: fare truncate N bytes */
170
171 /* if there is a buffer, discards current buffer memory and realloc
172 a new memory buffer with a new size expressed in bytes. */
173 void alloc_bytes(unsigned int);
174
175 /* if there is a buffer, discards current buffer memory and realloc
176 a new memory buffer with a new size expressed in seconds, integer and float. */
177 void alloc_seconds(unsigned int);
178 void alloc_seconds(float);
179
180 /* resizes in bytes the current buffer, without discarding
181 previously audio data received */
182 void resize_bytes(unsigned int);
183
184 /* resizes in seconds the current buffer, without discarding
185 previously audio data received */
186 void resize_seconds( unsigned int );
187 void resize_seconds( float );
188
189 /* Inherited Functions from `audio_receiver' */
190 void audio_receive(unsigned char *, unsigned int);
191
192 /* Inherited Functions from `audio_buffer' */
193 unsigned int read(BYTE *, unsigned int);
194 bool finished(void);
195};
196
198
199#endif /* _AUDIOMEMBUFFER__H_ */
#define read
Definition: acwin.h:96
static unsigned char bytes[4]
Definition: adnsresfilter.c:74
#define _AUDIO_NAMESPACE_START_
Definition: audio_def.hpp:24
#define _AUDIO_DEFAULT_FORMAT
Definition: audio_def.hpp:13
#define _AUDIO_DEFAULT_BUFSECS
Definition: audio_def.hpp:21
#define _AUDIO_NAMESPACE_END_
Definition: audio_def.hpp:25
unsigned int byte_rate(void) const
unsigned int samples_in_seconds(float seconds) const
unsigned int samples_in_bytes(unsigned int bytes) const
float fseconds_total(void) const
void free_mem_(void)
void audio_receive(unsigned char *, unsigned int)
float fseconds_recorded(void) const
audio_membuffer(audio_format aud_fmt, float seconds)
audio_membuffer(audio_format aud_fmt, unsigned int seconds)
unsigned int buf_size
unsigned int samples_received(void) const
virtual ~audio_membuffer(void)
audio_format & audinfo(void)
void alloc_seconds(unsigned int)
unsigned int mem_size(void) const
void resize_bytes(unsigned int)
unsigned int seconds_recorded(void) const
void alloc_mem_(unsigned int)
void resize_seconds(unsigned int)
unsigned int init_size
audio_membuffer(audio_format aud_fmt)
BYTE * audio_buffer(void) const
void resize_mem_(unsigned int)
audio_format aud_info
audio_membuffer(unsigned int bytes)
void truncate_(void)
unsigned int seconds_total(void) const
unsigned int bytes_recorded(void) const
void(* audio_arrival)(unsigned int)
void(* buffer_resized)(unsigned int)
unsigned int total_samples(void) const
void alloc_bytes(unsigned int)
unsigned int bytes_received
unsigned int(__cdecl typeof(jpeg_read_scanlines))(struct jpeg_decompress_struct *
Definition: typeof.h:31
static float(__cdecl *square_half_float)(float x
unsigned char BYTE
Definition: xxhash.c:193