ReactOS Fundraising Campaign 2012
 
€ 4,410 / € 30,000

Information | Donate

Home | Info | Community | Development | myReactOS | Contact Us

  1. Home
  2. Community
  3. Development
  4. myReactOS
  5. Fundraiser 2012

  1. Main Page
  2. Alphabetical List
  3. Data Structures
  4. Directories
  5. File List
  6. Data Fields
  7. Globals
  8. Related Pages

ReactOS Development > Doxygen

audio_membuffer.hpp
Go to the documentation of this file.
00001 /* PROJECT:         ReactOS sndrec32
00002  * LICENSE:         GPL - See COPYING in the top level directory
00003  * FILE:            base/applications/sndrec32/audio_membuffer.hpp
00004  * PURPOSE:         Allocs audio buffer
00005  * PROGRAMMERS:     Marco Pagliaricci (irc: rendar)
00006  */
00007 
00008 
00009 #ifndef _AUDIOMEMBUFFER__H_
00010 #define _AUDIOMEMBUFFER__H_
00011 
00012 
00013 
00014 #include "audio_def.hpp"
00015 #include "audio_receiver.hpp"
00016 #include "audio_format.hpp"
00017 #include "audio_producer.hpp"
00018 
00019 
00020 
00021 
00022 _AUDIO_NAMESPACE_START_
00023 
00024 
00025 
00026 class audio_membuffer : public audio_receiver, public audio_producer
00027 {
00028 
00029 
00030     
00031 
00032 
00033     protected:
00034 
00035         BYTE * audio_data;
00036         audio_format aud_info;
00037         unsigned int buf_size;
00038         unsigned int init_size;
00039 
00040 
00041 
00042         //
00043         // Protected Functions
00044         //
00045 
00046 
00047         //allocs N bytes for the audio buffer.
00048         void alloc_mem_( unsigned int );
00049 
00050 
00051         //frees memory
00052         void free_mem_( void );
00053 
00054 
00055         //resizes memory, and copies old
00056         //audio data to new-size memory
00057         void resize_mem_( unsigned int );
00058 
00059 
00060         //truncates and discards unused memory.
00061         //`buf_size' will be the same as `bytes_received'.
00062         void truncate_( void );
00063 
00064 
00065 
00066 
00067     public:
00068 
00069         
00070         void ( * audio_arrival )( unsigned int );
00071         void ( * buffer_resized ) ( unsigned int );
00072 
00073         
00074         //
00075         // Ctors
00076         //
00077 
00078         audio_membuffer( void )
00079             : audio_data( 0 ), aud_info( _AUDIO_DEFAULT_FORMAT ),
00080             buf_size( 0 ), init_size( 0 )
00081         {  
00082             
00083             //
00084             // Allocs memory for at least 1 or some seconds
00085             // of recording.
00086             //
00087             init_size = ( unsigned int )
00088                 (( float )aud_info.byte_rate() * _AUDIO_DEFAULT_BUFSECS );
00089 
00090 
00091             alloc_mem_( init_size );
00092 
00093         
00094         }
00095 
00096 
00097 
00098         audio_membuffer( audio_format aud_fmt )
00099             : audio_data( 0 ), aud_info( aud_fmt ), buf_size( 0 ),
00100             init_size( 0 )
00101         {  
00102         
00103             //
00104             // Allocs memory for at least 1 or some seconds
00105             // of recording.
00106             //
00107             init_size = ( unsigned int )
00108                 (( float )aud_info.byte_rate() * _AUDIO_DEFAULT_BUFSECS );
00109 
00110 
00111             alloc_mem_( init_size );
00112         
00113         }
00114 
00115 
00116 
00117 
00118         audio_membuffer( audio_format aud_fmt, unsigned int seconds )
00119             : audio_data( 0 ), aud_info( aud_fmt ), buf_size( 0 ),
00120             init_size( 0 )
00121         {  
00122             
00123             //
00124             // Allocs memory for audio recording
00125             // the specified number of seconds.
00126             //
00127             init_size = aud_info.byte_rate() * seconds;
00128             alloc_mem_( init_size );
00129         
00130         }
00131 
00132 
00133 
00134         audio_membuffer( audio_format aud_fmt, float seconds )
00135             : audio_data( 0 ), aud_info( aud_fmt ), buf_size( 0 ),
00136             init_size( 0 )
00137         {  
00138             
00139             //
00140             // Allocs memory for audio recording
00141             // the specified number of seconds.
00142             //
00143             init_size = ( unsigned int )(( float ) aud_info.byte_rate() * 
00144                 seconds <= 0 ? 1 : seconds );
00145 
00146 
00147             alloc_mem_( init_size );
00148         
00149         }
00150 
00151 
00152 
00153 
00154         audio_membuffer( unsigned int bytes )
00155             : audio_data( 0 ), aud_info( _AUDIO_DEFAULT_FORMAT ),
00156             buf_size( 0 ), init_size( 0 )
00157         {  
00158         
00159             //
00160             // Allocs memory for the specified bytes
00161             //
00162             init_size = bytes;
00163             alloc_mem_( init_size );
00164         
00165         }
00166 
00167 
00168 
00169 
00170         //
00171         // Dtor
00172         //
00173 
00174         virtual ~audio_membuffer( void )
00175         { 
00176         
00177             //
00178             // Frees memory and reset values.
00179             //
00180 
00181             clear();
00182         
00183         }
00184 
00185 
00186 
00187 
00188 
00189 
00190 
00191 
00192 
00193         //
00194         // Public functions
00195         //
00196 
00197 
00198 
00199         //returns the audio buffer size in bytes.
00200         unsigned int mem_size( void ) const
00201         { return buf_size; }
00202 
00203 
00204         //returns how many audio data has been
00205         //received, in bytes.
00206         unsigned int bytes_recorded( void ) const
00207         { return bytes_received; }
00208 
00209 
00210         //returns the integer number of seconds
00211         //that the buffer can record
00212         unsigned int seconds_total( void ) const
00213         { return buf_size / aud_info.byte_rate(); }
00214 
00215 
00216         //returns the integer number of seconds
00217         //that the buffer can record
00218         unsigned int seconds_recorded( void ) const
00219         { return bytes_received / aud_info.byte_rate(); }
00220 
00221 
00222         //returns the float number of seconds
00223         //that the buffer can record
00224         float fseconds_total( void ) const
00225         { return ( float )(( float ) buf_size / 
00226                         ( float ) aud_info.byte_rate()); }
00227 
00228 
00229         //returns the float number of seconds
00230         //that has been recorded
00231         float fseconds_recorded( void ) const
00232         { return ( float )(( float ) bytes_received / 
00233                         ( float ) aud_info.byte_rate()); }
00234 
00235 
00236         unsigned int total_samples( void ) const
00237         {
00238 
00239             return ( aud_info.samples_in_seconds( fseconds_total() ));
00240 
00241         }
00242 
00243 
00244         unsigned int samples_received( void ) const
00245         {
00246 
00247 
00248             return ( aud_info.samples_in_bytes( bytes_received ));
00249 
00250         }
00251 
00252 
00253 
00254         //returns a pointer to the audio buffer
00255         BYTE * audio_buffer( void ) const
00256         { return audio_data; }
00257 
00258 
00259 
00260         //frees memory and resets values.
00261         void clear( void );
00262 
00263 
00264         audio_format & audinfo( void ) { return aud_info; }
00265 
00266 
00267         //discard audio data, resets values,
00268         //but, instead of clear() which frees memory,
00269         //reset the memory to the initial size, ready
00270         //for receiving "new" audio data.
00271         void reset( void );
00272 
00273 
00274         //truncates and discards unused memory.
00275         //`buf_size' will be the same as `bytes_received'.
00276         void truncate( void )
00277         { truncate_( ); }//TODO: fare truncate N bytes
00278 
00279 
00280         //if there is a buffer, discards current buffer
00281         //memory and realloc a new memory buffer with a 
00282         //new size expressed in bytes.
00283         void alloc_bytes( unsigned int );
00284 
00285 
00286 
00287         //if there is a buffer, discards current buffer
00288         //memory and realloc a new memory buffer with a 
00289         //new size expressed in seconds, integer and float.
00290         void alloc_seconds( unsigned int );
00291         void alloc_seconds( float );
00292 
00293 
00294 
00295         //resizes in bytes the current buffer, 
00296         //without discarding previsiously audio data received.
00297         void resize_bytes( unsigned int );
00298 
00299 
00300         //resizes in seconds the current buffer, 
00301         //without discarding previsiously audio data received.
00302         void resize_seconds( unsigned int );
00303         void resize_seconds( float );
00304 
00305 
00306 
00307 
00308 
00309 
00310 
00311         
00312         
00313         //
00314         // Inherited Functions from `audio_receiver'
00315         //
00316 
00317         void audio_receive( unsigned char *, unsigned int );
00318 
00319 
00320 
00321         
00322         //
00323         // Inherited Functions from `audio_buffer'
00324         //
00325 
00326 
00327         unsigned int read( BYTE *, unsigned int );
00328         bool finished( void );
00329         
00330 
00331 
00332 };
00333 
00334 
00335 
00336 
00337 
00338 
00339 
00340 _AUDIO_NAMESPACE_END_
00341 
00342 
00343 
00344 
00345 
00346 #endif //ifdef _AUDIOMEMBUFFER__H_

Generated on Sun May 27 2012 04:17:43 for ReactOS by doxygen 1.7.6.1

ReactOS is a registered trademark or a trademark of ReactOS Foundation in the United States and other countries.