* Added wavebar
authorJohannes Anderwald <johannes.anderwald@reactos.org>
Tue, 15 Dec 2009 22:39:18 +0000 (22:39 +0000)
committerJohannes Anderwald <johannes.anderwald@reactos.org>
Tue, 15 Dec 2009 22:39:18 +0000 (22:39 +0000)
* Added format, duration, buffer, position labels
- Now wave_in/out objects are opened only when pressed rec/play buttons.
- The slider bar now real points to audio samples in the buffer
- Some other little Gui changes
- by Marco Pagliaricci (IRC: rendar)

svn path=/trunk/; revision=44613

23 files changed:
reactos/base/applications/sndrec32/audio_def.hpp
reactos/base/applications/sndrec32/audio_format.cpp
reactos/base/applications/sndrec32/audio_format.hpp
reactos/base/applications/sndrec32/audio_membuffer.cpp
reactos/base/applications/sndrec32/audio_membuffer.hpp
reactos/base/applications/sndrec32/audio_producer.cpp
reactos/base/applications/sndrec32/audio_producer.hpp
reactos/base/applications/sndrec32/audio_receiver.cpp
reactos/base/applications/sndrec32/audio_receiver.hpp
reactos/base/applications/sndrec32/audio_resampler_acm.cpp
reactos/base/applications/sndrec32/audio_resampler_acm.hpp
reactos/base/applications/sndrec32/audio_wavein.cpp
reactos/base/applications/sndrec32/audio_wavein.hpp
reactos/base/applications/sndrec32/audio_waveout.cpp
reactos/base/applications/sndrec32/audio_waveout.hpp
reactos/base/applications/sndrec32/lang/en-US.rc
reactos/base/applications/sndrec32/lang/it-IT.rc
reactos/base/applications/sndrec32/resource.h
reactos/base/applications/sndrec32/sndrec32.cpp
reactos/base/applications/sndrec32/sndrec32.h
reactos/base/applications/sndrec32/sndrec32.rbuild
reactos/base/applications/sndrec32/stdafx.h
reactos/base/applications/sndrec32/targetver.h

index ee8186c..32ff48e 100644 (file)
@@ -1,24 +1,38 @@
+/* PROJECT:         ReactOS sndrec32
+ * LICENSE:         GPL - See COPYING in the top level directory
+ * FILE:            base/applications/sndrec32/audio_def.hpp
+ * PURPOSE:         Winmm abstraction settings
+ * PROGRAMMERS:     Marco Pagliaricci (irc: rendar)
+ */
+
+
+
 #ifndef _AUDIO_DEF__H_
 #define _AUDIO_DEF__H_
 
 
 #include <iostream>
 
 #ifndef _AUDIO_DEF__H_
 #define _AUDIO_DEF__H_
 
 
 #include <iostream>
 
+
+
 //
 // Defaults
 //
 
 //
 // Defaults
 //
 
+
+
 #define _AUDIO_DEFAULT_FORMAT A44100_16BIT_STEREO
 
 #define _AUDIO_DEFAULT_FORMAT A44100_16BIT_STEREO
 
-#define _AUDIO_DEFAULT_WAVEINBUFFERS 8
-#define _AUDIO_DEFAULT_WAVEINBUFSECS 0.1f
+#define _AUDIO_DEFAULT_WAVEINBUFFERS 3
+#define _AUDIO_DEFAULT_WAVEINBUFSECS 0.5f
 
 
-#define _AUDIO_DEFAULT_WAVEOUTBUFFERS 2
-#define _AUDIO_DEFAULT_WAVEOUTBUFSECS 1.0f
+#define _AUDIO_DEFAULT_WAVEOUTBUFFERS 3
+#define _AUDIO_DEFAULT_WAVEOUTBUFSECS 0.1f
 
 #define _AUDIO_DEFAULT_BUFSECS 1.0f
 
 
 
 #define _AUDIO_DEFAULT_BUFSECS 1.0f
 
 
+
 //
 // Namespace stuff
 //
 //
 // Namespace stuff
 //
 #define _AUDIO_NAMESPACE_START_ namespace snd {
 #define _AUDIO_NAMESPACE_END_ };
 
 #define _AUDIO_NAMESPACE_START_ namespace snd {
 #define _AUDIO_NAMESPACE_END_ };
 
+
+
+
+
 //
 // Platform depend stuff
 //
 //
 // Platform depend stuff
 //
 #include <windows.h>
 #include <mmsystem.h> //Windows MultiMedia (WINMM) audio apis
 #include <mmreg.h> //codecs stuff
 #include <windows.h>
 #include <mmsystem.h> //Windows MultiMedia (WINMM) audio apis
 #include <mmreg.h> //codecs stuff
-#include <msacm.h> //codecs stuff
+#include <Msacm.h> //codecs stuff
+
+
+
+
 
 //#pragma comment(lib, "winmm.lib")
 //#pragma comment(lib, "msacm32.lib")
 
 
 //#pragma comment(lib, "winmm.lib")
 //#pragma comment(lib, "msacm32.lib")
 
+
+
+
+
+
+
+
 #endif //ifdef _AUDIO_DEF__H_
 #endif //ifdef _AUDIO_DEF__H_
index c50adff..be927bf 100644 (file)
@@ -1,16 +1,23 @@
-/*
- * PROJECT:         ReactOS Sound Record Application
+/* PROJECT:         ReactOS sndrec32
  * LICENSE:         GPL - See COPYING in the top level directory
  * FILE:            base/applications/sndrec32/audio_format.cpp
  * LICENSE:         GPL - See COPYING in the top level directory
  * FILE:            base/applications/sndrec32/audio_format.cpp
- * PURPOSE:         Audio Format
- * PROGRAMMERS:     Marco Pagliaricci <ms_blue (at) hotmail (dot) it>
+ * PURPOSE:         Sound recording
+ * PROGRAMMERS:     Marco Pagliaricci (irc: rendar)
  */
 
  */
 
+
+
+
 #include "stdafx.h"
 #include "audio_format.hpp"
 
 #include "stdafx.h"
 #include "audio_format.hpp"
 
+
+
+
 _AUDIO_NAMESPACE_START_
 
 _AUDIO_NAMESPACE_START_
 
+
+
 //
 // Standard audio formats (declared as
 // externs in `audio_format.hpp')
 //
 // Standard audio formats (declared as
 // externs in `audio_format.hpp')
@@ -18,6 +25,11 @@ _AUDIO_NAMESPACE_START_
 
 audio_format UNNKOWN_FORMAT( 0, 0, 0);
 audio_format A44100_16BIT_STEREO( 44100, 16, 2 );
 
 audio_format UNNKOWN_FORMAT( 0, 0, 0);
 audio_format A44100_16BIT_STEREO( 44100, 16, 2 );
+audio_format A44100_16BIT_MONO( 44100, 16, 1 );
+
+
 
 
-_AUDIO_NAMESPACE_END_
 
 
+
+
+_AUDIO_NAMESPACE_END_
index f503225..947e34d 100644 (file)
@@ -1,3 +1,12 @@
+/* PROJECT:         ReactOS sndrec32
+ * LICENSE:         GPL - See COPYING in the top level directory
+ * FILE:            base/applications/sndrec32/audio_format.hpp
+ * PURPOSE:         Audio format abstraction
+ * PROGRAMMERS:     Marco Pagliaricci (irc: rendar)
+ */
+
+
+
 #ifndef _AUDIOFORMAT__H_
 #define _AUDIOFORMAT__H_
 
 #ifndef _AUDIOFORMAT__H_
 #define _AUDIOFORMAT__H_
 
@@ -18,116 +27,116 @@ _AUDIO_NAMESPACE_START_
 
 class audio_format
 {
 
 class audio_format
 {
-       protected:
-
+    protected:
+    
 
 
-               unsigned int samples_psec;
-               unsigned short int bits_psample;
-               unsigned short int chan;
+        unsigned int samples_psec;
+        unsigned short int bits_psample;
+        unsigned short int chan;
 
 
 
 
-       public:
+    public:
+        
+        
+        //
+        // Ctors
+        //
 
 
+        audio_format( unsigned int samples_per_second, 
+            unsigned short int bits_per_sample, unsigned short int channels )
 
 
-               //
-               // Ctors
-               //
+            : samples_psec( samples_per_second ), bits_psample( bits_per_sample ),
+            chan( channels )
 
 
-               audio_format( unsigned int samples_per_second,
-                       unsigned short int bits_per_sample, unsigned short int channels )
+        {     }
 
 
-                       : samples_psec( samples_per_second ), bits_psample( bits_per_sample ),
-                       chan( channels )
 
 
-               {     }
 
 
 
 
 
 
 
 
 
 
+        //
+        // Dtor
+        //
 
 
+        virtual ~audio_format( void )
+        { }
 
 
-               //
-               // Dtor
-               //
 
 
-               virtual ~audio_format( void )
-               { }
 
 
 
 
 
 
 
 
 
 
+        //
+        // Operators
+        //
 
 
+        bool operator==( audio_format & eq ) const
+        {
+            //
+            // The same audio format is when samples per second,
+            // bit per sample, and channels mono/stereo are equal.
+            //
 
 
-               //
-               // Operators
-               //
+            return (( samples_psec == eq.samples_psec ) 
+                && ( bits_psample == eq.bits_psample ) && ( chan == eq.chan ));
+        }
 
 
-               bool operator==( audio_format & eq ) const
-               {
-                       //
-                       // The same audio format is when samples per second,
-                       // bit per sample, and channels mono/stereo are equal.
-                       //
 
 
-                       return (( samples_psec == eq.samples_psec )
-                               && ( bits_psample == eq.bits_psample ) && ( chan == eq.chan ));
-               }
 
 
 
 
 
 
 
 
 
 
 
 
+        //
+        // Public Functions
+        //
 
 
+        unsigned int sample_rate( void ) const
+        { return samples_psec; }
 
 
-               //
-               // Public Functions
-               //
 
 
-               unsigned int sample_rate( void ) const
-               { return samples_psec; }
+        unsigned short int bits( void ) const
+        { return bits_psample; }
 
 
 
 
-               unsigned short int bits( void ) const
-               { return bits_psample; }
+        unsigned short int channels( void ) const
+        { return chan; }
 
 
 
 
-               unsigned short int channels( void ) const
-               { return chan; }
+        unsigned int byte_rate( void ) const
+        { return ( samples_psec * chan * ( bits_psample / 8 )); }
 
 
 
 
-               unsigned int byte_rate( void ) const
-               { return ( samples_psec * chan * ( bits_psample / 8 )); }
+        unsigned int block_align( void ) const
+        { return ( chan * ( bits_psample / 8 )); }
 
 
 
 
-               unsigned int block_align( void ) const
-               { return ( chan * ( bits_psample / 8 )); }
 
 
+        unsigned int samples_in_seconds( float seconds ) const
+        {
 
 
+            return ( unsigned int )
+                ((( float )samples_psec * ( float ) chan ) * seconds );
 
 
-               unsigned int samples_in_seconds( float seconds ) const
-               {
+        }
 
 
-                       return ( unsigned int )
-                               ((( float )samples_psec * ( float ) chan ) * seconds );
+        unsigned int samples_in_bytes ( unsigned int bytes ) const
+        {
 
 
-               }
+            return ( bytes / (( bits_psample / 8 ) * chan ));
 
 
-               unsigned int samples_in_bytes ( unsigned int bytes ) const
-               {
+        }
 
 
-                       return ( bytes / (( bits_psample / 8 ) * chan ));
+        unsigned int bytes_in_samples( unsigned int samples ) const
+        {
 
 
-               }
+            return ( samples * (( bits_psample / 8 ) * chan ));
 
 
-               unsigned int bytes_in_samples( unsigned int samples ) const
-               {
-
-                       return (( samples * ( bits_psample / 8 )) * chan );
-
-               }
+        }
 
 };
 
 
 };
 
@@ -136,7 +145,7 @@ class audio_format
 
 extern audio_format UNKNOWN_FORMAT;
 extern audio_format A44100_16BIT_STEREO;
 
 extern audio_format UNKNOWN_FORMAT;
 extern audio_format A44100_16BIT_STEREO;
-
+extern audio_format A44100_16BIT_MONO;
 
 
 
 
 
 
index e9e353d..bf91504 100644 (file)
@@ -1,12 +1,13 @@
-/*
- * PROJECT:         ReactOS Sound Record Application
+/* PROJECT:         ReactOS sndrec32
  * LICENSE:         GPL - See COPYING in the top level directory
  * FILE:            base/applications/sndrec32/audio_membuffer.cpp
  * LICENSE:         GPL - See COPYING in the top level directory
  * FILE:            base/applications/sndrec32/audio_membuffer.cpp
- * PURPOSE:         Audio MemBuffer
- * PROGRAMMERS:     Marco Pagliaricci <ms_blue (at) hotmail (dot) it>
+ * PURPOSE:         Sound recording
+ * PROGRAMMERS:     Marco Pagliaricci (irc: rendar)
  */
 
  */
 
-#include "stdafx.h"
+
+
+#include "StdAfx.h"
 #include "audio_membuffer.hpp"
 
 
 #include "audio_membuffer.hpp"
 
 
@@ -21,50 +22,50 @@ _AUDIO_NAMESPACE_START_
 //////////////////////////////////////
 
 
 //////////////////////////////////////
 
 
-void
+void 
 audio_membuffer::alloc_mem_( unsigned int bytes )
 {
 
 audio_membuffer::alloc_mem_( unsigned int bytes )
 {
 
-       //
-       // Some checking
-       //
+    //
+    // Some checking
+    //
 
 
-       if ( bytes == 0 )
-               return;
+    if ( bytes == 0 )
+        return;
 
 
 
 
 
 
 
 
 
 
-       //
-       // Checks previsiously alloc'd memory
-       // and frees it.
-       //
+    //
+    // Checks previsiously alloc'd memory
+    // and frees it.
+    //
 
 
-       if ( audio_data )
-               delete[] audio_data;
+    if ( audio_data )
+        delete[] audio_data;
 
 
 
 
 
 
-       //
-       // Allocs new memory and zeros it.
-       //
+    //
+    // Allocs new memory and zeros it.
+    //
 
 
-       audio_data = new BYTE[ bytes ];
+    audio_data = new BYTE[ bytes ];
 
 
 
 
-       memset( audio_data, 0, bytes * sizeof( BYTE ));
+    memset( audio_data, 0, bytes * sizeof( BYTE ));
 
 
 
 
 
 
-       //
-       // Sets the correct buffer size
-       //
+    //
+    // Sets the correct buffer size
+    //
 
 
-       buf_size = bytes;
+    buf_size = bytes;
 
 
 
 
-       init_size = bytes;
+    init_size = bytes;
 
 
 
 
 
 
@@ -75,11 +76,11 @@ void
 audio_membuffer::free_mem_( void )
 {
 
 audio_membuffer::free_mem_( void )
 {
 
-       if ( audio_data )
-               delete[] audio_data;
+    if ( audio_data )
+        delete[] audio_data;
 
 
-       buf_size = 0;
-       audio_data = 0;
+    buf_size = 0;
+    audio_data = 0;
 
 }
 
 
 }
 
@@ -89,152 +90,152 @@ audio_membuffer::resize_mem_( unsigned int new_size )
 {
 
 
 {
 
 
-       if ( new_size == 0 )
-               return;
+    if ( new_size == 0 )
+        return;
 
 
 
 
-       //
-       // The new_size, cannot be <= of the
-       // `bytes_received' member value of the
-       // parent class `audio_receiver'.
-       // We cannot touch received audio data,
-       // so we have to alloc at least
-       // bytes_received+1 bytes.
-       //
-       // But we can truncate unused memory, so
-       // `new_size' can be < of `buf_size'.
-       //
+    //
+    // The new_size, cannot be <= of the
+    // `bytes_received' member value of the
+    // parent class `audio_receiver'.
+    // We cannot touch received audio data,
+    // so we have to alloc at least
+    // bytes_received+1 bytes.
+    //
+    // But we can truncate unused memory, so
+    // `new_size' can be < of `buf_size'.
+    //
 
 
-       if ( new_size <= bytes_received )
-               return;
+    if ( new_size <= bytes_received )
+        return;
 
 
 
 
+    
 
 
+    BYTE * new_mem;
 
 
-       BYTE * new_mem;
 
 
 
 
+    //
+    // Allocs new memory and zeros it.
+    //
 
 
-       //
-       // Allocs new memory and zeros it.
-       //
 
 
+    new_mem = new BYTE[ new_size ];
 
 
-       new_mem = new BYTE[ new_size ];
+    memset( new_mem, 0, new_size * sizeof( BYTE ));
 
 
-       memset( new_mem, 0, new_size * sizeof( BYTE ));
 
 
 
 
+    if ( audio_data )
+    {
 
 
-       if ( audio_data )
-       {
 
 
+        //
+        // Copies received audio data, and discard
+        // unused memory.
+        //
 
 
-               //
-               // Copies received audio data, and discard
-               // unused memory.
-               //
+        memcpy( new_mem, audio_data, bytes_received );
 
 
-               memcpy( new_mem, audio_data, bytes_received );
 
 
 
 
+        //
+        // Frees old memory.
+        //
 
 
-               //
-               // Frees old memory.
-               //
+        delete[] audio_data;
 
 
-               delete[] audio_data;
 
 
 
 
 
 
 
 
+        //
+        // Commit new memory.
+        //
 
 
-               //
-               // Commit new memory.
-               //
+        audio_data = new_mem;
+        buf_size = new_size;
 
 
-               audio_data = new_mem;
-               buf_size = new_size;
 
 
 
 
 
 
+    } else {
 
 
-       } else {
+        audio_data = new_mem;
+        buf_size = new_size;
+    }
 
 
-               audio_data = new_mem;
-               buf_size = new_size;
-       }
 
 
-
-       if ( buffer_resized )
-               buffer_resized( new_size );
+    if ( buffer_resized )
+        buffer_resized( new_size );
 
 }
 
 
 
 
 
 }
 
 
 
 
-void
+void 
 audio_membuffer::truncate_( void )
 {
 
 audio_membuffer::truncate_( void )
 {
 
-       //
-       // If `buf_size' is already = to the
-       // `bytes_received' of audio data, then
-       // this operation is useless; simply return.
-       //
-
-       if ( bytes_received == buf_size )
-               return;
+    //
+    // If `buf_size' is already = to the
+    // `bytes_received' of audio data, then
+    // this operation is useless; simply return.
+    //
 
 
+    if ( bytes_received == buf_size )
+        return;
 
 
 
 
-       if ( audio_data )
-       {
 
 
+    if ( audio_data )
+    {
 
 
-               //
-               // Allocs a new buffer.
-               //
+        
+        //
+        // Allocs a new buffer.
+        //
 
 
-               BYTE * newbuf = new BYTE[ bytes_received ];
+        BYTE * newbuf = new BYTE[ bytes_received ];
 
 
 
 
 
 
 
 
-               //
-               // Copies audio data.
-               //
+        //
+        // Copies audio data.
+        //
 
 
-               memcpy( newbuf, audio_data, bytes_received );
+        memcpy( newbuf, audio_data, bytes_received );
 
 
 
 
 
 
-               //
-               // Frees old memory.
-               //
+        //
+        // Frees old memory.
+        //
 
 
-               delete[] audio_data;
+        delete[] audio_data;
 
 
 
 
 
 
-               //
-               // Commit the new buffer.
-               //
+        //
+        // Commit the new buffer.
+        //
 
 
-               audio_data = newbuf;
-               buf_size = bytes_received;
+        audio_data = newbuf;
+        buf_size = bytes_received;
 
 
 
 
 
 
-               //
-               // Buffer truncation successfull.
-               // Now the buffer size is exactly big
-               // as much audio data was received.
-               //
+        //
+        // Buffer truncation successfull.
+        // Now the buffer size is exactly big
+        // as much audio data was received.
+        //
 
 
 
 
-       }
+    }
 
 
 }
 
 
 }
@@ -255,94 +256,94 @@ void
 audio_membuffer::clear( void )
 {
 
 audio_membuffer::clear( void )
 {
 
-       free_mem_();
+    free_mem_();
 
 
-       bytes_received = 0;
+    bytes_received = 0;
 }
 
 
 
 }
 
 
 
-void
+void 
 audio_membuffer::reset( void )
 {
 
 
 audio_membuffer::reset( void )
 {
 
 
-       //
-       // Frees memory and reset
-       // to initial state.
-       //
+    //
+    // Frees memory and reset
+    // to initial state.
+    //
 
 
-       clear();
+    clear();
 
 
 
 
 
 
-       //
-       // Alloc memory of size specified
-       // at the constructor.
-       //
+    //
+    // Alloc memory of size specified
+    // at the constructor.
+    //
 
 
-       alloc_mem_( init_size );
+    alloc_mem_( init_size );
 
 
 }
 
 
 
 }
 
-void
+void 
 audio_membuffer::alloc_bytes( unsigned int bytes )
 {
 
 audio_membuffer::alloc_bytes( unsigned int bytes )
 {
 
-       alloc_mem_( bytes );
+    alloc_mem_( bytes );
 
 }
 
 
 
 
 }
 
 
 
-
-void
+        
+void 
 audio_membuffer::alloc_seconds( unsigned int secs )
 {
 audio_membuffer::alloc_seconds( unsigned int secs )
 {
-
-       alloc_mem_( aud_info.byte_rate() * secs );
+    
+    alloc_mem_( aud_info.byte_rate() * secs );
 
 }
 
 
 
 }
 
 
-void
+void 
 audio_membuffer::alloc_seconds( float secs )
 {
 
 audio_membuffer::alloc_seconds( float secs )
 {
 
-       alloc_mem_(( unsigned int )(( float ) aud_info.byte_rate() * secs ));
+    alloc_mem_(( unsigned int )(( float ) aud_info.byte_rate() * secs ));
 
 }
 
 
 
 
 
 }
 
 
 
 
-void
+void 
 audio_membuffer::resize_bytes( unsigned int bytes )
 {
 
 audio_membuffer::resize_bytes( unsigned int bytes )
 {
 
-       resize_mem_( bytes );
+    resize_mem_( bytes );
 
 }
 
 
 
 }
 
 
-
-void
+        
+void 
 audio_membuffer::resize_seconds( unsigned int secs )
 {
 
 audio_membuffer::resize_seconds( unsigned int secs )
 {
 
-       resize_mem_( aud_info.byte_rate() * secs );
+    resize_mem_( aud_info.byte_rate() * secs );
 
 }
 
 
 
 }
 
 
-void
+void 
 audio_membuffer::resize_seconds( float secs )
 {
 
 audio_membuffer::resize_seconds( float secs )
 {
 
-       resize_mem_(( unsigned int )
-               (( float )aud_info.byte_rate() * secs )
-       );
+    resize_mem_(( unsigned int )
+        (( float )aud_info.byte_rate() * secs )
+    );
 
 }
 
 
 }
 
@@ -350,7 +351,6 @@ audio_membuffer::resize_seconds( float secs )
 
 
 
 
 
 
-
 ///////////////////////////////////////
 ///////  Inherited Functions  /////////
 ///////////////////////////////////////
 ///////////////////////////////////////
 ///////  Inherited Functions  /////////
 ///////////////////////////////////////
@@ -361,150 +361,153 @@ audio_membuffer::resize_seconds( float secs )
 
 
 
 
 
 
-void
+void 
 audio_membuffer::audio_receive
 audio_membuffer::audio_receive
-               ( unsigned char * data, unsigned int size )
+        ( unsigned char * data, unsigned int size )
 {
 
 {
 
+    
 
 
-       //
-       // If there isn't a buffer, allocs memory for
-       // it of size*2, and copies audio data arrival.
-       //
 
 
-       if (( audio_data == 0 ) || ( buf_size == 0 ))
-       {
-               alloc_mem_( size * 2 );
+    //
+    // If there isn't a buffer, allocs memory for
+    // it of size*2, and copies audio data arrival.
+    //
 
 
-               memcpy( audio_data, data, size );
+    if (( audio_data == 0 ) || ( buf_size == 0 ))
+    {
+        alloc_mem_( size * 2 );
 
 
-               return;
+        memcpy( audio_data, data, size );
 
 
-       }
+        return;
 
 
+    }
 
 
 
 
 
 
 
 
-       //
-       // If buffer's free memory is < of `size',
-       // we have to realloc buffer memory of
-       // buf_size*2, while free memory is enough
-       // to contain `size' bytes.
-       //
-       // In this case free memory is represented
-       // by `buf_size - bytes_recorded'.
-       //
 
 
-       unsigned int tot_mem = buf_size,
-               free_mem = buf_size - bytes_received;
+    //
+    // If buffer's free memory is < of `size',
+    // we have to realloc buffer memory of
+    // buf_size*2, while free memory is enough
+    // to contain `size' bytes.
+    //
+    // In this case free memory is represented
+    // by `buf_size - bytes_recorded'.
+    //
 
 
+    unsigned int tot_mem = buf_size,
+        free_mem = buf_size - bytes_received;
 
 
-       if ( free_mem < size )
-       {
 
 
-               //
-               // Calcs new buffer size.
-               // TODO: flags for other behaviour?
+    if ( free_mem < size )
+    {
 
 
-               while ( free_mem < size )
-               {
-                       tot_mem *= 2;
+        //
+        // Calcs new buffer size.
+        // TODO: flags for other behaviour?
 
 
-                       free_mem = tot_mem - bytes_received;
-               }
+        while ( free_mem < size )
+        {
+            tot_mem *= 2;
 
 
+            free_mem = tot_mem - bytes_received;
+        }
 
 
 
 
-               //
-               // Resize buffer memory.
-               //
 
 
-               resize_mem_( tot_mem );
+        //
+        // Resize buffer memory.
+        //
 
 
-       }
+        resize_mem_( tot_mem );
 
 
+    }
+        
 
 
-       //
-       // Now we have enough free space in the
-       // buffer, so let's copy audio data arrivals.
-       //
+    //
+    // Now we have enough free space in the
+    // buffer, so let's copy audio data arrivals.
+    //
 
 
-       memcpy( audio_data + bytes_received, data, size );
+    memcpy( audio_data + bytes_received, data, size );
 
 
 
 
-
-
-       if ( audio_arrival )
-               audio_arrival( aud_info.samples_in_bytes( size ));
-
+    
+    
+    if ( audio_arrival )
+        audio_arrival( aud_info.samples_in_bytes( size ));
+    
 
 
 }
 
 
 
 
 }
 
 
-unsigned int
+unsigned int 
 audio_membuffer::read( BYTE * out_buf, unsigned int bytes )
 {
 
 audio_membuffer::read( BYTE * out_buf, unsigned int bytes )
 {
 
-       //
-       // Some checking
-       //
-
-       if ( !audio_data )
-               return 0;
-
 
 
-       if ( bytes_played_ >= bytes_received )
-               return 0;
+    //
+    // Some checking
+    //
+    
+    if ( !audio_data )
+        return 0;
 
 
 
 
+    if ( bytes_played_ >= bytes_received )
+        return 0;
 
 
-       unsigned int to_play =
-               bytes_received - bytes_played_;
 
 
 
 
-       unsigned int to_copy =
-               bytes > to_play ? to_play : bytes;
+    unsigned int to_play =  
+        bytes_received - bytes_played_;
 
 
 
 
-       //
-       // Copies the audio data out.
-       //
+    unsigned int to_copy = 
+        bytes > to_play ? to_play : bytes;
+    
 
 
-       if (( out_buf ) && ( to_copy ) && ( audio_data ))
-               memcpy( out_buf, audio_data + bytes_played_, to_copy );
+    //
+    // Copies the audio data out.
+    //
 
 
+    if (( out_buf ) && ( to_copy ) && ( audio_data ))
+        memcpy( out_buf, audio_data + bytes_played_, to_copy );
 
 
-       //
-       // Increments the number of total bytes
-       // played (audio data gone out from the
-       // `audio_producer' object).
-       //
 
 
-       bytes_played_ += bytes;
+    //
+    // Increments the number of total bytes
+    // played (audio data gone out from the
+    // `audio_producer' object).
+    //
 
 
+    bytes_played_ += to_copy;
 
 
-       if ( audio_arrival )
-               audio_arrival( aud_info.samples_in_bytes( bytes ));
 
 
+    if ( audio_arrival )
+        audio_arrival( aud_info.samples_in_bytes( to_copy ));
 
 
-       //
-       // Returns the exact size of audio data
-       // produced.
-       //
+    
+    //
+    // Returns the exact size of audio data
+    // produced.
+    //
 
 
-       return to_copy;
+    return to_copy;
 }
 
 
 bool
 }
 
 
 bool
-audio_membuffer::finished( void )
+audio_membuffer::finished( void ) 
 {
 {
-       if ( bytes_played_ < bytes_received )
-               return false;
-       else
-               return true;
+    if ( bytes_played_ < bytes_received )
+        return false;
+    else
+        return true;
 }
 
 
 }
 
 
index 7cd1dc4..342c26e 100644 (file)
@@ -1,3 +1,11 @@
+/* PROJECT:         ReactOS sndrec32
+ * LICENSE:         GPL - See COPYING in the top level directory
+ * FILE:            base/applications/sndrec32/audio_membuffer.hpp
+ * PURPOSE:         Allocs audio buffer
+ * PROGRAMMERS:     Marco Pagliaricci (irc: rendar)
+ */
+
+
 #ifndef _AUDIOMEMBUFFER__H_
 #define _AUDIOMEMBUFFER__H_
 
 #ifndef _AUDIOMEMBUFFER__H_
 #define _AUDIOMEMBUFFER__H_
 
@@ -19,306 +27,306 @@ class audio_membuffer : public audio_receiver, public audio_producer
 {
 
 
 {
 
 
+    
 
 
 
 
+    protected:
 
 
-       protected:
-
-               BYTE * audio_data;
-               audio_format aud_info;
-               unsigned int buf_size;
-               unsigned int init_size;
-
-
-
-               //
-               // Protected Functions
-               //
-
-
-               //allocs N bytes for the audio buffer.
-               void alloc_mem_( unsigned int );
-
-
-               //frees memory
-               void free_mem_( void );
-
-
-               //resizes memory, and copies old
-               //audio data to new-size memory
-               void resize_mem_( unsigned int );
-
-
-               //truncates and discards unused memory.
-               //`buf_size' will be the same as `bytes_received'.
-               void truncate_( void );
-
-
-
-
-       public:
-
-
-               void ( * audio_arrival )( unsigned int );
-               void ( * buffer_resized ) ( unsigned int );
-
+        BYTE * audio_data;
+        audio_format aud_info;
+        unsigned int buf_size;
+        unsigned int init_size;
 
 
-               //
-               // Ctors
-               //
 
 
-               audio_membuffer( void )
-                       : audio_data( 0 ), aud_info( _AUDIO_DEFAULT_FORMAT ),
-                       buf_size( 0 ), init_size( 0 )
-               {
 
 
-                       //
-                       // Allocs memory for at least 1 or some seconds
-                       // of recording.
-                       //
-                       init_size = ( unsigned int )
-                               (( float )aud_info.byte_rate() * _AUDIO_DEFAULT_BUFSECS );
+        //
+        // Protected Functions
+        //
 
 
 
 
-                       alloc_mem_( init_size );
+        //allocs N bytes for the audio buffer.
+        void alloc_mem_( unsigned int );
 
 
 
 
-               }
+        //frees memory
+        void free_mem_( void );
 
 
 
 
+        //resizes memory, and copies old
+        //audio data to new-size memory
+        void resize_mem_( unsigned int );
 
 
-               audio_membuffer( audio_format aud_fmt )
-                       : audio_data( 0 ), aud_info( aud_fmt ), buf_size( 0 ),
-                       init_size( 0 )
-               {
 
 
-                       //
-                       // Allocs memory for at least 1 or some seconds
-                       // of recording.
-                       //
-                       init_size = ( unsigned int )
-                               (( float )aud_info.byte_rate() * _AUDIO_DEFAULT_BUFSECS );
+        //truncates and discards unused memory.
+        //`buf_size' will be the same as `bytes_received'.
+        void truncate_( void );
 
 
 
 
-                       alloc_mem_( init_size );
 
 
-               }
 
 
+    public:
 
 
+        
+        void ( * audio_arrival )( unsigned int );
+        void ( * buffer_resized ) ( unsigned int );
 
 
+        
+        //
+        // Ctors
+        //
 
 
-               audio_membuffer( audio_format aud_fmt, unsigned int seconds )
-                       : audio_data( 0 ), aud_info( aud_fmt ), buf_size( 0 ),
-                       init_size( 0 )
-               {
+        audio_membuffer( void )
+            : audio_data( 0 ), aud_info( _AUDIO_DEFAULT_FORMAT ),
+            buf_size( 0 ), init_size( 0 )
+        {  
+            
+            //
+            // Allocs memory for at least 1 or some seconds
+            // of recording.
+            //
+            init_size = ( unsigned int )
+                (( float )aud_info.byte_rate() * _AUDIO_DEFAULT_BUFSECS );
 
 
-                       //
-                       // Allocs memory for audio recording
-                       // the specified number of seconds.
-                       //
-                       init_size = aud_info.byte_rate() * seconds;
-                       alloc_mem_( init_size );
 
 
-               }
+            alloc_mem_( init_size );
 
 
+        
+        }
 
 
 
 
-               audio_membuffer( audio_format aud_fmt, float seconds )
-                       : audio_data( 0 ), aud_info( aud_fmt ), buf_size( 0 ),
-                       init_size( 0 )
-               {
 
 
-                       //
-                       // Allocs memory for audio recording
-                       // the specified number of seconds.
-                       //
-                       init_size = ( unsigned int )(( float ) aud_info.byte_rate() *
-                               seconds <= 0 ? 1 : seconds );
+        audio_membuffer( audio_format aud_fmt )
+            : audio_data( 0 ), aud_info( aud_fmt ), buf_size( 0 ),
+            init_size( 0 )
+        {  
+        
+            //
+            // Allocs memory for at least 1 or some seconds
+            // of recording.
+            //
+            init_size = ( unsigned int )
+                (( float )aud_info.byte_rate() * _AUDIO_DEFAULT_BUFSECS );
 
 
 
 
-                       alloc_mem_( init_size );
+            alloc_mem_( init_size );
+        
+        }
 
 
-               }
 
 
 
 
 
 
+        audio_membuffer( audio_format aud_fmt, unsigned int seconds )
+            : audio_data( 0 ), aud_info( aud_fmt ), buf_size( 0 ),
+            init_size( 0 )
+        {  
+            
+            //
+            // Allocs memory for audio recording
+            // the specified number of seconds.
+            //
+            init_size = aud_info.byte_rate() * seconds;
+            alloc_mem_( init_size );
+        
+        }
 
 
-               audio_membuffer( unsigned int bytes )
-                       : audio_data( 0 ), aud_info( _AUDIO_DEFAULT_FORMAT ),
-                       buf_size( 0 ), init_size( 0 )
-               {
 
 
-                       //
-                       // Allocs memory for the specified bytes
-                       //
-                       init_size = bytes;
-                       alloc_mem_( init_size );
 
 
-               }
+        audio_membuffer( audio_format aud_fmt, float seconds )
+            : audio_data( 0 ), aud_info( aud_fmt ), buf_size( 0 ),
+            init_size( 0 )
+        {  
+            
+            //
+            // Allocs memory for audio recording
+            // the specified number of seconds.
+            //
+            init_size = ( unsigned int )(( float ) aud_info.byte_rate() * 
+                seconds <= 0 ? 1 : seconds );
 
 
 
 
+            alloc_mem_( init_size );
+        
+        }
 
 
 
 
-               //
-               // Dtor
-               //
 
 
-               virtual ~audio_membuffer( void )
-               {
 
 
-                       //
-                       // Frees memory and reset values.
-                       //
+        audio_membuffer( unsigned int bytes )
+            : audio_data( 0 ), aud_info( _AUDIO_DEFAULT_FORMAT ),
+            buf_size( 0 ), init_size( 0 )
+        {  
+        
+            //
+            // Allocs memory for the specified bytes
+            //
+            init_size = bytes;
+            alloc_mem_( init_size );
+        
+        }
 
 
-                       clear();
 
 
-               }
 
 
 
 
+        //
+        // Dtor
+        //
 
 
+        virtual ~audio_membuffer( void )
+        { 
+        
+            //
+            // Frees memory and reset values.
+            //
 
 
+            clear();
+        
+        }
 
 
 
 
 
 
 
 
 
 
-               //
-               // Public functions
-               //
 
 
 
 
 
 
-               //returns the audio buffer size in bytes.
-               unsigned int mem_size( void ) const
-               { return buf_size; }
 
 
+        //
+        // Public functions
+        //
 
 
-               //returns how many audio data has been
-               //received, in bytes.
-               unsigned int bytes_recorded( void ) const
-               { return bytes_received; }
 
 
 
 
-               //returns the integer number of seconds
-               //that the buffer can record
-               unsigned int seconds_total( void ) const
-               { return buf_size / aud_info.byte_rate(); }
+        //returns the audio buffer size in bytes.
+        unsigned int mem_size( void ) const
+        { return buf_size; }
 
 
 
 
-               //returns the integer number of seconds
-               //that the buffer can record
-               unsigned int seconds_recorded( void ) const
-               { return bytes_received / aud_info.byte_rate(); }
+        //returns how many audio data has been
+        //received, in bytes.
+        unsigned int bytes_recorded( void ) const
+        { return bytes_received; }
 
 
 
 
-               //returns the float number of seconds
-               //that the buffer can record
-               float fseconds_total( void ) const
-               { return ( float )(( float ) buf_size /
-                                               ( float ) aud_info.byte_rate()); }
+        //returns the integer number of seconds
+        //that the buffer can record
+        unsigned int seconds_total( void ) const
+        { return buf_size / aud_info.byte_rate(); }
 
 
 
 
-               //returns the float number of seconds
-               //that has been recorded
-               float fseconds_recorded( void ) const
-               { return ( float )(( float ) bytes_received /
-                                               ( float ) aud_info.byte_rate()); }
+        //returns the integer number of seconds
+        //that the buffer can record
+        unsigned int seconds_recorded( void ) const
+        { return bytes_received / aud_info.byte_rate(); }
 
 
 
 
-               unsigned int total_samples( void ) const
-               {
+        //returns the float number of seconds
+        //that the buffer can record
+        float fseconds_total( void ) const
+        { return ( float )(( float ) buf_size / 
+                        ( float ) aud_info.byte_rate()); }
 
 
-                       return ( aud_info.samples_in_seconds( fseconds_total() ));
 
 
-               }
+        //returns the float number of seconds
+        //that has been recorded
+        float fseconds_recorded( void ) const
+        { return ( float )(( float ) bytes_received / 
+                        ( float ) aud_info.byte_rate()); }
 
 
 
 
-               unsigned int samples_received( void ) const
-               {
+        unsigned int total_samples( void ) const
+        {
 
 
+            return ( aud_info.samples_in_seconds( fseconds_total() ));
 
 
-                       return ( aud_info.samples_in_bytes( bytes_received ));
+        }
 
 
-               }
 
 
+        unsigned int samples_received( void ) const
+        {
 
 
 
 
-               //returns a pointer to the audio buffer
-               BYTE * audio_buffer( void ) const
-               { return audio_data; }
+            return ( aud_info.samples_in_bytes( bytes_received ));
 
 
+        }
 
 
 
 
-               //frees memory and resets values.
-               void clear( void );
 
 
+        //returns a pointer to the audio buffer
+        BYTE * audio_buffer( void ) const
+        { return audio_data; }
 
 
-               audio_format & audinfo( void ) { return aud_info; }
 
 
 
 
-               //discard audio data, resets values,
-               //but, instead of clear() which frees memory,
-               //reset the memory to the initial size, ready
-               //for receiving "new" audio data.
-               void reset( void );
+        //frees memory and resets values.
+        void clear( void );
 
 
 
 
-               //truncates and discards unused memory.
-               //`buf_size' will be the same as `bytes_received'.
-               void truncate( void )
-               { truncate_( ); }//TODO: fare truncate N bytes
+        audio_format & audinfo( void ) { return aud_info; }
 
 
 
 
-               //if there is a buffer, discards current buffer
-               //memory and realloc a new memory buffer with a
-               //new size expressed in bytes.
-               void alloc_bytes( unsigned int );
+        //discard audio data, resets values,
+        //but, instead of clear() which frees memory,
+        //reset the memory to the initial size, ready
+        //for receiving "new" audio data.
+        void reset( void );
 
 
 
 
+        //truncates and discards unused memory.
+        //`buf_size' will be the same as `bytes_received'.
+        void truncate( void )
+        { truncate_( ); }//TODO: fare truncate N bytes
 
 
-               //if there is a buffer, discards current buffer
-               //memory and realloc a new memory buffer with a
-               //new size expressed in seconds, integer and float.
-               void alloc_seconds( unsigned int );
-               void alloc_seconds( float );
 
 
+        //if there is a buffer, discards current buffer
+        //memory and realloc a new memory buffer with a 
+        //new size expressed in bytes.
+        void alloc_bytes( unsigned int );
 
 
 
 
-               //resizes in bytes the current buffer,
-               //without discarding previsiously audio data received.
-               void resize_bytes( unsigned int );
 
 
+        //if there is a buffer, discards current buffer
+        //memory and realloc a new memory buffer with a 
+        //new size expressed in seconds, integer and float.
+        void alloc_seconds( unsigned int );
+        void alloc_seconds( float );
 
 
-               //resizes in seconds the current buffer,
-               //without discarding previsiously audio data received.
-               void resize_seconds( unsigned int );
-               void resize_seconds( float );
 
 
 
 
+        //resizes in bytes the current buffer, 
+        //without discarding previsiously audio data received.
+        void resize_bytes( unsigned int );
 
 
 
 
+        //resizes in seconds the current buffer, 
+        //without discarding previsiously audio data received.
+        void resize_seconds( unsigned int );
+        void resize_seconds( float );
 
 
 
 
 
 
 
 
 
 
-               //
-               // Inherited Functions from `audio_receiver'
-               //
 
 
-               void audio_receive( unsigned char *, unsigned int );
 
 
+        
+        
+        //
+        // Inherited Functions from `audio_receiver'
+        //
 
 
+        void audio_receive( unsigned char *, unsigned int );
 
 
 
 
-               //
-               // Inherited Functions from `audio_buffer'
-               //
 
 
+        
+        //
+        // Inherited Functions from `audio_buffer'
+        //
 
 
-               unsigned int read( BYTE *, unsigned int );
-               bool finished( void );
 
 
+        unsigned int read( BYTE *, unsigned int );
+        bool finished( void );
+        
 
 
 };
 
 
 };
index 2504c1b..805bec9 100644 (file)
@@ -1,9 +1,8 @@
-/*
- * PROJECT:         ReactOS Sound Record Application
+/* PROJECT:         ReactOS sndrec32
  * LICENSE:         GPL - See COPYING in the top level directory
  * FILE:            base/applications/sndrec32/audio_producer.cpp
  * LICENSE:         GPL - See COPYING in the top level directory
  * FILE:            base/applications/sndrec32/audio_producer.cpp
- * PURPOSE:         Audio Format
- * PROGRAMMERS:     Marco Pagliaricci <ms_blue (at) hotmail (dot) it>
+ * PURPOSE:         Sound recording
+ * PROGRAMMERS:     Marco Pagliaricci (irc: rendar)
  */
 
 #include "stdafx.h"
  */
 
 #include "stdafx.h"
index 50cba93..678dad7 100644 (file)
+/* PROJECT:         ReactOS sndrec32
+ * LICENSE:         GPL - See COPYING in the top level directory
+ * FILE:            base/applications/sndrec32/audio_producer.hpp
+ * PURPOSE:         Audio producer
+ * PROGRAMMERS:     Marco Pagliaricci (irc: rendar)
+ */
+
 #ifndef _AUDIOAUDBUF__H_
 #define _AUDIOAUDBUF__H_
 
 
 
 #include "audio_def.hpp"
 #ifndef _AUDIOAUDBUF__H_
 #define _AUDIOAUDBUF__H_
 
 
 
 #include "audio_def.hpp"
+#include "audio_producer.hpp"
+
 
 
 
 
-_AUDIO_NAMESPACE_START_
 
 
 
 
-class audio_producer
-{
+
+_AUDIO_NAMESPACE_START_
+
 
 
 
 
-       protected:
 
 
 
 
-               unsigned int bytes_played_;
+class audio_producer
+{
 
 
 
 
+    protected:
+        
+        
+        unsigned int bytes_played_;
 
 
 
 
 
 
-       public:
 
 
 
 
-               //
-               // Ctors
-               //
+    public:
 
 
-               audio_producer ( ) : bytes_played_( 0 )
-               {  }
 
 
+        //
+        // Ctors
+        //
 
 
+        audio_producer ( ) : bytes_played_( 0 ), play_finished ( 0 )
+        {  }
 
 
 
 
+        
 
 
 
 
 
 
 
 
 
 
-               //
-               // Dtor
-               //
+        
+        //
+        // Dtor
+        //
 
 
-               virtual ~audio_producer( void )
-               {  }
+        virtual ~audio_producer( void )
+        {  }
 
 
 
 
 
 
 
 
-               //
-               // Public Functions
-               //
+        //
+        // Public Functions
+        //
 
 
 
 
-               //reads N bytes from the buffer
-               virtual unsigned int read( BYTE *, unsigned int ) = 0;
+        //reads N bytes from the buffer
+        virtual unsigned int read( BYTE *, unsigned int ) = 0;
 
 
-               virtual bool finished ( void ) = 0;
+        virtual bool finished ( void ) = 0;
 
 
 
 
 
 
 
 
-               unsigned int bytes_played( void ) const
-               {
-                       return bytes_played_;
-               }
+        unsigned int bytes_played( void ) const
+        {
+            return bytes_played_;
+        }
 
 
 
 
-               void set_position( unsigned int pos )
-               {
-                       bytes_played_ = pos;
-               }
+        void set_position( unsigned int pos )
+        {
+            bytes_played_ = pos;
+        }
 
 
-               void set_position_start( void )
-               {
-                       bytes_played_ = 0 ;
-               }
+        void set_position_start( void )
+        {
+            bytes_played_ = 0 ;
+        }
 
 
 
 
 
 
-               void forward( unsigned int bytes )
-               {
-                       bytes_played_ += bytes ;
-               }
+        void forward( unsigned int bytes )
+        {
+            bytes_played_ += bytes ;
+        }
 
 
 
 
-               void backward( unsigned int bytes )
-               {
-                       bytes_played_ += bytes ;
-               }
+        void backward( unsigned int bytes )
+        {
+            bytes_played_ += bytes ;
+        }
 
 
-               void ( * play_finished )( void );
+        void ( * play_finished )( void );
 
 
 
 
 
 
index 77b7c3f..1d73e5c 100644 (file)
@@ -1,17 +1,9 @@
-/*
- * PROJECT:         ReactOS Sound Record Application
+/* PROJECT:         ReactOS sndrec32
  * LICENSE:         GPL - See COPYING in the top level directory
  * LICENSE:         GPL - See COPYING in the top level directory
- * FILE:            base/applications/sndrec32/audio_producer.cpp
- * PURPOSE:         Audio Format
- * PROGRAMMERS:     Marco Pagliaricci <ms_blue (at) hotmail (dot) it>
+ * FILE:            base/applications/sndrec32/audio_receiver.cpp
+ * PURPOSE:         Sound recording
+ * PROGRAMMERS:     Marco Pagliaricci (irc: rendar)
  */
 
 #include "stdafx.h"
 #include "audio_receiver.hpp"
  */
 
 #include "stdafx.h"
 #include "audio_receiver.hpp"
-
-
-
-
-_AUDIO_NAMESPACE_START_
-
-_AUDIO_NAMESPACE_END_
index 6e39d56..1d79aaf 100644 (file)
@@ -1,3 +1,12 @@
+/* PROJECT:         ReactOS sndrec32
+ * LICENSE:         GPL - See COPYING in the top level directory
+ * FILE:            base/applications/sndrec32/audio_receiver.hpp
+ * PURPOSE:         Audio receiver
+ * PROGRAMMERS:     Marco Pagliaricci (irc: rendar)
+ */
+
+
+
 #ifndef _AUDIORECEIVER_DEF__H_
 #define _AUDIORECEIVER_DEF__H_
 
 #ifndef _AUDIORECEIVER_DEF__H_
 #define _AUDIORECEIVER_DEF__H_
 
@@ -13,8 +22,7 @@ _AUDIO_NAMESPACE_START_
 
 
 
 
 
 
-//TODO: differenziare audio_receiver da audio_sink?
-//TODO: creare un audio_receiver Tee
+
 
 
 
 
 
 
@@ -23,67 +31,64 @@ _AUDIO_NAMESPACE_START_
 class audio_receiver
 {
 
 class audio_receiver
 {
 
-               //
-               // The `audio_wavein' class, while is
-               // recording audio, has to access to
-               // protected members of `audio_receiver'
-               // such as `bytes_received' protected
-               // variable.
-               //
-
-               friend class audio_wavein;
-
-
-
+        //
+        // The `audio_wavein' class, while is
+        // recording audio, has to access to 
+        // protected members of `audio_receiver'
+        // such as `bytes_received' protected
+        // variable.
+        //
 
 
+        friend class audio_wavein;
 
 
 
 
-       protected:
 
 
 
 
-               unsigned int bytes_received;
-               unsigned int status;
 
 
 
 
+    protected:
 
 
-       public:
 
 
+        unsigned int bytes_received;
 
 
-               //
-               // Ctors
-               //
 
 
-               audio_receiver( void )
-                       : bytes_received( 0 )
-               {  }
 
 
+    public:
+        
+        
+        //
+        // Ctors
+        //
 
 
+        audio_receiver( void )
+            : bytes_received( 0 )
+        {  }
 
 
 
 
 
 
-               //
-               // Dtor
-               //
 
 
-               virtual ~audio_receiver( void )
-               {  }
 
 
+        //
+        // Dtor
+        //
 
 
+        virtual ~audio_receiver( void )
+        {  }
 
 
 
 
-               //
-               // Public Functions
-               //
 
 
-               virtual void audio_receive( unsigned char *, unsigned int ) = 0;
+        
+        //
+        // Public Functions
+        //
 
 
-               //virtual void start_rec( void ) = 0;
-               //virtual void stop_rec( void ) = 0;
+        virtual void audio_receive( unsigned char *, unsigned int ) = 0;
+        
 
 
 
 
 
 
-               void set_b_received( unsigned int r )
-               { bytes_received = r; }
+        void set_b_received( unsigned int r )
+        { bytes_received = r; }
 };
 
 
 };
 
 
index e30065d..e1c3bc8 100644 (file)
@@ -1,11 +1,11 @@
-/*
- * PROJECT:         ReactOS Sound Record Application
+/* PROJECT:         ReactOS sndrec32
  * LICENSE:         GPL - See COPYING in the top level directory
  * FILE:            base/applications/sndrec32/audio_resampler_acm.cpp
  * LICENSE:         GPL - See COPYING in the top level directory
  * FILE:            base/applications/sndrec32/audio_resampler_acm.cpp
- * PURPOSE:         Audio Resampler
- * PROGRAMMERS:     Marco Pagliaricci <ms_blue (at) hotmail (dot) it>
+ * PURPOSE:         Sound recording
+ * PROGRAMMERS:     Marco Pagliaricci (irc: rendar)
  */
 
  */
 
+
 #include "stdafx.h"
 #include "audio_resampler_acm.hpp"
 #include <stdio.h>
 #include "stdafx.h"
 #include "audio_resampler_acm.hpp"
 #include <stdio.h>
@@ -26,53 +26,53 @@ audio_resampler_acm::init_( void )
 
 
 
 
 
 
-       //
-       // Zeroing structures
-       //
-
-       ZeroMemory( &acm_header, sizeof( ACMSTREAMHEADER ));
-       ZeroMemory( &wformat_src, sizeof( WAVEFORMATEX ));
-       ZeroMemory( &wformat_dst, sizeof( WAVEFORMATEX ));
-
+    //
+    // Zeroing structures
+    //
 
 
+    ZeroMemory( &acm_header, sizeof( ACMSTREAMHEADER ));
+    ZeroMemory( &wformat_src, sizeof( WAVEFORMATEX ));
+    ZeroMemory( &wformat_dst, sizeof( WAVEFORMATEX ));
 
 
 
 
-       //
-       // Setting structures sizes
-       //
+    
+    
+    //
+    // Setting structures sizes
+    //
 
 
-       acm_header.cbStruct = sizeof( ACMSTREAMHEADER );
-       wformat_src.cbSize = sizeof( WAVEFORMATEX );
-       wformat_dst.cbSize = sizeof( WAVEFORMATEX );
+    acm_header.cbStruct = sizeof( ACMSTREAMHEADER );
+    wformat_src.cbSize = sizeof( WAVEFORMATEX );
+    wformat_dst.cbSize = sizeof( WAVEFORMATEX );
 
 
 
 
 
 
 
 
-       //
-       // Setting WAVEFORMATEX structure parameters
-       // according to `audio_format' in/out classes
-       //
+    //
+    // Setting WAVEFORMATEX structure parameters
+    // according to `audio_format' in/out classes
+    //
 
 
-       wformat_src.wFormatTag = WAVE_FORMAT_PCM;
-       wformat_src.nSamplesPerSec = audfmt_in.sample_rate();
-       wformat_src.nChannels = audfmt_in.channels();
-       wformat_src.wBitsPerSample = audfmt_in.bits();
-       wformat_src.nAvgBytesPerSec =  audfmt_in.byte_rate();
-       wformat_src.nBlockAlign = audfmt_in.block_align();
+    wformat_src.wFormatTag = WAVE_FORMAT_PCM;
+    wformat_src.nSamplesPerSec = audfmt_in.sample_rate();
+    wformat_src.nChannels = audfmt_in.channels();
+    wformat_src.wBitsPerSample = audfmt_in.bits();
+    wformat_src.nAvgBytesPerSec =  audfmt_in.byte_rate();
+    wformat_src.nBlockAlign = audfmt_in.block_align();
 
 
 
 
-       wformat_dst.wFormatTag = WAVE_FORMAT_PCM;
-       wformat_dst.nSamplesPerSec = audfmt_out.sample_rate();
-       wformat_dst.nChannels = audfmt_out.channels();
-       wformat_dst.wBitsPerSample = audfmt_out.bits();
-       wformat_dst.nAvgBytesPerSec =  audfmt_out.byte_rate();
-       wformat_dst.nBlockAlign = audfmt_out.block_align();
+    wformat_dst.wFormatTag = WAVE_FORMAT_PCM;
+    wformat_dst.nSamplesPerSec = audfmt_out.sample_rate();
+    wformat_dst.nChannels = audfmt_out.channels();
+    wformat_dst.wBitsPerSample = audfmt_out.bits();
+    wformat_dst.nAvgBytesPerSec =  audfmt_out.byte_rate();
+    wformat_dst.nBlockAlign = audfmt_out.block_align();
 
 
 
 
 
 
-       //
-       // Init acm structures completed successfull
-       //
+    //
+    // Init acm structures completed successfull
+    //
 }
 
 
 }
 
 
@@ -97,68 +97,68 @@ audio_resampler_acm::open( void )
 {
 
 
 {
 
 
-       MMRESULT err;
-
-
-       //
-       // Opens ACM stream
-       //
+    MMRESULT err;
 
 
-       err = acmStreamOpen( &acm_stream, 0, &wformat_src, &wformat_dst,
-                                       0, 0, 0, ACM_STREAMOPENF_NONREALTIME );
 
 
+    //
+    // Opens ACM stream
+    //
 
 
-       if ( err != MMSYSERR_NOERROR )
-       {
-               //TODO: throw error
-               MessageBox( 0, _T("acmOpen error: %i"), _T("ERROR"), MB_ICONERROR );
+    err = acmStreamOpen( &acm_stream, 0, &wformat_src, &wformat_dst, 
+                    0, 0, 0, ACM_STREAMOPENF_NONREALTIME );
 
 
-       }
 
 
+    if ( err != MMSYSERR_NOERROR )
+    {
+        //TODO: throw error
+        MessageBox( 0, _T("acmOpen error: %i"), _T("ERROR"), MB_ICONERROR );
 
 
+    }
 
 
-       //
-       // Calcs source buffer lenght
-       //
 
 
-       src_buflen = ( unsigned int )
-               (( float )audfmt_in.byte_rate() * ( float )buf_secs );
 
 
+    //
+    // Calcs source buffer lenght
+    //
 
 
+    src_buflen = ( unsigned int )
+        (( float )audfmt_in.byte_rate() * ( float )buf_secs );
 
 
 
 
+    
+    
+    
+    
+    //
+    // Calcs destination source buffer lenght
+    // with help of ACM apis
+    //
 
 
+    err = acmStreamSize( acm_stream, 
+        src_buflen, &dst_buflen, ACM_STREAMSIZEF_SOURCE );
+    
 
 
-       //
-       // Calcs destination source buffer lenght
-       // with help of ACM apis
-       //
+    if ( err != MMSYSERR_NOERROR )
+    {
+        //TODO: throw error
+        MessageBox( 0, _T("acmStreamSize error"), _T("ERROR"), MB_ICONERROR );
 
 
-       err = acmStreamSize( acm_stream,
-               src_buflen, &dst_buflen, ACM_STREAMSIZEF_SOURCE );
 
 
+    }
 
 
-       if ( err != MMSYSERR_NOERROR )
-       {
-               //TODO: throw error
-               MessageBox( 0, _T("acmStreamSize error"), _T("ERROR"), MB_ICONERROR );
 
 
 
 
-       }
+    //
+    // Initialize ACMSTREAMHEADER structure,
+    // and alloc memory for source and destination
+    // buffers.
+    //
 
 
+    acm_header.fdwStatus = 0;
+    acm_header.dwUser = 0;
 
 
-
-       //
-       // Initialize ACMSTREAMHEADER structure,
-       // and alloc memory for source and destination
-       // buffers.
-       //
-
-       acm_header.fdwStatus = 0;
-       acm_header.dwUser = 0;
-
-
-       acm_header.pbSrc = ( LPBYTE ) new BYTE [ src_buflen ];
+    
+    acm_header.pbSrc = ( LPBYTE ) new BYTE [ src_buflen ];
     acm_header.cbSrcLength = src_buflen;
     acm_header.cbSrcLengthUsed = 0;
     acm_header.dwSrcUser = src_buflen;
     acm_header.cbSrcLength = src_buflen;
     acm_header.cbSrcLengthUsed = 0;
     acm_header.dwSrcUser = src_buflen;
@@ -172,29 +172,29 @@ audio_resampler_acm::open( void )
 
 
 
 
 
 
-       //
-       // Give ACMSTREAMHEADER initialized correctly to the
-       // driver.
-       //
+    //
+    // Give ACMSTREAMHEADER initialized correctly to the
+    // driver.
+    //
 
 
-       err = acmStreamPrepareHeader( acm_stream, &acm_header, 0L );
+    err = acmStreamPrepareHeader( acm_stream, &acm_header, 0L );
 
 
-       if ( err != MMSYSERR_NOERROR )
-       {
-               //TODO: throw error
-               MessageBox( 0, _T("acmStreamPrepareHeader error"), _T("ERROR"), MB_ICONERROR );
+    if ( err != MMSYSERR_NOERROR )
+    {
+        //TODO: throw error
+        MessageBox( 0, _T("acmStreamPrepareHeader error"), _T("ERROR"), MB_ICONERROR );
 
 
 
 
-       }
+    }
 
 
 
 
 
 
 
 
-       //
-       // ACM stream successfully opened.
-       //
+    //
+    // ACM stream successfully opened.
+    //
 
 
-       stream_opened = true;
+    stream_opened = true;
 
 }
 
 
 }
 
@@ -206,131 +206,131 @@ audio_resampler_acm::close( void )
 {
 
 
 {
 
 
-       MMRESULT err;
+    MMRESULT err;
 
 
 
 
-       if ( acm_stream )
-       {
+    if ( acm_stream )
+    {
 
 
-               if ( acm_header.fdwStatus & ACMSTREAMHEADER_STATUSF_PREPARED )
-               {
+        if ( acm_header.fdwStatus & ACMSTREAMHEADER_STATUSF_PREPARED )
+        {
 
 
-                       acm_header.cbSrcLength = src_buflen;
+            acm_header.cbSrcLength = src_buflen;
             acm_header.cbDstLength = dst_buflen;
 
             err = acmStreamUnprepareHeader( acm_stream, &acm_header, 0L );
 
             acm_header.cbDstLength = dst_buflen;
 
             err = acmStreamUnprepareHeader( acm_stream, &acm_header, 0L );
 
+        
+            if ( err != MMSYSERR_NOERROR )
+            {
+            
+                //
+                // Free buffer memory
+                //
 
 
-                       if ( err != MMSYSERR_NOERROR )
-                       {
-
-                               //
-                               // Free buffer memory
-                               //
+                if ( acm_header.pbSrc != 0 )
+                    delete[] acm_header.pbSrc;
 
 
-                               if ( acm_header.pbSrc != 0 )
-                                       delete[] acm_header.pbSrc;
+                if ( acm_header.pbDst != 0 )
+                    delete[] acm_header.pbDst;
 
 
-                               if ( acm_header.pbDst != 0 )
-                                       delete[] acm_header.pbDst;
 
 
+                //
+                // Re-init structures
+                //
 
 
-                               //
-                               // Re-init structures
-                               //
+                init_();
 
 
-                               init_();
+                //
+                // Updating status
+                //
 
 
-                               //
-                               // Updating status
-                               //
+                stream_opened = false;
 
 
-                               stream_opened = false;
 
 
+                //TODO: throw error
+                MessageBox( 0, _T("acmStreamUnPrepareHeader error"), _T("ERROR"), MB_ICONERROR );
 
 
-                               //TODO: throw error
-                               MessageBox( 0, _T("acmStreamUnPrepareHeader error"), _T("ERROR"), MB_ICONERROR );
+            
+            }
+        }
 
 
 
 
-                       }
-               }
-
-
-               err = acmStreamClose( acm_stream, 0 );
+        err = acmStreamClose( acm_stream, 0 );
         acm_stream = 0;
 
         acm_stream = 0;
 
-               if ( err != MMSYSERR_NOERROR )
-               {
+        if ( err != MMSYSERR_NOERROR )
+        {
 
 
-                       //
-                       // Free buffer memory
-                       //
+            //
+            // Free buffer memory
+            //
 
 
-                       if ( acm_header.pbSrc != 0 )
-                               delete[] acm_header.pbSrc;
+            if ( acm_header.pbSrc != 0 )
+                delete[] acm_header.pbSrc;
 
 
-                       if ( acm_header.pbDst != 0 )
-                               delete[] acm_header.pbDst;
+            if ( acm_header.pbDst != 0 )
+                delete[] acm_header.pbDst;
 
 
 
 
-                       //
-                       // Re-init structures
-                       //
+            //
+            // Re-init structures
+            //
 
 
-                       init_();
+            init_();
 
 
 
 
-                       //
-                       // Updating status
-                       //
+            //
+            // Updating status
+            //
 
 
-                       stream_opened = false;
+            stream_opened = false;
 
 
 
 
-                       //TODO: throw error!
+            //TODO: throw error!
 
 
-                       MessageBox( 0, _T("acmStreamClose error"), _T("ERROR"), MB_ICONERROR );
+            MessageBox( 0, _T("acmStreamClose error"), _T("ERROR"), MB_ICONERROR );
 
 
 
 
-               }
+        }
 
 
 
 
-       }//if acm_stream != 0
+    }//if acm_stream != 0
 
 
 
 
 
 
 
 
 
 
 
 
-       //
-       // Free buffer memory
-       //
+    //
+    // Free buffer memory
+    //
 
 
-       if ( acm_header.pbSrc != 0 )
-               delete[] acm_header.pbSrc;
+    if ( acm_header.pbSrc != 0 )
+        delete[] acm_header.pbSrc;
 
 
-       if ( acm_header.pbDst != 0 )
-               delete[] acm_header.pbDst;
+    if ( acm_header.pbDst != 0 )
+        delete[] acm_header.pbDst;
 
 
 
 
-       //
-       // Re-init structures
-       //
+    //
+    // Re-init structures
+    //
 
 
-       init_();
+    init_();
 
 
 
 
-       //
-       // Updating status
-       //
+    //
+    // Updating status
+    //
 
 
-       stream_opened = false;
+    stream_opened = false;
 
 
 
 
 
 
-       //
-       // ACM sream successfully closed.
-       //
+    //
+    // ACM sream successfully closed.
+    //
 
 
 }
 
 
 }
@@ -338,63 +338,70 @@ audio_resampler_acm::close( void )
 
 
 
 
 
 
-void
+void 
 audio_resampler_acm::audio_receive( unsigned char * data, unsigned int size )
 {
 
 audio_resampler_acm::audio_receive( unsigned char * data, unsigned int size )
 {
 
-       MMRESULT err;
+    MMRESULT err;
 
 
-       //
-       // Checking for acm stream opened
-       //
+    //
+    // Checking for acm stream opened
+    //
 
 
-       if ( stream_opened )
-       {
+    if ( stream_opened )
+    {
 
 
+        
+        //
+        // Copy audio data from extern to
+        // internal source buffer
+        //
 
 
-               //
-               // Copy audio data from extern to
-               // internal source buffer
-               //
+        memcpy( acm_header.pbSrc, data, size );
 
 
-               memcpy( acm_header.pbSrc, data, size );
 
 
+        acm_header.cbSrcLength = size;
+        acm_header.cbDstLengthUsed = 0;
 
 
-               acm_header.cbSrcLength = size;
-               acm_header.cbDstLengthUsed = 0;
+        err = acmStreamConvert( acm_stream, &acm_header, ACM_STREAMCONVERTF_BLOCKALIGN );
 
 
-               err = acmStreamConvert( acm_stream, &acm_header, ACM_STREAMCONVERTF_BLOCKALIGN );
+        if ( err != MMSYSERR_NOERROR )
+        {
+            //TODO: throw error
+            MessageBox( 0, _T("acmStreamConvert error"), _T("ERROR"), MB_ICONERROR );
 
 
-               if ( err != MMSYSERR_NOERROR )
-               {
-                       //TODO: throw error
-                       MessageBox( 0, _T("acmStreamConvert error"), _T("ERROR"), MB_ICONERROR );
 
 
+        }
 
 
-               }
 
 
+        //
+        // Wait for sound conversion
+        //
 
 
-               //
-               // Wait for sound conversion
-               //
+        while(( ACMSTREAMHEADER_STATUSF_DONE & acm_header.fdwStatus ) == 0 );
+    
 
 
-               while(( ACMSTREAMHEADER_STATUSF_DONE & acm_header.fdwStatus ) == 0 );
+        
 
 
 
 
-               //printf("Processed successfully %i bytes of audio.\n", acm_header.cbDstLengthUsed );
+        //
+        // Copy resampled audio, to destination buffer.
+        //
+
+        //memcpy( pbOutputData, acm_header.pbDst, acm_header.cbDstLengthUsed );
+
+
+    }
+
+}
+
 
 
 
 
 
 
-               //
-               // Copy resampled audio, to destination buffer.
-               //
 
 
-               //memcpy( pbOutputData, acm_header.pbDst, acm_header.cbDstLengthUsed );
 
 
 
 
-       }
 
 
-}
 
 
 _AUDIO_NAMESPACE_END_
 
 
 _AUDIO_NAMESPACE_END_
index 6cd6536..0f95736 100644 (file)
@@ -1,3 +1,11 @@
+/* PROJECT:         ReactOS sndrec32
+ * LICENSE:         GPL - See COPYING in the top level directory
+ * FILE:            base/applications/sndrec32/audio_resampler_acm.hpp
+ * PURPOSE:         Windows ACM wrapper
+ * PROGRAMMERS:     Marco Pagliaricci (irc: rendar)
+ */
+
+
 #ifndef _AUDIORESAMPLERACM__H_
 #define _AUDIORESAMPLERACM__H_
 
 #ifndef _AUDIORESAMPLERACM__H_
 #define _AUDIORESAMPLERACM__H_
 
@@ -18,73 +26,73 @@ _AUDIO_NAMESPACE_START_
 class audio_resampler_acm : public audio_receiver
 {
 
 class audio_resampler_acm : public audio_receiver
 {
 
-       private:
-               void init_( void );
-
-
-       protected:
-
-
-               HACMSTREAM acm_stream;
-               ACMSTREAMHEADER acm_header;
-               DWORD src_buflen;
-               DWORD dst_buflen;
-               bool stream_opened;
-
-               audio_format audfmt_in;
-               audio_format audfmt_out;
+    private:
+        void init_( void );
 
 
-               float buf_secs;
 
 
-               WAVEFORMATEX wformat_src;
-               WAVEFORMATEX wformat_dst;
+    protected:
 
 
 
 
+        HACMSTREAM acm_stream;
+        ACMSTREAMHEADER acm_header;
+        DWORD src_buflen;
+        DWORD dst_buflen;
+        bool stream_opened;
 
 
+        audio_format audfmt_in;
+        audio_format audfmt_out;
 
 
-       public:
+        float buf_secs;
 
 
+        WAVEFORMATEX wformat_src;
+        WAVEFORMATEX wformat_dst;
 
 
-               //
-               // Ctors
-               //
 
 
-               audio_resampler_acm( audio_format fmt_in, audio_format fmt_out )
-                       : acm_stream( 0 ), src_buflen( 0 ), dst_buflen( 0 ),
-                       stream_opened( false ), audfmt_in( fmt_in ), audfmt_out( fmt_out ),
-                       buf_secs( _AUDIO_DEFAULT_BUFSECS )
 
 
-               {
 
 
+    public:
 
 
-                       init_();
 
 
+        //
+        // Ctors
+        //
 
 
-               }
+        audio_resampler_acm( audio_format fmt_in, audio_format fmt_out )
+            : acm_stream( 0 ), src_buflen( 0 ), dst_buflen( 0 ),
+            stream_opened( false ), audfmt_in( fmt_in ), audfmt_out( fmt_out ),
+            buf_secs( _AUDIO_DEFAULT_BUFSECS )
 
 
+        {   
+        
 
 
+            init_();
+        
+        
+        }
 
 
 
 
 
 
-               //
-               // Dtor
-               //
+        
+        
+        //
+        // Dtor
+        //
 
 
-               ~audio_resampler_acm( void )
-               {   }
+        ~audio_resampler_acm( void )
+        {   }
 
 
 
 
 
 
-               //
-               // Public functions
-               //
+        //
+        // Public functions
+        //
 
 
-               void open( void );
-               void close( void );
+        void open( void );
+        void close( void );
 
 
 
 
 
 
-               void audio_receive( unsigned char *, unsigned int );
+        void audio_receive( unsigned char *, unsigned int );
 
 
 
 
 
 
index 4ce04f7..bb64191 100644 (file)
@@ -1,11 +1,12 @@
-/*
- * PROJECT:         ReactOS Sound Record Application
+/* PROJECT:         ReactOS sndrec32
  * LICENSE:         GPL - See COPYING in the top level directory
  * FILE:            base/applications/sndrec32/audio_wavein.cpp
  * LICENSE:         GPL - See COPYING in the top level directory
  * FILE:            base/applications/sndrec32/audio_wavein.cpp
- * PURPOSE:         Audio WaveIn
- * PROGRAMMERS:     Marco Pagliaricci <ms_blue (at) hotmail (dot) it>
+ * PURPOSE:         Sound recording
+ * PROGRAMMERS:     Marco Pagliaricci (irc: rendar)
  */
 
  */
 
+
+
 #include "stdafx.h"
 #include "audio_wavein.hpp"
 
 #include "stdafx.h"
 #include "audio_wavein.hpp"
 
@@ -17,19 +18,21 @@ _AUDIO_NAMESPACE_START_
 void
 audio_wavein::init_( void )
 {
 void
 audio_wavein::init_( void )
 {
-       ZeroMemory(( LPVOID ) &wave_format,
-                                       sizeof( WAVEFORMATEX ));
+    ZeroMemory(( LPVOID ) &wave_format, 
+                    sizeof( WAVEFORMATEX ));
+
+    wave_format.cbSize = sizeof( WAVEFORMATEX );
 
 
-       wave_format.cbSize = sizeof( WAVEFORMATEX );
+    wavein_handle = 0;
+    recthread_id = 0;
+    wakeup_recthread = 0;
 
 
-       wavein_handle = 0;
-       recthread_id = 0;
-       wakeup_recthread = 0;
+    data_flushed_event = 0;
 
 
-       buf_secs = _AUDIO_DEFAULT_WAVEINBUFSECS;
+    buf_secs = _AUDIO_DEFAULT_WAVEINBUFSECS;
 
 
 
 
-       status = WAVEIN_NOTREADY;
+    status = WAVEIN_NOTREADY;
 }
 
 
 }
 
 
@@ -38,321 +41,321 @@ audio_wavein::alloc_buffers_mem_( unsigned int buffs, float secs )
 {
 
 
 {
 
 
-       unsigned int
-               onebuf_size = 0, tot_size = 0;
-
-
-       //
-       // Release old memory
-       //
+    unsigned int 
+        onebuf_size = 0, tot_size = 0;
 
 
-       if ( main_buffer )
-               delete[] main_buffer;
 
 
+    //
+    // Release old memory
+    //
 
 
-       if ( wave_headers )
-               delete[] wave_headers;
+    if ( main_buffer )
+        delete[] main_buffer;
 
 
 
 
+    if ( wave_headers )
+        delete[] wave_headers;
 
 
-       //
-       // Calcs size of the buffers
-       //
 
 
-       onebuf_size = ( unsigned int )
-               (( float )aud_info.byte_rate() * secs );
 
 
+    //
+    // Calcs size of the buffers
+    //
 
 
-       tot_size = onebuf_size * buffs;
+    onebuf_size = ( unsigned int )
+        (( float )aud_info.byte_rate() * secs ); 
 
 
 
 
+    tot_size = onebuf_size * buffs;
 
 
+    
+    
+    
+    //
+    // Allocs memory for the audio buffers
+    //
 
 
-       //
-       // Allocs memory for the audio buffers
-       //
+    main_buffer = new BYTE [ tot_size ];
 
 
-       main_buffer = new BYTE [ tot_size ];
 
 
 
 
+    //
+    // Allocs memory for the `WAVEHDR' structures.
+    //
 
 
-       //
-       // Allocs memory for the `WAVEHDR' structures.
-       //
+    wave_headers = ( WAVEHDR * ) 
+        new BYTE [ sizeof( WAVEHDR ) * buffs ];
 
 
-       wave_headers = ( WAVEHDR * )
-               new BYTE [ sizeof( WAVEHDR ) * buffs ];
 
 
 
 
+    //
+    // Zeros memory.
+    //
 
 
-       //
-       // Zeros memory.
-       //
+    ZeroMemory( main_buffer, tot_size );
 
 
-       ZeroMemory( main_buffer, tot_size );
+    ZeroMemory( wave_headers, 
+        sizeof( WAVEHDR ) * buffs );
 
 
-       ZeroMemory( wave_headers,
-               sizeof( WAVEHDR ) * buffs );
 
 
+    //
+    // Updates total size of the buffers.
+    //
 
 
-       //
-       // Updates total size of the buffers.
-       //
-
-       mb_size = tot_size;
+    mb_size = tot_size;
 
 }
 
 
 
 }
 
 
-void
+void 
 audio_wavein::free_buffers_mem_( void )
 {
 
 
 audio_wavein::free_buffers_mem_( void )
 {
 
 
-       //
-       // Frees memory
-       //
+    //
+    // Frees memory
+    //
 
 
-       if ( main_buffer )
-               delete[] main_buffer;
+    if ( main_buffer )
+        delete[] main_buffer;
 
 
 
 
-       if ( wave_headers )
-               delete[] wave_headers;
+    if ( wave_headers )
+        delete[] wave_headers;
 
 
 
 
-       main_buffer = 0;
-       wave_headers = 0;
+    main_buffer = 0;
+    wave_headers = 0;
 
 }
 
 
 
 }
 
 
-void
+void 
 audio_wavein::init_headers_( void )
 {
 
 
 
 audio_wavein::init_headers_( void )
 {
 
 
 
-       //
-       // If there is no memory for memory or
-       // headers, simply return.
-       //
+    //
+    // If there is no memory for memory or
+    // headers, simply return.
+    //
 
 
-       if (( !wave_headers ) || ( !main_buffer ))
-               return;
+    if (( !wave_headers ) || ( !main_buffer ))
+        return;
 
 
 
 
-       //
-       // This is the size for one buffer
-       //
+    //
+    // This is the size for one buffer
+    //
 
 
-       DWORD buf_sz = mb_size / buffers;
+    DWORD buf_sz = mb_size / buffers;
 
 
 
 
 
 
-       //
-       // This is the base address for one buffer
-       //
+    //
+    // This is the base address for one buffer
+    //
+    
+    BYTE * buf_addr = main_buffer;
 
 
-       BYTE * buf_addr = main_buffer;
 
 
+    //
+    // Initializes headers.
+    //
 
 
-       //
-       // Initializes headers.
-       //
+    for ( unsigned int i = 0; i < buffers; ++i )
+    {
+        wave_headers[ i ].dwBufferLength = mb_size / buffers;
+        wave_headers[ i ].lpData = ( LPSTR ) buf_addr;
 
 
-       for ( unsigned int i = 0; i < buffers; ++i )
-       {
-               wave_headers[ i ].dwBufferLength = mb_size / buffers;
-               wave_headers[ i ].lpData = ( LPSTR ) buf_addr;
-
-               buf_addr += buf_sz;
-       }
+        buf_addr += buf_sz;
+    }
 
 }
 
 
 
 }
 
 
-void
+void 
 audio_wavein::prep_headers_( void )
 {
 audio_wavein::prep_headers_( void )
 {
-       MMRESULT err;
-       bool error = false;
+    MMRESULT err;
+    bool error = false;
 
 
 
 
-       //
-       // If there is no memory for memory or
-       // headers, throw error.
-       //
+    //
+    // If there is no memory for memory or
+    // headers, throw error.
+    //
 
 
-       if (( !wave_headers )
-               || ( !main_buffer ) || ( !wavein_handle ))
-       {} //TODO: throw error!
+    if (( !wave_headers ) 
+        || ( !main_buffer ) || ( !wavein_handle ))
+    {} //TODO: throw error!
 
 
 
 
 
 
-       for ( unsigned int i = 0; i < buffers; ++i )
-       {
-               err = waveInPrepareHeader( wavein_handle,
-                                       &wave_headers[ i ], sizeof( WAVEHDR ));
+    for ( unsigned int i = 0; i < buffers; ++i )
+    {
+        err = waveInPrepareHeader( wavein_handle, 
+                    &wave_headers[ i ], sizeof( WAVEHDR ));
 
 
 
 
-               if ( err != MMSYSERR_NOERROR )
-                       error = true;
+        if ( err != MMSYSERR_NOERROR )
+            error = true;
 
 
-       }
+    }
+    
 
 
-
-       if ( error )
-               MessageBox( 0, TEXT("waveInPrepareHeader Error."), 0, 0 );
+    if ( error )
+        MessageBox( 0, TEXT("waveInPrepareHeader Error."), 0, 0 );
 
 
 
 }
 
 
 
 
 }
 
-void
+void 
 audio_wavein::unprep_headers_( void )
 {
 audio_wavein::unprep_headers_( void )
 {
-       MMRESULT err;
-       bool error = false;
-
+    MMRESULT err;
+    bool error = false;
 
 
 
 
-       //
-       // If there is no memory for memory or
-       // headers, throw error.
-       //
 
 
-       if (( !wave_headers )
-               || ( !main_buffer ) || ( !wavein_handle ))
-       {} //TODO: throw error!
+    //
+    // If there is no memory for memory or
+    // headers, throw error.
+    //
 
 
+    if (( !wave_headers ) 
+        || ( !main_buffer ) || ( !wavein_handle ))
+    {} //TODO: throw error!
 
 
 
 
-       for ( unsigned int i = 0; i < buffers; ++i )
-       {
-               err = waveInUnprepareHeader( wavein_handle,
-                                       &wave_headers[ i ], sizeof( WAVEHDR ));
 
 
+    for ( unsigned int i = 0; i < buffers; ++i )
+    {
+        err = waveInUnprepareHeader( wavein_handle, 
+                    &wave_headers[ i ], sizeof( WAVEHDR ));
 
 
-               if ( err != MMSYSERR_NOERROR )
-                       error = true;
 
 
-       }
+        if ( err != MMSYSERR_NOERROR )
+            error = true;
 
 
+    }
+    
 
 
-       if ( error )
-               MessageBox( 0, TEXT("waveInUnPrepareHeader Error."), 0, 0 );
+    if ( error )
+        MessageBox( 0, TEXT("waveInUnPrepareHeader Error."), 0, 0 );
 
 }
 
 
 
 }
 
 
-void
+void 
 audio_wavein::add_buffers_to_driver_( void )
 {
 audio_wavein::add_buffers_to_driver_( void )
 {
-       MMRESULT err;
-       bool error = false;
-
+    MMRESULT err;
+    bool error = false;
 
 
 
 
-       //
-       // If there is no memory for memory or
-       // headers, throw error.
-       //
 
 
-       if (( !wave_headers )
-               || ( !main_buffer ) || ( !wavein_handle ))
-       {} //TODO: throw error!
+    //
+    // If there is no memory for memory or
+    // headers, throw error.
+    //
 
 
+    if (( !wave_headers ) 
+        || ( !main_buffer ) || ( !wavein_handle ))
+    {} //TODO: throw error!
 
 
 
 
 
 
-       for ( unsigned int i = 0; i < buffers; ++i )
-       {
-               err = waveInAddBuffer( wavein_handle,
-                               &wave_headers[ i ], sizeof( WAVEHDR ));
 
 
+    for ( unsigned int i = 0; i < buffers; ++i )
+    {
+        err = waveInAddBuffer( wavein_handle, 
+                &wave_headers[ i ], sizeof( WAVEHDR ));
 
 
-               if ( err != MMSYSERR_NOERROR )
-                       error = true;
 
 
-       }
+        if ( err != MMSYSERR_NOERROR )
+            error = true;
 
 
+    }
+    
 
 
-       if ( error )
-               MessageBox( 0, TEXT("waveInAddBuffer Error."), 0, 0 );
+    if ( error )
+        MessageBox( 0, TEXT("waveInAddBuffer Error."), 0, 0 );
 
 }
 
 
 
 void
 
 }
 
 
 
 void
-audio_wavein::close( void )
+audio_wavein::close( void ) 
 {
 
 
 
 
 {
 
 
 
 
-       //
-       // If wavein object is already in the status
-       // NOTREADY, nothing to do.
-       //
+    //
+    // If wavein object is already in the status
+    // NOTREADY, nothing to do. 
+    //
 
 
-       if ( status == WAVEIN_NOTREADY )
-               return;
+    if ( status == WAVEIN_NOTREADY )
+        return;
 
 
 
 
 
 
-       //
-       // If the wavein is recording,
-       // then stop recording and close it.
-       //
+    //
+    // If the wavein is recording,
+    // then stop recording and close it.
+    //
+    
+    if ( status == WAVEIN_RECORDING )
+        stop_recording();
 
 
-       if ( status == WAVEIN_RECORDING )
-               stop_recording();
 
 
+    //
+    // Updating status.
+    //
 
 
-       //
-       // Updating status.
-       //
+    status = WAVEIN_NOTREADY;
 
 
-       status = WAVEIN_NOTREADY;
 
 
 
 
 
 
+    //
+    // Wakeing up recording thread, so it
+    // can receive the `MM_WIM_CLOSE' message
+    // then dies.
+    //
+    if ( wakeup_recthread )
+        SetEvent( wakeup_recthread );
 
 
-       //
-       // Wakeing up recording thread, so it
-       // can receive the `MM_WIM_CLOSE' message
-       // then dies.
-       //
-       if ( wakeup_recthread )
-               SetEvent( wakeup_recthread );
 
 
 
 
+    //
+    // Closing wavein stream
+    //
 
 
-       //
-       // Closing wavein stream
-       //
+    while (( waveInClose( wavein_handle )) 
+                    != MMSYSERR_NOERROR ) Sleep( 1 );
 
 
-       while (( waveInClose( wavein_handle ))
-                                       != MMSYSERR_NOERROR ) Sleep( 1 );
 
 
 
 
+    //
+    // Release buffers memory.
+    //
 
 
-       //
-       // Release buffers memory.
-       //
+    free_buffers_mem_();
 
 
-       free_buffers_mem_();
 
 
+    //
+    // Re-initialize variables to the
+    // initial state.
+    //
 
 
-       //
-       // Re-initialize variables to the
-       // initial state.
-       //
-
-       init_();
-
+    init_();
+    
 }
 
 
 }
 
 
@@ -360,160 +363,160 @@ void
 audio_wavein::open( void )
 {
 
 audio_wavein::open( void )
 {
 
-       MMRESULT err;
-       HANDLE recthread_handle = 0;
-
+    MMRESULT err;
+    HANDLE recthread_handle = 0;
 
 
-       //
-       // Checkin the status of the object
-       //
 
 
-       if ( status != WAVEIN_NOTREADY )
-       {} //TODO: throw error
+    //
+    // Checkin the status of the object
+    //
 
 
+    if ( status != WAVEIN_NOTREADY )
+    {} //TODO: throw error
 
 
 
 
-       //
-       // Creating the EVENT object that will be signaled
-       // when the recording thread has to wake up.
-       //
 
 
-       wakeup_recthread =
-               CreateEvent( 0, FALSE, FALSE, 0 );
+    //
+    // Creating the EVENT object that will be signaled
+    // when the recording thread has to wake up.
+    //
 
 
+    wakeup_recthread = 
+        CreateEvent( 0, FALSE, FALSE, 0 );
 
 
-       data_flushed_event =
-               CreateEvent( 0, FALSE, FALSE, 0 );
 
 
+    data_flushed_event = 
+        CreateEvent( 0, FALSE, FALSE, 0 );
 
 
 
 
-       if (( !wakeup_recthread ) || ( !data_flushed_event ))
-       {
 
 
+    if (( !wakeup_recthread ) || ( !data_flushed_event ))
+    {
 
 
-               status = WAVEIN_ERR;
 
 
-               MessageBox( 0, TEXT("Thread Error."), 0, 0 );
+        status = WAVEIN_ERR;
 
 
-               //TODO: throw error
-       }
+        MessageBox( 0, TEXT("Thread Error."), 0, 0 );
 
 
+        //TODO: throw error
+    }
 
 
 
 
-       //
-       // Inialize buffers for recording audio
-       // data from the wavein audio line.
-       //
 
 
-       alloc_buffers_mem_( buffers, buf_secs );
-       init_headers_();
+    //
+    // Inialize buffers for recording audio 
+    // data from the wavein audio line.
+    //
 
 
+    alloc_buffers_mem_( buffers, buf_secs );
+    init_headers_();
 
 
 
 
 
 
 
 
 
 
-       //
-       // Sound format that will be captured by wavein
-       //
 
 
-       wave_format.wFormatTag = WAVE_FORMAT_PCM;
+    //
+    // Sound format that will be captured by wavein
+    //
 
 
-       wave_format.nChannels = aud_info.channels();
-       wave_format.nSamplesPerSec = aud_info.sample_rate();
-       wave_format.wBitsPerSample = aud_info.bits();
-       wave_format.nBlockAlign = aud_info.block_align();
-       wave_format.nAvgBytesPerSec = aud_info.byte_rate();
+    wave_format.wFormatTag = WAVE_FORMAT_PCM;
 
 
+    wave_format.nChannels = aud_info.channels();
+    wave_format.nSamplesPerSec = aud_info.sample_rate();
+    wave_format.wBitsPerSample = aud_info.bits();
+    wave_format.nBlockAlign = aud_info.block_align();
+    wave_format.nAvgBytesPerSec = aud_info.byte_rate();
 
 
 
 
-       //
-       // Creating the recording thread
-       //
 
 
-       recthread_handle =
-               CreateThread( NULL,
-                                         0,
-                                         audio_wavein::recording_procedure,
-                                         ( PVOID ) this,
-                                         0,
-                                         &recthread_id
-                       );
+    //
+    // Creating the recording thread
+    //
 
 
+    recthread_handle = 
+        CreateThread( NULL, 
+                      0, 
+                      audio_wavein::recording_procedure, 
+                      ( PVOID ) this, 
+                      0, 
+                      &recthread_id 
+            );
 
 
+    
 
 
-       //
-       // Checking thread handle
-       //
+    //
+    // Checking thread handle
+    //
 
 
-       if ( !recthread_handle )
-       {
+    if ( !recthread_handle )
+    {
 
 
-               //
-               // Updating status
-               //
+        //
+        // Updating status
+        //
 
 
-               status = WAVEIN_ERR;
+        status = WAVEIN_ERR;
 
 
-               MessageBox( 0, TEXT("Thread Error."), 0, 0 );
-               //TODO: throw error
+        MessageBox( 0, TEXT("Thread Error."), 0, 0 );
+        //TODO: throw error
 
 
-       }
+    }
 
 
 
 
-       //
-       // We don't need the thread handle anymore,
-       // so we can close it from now. (We'll just
-       // need the thread ID for the `waveInOpen' API)
-       //
+    //
+    // We don't need the thread handle anymore,
+    // so we can close it from now. (We'll just
+    // need the thread ID for the `waveInOpen' API)
+    //
 
 
-       CloseHandle( recthread_handle );
+    CloseHandle( recthread_handle );
 
 
 
 
 
 
-       //
-       // Opening audio line wavein
-       //
+    //
+    // Opening audio line wavein
+    //
 
 
-       err = waveInOpen( &wavein_handle,
-                                         0,
-                                         &wave_format,
-                                         recthread_id,
-                                         0,
-                                         CALLBACK_THREAD
-                       );
+    err = waveInOpen( &wavein_handle, 
+                      0, 
+                      &wave_format, 
+                      recthread_id, 
+                      0, 
+                      CALLBACK_THREAD 
+            );
 
 
 
 
-       if ( err != MMSYSERR_NOERROR )
-       {
+    if ( err != MMSYSERR_NOERROR ) 
+    {
 
 
 
 
-               //
-               // Updating status
-               //
+        //
+        // Updating status
+        //
 
 
-               status = WAVEIN_ERR;
+        status = WAVEIN_ERR;
 
 
-               if ( err == WAVERR_BADFORMAT )
-                       MessageBox( 0, TEXT("waveInOpen Error"), 0, 0 );
+        if ( err == WAVERR_BADFORMAT )
+            MessageBox( 0, TEXT("waveInOpen Error"), 0, 0 );
 
 
 
 
-               //TODO: throw error
-       }
+        //TODO: throw error
+    }
 
 
 
 
-       //
-       // Update object status
-       //
+    //
+    // Update object status
+    //
 
 
-       status = WAVEIN_READY;
+    status = WAVEIN_READY;
 
 
 
 
 
 
-       //
-       // Now `audio_wavein' object is ready
-       // for audio recording!
-       //
+    //
+    // Now `audio_wavein' object is ready
+    // for audio recording!
+    //
 }
 
 
 }
 
 
@@ -522,89 +525,89 @@ void
 audio_wavein::start_recording( void )
 {
 
 audio_wavein::start_recording( void )
 {
 
-       MMRESULT err;
-       BOOL ev;
-
-
+    MMRESULT err;
+    BOOL ev;
 
 
-       if (( status != WAVEIN_READY )
-                               && ( status != WAVEIN_STOP ))
-       {} //TODO: throw error
 
 
 
 
+    if (( status != WAVEIN_READY ) 
+                && ( status != WAVEIN_STOP ))
+    {} //TODO: throw error
 
 
 
 
-       //
-       // Updating to the recording status
-       //
 
 
-       status = WAVEIN_RECORDING;
 
 
+    //
+    // Updating to the recording status
+    //
 
 
+    status = WAVEIN_RECORDING;
 
 
 
 
-       //
-       // Let's prepare header of type WAVEHDR that
-       // we will pass to the driver with our
-       // audio informations, and buffer informations.
-       //
 
 
-       prep_headers_();
 
 
+    //
+    // Let's prepare header of type WAVEHDR that
+    // we will pass to the driver with our
+    // audio informations, and buffer informations.
+    //
+    
+    prep_headers_();
 
 
 
 
-       //
-       // The waveInAddBuffer function sends an input buffer
-       // to the given waveform-audio input device.
-       // When the buffer is filled, the application is notified.
-       //
 
 
-       add_buffers_to_driver_();
+    //
+    // The waveInAddBuffer function sends an input buffer 
+    // to the given waveform-audio input device. 
+    // When the buffer is filled, the application is notified.
+    //
 
 
+    add_buffers_to_driver_();
 
 
 
 
 
 
 
 
-       //
-       // Signaling event for waking up
-       // the recorder thread.
-       //
 
 
-       ev = SetEvent( wakeup_recthread );
+    //
+    // Signaling event for waking up
+    // the recorder thread.
+    //
+    
+    ev = SetEvent( wakeup_recthread );
 
 
 
 
-       if ( !ev )
-       {
+    if ( !ev ) 
+    {
 
 
 
 
-               MessageBox( 0, TEXT("Event Error."), 0, 0 );
+        MessageBox( 0, TEXT("Event Error."), 0, 0 );
 
 
-       }
+    }
+    
 
 
+    //
+    // Start recording
+    //
 
 
-       //
-       // Start recording
-       //
+    
+    err = waveInStart( wavein_handle );
 
 
 
 
-       err = waveInStart( wavein_handle );
+    if ( err != MMSYSERR_NOERROR )
+    {
 
 
+        //
+        // Updating status
+        //
 
 
-       if ( err != MMSYSERR_NOERROR )
-       {
+        status = WAVEIN_ERR;
 
 
-               //
-               // Updating status
-               //
+        MessageBox( 0, TEXT("waveInStart Error."), 0, 0 );
 
 
-               status = WAVEIN_ERR;
 
 
-               MessageBox( 0, TEXT("waveInStart Error."), 0, 0 );
+        //TODO: throw error
 
 
-
-               //TODO: throw error
-
-       }
+    }
 
 }
 
 
 }
 
@@ -613,263 +616,267 @@ audio_wavein::start_recording( void )
 void
 audio_wavein::stop_recording( void )
 {
 void
 audio_wavein::stop_recording( void )
 {
+        
 
 
-
-       MMRESULT err;
-       DWORD wait;
+    MMRESULT err;
+    DWORD wait;
 
 
 
 
-       if ( status != WAVEIN_RECORDING )
-               return;
+    if ( status != WAVEIN_RECORDING )
+        return;
 
 
 
 
+    
+    status = WAVEIN_FLUSHING;
 
 
-       status = WAVEIN_FLUSHING;
 
 
+    //
+    // waveInReset will make all pending buffer as done.
+    //
 
 
-       if ( data_flushed_event )
-               wait = WaitForSingleObject(
-                                               data_flushed_event, INFINITE
-                                       );
+    err = waveInReset( wavein_handle );
 
 
 
 
+    if ( err != MMSYSERR_NOERROR )
+    {
 
 
-       //
-       // waveInReset will make all pending buffer as done.
-       //
+        //TODO: throw error
 
 
-       err = waveInReset( wavein_handle );
+        MessageBox( 0, TEXT("waveInReset Error."), 0, 0 );
 
 
 
 
-       if ( err != MMSYSERR_NOERROR )
-       {
 
 
-               //TODO: throw error
+    }
 
 
-               MessageBox( 0, TEXT("waveInReset Error."), 0, 0 );
 
 
+    if ( data_flushed_event )
+        wait = WaitForSingleObject( 
+                        data_flushed_event, INFINITE 
+                    );
 
 
 
 
-       }
 
 
+    
 
 
 
 
-       //
-       // Stop recording.
-       //
+    
+    //
+    // Stop recording.
+    //
 
 
-       err = waveInStop( wavein_handle );
+    err = waveInStop( wavein_handle );
 
 
 
 
-       if ( err != MMSYSERR_NOERROR )
-       {
+    if ( err != MMSYSERR_NOERROR )
+    {
 
 
-               //TODO: throw error
+        //TODO: throw error
 
 
-               MessageBox( 0, TEXT("waveInStop Error."), 0, 0 );
+        MessageBox( 0, TEXT("waveInStop Error."), 0, 0 );
 
 
 
 
 
 
-       }
+    }
 
 
 
 
-       //
-       // The waveInUnprepareHeader function cleans up the
-       // preparation performed by the waveInPrepareHeader function.
-       //
+    //
+    // The waveInUnprepareHeader function cleans up the 
+    // preparation performed by the waveInPrepareHeader function. 
+    //
 
 
-       unprep_headers_();
+    unprep_headers_();
 
 
 
 
 
 
 
 
 
 
+    
 
 
 
 
 
 
 
 
 
 
-
-       status = WAVEIN_STOP;
+    status = WAVEIN_STOP;
 
 }
 
 
 
 
 }
 
 
 
-DWORD WINAPI
+DWORD WINAPI 
 audio_wavein::recording_procedure( LPVOID arg )
 {
 
 
 audio_wavein::recording_procedure( LPVOID arg )
 {
 
 
-       MSG msg;
-       WAVEHDR * phdr;
-       DWORD wait;
-       audio_wavein * _this = ( audio_wavein * ) arg;
-
-
-
-
-       //
-       // Check the arg pointer
-       //
-
-       if ( _this == 0 )
-               return 0;
-
-
-
-       //
-       // The thread can go to sleep for now.
-       // It will be wake up only when there is audio data
-       // to be recorded.
-       //
-
-       if ( _this->wakeup_recthread )
-               wait = WaitForSingleObject(
-                                               _this->wakeup_recthread, INFINITE
-                                       );
-
-
-
-
-
-
-       //
-       // If status of the `audio_wavein' object
-       // is not ready or recording the thread can exit.
-       //
-
-       if (( _this->status != WAVEIN_READY ) &&
-                               ( _this->status != WAVEIN_RECORDING ))
-               return 0;
+    MSG msg;
+    WAVEHDR * phdr;
+    DWORD wait;
+    audio_wavein * _this = ( audio_wavein * ) arg;
 
 
+    
 
 
 
 
+    //
+    // Check the arg pointer
+    //
 
 
+    if ( _this == 0 )
+        return 0;
 
 
+    
+    
+    //
+    // The thread can go to sleep for now.
+    // It will be wake up only when there is audio data
+    // to be recorded.
+    //
 
 
+    if ( _this->wakeup_recthread )
+        wait = WaitForSingleObject( 
+                        _this->wakeup_recthread, INFINITE 
+                    );
 
 
-       //
-       // Entering main polling loop
-       //
 
 
-       while ( GetMessage( &msg, 0, 0, 0 )) 
-       {
 
 
-               switch ( msg.message )
-               {
 
 
-                       case MM_WIM_DATA:
 
 
-                               phdr = ( WAVEHDR * ) msg.lParam;
+    
+    //
+    // If status of the `audio_wavein' object 
+    // is not ready or recording the thread can exit.
+    //
 
 
-                               if (( _this->status == WAVEIN_RECORDING )
-                                                       || ( _this->status == WAVEIN_FLUSHING ))
-                               {
+    if (( _this->status != WAVEIN_READY ) && 
+                ( _this->status != WAVEIN_RECORDING ))
+        return 0;
 
 
-                                       //
-                                       // Flushes recorded audio data to
-                                       // the `audio_receiver' object.
-                                       //
 
 
-                                       _this->audio_rcvd.audio_receive(
-                                                       ( unsigned char * )phdr->lpData,
-                                                       phdr->dwBytesRecorded
-                                               );
+    
 
 
 
 
-                                       //
-                                       // Updating `audio_receiver' total
-                                       // bytes received _AFTER_ calling
-                                       // `audio_receive' function.
-                                       //
 
 
-                                       _this->audio_rcvd.bytes_received +=
-                                                                       phdr->dwBytesRecorded;
 
 
+    //
+    // Entering main polling loop
+    //
 
 
+    while ( GetMessage( &msg, 0, 0, 0 ))       
+    {  
 
 
+        switch ( msg.message )
+        {
+                
+            case MM_WIM_DATA:
+            
+                phdr = ( WAVEHDR * ) msg.lParam;
 
 
-                                       //
-                                       // If status is not flushing data, then
-                                       // we can re-add the buffer for reusing it.
-                                       // Otherwise, if we are flushing pending data,
-                                       // we cannot re-add buffer because we don't need
-                                       // it anymore
-                                       //
+                if (( _this->status == WAVEIN_RECORDING ) 
+                            || ( _this->status == WAVEIN_FLUSHING ))
+                {
 
 
-                                       if ( _this->status != WAVEIN_FLUSHING )
-                                       {
 
 
-                                               //
-                                               // Let the audio driver reuse the buffer
-                                               //
+                    if ( phdr->dwFlags & WHDR_DONE )
+                    {
 
 
-                                               waveInAddBuffer( _this->wavein_handle,
-                                                                                       phdr, sizeof( WAVEHDR ));
+                        //
+                        // Flushes recorded audio data to 
+                        // the `audio_receiver' object.
+                        //
 
 
+                        _this->audio_rcvd.audio_receive(
+                                ( unsigned char * )phdr->lpData, 
+                                phdr->dwBytesRecorded 
+                            );
 
 
-                                       } else {
+                        
+                        //
+                        // Updating `audio_receiver' total
+                        // bytes received _AFTER_ calling
+                        // `audio_receive' function.
+                        //
 
 
-                                               //
-                                               // If we are flushing pending data, we have
-                                               // to prepare to stop recording.
-                                               // Set WAVEHDR flag to 0, and fires the event
-                                               // `data_flushed_event', that will wake up
-                                               // the main thread that is sleeping into
-                                               // wavein_in::stop_recording() member function,
-                                               // waiting the last `MM_WIM_DATA' message that
-                                               // contain pending data.
-                                               //
+                        _this->audio_rcvd.bytes_received += 
+                                        phdr->dwBytesRecorded;
+                    }
+    
 
 
+                            
+                    //
+                    // If status is not flushing data, then
+                    // we can re-add the buffer for reusing it.
+                    // Otherwise, if we are flushing pending data,
+                    // we cannot re-add buffer because we don't need
+                    // it anymore
+                    //
 
 
+                    if ( _this->status != WAVEIN_FLUSHING )
+                    {
 
 
+                        //
+                        // Let the audio driver reuse the buffer
+                        //
 
 
-                                               phdr->dwFlags = 0;
+                        waveInAddBuffer( _this->wavein_handle, 
+                                            phdr, sizeof( WAVEHDR ));
 
 
-                                               SetEvent( _this->data_flushed_event );
 
 
+                    } else {
 
 
-                                               //
-                                               // The recording is gooing to stop, so the
-                                               // recording thread can go to sleep!
-                                               //
+                        //
+                        // If we are flushing pending data, we have
+                        // to prepare to stop recording.
+                        // Set WAVEHDR flag to 0, and fires the event
+                        // `data_flushed_event', that will wake up
+                        // the main thread that is sleeping into
+                        // wavein_in::stop_recording() member function,
+                        // waiting the last `MM_WIM_DATA' message that
+                        // contain pending data.
+                        //
 
 
-                                               wait = WaitForSingleObject(
-                                                                       _this->wakeup_recthread, INFINITE );
+                        phdr->dwFlags = 0;
 
 
-                                       }
+                        SetEvent( _this->data_flushed_event );
 
 
 
 
-                               }//if WAVEIN_RECORDING || WAVEIN_FLUSHING
+                        //
+                        // The recording is gooing to stop, so the
+                        // recording thread can go to sleep!
+                        //
 
 
-                               break;
+                        wait = WaitForSingleObject( 
+                                    _this->wakeup_recthread, INFINITE );
+                            
+                    }
 
 
 
 
+                }//if WAVEIN_RECORDING || WAVEIN_FLUSHING
 
 
+                break;
 
 
 
 
+            
 
 
+                        
 
 
 
 
 
 
-                       case MM_WIM_CLOSE:
 
 
-                               //
-                               // The thread can exit now.
-                               //
+            case MM_WIM_CLOSE:
 
 
-                               return 0;
+                //
+                // The thread can exit now.
+                //
 
 
-                               break;
+                return 0;
 
 
+                break;
 
 
 
 
-               }  //end switch( msg.message )
 
 
-       }  //end while( GetMessage( ... ))
+        }  //end switch( msg.message )
+        
+    }  //end while( GetMessage( ... ))
 
 
-       return 0;
+    return 0;                          
 }
 
 
 }
 
 
index 878640a..0288ea6 100644 (file)
@@ -1,3 +1,11 @@
+/* PROJECT:         ReactOS sndrec32
+ * LICENSE:         GPL - See COPYING in the top level directory
+ * FILE:            base/applications/sndrec32/audio_wavein.hpp
+ * PURPOSE:         Windows MM wave in abstraction
+ * PROGRAMMERS:     Marco Pagliaricci (irc: rendar)
+ */
+
+
 #ifndef _AUDIOWAVEIN_H_
 #define _AUDIOWAVEIN_H_
 
 #ifndef _AUDIOWAVEIN_H_
 #define _AUDIOWAVEIN_H_
 
@@ -14,11 +22,11 @@ _AUDIO_NAMESPACE_START_
 
 
 
 
 
 
-enum audio_wavein_status { WAVEIN_NOTREADY, WAVEIN_READY,
-                                                  WAVEIN_RECORDING, WAVEIN_ERR,
-                                                  WAVEIN_STOP, WAVEIN_FLUSHING
-
-                                                 };
+enum audio_wavein_status { WAVEIN_NOTREADY, WAVEIN_READY, 
+                           WAVEIN_RECORDING, WAVEIN_ERR,
+                           WAVEIN_STOP, WAVEIN_FLUSHING
+                        
+                          };
 
 
 
 
 
 
@@ -26,30 +34,30 @@ enum audio_wavein_status { WAVEIN_NOTREADY, WAVEIN_READY,
 
 class audio_wavein
 {
 
 class audio_wavein
 {
-       private:
+    private:
 
 
 
 
 
 
-               //
-               // The new recording thread sends message to this procedure
-               // about open recording, close, and sound data recorded
-               //
+        //
+        // The new recording thread sends message to this procedure
+        // about open recording, close, and sound data recorded
+        //
 
 
-               static DWORD WINAPI recording_procedure( LPVOID );
+        static DWORD WINAPI recording_procedure( LPVOID );
 
 
-               //
-               // When this event is signaled, then the previsiously created
-               // recording thread will wake up and start recording audio
-               // and will pass audio data to an `audio_receiver' object.
-               //
+        //
+        // When this event is signaled, then the previsiously created
+        // recording thread will wake up and start recording audio
+        // and will pass audio data to an `audio_receiver' object.
+        //
 
 
-               HANDLE wakeup_recthread;
-               HANDLE data_flushed_event;
+        HANDLE wakeup_recthread;
+        HANDLE data_flushed_event;
 
 
 
 
 
 
 
 
-       protected:
+    protected:
 
 
 //TODO: puts these structs in private?!
 
 
 //TODO: puts these structs in private?!
@@ -57,207 +65,256 @@ class audio_wavein
 
 
 
 
 
 
-               //
-               // Audio wavein device stuff
-               //
+        //
+        // Audio wavein device stuff
+        //
+
+        WAVEFORMATEX   wave_format;
+        WAVEHDR        * wave_headers;
+        HWAVEIN        wavein_handle;
+
+
+
+    
+
+        audio_format aud_info;
+        
+        audio_receiver & audio_rcvd;
+
+
+        
+        //
+        // Audio Recorder Thread id
+        //
+
+        DWORD     recthread_id;
+
+
+        
+
+        //
+        // Object status
+        //
+
+        audio_wavein_status status;
+
 
 
-               WAVEFORMATEX   wave_format;
-               WAVEHDR        * wave_headers;
-               HWAVEIN        wavein_handle;
 
 
 
 
 
 
 
 
 
 
-               audio_format aud_info;
+        //
+        // How many seconds of audio
+        // can record the internal buffer
+        // before flushing audio data 
+        // to the `audio_receiver' class?
+        //
 
 
-               audio_receiver & audio_rcvd;
+        float buf_secs;
 
 
 
 
+        //
+        // The temporary buffers for the audio
+        // data incoming from the wavein device
+        // and its size, and its total number.
+        //
 
 
-               //
-               // Audio Recorder Thread id
-               //
+        BYTE * main_buffer;
+        unsigned int mb_size;
 
 
-               DWORD     recthread_id;
+        unsigned int buffers;
 
 
 
 
 
 
 
 
-               //
-               // Object status
-               //
 
 
-               audio_wavein_status status;
+        //
+        // Protected Functions
+        //
 
 
 
 
+        //initialize all structures and variables.
+        void init_( void );
 
 
+        void alloc_buffers_mem_( unsigned int, float );
+        void free_buffers_mem_( void );
 
 
+        void init_headers_( void );
+        void prep_headers_( void );
+        void unprep_headers_( void );
+        void add_buffers_to_driver_( void );
 
 
 
 
 
 
-               //
-               // How many seconds of audio
-               // can record the internal buffer
-               // before flushing audio data
-               // to the `audio_receiver' class?
-               //
 
 
-               float buf_secs;
 
 
 
 
-               //
-               // The temporary buffers for the audio
-               // data incoming from the wavein device
-               // and its size, and its total number.
-               //
 
 
-               BYTE * main_buffer;
-               unsigned int mb_size;
+    public:
 
 
-               unsigned int buffers;
 
 
+        //
+        // Ctors
+        //
 
 
+        audio_wavein(
+            const audio_format & a_info, audio_receiver & a_receiver )
 
 
+            : wave_headers( 0 ),
+            aud_info( a_info ), audio_rcvd( a_receiver ), 
+            status( WAVEIN_NOTREADY ), main_buffer( 0 ), mb_size( 0 ),
+            buffers( _AUDIO_DEFAULT_WAVEINBUFFERS )
+        {
 
 
+            //
+            // Initializing internal wavein data
+            //
+            
+            
+            init_();
 
 
-               //
-               // Protected Functions
-               //
+            aud_info = a_info;
+        }
 
 
 
 
-               //initialize all structures and variables.
-               void init_( void );
 
 
-               void alloc_buffers_mem_( unsigned int, float );
-               void free_buffers_mem_( void );
 
 
-               void init_headers_( void );
-               void prep_headers_( void );
-               void unprep_headers_( void );
-               void add_buffers_to_driver_( void );
 
 
 
 
 
 
+        //
+        // Dtor
+        //
 
 
+        ~audio_wavein( void )
+        {
+            
+            //close(); TODO!
 
 
+        }
 
 
 
 
-       public:
 
 
+        //
+        // Public functions
+        //
 
 
-               //
-               // Ctors
-               //
+        void open( void );
+        void close ( void );
 
 
-               audio_wavein(
-                       const audio_format & a_info, audio_receiver & a_receiver )
 
 
-                       : wave_headers( 0 ),
-                       aud_info( a_info ), audio_rcvd( a_receiver ),
-                       status( WAVEIN_NOTREADY ), main_buffer( 0 ), mb_size( 0 ),
-                       buffers( _AUDIO_DEFAULT_WAVEINBUFFERS )
-               {
+        void start_recording( void );
+        void stop_recording( void );
 
 
-                       //
-                       // Initializing internal wavein data
-                       //
 
 
 
 
-                       init_();
+        audio_wavein_status current_status ( void ) const
+        {
+            return status;
+        }
 
 
-                       aud_info = a_info;
-               }
+        float buffer_secs( void ) const
+        { return buf_secs; }
 
 
 
 
+        void buffer_secs( float bsecs )
+        { 
+            //
+            // Some checking
+            //
 
 
+            if ( bsecs <= 0 )
+                return;
 
 
 
 
+            //
+            // Set seconds lenght for each
+            // buffer.
+            //
 
 
+            buf_secs = bsecs; 
+        }
 
 
-               //
-               // Dtor
-               //
 
 
-               ~audio_wavein( void )
-               {
+        unsigned int total_buffers( void ) const
+        { return buffers; }
 
 
-                       //close(); TODO!
 
 
-               }
 
 
+        void total_buffers( unsigned int tot_bufs )
+        {
 
 
+            //
+            // Some checking
+            //
 
 
-               //
-               // Public functions
-               //
+            if ( tot_bufs == 0 )
+                return;
 
 
-               void open( void );
-               void close ( void );
+            
+            //
+            // Sets the number of total buffers.
+            //
 
 
+            buffers = tot_bufs;
+        }
 
 
-               void start_recording( void );
-               void stop_recording( void );
 
 
+        audio_format format( void ) const
+        { return aud_info; }
 
 
 
 
-               audio_wavein_status current_status ( void ) const
-               {
-                       return status;
-               }
 
 
-               float buffer_secs( void ) const
-               { return buf_secs; }
+        
+        BYTE * buf( void ) { return main_buffer; }
+        unsigned int bufsz( void ) { return mb_size; }
 
 
 
 
-               void buffer_secs( float bsecs )
-               {
-                       //
-                       // Some checking
-                       //
+        unsigned int samplevalue_max( void )
+        {
 
 
-                       if ( bsecs <= 0 )
-                               return;
+            if ( aud_info.bits() == 16 )
+                return (unsigned int )65535;
 
 
+            else if ( aud_info.bits() == 8 )
+                return (unsigned int)255;
 
 
-                       //
-                       // Set seconds lenght for each
-                       // buffer.
-                       //
+            else 
+                return 0;
+        }
 
 
-                       buf_secs = bsecs;
-               }
 
 
+        unsigned tot_samples_buf( void )
+        {
 
 
-               unsigned int total_buffers( void ) const
-               { return buffers; }
 
 
+            return aud_info.samples_in_bytes( mb_size );
 
 
 
 
-               void total_buffers( unsigned int tot_bufs )
-               {
+        }
 
 
-                       //
-                       // Some checking
-                       //
+        unsigned int nsample ( unsigned int nsamp )
+        {
 
 
-                       if ( tot_bufs == 0 )
-                               return;
 
 
+            unsigned int svalue;
 
 
-                       //
-                       // Sets the number of total buffers.
-                       //
 
 
-                       buffers = tot_bufs;
-               }
 
 
+            if ( aud_info.bits() == 16 )
+                svalue = ( unsigned int )  abs( *(( short * ) (main_buffer + aud_info.bytes_in_samples( nsamp ))));
+            else if ( aud_info.bits() == 8 )
+               svalue = (unsigned int)(( unsigned char * ) *(main_buffer + aud_info.bytes_in_samples( nsamp )));
 
 
-               audio_format format( void ) const
-               { return aud_info; }
+            else 
+                svalue = 0;
 
 
+            return svalue;
 
 
+        }
 
 
+    
 };
 
 
 };
 
 
index b8e877b..9850aa5 100644 (file)
@@ -1,11 +1,12 @@
-/*
- * PROJECT:         ReactOS Sound Record Application
+/* PROJECT:         ReactOS sndrec32
  * LICENSE:         GPL - See COPYING in the top level directory
  * FILE:            base/applications/sndrec32/audio_waveout.cpp
  * LICENSE:         GPL - See COPYING in the top level directory
  * FILE:            base/applications/sndrec32/audio_waveout.cpp
- * PURPOSE:         Audio WaveOut
- * PROGRAMMERS:     Marco Pagliaricci <ms_blue (at) hotmail (dot) it>
+ * PURPOSE:         Sound recording
+ * PROGRAMMERS:     Marco Pagliaricci (irc: rendar)
  */
 
  */
 
+
+
 #include "stdafx.h"
 #include "audio_waveout.hpp"
 
 #include "stdafx.h"
 #include "audio_waveout.hpp"
 
@@ -18,244 +19,244 @@ void
 audio_waveout::init_( void )
 {
 
 audio_waveout::init_( void )
 {
 
-       ZeroMemory(( LPVOID ) &wave_format,
-                                       sizeof( WAVEFORMATEX ));
+    ZeroMemory(( LPVOID ) &wave_format, 
+                    sizeof( WAVEFORMATEX ));
 
 
-       wave_format.cbSize = sizeof( WAVEFORMATEX );
+    wave_format.cbSize = sizeof( WAVEFORMATEX );
 
 
-       waveout_handle = 0;
+    waveout_handle = 0;
 
 
-       playthread_id = 0;
-       wakeup_playthread = 0;
+    playthread_id = 0;
+    wakeup_playthread = 0;
 
 
-       buf_secs = _AUDIO_DEFAULT_WAVEOUTBUFSECS;
+    buf_secs = _AUDIO_DEFAULT_WAVEOUTBUFSECS;
 
 
 
 
-       status = WAVEOUT_NOTREADY;
+    status = WAVEOUT_NOTREADY;
 
 }
 
 
 
 
 
 }
 
 
 
 
-void
+void 
 audio_waveout::alloc_buffers_mem_( unsigned int buffs, float secs )
 {
 
 
 audio_waveout::alloc_buffers_mem_( unsigned int buffs, float secs )
 {
 
 
-       unsigned int
-               onebuf_size = 0, tot_size = 0;
-
+    unsigned int 
+        onebuf_size = 0, tot_size = 0;
 
 
-       //
-       // Release old memory
-       //
 
 
-       if ( main_buffer )
-               delete[] main_buffer;
+    //
+    // Release old memory
+    //
 
 
+    if ( main_buffer )
+        delete[] main_buffer;
 
 
-       if ( wave_headers )
-               delete[] wave_headers;
 
 
+    if ( wave_headers )
+        delete[] wave_headers;
 
 
 
 
-       //
-       // Calcs size of the buffers
-       //
 
 
-       onebuf_size = ( unsigned int )
-               (( float )aud_info.byte_rate() * secs );
+    //
+    // Calcs size of the buffers
+    //
 
 
+    onebuf_size = ( unsigned int )
+        (( float )aud_info.byte_rate() * secs ); 
 
 
-       tot_size = onebuf_size * buffs;
 
 
+    tot_size = onebuf_size * buffs;
 
 
+    
+    
+    
+    //
+    // Allocs memory for the audio buffers
+    //
 
 
+    main_buffer = new BYTE [ tot_size ];
 
 
-       //
-       // Allocs memory for the audio buffers
-       //
 
 
-       main_buffer = new BYTE [ tot_size ];
 
 
+    //
+    // Allocs memory for the `WAVEHDR' structures.
+    //
 
 
+    wave_headers = ( WAVEHDR * ) 
+        new BYTE [ sizeof( WAVEHDR ) * buffs ];
 
 
-       //
-       // Allocs memory for the `WAVEHDR' structures.
-       //
 
 
-       wave_headers = ( WAVEHDR * )
-               new BYTE [ sizeof( WAVEHDR ) * buffs ];
 
 
+    //
+    // Zeros memory.
+    //
 
 
+    ZeroMemory( main_buffer, tot_size );
 
 
-       //
-       // Zeros memory.
-       //
+    ZeroMemory( wave_headers, 
+        sizeof( WAVEHDR ) * buffs );
 
 
-       ZeroMemory( main_buffer, tot_size );
 
 
-       ZeroMemory( wave_headers,
-               sizeof( WAVEHDR ) * buffs );
+    //
+    // Updates total size of the buffers.
+    //
 
 
-
-       //
-       // Updates total size of the buffers.
-       //
-
-       mb_size = tot_size;
+    mb_size = tot_size;
 }
 
 
 }
 
 
-void
+void 
 audio_waveout::init_headers_( void )
 {
 
 
 
 audio_waveout::init_headers_( void )
 {
 
 
 
-       //
-       // If there is no memory for memory or
-       // headers, simply return.
-       //
+    //
+    // If there is no memory for memory or
+    // headers, simply return.
+    //
 
 
-       if (( !wave_headers ) || ( !main_buffer ))
-               return;
+    if (( !wave_headers ) || ( !main_buffer ))
+        return;
 
 
 
 
-       //
-       // This is the size for one buffer
-       //
+    //
+    // This is the size for one buffer
+    //
 
 
-       DWORD buf_sz = mb_size / buffers;
+    DWORD buf_sz = mb_size / buffers;
 
 
 
 
 
 
-       //
-       // This is the base address for one buffer
-       //
+    //
+    // This is the base address for one buffer
+    //
+    
+    BYTE * buf_addr = main_buffer;
 
 
-       BYTE * buf_addr = main_buffer;
 
 
 
 
+    ZeroMemory( wave_headers, sizeof( WAVEHDR ) * buffers );
 
 
-       ZeroMemory( wave_headers, sizeof( WAVEHDR ) * buffers );
 
 
+    //
+    // Initializes headers.
+    //
 
 
-       //
-       // Initializes headers.
-       //
+    for ( unsigned int i = 0; i < buffers; ++i )
+    {
+        
+        //
+        // Sets the correct base address and 
+        // lenght for the little buffer.
+        //
 
 
-       for ( unsigned int i = 0; i < buffers; ++i )
-       {
+        wave_headers[ i ].dwBufferLength = mb_size / buffers;
+        wave_headers[ i ].lpData = ( LPSTR ) buf_addr;
 
 
-               //
-               // Sets the correct base address and
-               // lenght for the little buffer.
-               //
+        //
+        // Unsets the WHDR_DONE flag.
+        //
 
 
-               wave_headers[ i ].dwBufferLength = mb_size / buffers;
-               wave_headers[ i ].lpData = ( LPSTR ) buf_addr;
+        wave_headers[ i ].dwFlags &= ~WHDR_DONE;
 
 
-               //
-               // Unsets the WHDR_DONE flag.
-               //
 
 
-               wave_headers[ i ].dwFlags &= ~WHDR_DONE;
+        
+        //
+        // Sets the WAVEHDR user data with an
+        // unique little buffer ID#
+        //
 
 
+        wave_headers[ i ].dwUser = ( unsigned int ) i;
 
 
+        
+        
+        //
+        // Increments little buffer base address.
+        //
 
 
-               //
-               // Sets the WAVEHDR user data with an
-               // unique little buffer ID#
-               //
-
-               wave_headers[ i ].dwUser = ( unsigned int ) i;
-
-
-
-               //
-               // Increments little buffer base address.
-               //
-
-               buf_addr += buf_sz;
-       }
+        buf_addr += buf_sz;
+    }
 
 }
 
 
 
 }
 
 
-void
+void 
 audio_waveout::prep_headers_( void )
 {
 audio_waveout::prep_headers_( void )
 {
-       MMRESULT err;
-       bool error = false;
+    MMRESULT err;
+    bool error = false;
 
 
 
 
-       //
-       // If there is no memory for memory or
-       // headers, throw error.
-       //
+    //
+    // If there is no memory for memory or
+    // headers, throw error.
+    //
 
 
-       if (( !wave_headers )
-               || ( !main_buffer ) || ( !waveout_handle ))
-       {} //TODO: throw error!
+    if (( !wave_headers ) 
+        || ( !main_buffer ) || ( !waveout_handle ))
+    {} //TODO: throw error!
 
 
 
 
 
 
-       for ( unsigned int i = 0; i < buffers; ++i )
-       {
-               err = waveOutPrepareHeader( waveout_handle,
-                                       &wave_headers[ i ], sizeof( WAVEHDR ));
+    for ( unsigned int i = 0; i < buffers; ++i )
+    {
+        err = waveOutPrepareHeader( waveout_handle, 
+                    &wave_headers[ i ], sizeof( WAVEHDR ));
 
 
 
 
-               if ( err != MMSYSERR_NOERROR )
-                       error = true;
+        if ( err != MMSYSERR_NOERROR )
+            error = true;
 
 
-       }
+    }
+    
 
 
-
-       if ( error )
-       {} //TODO: throw error indicating which
-         //header i-th is errorneous
+    if ( error )
+    {} //TODO: throw error indicating which
+      //header i-th is errorneous
 
 
 
 }
 
 
 
 
 }
 
-void
+void 
 audio_waveout::unprep_headers_( void )
 {
 audio_waveout::unprep_headers_( void )
 {
-       MMRESULT err;
-       bool error = false;
-
+    MMRESULT err;
+    bool error = false;
 
 
 
 
-       //
-       // If there is no memory for memory or
-       // headers, throw error.
-       //
 
 
-       if (( !wave_headers )
-               || ( !main_buffer ) || ( !waveout_handle ))
-       {} //TODO: throw error!
+    //
+    // If there is no memory for memory or
+    // headers, throw error.
+    //
 
 
+    if (( !wave_headers ) 
+        || ( !main_buffer ) || ( !waveout_handle ))
+    {} //TODO: throw error!
 
 
 
 
-       for ( unsigned int i = 0; i < buffers; ++i )
-       {
-               err = waveOutUnprepareHeader( waveout_handle,
-                                       &wave_headers[ i ], sizeof( WAVEHDR ));
 
 
+    for ( unsigned int i = 0; i < buffers; ++i )
+    {
+        err = waveOutUnprepareHeader( waveout_handle, 
+                    &wave_headers[ i ], sizeof( WAVEHDR ));
 
 
-               if ( err != MMSYSERR_NOERROR )
-                       error = true;
 
 
-       }
+        if ( err != MMSYSERR_NOERROR )
+            error = true;
 
 
+    }
+    
 
 
-       if ( error )
-       {} //TODO: throw error indicating which
-         //header i-th is errorneous
+    if ( error )
+    {} //TODO: throw error indicating which
+      //header i-th is errorneous
 
 }
 
 
 }
 
@@ -267,26 +268,26 @@ audio_waveout::unprep_headers_( void )
 
 
 
 
 
 
-void
+void 
 audio_waveout::free_buffers_mem_( void )
 {
 
 
 
 audio_waveout::free_buffers_mem_( void )
 {
 
 
 
-       //
-       // Frees memory
-       //
+    //
+    // Frees memory
+    //
 
 
-       if ( main_buffer )
-               delete[] main_buffer;
+    if ( main_buffer )
+        delete[] main_buffer;
 
 
 
 
-       if ( wave_headers )
-               delete[] wave_headers;
+    if ( wave_headers )
+        delete[] wave_headers;
 
 
 
 
-       main_buffer = 0;
-       wave_headers = 0;
+    main_buffer = 0;
+    wave_headers = 0;
 
 
 
 
 
 
@@ -306,364 +307,398 @@ audio_waveout::free_buffers_mem_( void )
 
 
 
 
 
 
-void
+void 
 audio_waveout::open( void )
 {
 
 audio_waveout::open( void )
 {
 
-       MMRESULT err;
-       HANDLE playthread_handle = 0;
-
+    MMRESULT err;
+    HANDLE playthread_handle = 0;
 
 
-       //
-       // Checkin the status of the object
-       //
 
 
-       if ( status != WAVEOUT_NOTREADY )
-       {} //TODO: throw error
+    //
+    // Checkin the status of the object
+    //
 
 
+    if ( status != WAVEOUT_NOTREADY )
+    {} //TODO: throw error
 
 
-       //
-       // Creating the EVENT object that will be signaled
-       // when the playing thread has to wake up.
-       //
 
 
-       wakeup_playthread =
-               CreateEvent( 0, FALSE, FALSE, 0 );
+    //
+    // Creating the EVENT object that will be signaled
+    // when the playing thread has to wake up.
+    //
 
 
-       if ( !wakeup_playthread )
-       {
+    wakeup_playthread = 
+        CreateEvent( 0, FALSE, FALSE, 0 );
 
 
+    if ( !wakeup_playthread )
+    {
 
 
-               status = WAVEOUT_ERR;
 
 
-               //TODO: throw error
-       }
+        status = WAVEOUT_ERR;
 
 
+        //TODO: throw error
+    }
 
 
 
 
-       //
-       // Inialize buffers for recording audio
-       // data from the wavein audio line.
-       //
 
 
-       alloc_buffers_mem_( buffers, buf_secs );
-       init_headers_();
+    //
+    // Inialize buffers for recording audio 
+    // data from the wavein audio line.
+    //
 
 
+    alloc_buffers_mem_( buffers, buf_secs );
+    init_headers_();
 
 
 
 
 
 
 
 
 
 
-       //
-       // Sound format that will be captured by wavein
-       //
 
 
-       wave_format.wFormatTag = WAVE_FORMAT_PCM;
+    //
+    // Sound format that will be captured by wavein
+    //
 
 
-       wave_format.nChannels = aud_info.channels();
-       wave_format.nSamplesPerSec = aud_info.sample_rate();
-       wave_format.wBitsPerSample = aud_info.bits();
-       wave_format.nBlockAlign = aud_info.block_align();
-       wave_format.nAvgBytesPerSec = aud_info.byte_rate();
+    wave_format.wFormatTag = WAVE_FORMAT_PCM;
 
 
+    wave_format.nChannels = aud_info.channels();
+    wave_format.nSamplesPerSec = aud_info.sample_rate();
+    wave_format.wBitsPerSample = aud_info.bits();
+    wave_format.nBlockAlign = aud_info.block_align();
+    wave_format.nAvgBytesPerSec = aud_info.byte_rate();
 
 
 
 
-       //
-       // Creating the recording thread
-       //
 
 
-       playthread_handle =
-               CreateThread( NULL,
-                                         0,
-                                         audio_waveout::playing_procedure,
-                                         ( PVOID ) this,
-                                         0,
-                                         &playthread_id
-                       );
+    //
+    // Creating the recording thread
+    //
 
 
+    playthread_handle = 
+        CreateThread( NULL, 
+                      0, 
+                      audio_waveout::playing_procedure, 
+                      ( PVOID ) this, 
+                      0, 
+                      &playthread_id 
+            );
 
 
+    
 
 
-       //
-       // Checking thread handle
-       //
+    //
+    // Checking thread handle
+    //
 
 
-       if ( !playthread_handle )
-       {
+    if ( !playthread_handle )
+    {
 
 
-               //
-               // Updating status
-               //
+        //
+        // Updating status
+        //
 
 
-               status = WAVEOUT_ERR;
-               //TODO: throw error
+        status = WAVEOUT_ERR;          
+        //TODO: throw error
 
 
-       }
+    }
 
 
 
 
-       //
-       // We don't need the thread handle anymore,
-       // so we can close it from now. (We'll just
-       // need the thread ID for the `waveInOpen' API)
-       //
+    //
+    // We don't need the thread handle anymore,
+    // so we can close it from now. (We'll just
+    // need the thread ID for the `waveInOpen' API)
+    //
 
 
-       CloseHandle( playthread_handle );
+    CloseHandle( playthread_handle );
 
 
 
 
 
 
-       //
-       // Reset the `audio_source' to the start
-       // position.
-       //
+    //
+    // Reset the `audio_source' to the start
+    // position.
+    //
 
 
-       audio_buf.set_position_start();
+    audio_buf.set_position_start();
 
 
 
 
 
 
 
 
-       //
-       // Opens the WAVE_OUT device.
-       //
+    //
+    // Opens the WAVE_OUT device.
+    //
 
 
-       err = waveOutOpen(
-                               &waveout_handle,
-                               WAVE_MAPPER,
-                               &wave_format,
-                               playthread_id,
-                               0,
-                               CALLBACK_THREAD | WAVE_ALLOWSYNC
-                       );
+    err = waveOutOpen( 
+                &waveout_handle, 
+                WAVE_MAPPER, 
+                &wave_format, 
+                playthread_id, 
+                0, 
+                CALLBACK_THREAD | WAVE_ALLOWSYNC 
+            );
 
 
 
 
 
 
-       if ( err != MMSYSERR_NOERROR )
-       {
-               MessageBox(0, _T("waveOutOpen Error"), 0, 0);
-               //TODO: throw error
+    if ( err != MMSYSERR_NOERROR )
+    {
+        MessageBox(0, _T("waveOutOpen Error"), 0, 0);
+        //TODO: throw error
 
 
-       }
+    }
 
 
 
 
 
 
 
 
-       status = WAVEOUT_READY;
+    status = WAVEOUT_READY;
 
 
 }
 
 
 
 
 
 }
 
 
 
-void
+void 
 audio_waveout::play( void )
 {
 
 
 audio_waveout::play( void )
 {
 
 
-       MMRESULT err;
-       unsigned int i;
-       BOOL ev;
-
-
-       if ( !main_buffer )
-       { return; } //TODO; throw error, or assert
+    MMRESULT err;
+    unsigned int i;
+    BOOL ev;
 
 
 
 
+    if ( !main_buffer )
+    { return; } //TODO; throw error, or assert
 
 
 
 
-       //
-       // If the status is PAUSED, we have to
-       // resume the audio playing.
-       //
-       if ( status == WAVEOUT_PAUSED )
-       {
 
 
-               //
-               // Updates status.
-               //
 
 
-               status = WAVEOUT_PLAYING;
+    //
+    // If the status is PAUSED, we have to
+    // resume the audio playing.
+    //
+    if ( status == WAVEOUT_PAUSED )
+    {
 
 
+        //
+        // Updates status.
+        //
 
 
-               //
-               // Tells to the driver to resume
-               // audio playing.
-               //
+        status = WAVEOUT_PLAYING;
 
 
-               waveOutRestart( waveout_handle );
 
 
+        //
+        // Tells to the driver to resume
+        // audio playing.
+        //
 
 
-               //
-               // Wakeup playing thread.
-               //
+        waveOutRestart( waveout_handle );
+        
 
 
-               ev = SetEvent( wakeup_playthread );
+        //
+        // Wakeup playing thread.
+        //
 
 
-               return;
+        ev = SetEvent( wakeup_playthread );
 
 
-       } //if status == WAVEOUT_PAUSED
+        return;
 
 
+    } //if status == WAVEOUT_PAUSED
 
 
 
 
 
 
 
 
-       if ( status != WAVEOUT_READY )
-               return;
 
 
+    if ( status != WAVEOUT_READY ) 
+        return;
+    
 
 
 
 
 
 
-       //
-       // Prepares WAVEHDR structures.
-       //
+    //
+    // Prepares WAVEHDR structures.
+    //
 
 
-       prep_headers_();
+    prep_headers_();
 
 
 
 
 
 
-       //
-       // Sets correct status.
-       //
+    //
+    // Sets correct status.
+    //
 
 
-       status = WAVEOUT_PLAYING;
+    status = WAVEOUT_PLAYING;
+    
+    
 
 
+    //
+    // Reads the audio from the start.
+    //
 
 
+    //audio_buf.set_position_start();
 
 
-       //
-       // Reads the audio from the start.
-       //
+    
 
 
-       //audio_buf.set_position_start();
+    
+    //
+    // Reads the first N bytes from the audio
+    // buffer, where N = the total size of all
+    // little buffers.
+    //
 
 
+    audio_buf.read( main_buffer, mb_size );
 
 
+    
 
 
 
 
-       //
-       // Reads the first N bytes from the audio
-       // buffer, where N = the total size of all
-       // little buffers.
-       //
 
 
-       audio_buf.read( main_buffer, mb_size );
+    
+    //
+    // Wakeup the playing thread.
+    //
 
 
+    ev = SetEvent( wakeup_playthread );
 
 
 
 
 
 
 
 
+    //
+    // Sends all the little buffers to the
+    // audio driver, so it can play the sound 
+    // data.
+    //
 
 
-       //
-       // Wakeup the playing thread.
-       //
+    for ( i = 0; i < buffers; ++ i )
+    {
 
 
-       ev = SetEvent( wakeup_playthread );
+        
+        err = waveOutWrite( waveout_handle, &wave_headers[ i ], sizeof( WAVEHDR ));
 
 
+        if ( err != MMSYSERR_NOERROR )
+        {
+        
 
 
+            MessageBox(0, _T("waveOutWrite Error"), 0, 0);
+                                
+            //TODO: throw error
+        }
 
 
+    }
 
 
-       //
-       // Sends all the little buffers to the
-       // audio driver, so it can play the sound
-       // data.
-       //
-
-       for ( i = 0; i < buffers; ++ i )
-       {
+}
 
 
 
 
-               err = waveOutWrite( waveout_handle, &wave_headers[ i ], sizeof( WAVEHDR ));
+void 
+audio_waveout::pause( void )
+{
 
 
-               if ( err != MMSYSERR_NOERROR )
-               {
+    MMRESULT err;
 
 
 
 
-                       MessageBox(0, _T("waveOutWrite Error"), 0, 0);
+    //
+    // If the waveout object is not playing audio,
+    // do nothing.
+    //
+    
+    if ( status == WAVEOUT_PLAYING )
+    {
 
 
-                       //TODO: throw error
-               }
+        //
+        // Updating status.
+        //
 
 
-       }
+        status = WAVEOUT_PAUSED;
 
 
-}
 
 
+        //
+        // Tells to audio driver to pause audio.
+        //
 
 
-void
-audio_waveout::pause( void )
-{
+        err = waveOutPause( waveout_handle );
 
 
-       MMRESULT err;
 
 
+        if ( err != MMSYSERR_NOERROR )
+        {
 
 
-       //
-       // If the waveout object is not playing audio,
-       // do nothing.
-       //
+            MessageBox(0, _T("waveOutPause Error"), 0, 0);
+            //TODO: throw error
 
 
-       if ( status == WAVEOUT_PLAYING )
-       {
+        }
 
 
-               //
-               // Updating status.
-               //
+    }
 
 
-               status = WAVEOUT_PAUSED;
+}
 
 
 
 
-               //
-               // Tells to audio driver to pause audio.
-               //
+void 
+audio_waveout::stop( void )
+{
 
 
-               err = waveOutPause( waveout_handle );
+    MMRESULT err;
 
 
 
 
-               if ( err != MMSYSERR_NOERROR )
-               {
+    //
+    // Checks the current status
+    //
 
 
-                       MessageBox(0, _T("waveOutPause Error"), 0, 0);
-                       //TODO: throw error
+    if (( status != WAVEOUT_PLAYING ) 
+            && ( status != WAVEOUT_FLUSHING )
+            && ( status != WAVEOUT_PAUSED ))
+    {
+        //
+        // Do nothing.
+        //
 
 
-               }
+        return;
 
 
-       }
+    }
 
 
-}
 
 
 
 
-void
-audio_waveout::stop( void )
-{
+    //
+    // Sets a new status
+    //
 
 
-       MMRESULT err;
+    status = WAVEOUT_STOP;
 
 
 
 
-       status = WAVEOUT_STOP;
 
 
+    //
+    // Flushes pending audio datas
+    //
 
 
-       err = waveOutReset( waveout_handle );
+    err = waveOutReset( waveout_handle );
 
 
 
 
 
 
-       if ( err != MMSYSERR_NOERROR )
-       {
+    if ( err != MMSYSERR_NOERROR )
+    {
 
 
-               MessageBox(0, _T("err WaveOutReset.\n"),_T("ERROR"), 0);
-               //TODO: throw error
+        MessageBox(0, _T("err WaveOutReset.\n"),_T("ERROR"), 0);
+        //TODO: throw error
 
 
-       }
+    }
 
 
 
 
 
 
-       //
-       // Sets the start position of the audio
-       // buffer.
-       //
+    //
+    // Sets the start position of the audio
+    // buffer.
+    //
 
 
-       audio_buf.set_position_start();
+    audio_buf.set_position_start();
 
 
 
 
-       unprep_headers_();
+    //
+    // Cleans little buffers.
+    //
 
 
+    unprep_headers_();
+    init_headers_();
 
 
-       init_headers_();
 
 
+    
+    //
+    // Refreshes the status.
+    //
 
 
-       status = WAVEOUT_READY;
+    status = WAVEOUT_READY;
 
 }
 
 
 }
 
@@ -671,218 +706,297 @@ void
 audio_waveout::close( void )
 {
 
 audio_waveout::close( void )
 {
 
-       MMRESULT err;
+    MMRESULT err;
 
 
 
 
-       //
-       // If the `wave_out' object is playing audio,
-       // or it is in paused state, we have to call
-       // the `stop' member function, to flush
-       // pending buffers.
-       //
+    //
+    // If the `wave_out' object is playing audio,
+    // or it is in paused state, we have to call
+    // the `stop' member function, to flush 
+    // pending buffers.
+    //
+    
+    if (( status == WAVEOUT_PLAYING ) 
+                    || ( status== WAVEOUT_PAUSED ))
+    {
+    
+        stop();
 
 
-       if (( status == WAVEOUT_PLAYING )
-                                       || ( status== WAVEOUT_PAUSED ))
-       {
+    }
 
 
-               stop();
 
 
-       }
 
 
+    //
+    // When we have flushed all pending buffers,
+    // the wave out handle can be successfully closed.
+    //
 
 
+    err = waveOutClose( waveout_handle );
 
 
-       //
-       // When we have flushed all pending buffers,
-       // the wave out handle can be successfully closed.
-       //
 
 
-       err = waveOutClose( waveout_handle );
+    if ( err != MMSYSERR_NOERROR )
+    {
 
 
+        MessageBox(0, _T("waveOutClose Error"), 0, 0);
+        //TODO: throw error
 
 
-       if ( err != MMSYSERR_NOERROR )
-       {
+    }
 
 
-               MessageBox(0, _T("waveOutClose Error"), 0, 0);
-               //TODO: throw error
-
-       }
-
-       free_buffers_mem_();
+    free_buffers_mem_();
 
 }
 
 
 
 }
 
 
-DWORD WINAPI
+DWORD WINAPI 
 audio_waveout::playing_procedure( LPVOID arg )
 {
 audio_waveout::playing_procedure( LPVOID arg )
 {
-       MSG msg;
-       WAVEHDR * phdr;
-       DWORD wait;
-       MMRESULT err;
-       audio_waveout * _this = ( audio_waveout * ) arg;
-       unsigned int read_size;
-
-
-
-       //
-       // Check the arg pointer
-       //
-
-       if ( _this == 0 )
-               return 0;
-
-
-
-       //
-       // The thread can go to sleep for now.
-       // It will be wake up only when there is audio data
-       // to be recorded.
-       //
-
-       if ( _this->wakeup_playthread )
-               wait = WaitForSingleObject(
-                                               _this->wakeup_playthread, INFINITE
-                                       );
-
-
+    MSG msg;
+    WAVEHDR * phdr;
+    DWORD wait;
+    MMRESULT err;
+    audio_waveout * _this = ( audio_waveout * ) arg;
+    unsigned int read_size;
+    
+
+
+    //
+    // Check the arg pointer
+    //
+
+    if ( _this == 0 )
+        return 0;
+
+    
+    
+    //
+    // The thread can go to sleep for now.
+    // It will be wake up only when there is audio data
+    // to be recorded.
+    //
+
+    if ( _this->wakeup_playthread )
+        wait = WaitForSingleObject( 
+                        _this->wakeup_playthread, INFINITE 
+                    );
+
+
+
+    //
+    // Entering main polling loop
+    //
+
+    while ( GetMessage( &msg, 0, 0, 0 ))       
+    {  
+
+        switch ( msg.message )
+        {
+
+            case MM_WOM_DONE:
+            
+                phdr = ( WAVEHDR * ) msg.lParam;
+
 
 
-       //
-       // Entering main polling loop
-       //
+                //
+                // If the status of the `wave_out' object
+                // is different than playing, then the thread
+                // can go to sleep.
+                //
 
 
-       while ( GetMessage( &msg, 0, 0, 0 )) 
-       {
+                if (( _this->status != WAVEOUT_PLAYING ) && 
+                        ( _this->status != WAVEOUT_FLUSHING ) &&
+                                    ( _this->wakeup_playthread ))
+                {
+                
+                    wait = WaitForSingleObject( 
+                                    _this->wakeup_playthread, 
+                                    INFINITE 
+                                );
+                }
 
 
-               switch ( msg.message )
-               {
 
 
-                       case MM_WOM_DONE:
 
 
-                               phdr = ( WAVEHDR * ) msg.lParam;
+                //
+                // The playing thread doesn't have to sleep,
+                // so let's checking first if the little buffer
+                // has been sent to the audio driver (it has the 
+                // WHDR_DONE flag). If it is, we can read new
+                // audio datas from the `audio_producer' object,
+                // refill the little buffer, and resend it to the
+                // driver with waveOutWrite( ) API.
+                //
+                
+                if ( phdr->dwFlags & WHDR_DONE )
+                {
+
+                    if ( _this->status == WAVEOUT_PLAYING )
+                    {
 
 
+                        //
+                        // Here the thread is still playing a sound,
+                        // so it can read new audio data from the
+                        // `audio_producer' object.
+                        //
+                    
+                        read_size = 
+                            _this->audio_buf.read(
+                                            ( BYTE * ) phdr->lpData, 
+                                            phdr->dwBufferLength 
+                                        );
+
+                    } else
+                       read_size = 0;
+
+                    
+
+                    //
+                    // If the `audio_producer' object, has produced some
+                    // audio data, so `read_size' will be > 0.
+                    //
+                        
+                    if ( read_size )
+                    {
 
 
-                               //
-                               // If the status of the `wave_out' object
-                               // is different than playing, then the thread
-                               // can go to sleep.
-                               //
+                        //
+                        // Adjusts the correct effectively read size.
+                        //
+
+                        phdr->dwBufferLength = read_size;
+
+                        //
+                        // Before sending the little buffer to the
+                        // driver, we have to remove the `WHDR_DONE'
+                        // flag, because the little buffer now contain
+                        // new audio data that have to be played.
+                        //
 
 
-                               if (( _this->status != WAVEOUT_PLAYING )
-                                                               && ( _this->wakeup_playthread ))
-                               {
+                        phdr->dwFlags &= ~WHDR_DONE;
 
 
-                                       wait = WaitForSingleObject(
-                                                                       _this->wakeup_playthread,
-                                                                       INFINITE
-                                                               );
-                               }
 
 
-                               //TODO: quando il thread si risveglia, deve
-                               //entrare nel prossimo if o no? o metter un else { ?
+                        //
+                        // Plays the sound of the little buffer.
+                        //
 
 
+                        err = waveOutWrite( 
+                                    _this->waveout_handle, 
+                                    phdr, 
+                                    sizeof( WAVEHDR )
+                                );
 
 
 
 
-                               if ( phdr->dwFlags & WHDR_DONE )
-                               {
+                        //
+                        // Checking if any error has occured.
+                        //
 
 
-                                       read_size =
-                                               _this->audio_buf.read(
-                                                                               ( BYTE * ) phdr->lpData,
-                                                                               phdr->dwBufferLength
-                                                                       );
+                        if ( err != MMSYSERR_NOERROR )
+                        {
+                                MessageBox(0, _T("waveOutWrite Error"), 0, 0);
+                                //TODO: throw error
+                        }
 
 
 
 
-                                       if ( read_size )
-                                       {
-                                               phdr->dwBufferLength = read_size;
 
 
-                                               phdr->dwFlags &= ~WHDR_DONE;
 
 
-                                               err = waveOutWrite(
-                                                                       _this->waveout_handle,
-                                                                       phdr,
-                                                                       sizeof( WAVEHDR )
-                                                               );
+                    } else { // if ( read_size )
 
 
-                                               if ( err != MMSYSERR_NOERROR )
-                                               {
-                                                               MessageBox(0, _T("waveOutWrite Error"), 0, 0);
-                                                               //TODO: throw error
-                                               }
 
 
 
 
-                                       } else {
+                        //
+                        // Here `read_size' is 0, so the
+                        // `audio_producer' object, doesn't have any
+                        // sound data to produce anymore.
+                        // So, now we have to see the little buffer
+                        // #ID to establishing what to do.
+                        //
 
 
-                                               //
-                                               // Here `read_sizep' is 0
-                                               //
+                        if ( phdr->dwUser == 0 )
+                        {
 
 
-                                               if ( phdr->dwUser == ( _this->buffers - 1 ))
-                                               {
+                           
+                            
+                            //
+                            // Here `read_size' is 0, and the buffer
+                            // user data contain 0, so this is the
+                            // first of N little buffers that came
+                            // back with `WHDR_DONE' flag; this means
+                            // that this is the last little buffer in
+                            // which we have to read data to; so we
+                            // can _STOP_ reading data from the 
+                            // `audio_producer' object: doing this is
+                            // accomplished just setting the current
+                            // status as "WAVEOUT_FLUSHING".
+                            //
 
 
-                                                       //
-                                                       // Here `read_size' and the buffer user
-                                                       // data, that contain a buffer ID#,
-                                                       // is equal to the number of the total
-                                                       // buffers - 1. This means that this is the
-                                                       // _LAST_ little buffer that has been played
-                                                       // by the audio driver. We can STOP the
-                                                       // `wave_out' object now, or restart the
-                                                       // sound playing, if we have a infinite loop.
-                                                       //
+                            _this->status = WAVEOUT_FLUSHING;
 
 
 
 
-                                                       _this->stop();
+                        } else if ( phdr->dwUser == ( _this->buffers - 1 )) {
 
 
-                                                       //
-                                                       // Let the thread go to sleep.
-                                                       //
 
 
-                                                       if ( _this->audio_buf.play_finished )
-                                                               _this->audio_buf.play_finished();
+                           
+                            //
+                            // Here `read_size' and the buffer user
+                            // data, that contain a buffer ID#,
+                            // is equal to the number of the total
+                            // buffers - 1. This means that this is the
+                            // _LAST_ little buffer that has been played
+                            // by the audio driver. We can STOP the
+                            // `wave_out' object now, or restart the
+                            // sound playing, if we have a infinite loop.
+                            //
 
 
 
 
-                                                       if ( _this->wakeup_playthread )
-                                                                       wait = WaitForSingleObject(
-                                                                                                       _this->wakeup_playthread,
-                                                                                                       INFINITE
-                                                                                               );
+                            _this->stop();
+                            
+                            //
+                            // Let the thread go to sleep.
+                            //
 
 
-                                               }
+                            if ( _this->audio_buf.play_finished )
+                                _this->audio_buf.play_finished();
+                            
 
 
-                                       }  //if read_size != 0
+                            if ( _this->wakeup_playthread )
+                                    wait = WaitForSingleObject( 
+                                                    _this->wakeup_playthread, 
+                                                    INFINITE 
+                                                );
 
 
-                               }  //( phdr->dwFlags & WHDR_DONE )
+                        }  //if ( phdr->dwUser == ( _this->buffers - 1 ))
 
 
+                    }  //if read_size != 0
 
 
-                               break; // end case
+                }  //( phdr->dwFlags & WHDR_DONE )
+                    
 
 
+                break; // end case
 
 
 
 
-                       case MM_WOM_CLOSE:
-                               //
-                               // The thread can exit now.
-                               //
 
 
-                               return 0;
+            case MM_WOM_CLOSE:
 
 
-                               break;
+                //
+                // The thread can exit now.
+                //
 
 
+                return 0;
 
 
-                       case MM_WOM_OPEN:
+                break;
 
 
-                               //
-                               // Do nothing.
-                               //
 
 
-                               break;
+            case MM_WOM_OPEN:
+                
+                //
+                // Do nothing.
+                //
 
 
+                break;
 
 
-               }  //end switch( msg.message )
 
 
-       }  //end while( GetMessage( ... ))
+        }  //end switch( msg.message )
+        
+    }  //end while( GetMessage( ... ))
 
 
-       return 0;
+    return 0;                          
 }
 
 
 }
 
 
index 7238008..a36518d 100644 (file)
@@ -1,9 +1,21 @@
+/* PROJECT:         ReactOS sndrec32
+ * LICENSE:         GPL - See COPYING in the top level directory
+ * FILE:            base/applications/sndrec32/audio_waveout.hpp
+ * PURPOSE:         Windows MM wave out abstraction
+ * PROGRAMMERS:     Marco Pagliaricci (irc: rendar)
+ */
+
+
+
+
 #ifndef _AUDIOWAVEOUT__H_
 #define _AUDIOWAVEOUT__H_
 
 
 #include "audio_def.hpp"
 #include "audio_format.hpp"
 #ifndef _AUDIOWAVEOUT__H_
 #define _AUDIOWAVEOUT__H_
 
 
 #include "audio_def.hpp"
 #include "audio_format.hpp"
+
+
 #include "audio_producer.hpp"
 
 
 #include "audio_producer.hpp"
 
 
@@ -14,11 +26,12 @@ _AUDIO_NAMESPACE_START_
 
 
 
 
 
 
-enum audio_waveout_status { WAVEOUT_NOTREADY, WAVEOUT_READY,
-                                                   WAVEOUT_PLAYING, WAVEOUT_ERR,
-                                                   WAVEOUT_PAUSED, WAVEOUT_STOP
-
-                                                  };
+enum audio_waveout_status { WAVEOUT_NOTREADY, WAVEOUT_READY, 
+                            WAVEOUT_PLAYING, WAVEOUT_FLUSHING,
+                            WAVEOUT_PAUSED, WAVEOUT_STOP,
+                            WAVEOUT_ERR,
+                
+                           };
 
 
 
 
 
 
@@ -27,158 +40,203 @@ enum audio_waveout_status { WAVEOUT_NOTREADY, WAVEOUT_READY,
 class audio_waveout
 {
 
 class audio_waveout
 {
 
-       friend class audio_buffer;
+    friend class audio_buffer;
+
+
+
+    private:
+
+
+        static DWORD WINAPI 
+            playing_procedure( LPVOID );
 
 
 
 
+        
+        HANDLE wakeup_playthread;
 
 
-       private:
+        
 
 
 
 
-               static DWORD WINAPI playing_procedure( LPVOID );
+    protected:
 
 
+        
+        WAVEFORMATEX   wave_format;
+        WAVEHDR        * wave_headers;
+        HWAVEOUT       waveout_handle;
 
 
+        
+        
 
 
-               HANDLE wakeup_playthread;
+        
+        const audio_format & aud_info;
+        audio_producer & audio_buf;
 
 
 
 
+        
 
 
 
 
-       protected:
 
 
+        //
+        // Audio Playing Thread id
+        //
 
 
-               WAVEFORMATEX   wave_format;
-               WAVEHDR        * wave_headers;
-               HWAVEOUT       waveout_handle;
+        DWORD     playthread_id;
 
 
 
 
 
 
 
 
 
 
-               const audio_format & aud_info;
-               audio_producer & audio_buf;
+        audio_waveout_status status;
 
 
 
 
 
 
 
 
+        float buf_secs;
 
 
 
 
-               //
-               // Audio Playing Thread id
-               //
 
 
-               DWORD     playthread_id;
+        //
+        // The temporary buffers for the audio
+        // data outgoing to the waveout device
+        // and its size, and its total number.
+        //
 
 
 
 
+        //base address for entire memory
+        BYTE * main_buffer;
 
 
+        //size in bytes for the entire memory
+        unsigned int mb_size;
 
 
+        //number of little buffers
+        unsigned int buffers;
 
 
-               audio_waveout_status status;
 
 
+        
 
 
 
 
 
 
-               float buf_secs;
+        //
+        // Protected Functions
+        //
 
 
+        void init_( void );
+        void alloc_buffers_mem_( unsigned int, float );
+        void free_buffers_mem_( void );
 
 
 
 
-               //
-               // The temporary buffers for the audio
-               // data outgoing to the waveout device
-               // and its size, and its total number.
-               //
+        void init_headers_( void );
+        void prep_headers_( void );
+        void unprep_headers_( void );
 
 
 
 
-               //base address for entire memory
-               BYTE * main_buffer;
 
 
-               //size in bytes for the entire memory
-               unsigned int mb_size;
+        
 
 
-               //number of little buffers
-               unsigned int buffers;
 
 
 
 
+    public:
 
 
+        //
+        // Ctors
+        //
 
 
+        audio_waveout( const audio_format & aud_fmt,
+                                audio_producer & a_buf )
 
 
+            : wave_headers( 0 ), aud_info( aud_fmt ),
+            audio_buf( a_buf ),  status( WAVEOUT_NOTREADY ), 
+            main_buffer( 0 ), mb_size( 0 ),
+            buffers( _AUDIO_DEFAULT_WAVEOUTBUFFERS )
+        {
 
 
-               //
-               // Protected Functions
-               //
+            //
+            // Initializing internal wavein data
+            //
+            
+            
+            init_();
 
 
-               void init_( void );
-               void alloc_buffers_mem_( unsigned int, float );
-               void free_buffers_mem_( void );
+        }
 
 
+        
 
 
-               void init_headers_( void );
-               void prep_headers_( void );
-               void unprep_headers_( void );
 
 
 
 
+        
+        //
+        // Dtor
+        //
 
 
+        ~audio_waveout( void )
+        {  }
 
 
 
 
 
 
 
 
-       public:
+        //
+        // Public Functions
+        //
 
 
-               //
-               // Ctors
-               //
+        void open  ( void );
+        void play  ( void );
+        void pause ( void );
+        void stop  ( void );
+        void close ( void );
 
 
-               audio_waveout( const audio_format & aud_fmt,
-                                                               audio_producer & a_buf )
 
 
-                       : wave_headers( 0 ), aud_info( aud_fmt ),
-                       audio_buf( a_buf ),  status( WAVEOUT_NOTREADY ),
-                       main_buffer( 0 ), mb_size( 0 ),
-                       buffers( _AUDIO_DEFAULT_WAVEOUTBUFFERS )
-               {
+        audio_waveout_status current_status( void )
+        { return status; }
 
 
-                       //
-                       // Initializing internal wavein data
-                       //
 
 
 
 
-                       init_();
 
 
-               }
+        BYTE * buf( void ) { return main_buffer; }
+        unsigned int bufsz( void ) { return mb_size; }
 
 
 
 
+        unsigned int samplevalue_max( void )
+        {
 
 
+            if ( aud_info.bits() == 16 )
+                return (unsigned int )65535;
 
 
+            else if ( aud_info.bits() == 8 )
+                return (unsigned int)255;
 
 
+            else 
+                return 0;
+        }
 
 
-               //
-               // Dtor
-               //
 
 
-               ~audio_waveout( void )
-               {  }
+        unsigned tot_samples_buf( void )
+        {
 
 
 
 
+            return aud_info.samples_in_bytes( mb_size );
 
 
 
 
-               //
-               // Public Functions
-               //
+        }
 
 
-               void open  ( void );
-               void play  ( void );
-               void pause ( void );
-               void stop  ( void );
-               void close ( void );
+        unsigned int nsample ( unsigned int nsamp )
+        {
 
 
 
 
-               audio_waveout_status current_status( void )
-               { return status; }
+            unsigned int svalue;
 
 
 
 
 
 
+            if ( aud_info.bits() == 16 )
+                svalue = ( unsigned int )  abs( *(( short * ) (main_buffer + aud_info.bytes_in_samples( nsamp ))));
+            else if ( aud_info.bits() == 8 )
+               svalue = (unsigned int)(( unsigned char * ) *(main_buffer + aud_info.bytes_in_samples( nsamp )));
 
 
+            else 
+                svalue = 0;
 
 
+            return svalue;
 
 
+        }
 
 
 };
 
 
 };
index db4c780..56ba98c 100644 (file)
@@ -36,8 +36,19 @@ BEGIN
     END
 END
 
     END
 END
 
-STRINGTABLE
+STRINGTABLE 
 BEGIN
 BEGIN
-    IDS_APP_TITLE           "reactOS_sndrec32"
+    IDS_APP_TITLE           "Sound recorder"
     IDC_REACTOS_SNDREC32    "REACTOS_SNDREC32"
 END
     IDC_REACTOS_SNDREC32    "REACTOS_SNDREC32"
 END
+
+STRINGTABLE 
+BEGIN
+    IDS_STRPOS              "Position: %.2f s"
+    IDS_STRDUR              "Lenght: %.2f s"
+    IDS_STRBUF              "Buffer: %.2f kb"
+    IDS_STRFMT              "%.1f kHz %u bits"
+    IDS_STRMONO             "mono"
+    IDS_STRSTEREO           "stereo"
+    IDS_STRCHAN             "%s"
+END
index 6242d79..fca9da3 100644 (file)
@@ -21,23 +21,36 @@ IDR_MENU1 MENU
 BEGIN
     POPUP "File"
     BEGIN
 BEGIN
     POPUP "File"
     BEGIN
-        MENUITEM "New",                         ID_NEW
-        MENUITEM "Open...",                     ID_FILE_OPEN
-        MENUITEM "Save",                        ID_FILE_SAVE, GRAYED
-        MENUITEM "Save As...",                  ID_FILE_SAVEAS, GRAYED
+        MENUITEM "Nuovo",                         ID_NEW
+        MENUITEM "Apri...",                     ID_FILE_OPEN
+        MENUITEM "Salva",                        ID_FILE_SAVE, GRAYED
+        MENUITEM "Salva con nome...",                  ID_FILE_SAVEAS, GRAYED
         MENUITEM SEPARATOR
         MENUITEM SEPARATOR
-        MENUITEM "Exit",                        ID_EXIT
+        MENUITEM "Esci",                        ID_EXIT
     END
     MENUITEM "todo1",                       0
     MENUITEM "todo2",                       0
     POPUP "?"
     BEGIN
     END
     MENUITEM "todo1",                       0
     MENUITEM "todo2",                       0
     POPUP "?"
     BEGIN
-        MENUITEM "About...",                    ID__ABOUT
+        MENUITEM "Informazioni...",                    ID__ABOUT
     END
 END
 
     END
 END
 
-STRINGTABLE
+
+
+STRINGTABLE 
 BEGIN
 BEGIN
-    IDS_APP_TITLE           "reactOS_sndrec32"
+    IDS_APP_TITLE           "Registratore di suoni"
     IDC_REACTOS_SNDREC32    "REACTOS_SNDREC32"
 END
     IDC_REACTOS_SNDREC32    "REACTOS_SNDREC32"
 END
+
+STRINGTABLE 
+BEGIN
+    IDS_STRPOS              "Posizione: %.2f s"
+    IDS_STRDUR              "Durata: %.2f s"
+    IDS_STRBUF              "Buffer: %.2f kb"
+    IDS_STRFMT              "%.1f kHz %u bits"
+    IDS_STRMONO             "mono"
+    IDS_STRSTEREO           "stereo"
+    IDS_STRCHAN             "%s"
+END
index ed5e608..016f603 100644 (file)
@@ -1,6 +1,6 @@
 //{{NO_DEPENDENCIES}}
 // Microsoft Visual C++ generated include file.
 //{{NO_DEPENDENCIES}}
 // Microsoft Visual C++ generated include file.
-// Used by reactOS_sndrec32.rc
+// Used by rsrc.rc
 //
 #define IDC_MYICON                      2
 #define IDB_BITMAP2_STOP_DIS            8
 //
 #define IDC_MYICON                      2
 #define IDB_BITMAP2_STOP_DIS            8
 #define IDB_BITMAP2_PLAY_DIS            142
 #define IDB_BITMAP2_REC_DIS             143
 #define IDB_BITMAP2_START_DIS           144
 #define IDB_BITMAP2_PLAY_DIS            142
 #define IDB_BITMAP2_REC_DIS             143
 #define IDB_BITMAP2_START_DIS           144
+#define IDS_STRPOS                      400
+#define IDS_STRDUR                      401
+#define IDS_STRBUF                      402
+#define IDS_STRFMT                      403
+#define IDS_STRMONO                     404
+#define IDS_STRSTEREO                   405
+#define IDS_STRING406                   406
+#define IDS_STRCHAN                     406
 #define ID_FILE_NEW                     32771
 #define ID_FILE_OPEN                    32772
 #define ID_FILE_SAVE                    32773
 #define ID_FILE_NEW                     32771
 #define ID_FILE_OPEN                    32772
 #define ID_FILE_SAVE                    32773
@@ -39,7 +47,7 @@
 #define IDC_STATIC                      -1
 
 // Next default values for new objects
 #define IDC_STATIC                      -1
 
 // Next default values for new objects
-//
+// 
 #ifdef APSTUDIO_INVOKED
 #ifndef APSTUDIO_READONLY_SYMBOLS
 #define _APS_NO_MFC                     1
 #ifdef APSTUDIO_INVOKED
 #ifndef APSTUDIO_READONLY_SYMBOLS
 #define _APS_NO_MFC                     1
index 9d17dc1..9366a87 100644 (file)
@@ -1,33 +1,40 @@
-/*
- * PROJECT:         ReactOS Sound Record Application
+/* PROJECT:         ReactOS sndrec32
  * LICENSE:         GPL - See COPYING in the top level directory
  * FILE:            base/applications/sndrec32/sndrec32.cpp
  * LICENSE:         GPL - See COPYING in the top level directory
  * FILE:            base/applications/sndrec32/sndrec32.cpp
- * PURPOSE:         Application Startup
- * PROGRAMMERS:     Marco Pagliaricci <ms_blue (at) hotmail (dot) it>
+ * PURPOSE:         Sound recording
+ * PROGRAMMERS:     Marco Pagliaricci (irc: rendar)
  */
 
  */
 
+#ifndef _UNICODE
+#define gprintf _snprintf
+#else
+#define gprintf _snwprintf
+#endif
+
 #include "stdafx.h"
 #include "sndrec32.h"
 
 
 
 
 #include "stdafx.h"
 #include "sndrec32.h"
 
 
 
 
-//#pragma comment(lib, "comctl32.lib")
-
-
-HINSTANCE hInst;
-TCHAR szTitle[MAX_LOADSTRING];
-TCHAR szWindowClass[MAX_LOADSTRING];
 
 
+HINSTANCE hInst;                                                               
+TCHAR szTitle[MAX_LOADSTRING];                                 
+TCHAR szWindowClass[MAX_LOADSTRING];           
 
 
-ATOM                   MyRegisterClass(HINSTANCE hInstance);
-BOOL                   InitInstance(HINSTANCE, int);
-LRESULT CALLBACK       WndProc(HWND, UINT, WPARAM, LPARAM);
-INT_PTR CALLBACK       About(HWND, UINT, WPARAM, LPARAM);
 
 
+ATOM                           MyRegisterClass( HINSTANCE hInstance );
+ATOM                           MyRegisterClass_wave( HINSTANCE hInstance );
+BOOL                           InitInstance( HINSTANCE, int );
+BOOL                           InitInstance_wave( HWND, HINSTANCE, int );
+LRESULT CALLBACK       WndProc( HWND, UINT, WPARAM, LPARAM );
+LRESULT CALLBACK       WndProc_wave( HWND, UINT, WPARAM, LPARAM );
+INT_PTR CALLBACK       About( HWND, UINT, WPARAM, LPARAM );
 
 
+BOOL win_first, wout_first;
 
 HWND main_win;
 
 HWND main_win;
+HWND wave_win;
 HWND slider;
 HWND buttons[5];
 HBITMAP butbmps[5];
 HWND slider;
 HWND buttons[5];
 HBITMAP butbmps[5];
@@ -37,6 +44,7 @@ WNDPROC buttons_std_proc;
 BOOL butdisabled[5];
 BOOL stopped_flag;
 BOOL isnew;
 BOOL butdisabled[5];
 BOOL stopped_flag;
 BOOL isnew;
+BOOL display_dur;
 
 
 DWORD slider_pos;
 
 
 DWORD slider_pos;
@@ -47,6 +55,15 @@ DWORD samples_max;
 
 OPENFILENAME ofn;
 TCHAR file_path[MAX_PATH];
 
 OPENFILENAME ofn;
 TCHAR file_path[MAX_PATH];
+TCHAR str_pos[MAX_LOADSTRING];
+TCHAR str_dur[MAX_LOADSTRING];
+TCHAR str_buf[MAX_LOADSTRING];
+TCHAR str_fmt[MAX_LOADSTRING];
+TCHAR str_chan[MAX_LOADSTRING];
+
+TCHAR str_mono[10];
+TCHAR str_stereo[10];
+
 BOOL path_set;
 
 snd::audio_membuffer * AUD_BUF;
 BOOL path_set;
 
 snd::audio_membuffer * AUD_BUF;
@@ -57,6 +74,16 @@ snd::audio_wavein * AUD_IN;
 BOOL s_recording;
 
 
 BOOL s_recording;
 
 
+NONCLIENTMETRICS s_info;
+
+
+RECT text_rect;
+RECT text2_rect;
+RECT cli;
+
+
+
+
 
 int APIENTRY _tWinMain(HINSTANCE hInstance,
                      HINSTANCE hPrevInstance,
 
 int APIENTRY _tWinMain(HINSTANCE hInstance,
                      HINSTANCE hPrevInstance,
@@ -64,158 +91,234 @@ int APIENTRY _tWinMain(HINSTANCE hInstance,
                      int       nCmdShow)
 {
 
                      int       nCmdShow)
 {
 
-       UNREFERENCED_PARAMETER(hPrevInstance);
-       UNREFERENCED_PARAMETER(lpCmdLine);
+    UNREFERENCED_PARAMETER(hPrevInstance);
+    UNREFERENCED_PARAMETER(lpCmdLine);
+
+
+    MSG msg;
+    HACCEL hAccelTable;
+    
+    s_info.cbSize = sizeof( NONCLIENTMETRICS );
 
 
+    InitCommonControls();
 
 
-       MSG msg;
-       HACCEL hAccelTable;
+    win_first = wout_first = FALSE;
 
 
-       InitCommonControls();
+    text_rect.left = REFRESHA_X;
+    text_rect.top = REFRESHA_Y;
+    text_rect.right = REFRESHA_CX;
+    text_rect.bottom = REFRESHA_CY;
 
 
+    text2_rect.left = REFRESHB_X;
+    text2_rect.top = REFRESHB_Y;
+    text2_rect.right = REFRESHB_CX;
+    text2_rect.bottom = REFRESHB_CY;
 
 
-       butbmps[0] = LoadBitmap( hInstance, MAKEINTRESOURCE( IDB_BITMAP2_START ));
-       butbmps[1] = LoadBitmap( hInstance, MAKEINTRESOURCE( IDB_BITMAP2_END ));
-       butbmps[2] = LoadBitmap( hInstance, MAKEINTRESOURCE( IDB_BITMAP2_PLAY ));
-       butbmps[3] = LoadBitmap( hInstance, MAKEINTRESOURCE( IDB_BITMAP2_STOP ));
-       butbmps[4] = LoadBitmap( hInstance, MAKEINTRESOURCE( IDB_BITMAP2_REC ));
+    //
+    // Retrieving defaul system font, and others
+    // system informations.
+    //
+   
+    SystemParametersInfo( 
+                    SPI_GETNONCLIENTMETRICS, 
+                    sizeof( NONCLIENTMETRICS ), 
+                    &s_info, 
+                    0 
+                );
 
 
-       butbmps_dis[0] = LoadBitmap( hInstance, MAKEINTRESOURCE( IDB_BITMAP2_START_DIS ));
-       butbmps_dis[1] = LoadBitmap( hInstance, MAKEINTRESOURCE( IDB_BITMAP2_END_DIS ));
-       butbmps_dis[2] = LoadBitmap( hInstance, MAKEINTRESOURCE( IDB_BITMAP2_PLAY_DIS ));
-       butbmps_dis[3] = LoadBitmap( hInstance, MAKEINTRESOURCE( IDB_BITMAP2_STOP_DIS ));
-       butbmps_dis[4] = LoadBitmap( hInstance, MAKEINTRESOURCE( IDB_BITMAP2_REC_DIS ));
+    //
+    // Set font size
+    //
 
 
+    s_info.lfMenuFont.lfHeight = 14;
 
 
-       snd::audio_membuffer AUD_buffer( snd::A44100_16BIT_STEREO );
-       snd::audio_waveout AUD_waveout( snd::A44100_16BIT_STEREO, AUD_buffer );
-       snd::audio_wavein AUD_wavein( snd::A44100_16BIT_STEREO, AUD_buffer );
+    //
+    // Inits buttons bitmaps
+    //
 
 
-       AUD_buffer.play_finished = l_play_finished;
-       AUD_buffer.audio_arrival = l_audio_arrival;
-       AUD_buffer.buffer_resized = l_buffer_resized;
+    butbmps[0] = LoadBitmap( hInstance, MAKEINTRESOURCE( IDB_BITMAP2_START ));
+    butbmps[1] = LoadBitmap( hInstance, MAKEINTRESOURCE( IDB_BITMAP2_END ));
+    butbmps[2] = LoadBitmap( hInstance, MAKEINTRESOURCE( IDB_BITMAP2_PLAY ));
+    butbmps[3] = LoadBitmap( hInstance, MAKEINTRESOURCE( IDB_BITMAP2_STOP ));
+    butbmps[4] = LoadBitmap( hInstance, MAKEINTRESOURCE( IDB_BITMAP2_REC ));
 
 
-       AUD_buffer.alloc_seconds( INITIAL_BUFREC_SECONDS );
+    butbmps_dis[0] = LoadBitmap( hInstance, MAKEINTRESOURCE( IDB_BITMAP2_START_DIS ));
+    butbmps_dis[1] = LoadBitmap( hInstance, MAKEINTRESOURCE( IDB_BITMAP2_END_DIS ));
+    butbmps_dis[2] = LoadBitmap( hInstance, MAKEINTRESOURCE( IDB_BITMAP2_PLAY_DIS ));
+    butbmps_dis[3] = LoadBitmap( hInstance, MAKEINTRESOURCE( IDB_BITMAP2_STOP_DIS ));
+    butbmps_dis[4] = LoadBitmap( hInstance, MAKEINTRESOURCE( IDB_BITMAP2_REC_DIS ));
 
 
-       AUD_IN = &AUD_wavein;
-       AUD_OUT = &AUD_waveout;
-       AUD_BUF = &AUD_buffer;
 
 
 
 
+    //
+    // Inits audio devices and buffers
+    //
 
 
-       slider_pos = 0;
-       slider_min = 0;
-       slider_max = 32767;
+    snd::audio_membuffer AUD_buffer( snd::A44100_16BIT_STEREO );
+    snd::audio_waveout AUD_waveout( snd::A44100_16BIT_STEREO, AUD_buffer );
+    snd::audio_wavein AUD_wavein( snd::A44100_16BIT_STEREO, AUD_buffer );
 
 
+    AUD_buffer.play_finished = l_play_finished;
+    AUD_buffer.audio_arrival = l_audio_arrival;
+    AUD_buffer.buffer_resized = l_buffer_resized;
 
 
-       stopped_flag = FALSE;
-       path_set = FALSE;
-       isnew = TRUE;
+    AUD_buffer.alloc_seconds( INITIAL_BUFREC_SECONDS );
 
 
+    AUD_IN = &AUD_wavein;
+    AUD_OUT = &AUD_waveout;
+    AUD_BUF = &AUD_buffer;
 
 
-       samples_max = AUD_buffer.total_samples();
+    //
+    // Inits slider default parameters
+    //
 
 
+    slider_pos = 0;
+    slider_min = 0;
+    slider_max = SLIDER_W;
 
 
-       LoadString(hInstance,
-               IDS_APP_TITLE, szTitle, MAX_LOADSTRING);
 
 
+    stopped_flag = FALSE;
+    path_set = FALSE;
+    isnew = TRUE;
+    display_dur = TRUE;
 
 
+    samples_max = AUD_buffer.total_samples();
 
 
-       LoadString(hInstance,
-               IDC_REACTOS_SNDREC32, szWindowClass, MAX_LOADSTRING);
+    s_recording = false;
+   
+    //
+    // Inits strings
+    //
 
 
+    LoadString( hInstance, 
+        IDS_APP_TITLE, szTitle, MAX_LOADSTRING );
 
 
+    LoadString( hInstance, 
+        IDC_REACTOS_SNDREC32, szWindowClass, MAX_LOADSTRING );
 
 
-       MyRegisterClass(hInstance);
 
 
+    LoadString( hInstance, 
+        IDS_STRPOS, str_pos, MAX_LOADSTRING );
 
 
-       if (!InitInstance (hInstance, nCmdShow))
-       {
-               MessageBox(0, 0, TEXT("CreateWindow() Error!"), 0);
-               return FALSE;
-       }
 
 
-       hAccelTable = LoadAccelerators(hInstance,
-                               MAKEINTRESOURCE( IDC_REACTOS_SNDREC32 ));
+    LoadString( hInstance, 
+        IDS_STRDUR, str_dur, MAX_LOADSTRING );
 
 
+    LoadString( hInstance, 
+        IDS_STRBUF, str_buf, MAX_LOADSTRING );
 
 
+    LoadString( hInstance, 
+        IDS_STRFMT, str_fmt, MAX_LOADSTRING );
 
 
+    LoadString( hInstance, 
+        IDS_STRCHAN, str_chan, MAX_LOADSTRING );
 
 
+    LoadString( hInstance, 
+        IDS_STRMONO, str_mono, 10 );
 
 
+    LoadString( hInstance, 
+        IDS_STRSTEREO, str_stereo, 10 );
 
 
-       s_recording = false;
 
 
+    //
+    // Registers sndrec32 window class
+    //
 
 
+    MyRegisterClass( hInstance );
 
 
+    MyRegisterClass_wave( hInstance );
 
 
-       AUD_wavein.open();
-       AUD_waveout.open();
+    
+    if ( !InitInstance( hInstance, nCmdShow ))
+    {
+        MessageBox( 0, TEXT( "CreateWindow() Error!" ), TEXT( "ERROR" ), MB_ICONERROR );
+        return FALSE;
+    }
+    
+    //
+    // Loads key accelerators
+    //
 
 
+    hAccelTable = LoadAccelerators(hInstance, 
+                MAKEINTRESOURCE( IDC_REACTOS_SNDREC32 ));
 
 
+    
 
 
+    //
+    // Starts main loop
+    //
 
 
+    while ( GetMessage( &msg, NULL, 0, 0 ))
+    {
+        if ( !TranslateAccelerator( msg.hwnd, hAccelTable, &msg ))
+        {
+            TranslateMessage( &msg );
+            DispatchMessage( &msg );
+        }
+    }
 
 
+    if ( wout_first )
+    {
+        AUD_waveout.close();
 
 
-       while (GetMessage(&msg, NULL, 0, 0))
-       {
-               if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg))
-               {
-                       TranslateMessage(&msg);
-                       DispatchMessage(&msg);
-               }
-       }
+    }
 
 
-       AUD_waveout.close();
-       AUD_wavein.close();
 
 
-       AUD_buffer.clear();
+    if ( win_first )
+    {
+        AUD_wavein.close();
 
 
+    }
 
 
-       return (int) msg.wParam;
+    AUD_buffer.clear();
+
+    return ( int )msg.wParam;
 }
 
 
 
 
 }
 
 
 
 
-ATOM MyRegisterClass(HINSTANCE hInstance)
+ATOM 
+MyRegisterClass( HINSTANCE hInstance )
 {
 {
-       WNDCLASSEX wcex;
+    WNDCLASSEX wcex;
 
 
-       wcex.cbSize = sizeof(WNDCLASSEX);
+    wcex.cbSize = sizeof(WNDCLASSEX);
 
 
-       wcex.style                      = CS_HREDRAW | CS_VREDRAW;
-       wcex.lpfnWndProc        = WndProc;
-       wcex.cbClsExtra         = 0;
-       wcex.cbWndExtra         = 0;
-       wcex.hInstance          = hInstance;
-       wcex.hIcon                      = LoadIcon( hInstance, MAKEINTRESOURCE( IDI_SNDREC32 ));
-       wcex.hCursor            = LoadCursor( NULL, IDC_ARROW );
-       wcex.hbrBackground      = (HBRUSH)( 16 );
-       wcex.lpszMenuName       = MAKEINTRESOURCE( IDR_MENU1 );
-       wcex.lpszClassName      = szWindowClass;
-       wcex.hIconSm            = LoadIcon( wcex.hInstance, MAKEINTRESOURCE( IDI_SNDREC32 ));
+    wcex.style                 = CS_HREDRAW | CS_VREDRAW;
+    wcex.lpfnWndProc   = WndProc;
+    wcex.cbClsExtra            = 0;
+    wcex.cbWndExtra            = 0;
+    wcex.hInstance             = hInstance;
+    wcex.hIcon                 = LoadIcon( hInstance, MAKEINTRESOURCE( IDI_SNDREC32 ));
+    wcex.hCursor               = LoadCursor( NULL, IDC_ARROW );
+    wcex.hbrBackground = (HBRUSH)( 16 );
+    wcex.lpszMenuName  = MAKEINTRESOURCE( IDR_MENU1 );
+    wcex.lpszClassName = szWindowClass;
+    wcex.hIconSm               = LoadIcon( wcex.hInstance, MAKEINTRESOURCE( IDI_SNDREC32 ));
 
 
 
 
-       return RegisterClassEx( &wcex );
+    return RegisterClassEx( &wcex );
 }
 
 }
 
-BOOL InitInstance( HINSTANCE hInstance, int nCmdShow )
+BOOL 
+InitInstance( HINSTANCE hInstance, int nCmdShow )
 {
    HWND hWnd;
 
    hInst = hInstance;
 
    hWnd = CreateWindow(
 {
    HWND hWnd;
 
    hInst = hInstance;
 
    hWnd = CreateWindow(
-                                       szWindowClass,
-                                       szTitle,
-                                       WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX,
-                                       CW_USEDEFAULT,
-                                       CW_USEDEFAULT,
-                                       MAINWINDOW_W,
-                                       MAINWINDOW_H,
-                                       NULL, NULL,
-                                       hInstance, NULL
-                               );
+                    szWindowClass, 
+                    szTitle, 
+                    WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX,
+                    CW_USEDEFAULT, 
+                    CW_USEDEFAULT, 
+                    MAINWINDOW_W, 
+                    MAINWINDOW_H, 
+                    NULL, NULL, 
+                    hInstance, NULL
+                );
 
    if (!hWnd)
    {
 
    if (!hWnd)
    {
@@ -232,426 +335,802 @@ BOOL InitInstance( HINSTANCE hInstance, int nCmdShow )
 }
 
 
 }
 
 
-//
-LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
+
+
+
+ATOM 
+MyRegisterClass_wave( HINSTANCE hInstance )
+{
+    WNDCLASSEX wcex;
+
+    wcex.cbSize = sizeof( WNDCLASSEX );
+
+    wcex.style                 = CS_HREDRAW | CS_VREDRAW;
+    wcex.lpfnWndProc   = WndProc_wave;
+    wcex.cbClsExtra            = 0;
+    wcex.cbWndExtra            = 0;
+    wcex.hInstance             = hInstance;
+    wcex.hIcon                 = 0;
+    wcex.hCursor               = LoadCursor( NULL, IDC_ARROW );
+    wcex.hbrBackground = ( HBRUSH )GetStockObject( BLACK_BRUSH );
+    wcex.lpszMenuName  = 0;
+    wcex.lpszClassName = TEXT( "sndrec32_wave" );
+    wcex.hIconSm               = 0;
+
+
+    return RegisterClassEx( &wcex );
+}
+
+BOOL 
+InitInstance_wave( HWND f, HINSTANCE hInstance, int nCmdShow )
+{
+   HWND hWnd;
+
+   hInst = hInstance;
+
+   hWnd = CreateWindow(
+                    TEXT( "sndrec32_wave" ), 
+                    TEXT(""), 
+                    WS_DLGFRAME|WS_VISIBLE|WS_CHILD,
+                    WAVEBAR_X, 
+                    WAVEBAR_Y, 
+                    WAVEBAR_CX, 
+                    WAVEBAR_CY, 
+                    f, ( HMENU ) 8, 
+                    hInstance, 0
+                );
+
+   if ( !hWnd )
+   {
+      return FALSE;
+   }
+
+   ShowWindow( hWnd, nCmdShow );
+   UpdateWindow( hWnd );
+
+   wave_win = hWnd;
+
+
+   return TRUE;
+}
+
+
+LRESULT CALLBACK 
+WndProc_wave( HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam )
+{
+    PAINTSTRUCT ps;
+    HDC hdc;
+    HPEN pen;
+
+
+
+    unsigned int max_h = ( cli.bottom / 2 );
+    unsigned int samples;
+    unsigned int x, line_h;
+   
+   
+
+    switch ( message )
+    {
+
+
+    case WM_CREATE:
+
+
+        GetClientRect( hWnd, &cli );
+
+        break;
+
+
+    case WM_PAINT:
+        
+        //
+        // Initialize hdc objects
+        //
+
+        hdc = BeginPaint( hWnd, &ps );
+
+        pen = ( HPEN ) CreatePen( PS_SOLID, 1, WAVEBAR_COLOR );
+
+        SelectObject( hdc, ( HBRUSH )pen );
+
+        if ( AUD_OUT->current_status() == snd::WAVEOUT_PLAYING )
+        {
+
+            samples = AUD_OUT->tot_samples_buf();
+           
+
+            for ( unsigned int i = 0; i < WAVEBAR_CX; ++i )
+            {
+
+                x = ( i * samples ) / WAVEBAR_CX;
+
+                line_h = ( abs(AUD_OUT->nsample( x )) * max_h ) / AUD_OUT->samplevalue_max();
+
+
+                if ( line_h )
+                {
+                    MoveToEx( hdc, i, max_h, 0 );
+                    LineTo( hdc, i, max_h - ( line_h * 2 ));
+                    LineTo( hdc, i, max_h + ( line_h * 2 ));
+                } else
+                    SetPixel( hdc, i, max_h, WAVEBAR_COLOR );
+
+            }
+
+
+        } else if ( AUD_IN->current_status() == snd::WAVEIN_RECORDING ) {
+
+
+            samples = AUD_IN->tot_samples_buf();
+           
+
+            for ( unsigned int i = 0; i < WAVEBAR_CX; ++i )
+            {
+
+                x = ( i * samples ) / WAVEBAR_CX;
+
+                line_h = ( AUD_IN->nsample( x ) * max_h ) / AUD_IN->samplevalue_max();
+
+                
+                 if ( line_h )
+                {
+                    MoveToEx( hdc, i, max_h, 0 );
+                    LineTo( hdc, i, max_h - ( line_h * 2 ));
+                    LineTo( hdc, i, max_h + ( line_h * 2 ));
+                } else
+                    SetPixel( hdc, i, max_h, WAVEBAR_COLOR );
+
+            }
+
+
+        } else {
+
+            //
+            // In standby mode draw a simple line.
+            //
+
+            MoveToEx( hdc, 0, cli.bottom  / 2, 0 );
+            LineTo( hdc, WAVEBAR_CX, cli.bottom  / 2 );
+
+        }
+
+       
+        DeleteObject( pen );
+
+        EndPaint( hWnd, &ps );
+
+        break;
+
+        
+    case WM_USER:
+        
+        
+        break;
+
+
+    default:
+        return DefWindowProc( hWnd, message, wParam, lParam );
+
+
+    }
+
+
+    return 0;
+
+}
+
+
+
+LRESULT CALLBACK 
+WndProc( HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam )
 {
 {
-       int wmId, wmEvent;
-       RECT rect;
-       PAINTSTRUCT ps;
-       HDC hdc;
+    int wmId, wmEvent;
+    TCHAR str_tmp[MAX_LOADSTRING];
+    PAINTSTRUCT ps;
+    HDC hdc;
+    HFONT font;
+    long long slid_samp = 0;
+
+
+
+    //
+    // Checking for global pointers to buffer and
+    // io audio devices.
+    //
+
+    if (( !AUD_IN ) || ( !AUD_OUT ) || ( !AUD_BUF ))
+    {
+        MessageBox( 0, TEXT("Buffer Error"), 0, 0 );
+        return 1;
+    }
+    
+
+    switch ( message )
+    {
+
+
+    case WM_CREATE:
+
+
+        //
+        // Creating the wave bar
+        //
+
+        if ( !InitInstance_wave( hWnd, hInst, SW_SHOWNORMAL ))
+        {
+            MessageBox( 
+                    0, 
+                    TEXT( "CreateWindow() Error!" ), 
+                    TEXT( "ERROR" ), 
+                    MB_ICONERROR 
+                );
+            
+            return FALSE;
+        }
+
+
+
+
+        //
+        // Creating ALL the buttons
+        //
+        
+        for ( int i = 0; i < 5; ++ i )
+        {
+
+            buttons[i] = CreateWindow( 
+                                TEXT("button"), 
+                                TEXT(""), 
+                                WS_CHILD|WS_VISIBLE|BS_BITMAP, 
+                                BUTTONS_CX + ( i * (BUTTONS_W+((i == 0)?0:BUTTONS_SPACE))), 
+                                BUTTONS_CY, BUTTONS_W, BUTTONS_H, hWnd, 
+                                (HMENU)i, hInst, 0
+                            );
+
+            if ( !buttons[i] )
+            {
+                MessageBox(0, 0, TEXT("CreateWindow() Error!"), 0);
+                return FALSE;
+
+            }
+
+
+            //
+            // Realize the button bmp image
+            //
+
+            SendMessage(buttons[i], BM_SETIMAGE, ( WPARAM )IMAGE_BITMAP, ( LPARAM )butbmps[i]);
+            
+            UpdateWindow( buttons[i] );
+
+            disable_but( i );
+
+        }
+
+
+        //
+        // Creating the SLIDER window
+        //
+        
+        slider = CreateWindow( 
+                        TRACKBAR_CLASS, 
+                        TEXT(""), 
+                        WS_CHILD|WS_VISIBLE|TBS_NOTICKS|TBS_HORZ|TBS_ENABLESELRANGE, 
+                        SLIDER_CX, SLIDER_CY, SLIDER_W, SLIDER_H, hWnd, 
+                        ( HMENU )SLIDER_ID, hInst, 0
+                    );
+
+
+        if ( !slider )
+        {
+            MessageBox( 0, 0, TEXT( "CreateWindow() Error!" ), 0 );
+            return FALSE;
 
 
+        }
 
 
-       //
-       // Checking for global pointers to buffer and
-       // io audio devices.
-       //
 
 
-       if (( !AUD_IN ) || ( !AUD_OUT ) || ( !AUD_BUF ))
-       {
-               MessageBox( 0, TEXT("Buffer Error"), 0, 0 );
-               return 1;
-       }
+        //
+        // Sets slider limits
+        //
 
 
 
 
-       switch (message)
-       {
+        SendMessage( 
+                slider, 
+                TBM_SETRANGE,
+                ( WPARAM )TRUE, 
+                ( LPARAM )MAKELONG( slider_min, slider_max )
+            );
 
 
 
 
-       case WM_CREATE:
+        UpdateWindow( slider );
 
 
+        enable_but( BUTREC_ID );
 
 
+        EnableWindow( slider, FALSE );
 
 
-               //
-               // Creating ALL the buttons
-               //
 
 
-               for ( int i = 0; i < 5; ++ i )
-               {
 
 
-                       buttons[i] = CreateWindow(
-                                                               TEXT("button"),
-                                                               TEXT(""),
-                                                               WS_CHILD|WS_VISIBLE|BS_BITMAP,
-                                                               BUTTONS_CX + ( i * (BUTTONS_W+((i == 0)?0:BUTTONS_SPACE))),
-                                                               BUTTONS_CY, BUTTONS_W, BUTTONS_H, hWnd,
-                                                               (HMENU)i, hInst, 0
-                                                       );
 
 
-                       if ( !buttons[i] )
-                       {
-                               MessageBox(0, 0, TEXT("CreateWindow() Error!"), 0);
-                               return FALSE;
+        break;
 
 
-                       }
 
 
 
 
-                       //
-                       // Realize the button bmp image
-                       //
+    //
+    // Implements slider logic
+    //
 
 
-                       SendMessage(buttons[i], BM_SETIMAGE, ( WPARAM )IMAGE_BITMAP, ( LPARAM )butbmps[i]);
+    case WM_HSCROLL :
+    {
+        switch( LOWORD( wParam ))
+        {
+        
+        case SB_ENDSCROLL:
+            break;
 
 
-                       UpdateWindow( buttons[i] );
+        case SB_PAGERIGHT:
+        case SB_PAGELEFT:
+        case TB_THUMBTRACK:
 
 
-                       disable_but( i );
 
 
-               }
+            //
+            // If the user touch the slider bar,
+            // set the audio start position properly
+            //
 
 
 
 
-               //
-               // Creating the SLIDER window
-               //
+            slider_pos = SendMessage( slider, TBM_GETPOS, 0, 0 );
 
 
-               slider = CreateWindow(
-                                               TRACKBAR_CLASS,
-                                               TEXT(""),
-                                               WS_CHILD|WS_VISIBLE|TBS_NOTICKS|TBS_HORZ|TBS_ENABLESELRANGE,
-                                               SLIDER_CX, SLIDER_CY, SLIDER_W, SLIDER_H, hWnd,
-                                               (HMENU)SLIDER_ID, hInst, 0
-                                       );
+            slid_samp = ( __int64 )slider_pos * ( __int64 )samples_max;
 
 
+            AUD_BUF->set_position(
+                    AUD_BUF->audinfo().bytes_in_samples(
+                                    ( unsigned int )( slid_samp / ( __int64 )slider_max )
+                                )
+                );
 
 
-               if ( !slider )
-               {
-                       MessageBox(0, 0, TEXT("CreateWindow() Error!"), 0);
-                       return FALSE;
+            InvalidateRect( hWnd, &text_rect, TRUE );
 
 
-               }
 
 
+            break;
 
 
-               //
-               // Sets slider limits
-               //
+        }
 
 
+        break;
+    }
 
 
-               SendMessage(
-                               slider,
-                               TBM_SETRANGE,
-                               (WPARAM)TRUE,
-                               (LPARAM)MAKELONG(slider_min,slider_max)
-                       );
 
 
 
 
-               UpdateWindow( slider );
 
 
-               enable_but( BUTREC_ID );
 
 
-               EnableWindow( slider, FALSE );
 
 
+    case WM_COMMAND:
 
 
+        wmId    = LOWORD( wParam );
+        wmEvent = HIWORD( wParam );
+        
+        if (( wmId >= 0 ) && ( wmId < 5 ) && ( butdisabled[wmId] == TRUE ))
+            break;
 
 
+        switch ( wmId )
+        {
 
 
-               break;
+        case ID_NEW:
 
 
+            if ( !isnew )
+            {
 
 
+                if ( AUD_IN->current_status() == snd::WAVEIN_RECORDING )
+                    AUD_IN->stop_recording();
 
 
-       //
-       // Implements slider logic
-       //
 
 
-       case WM_HSCROLL :
-       {
-               switch( LOWORD( wParam ))
-               {
+                if (( AUD_OUT->current_status() == snd::WAVEOUT_PLAYING ) ||
+                    ( AUD_OUT->current_status() == snd::WAVEOUT_PAUSED ))
+                    AUD_OUT->stop();
 
 
-               case SB_ENDSCROLL:
-                       break;
 
 
-               case SB_PAGERIGHT:
-               case SB_PAGELEFT:
-               case TB_THUMBTRACK:
+                AUD_BUF->reset();
 
 
+                enable_but( BUTREC_ID );
+                disable_but( BUTSTART_ID );
+                disable_but( BUTEND_ID );
+                disable_but( BUTSTOP_ID );
+                disable_but( BUTPLAY_ID );
 
 
-                       //
-                       // If the user touch the slider bar,
-                       // set the audio start position properly
-                       //
 
 
+                samples_max = AUD_BUF->total_samples();
+                slider_pos = 0;
 
 
-                       slider_pos = SendMessage( slider, TBM_GETPOS, 0, 0 );
+                SendMessage(slider, TBM_SETPOS, (WPARAM) TRUE, (LPARAM) slider_pos);
 
 
+                EnableMenuItem( GetMenu( hWnd ), ID_FILE_SAVEAS, MF_GRAYED );
+                EnableMenuItem( GetMenu( hWnd ), ID_FILE_SAVE, MF_GRAYED );
 
 
-                       AUD_BUF->set_position(
-                                       AUD_BUF->audinfo().bytes_in_samples(
-                                                                       (( slider_pos * samples_max ) / slider_max )
-                                                               )
-                               );
+                isnew = TRUE;
+                display_dur = TRUE;
 
 
+                ZeroMemory( file_path, MAX_PATH );
 
 
-                       break;
+                EnableWindow( slider, FALSE );
 
 
-               }
+                InvalidateRect( hWnd, &text_rect, TRUE );
+                InvalidateRect( hWnd, &text2_rect, TRUE );
 
 
-               break;
-       }
+            }
 
 
+            
+            
+            break;
 
 
 
 
 
 
 
 
+        case ID_FILE_OPEN:
 
 
-       case WM_COMMAND:
+            ZeroMemory( &ofn, sizeof( ofn ));
 
 
-               wmId    = LOWORD( wParam );
-               wmEvent = HIWORD( wParam );
+            ofn.lStructSize = sizeof( ofn );
+            ofn.hwndOwner = hWnd;
+            ofn.lpstrFilter = TEXT("Audio Files (*.wav)\0*.wav\0All Files (*.*)\0*.*\0");
+            ofn.lpstrFile = file_path;
+            ofn.nMaxFile = MAX_PATH;
+            ofn.Flags = OFN_EXPLORER | OFN_FILEMUSTEXIST | OFN_HIDEREADONLY;
+            ofn.lpstrDefExt = TEXT("wav");
 
 
-               if (( wmId >= 0 ) && ( wmId < 5 ) && ( butdisabled[wmId] == TRUE ))
-                       break;
+            if( GetOpenFileName( &ofn ))
+            {
+                open_wav( file_path );
+                EnableMenuItem( GetMenu( hWnd ), ID_FILE_SAVE, MF_ENABLED );
+                EnableMenuItem( GetMenu( hWnd ), ID_FILE_SAVEAS, MF_ENABLED );
 
 
-               switch (wmId)
-               {
+                EnableWindow( slider, TRUE );
 
 
-               case ID_NEW:
+            }
 
 
-                       if ( !isnew )
-                       {
+            InvalidateRect( hWnd, &text_rect, TRUE );
+            InvalidateRect( hWnd, &text2_rect, TRUE );
 
 
-                               if ( AUD_IN->current_status() == snd::WAVEIN_RECORDING )
-                                       AUD_IN->stop_recording();
+            break;
 
 
 
 
-                               if (( AUD_OUT->current_status() == snd::WAVEOUT_PLAYING ) ||
-                                       ( AUD_OUT->current_status() == snd::WAVEOUT_PAUSED ))
-                                       AUD_OUT->stop();
 
 
 
 
-                               AUD_BUF->reset();
+        case ID__ABOUT:
+            
 
 
-                               enable_but( BUTREC_ID );
-                               disable_but( BUTSTART_ID );
-                               disable_but( BUTEND_ID );
-                               disable_but( BUTSTOP_ID );
-                               disable_but( BUTPLAY_ID );
+            
+            break;
 
 
 
 
-                               samples_max = AUD_BUF->total_samples();
-                               slider_pos = 0;
+        case ID_FILE_SAVEAS:
 
 
-                               SendMessage(slider, TBM_SETPOS, (WPARAM) TRUE, (LPARAM) slider_pos);
+            ZeroMemory( &ofn, sizeof( ofn ));
 
 
-                               EnableMenuItem( GetMenu( hWnd ), ID_FILE_SAVEAS, MF_GRAYED );
-                               EnableMenuItem( GetMenu( hWnd ), ID_FILE_SAVE, MF_GRAYED );
+            ofn.lStructSize = sizeof( ofn );
+            ofn.hwndOwner         = hWnd ;
+            ofn.Flags             = OFN_OVERWRITEPROMPT;
+            ofn.lpstrFilter = TEXT("Audio Files (*.wav)\0*.wav\0All Files (*.*)\0*.*\0");
+            ofn.lpstrFile = file_path;
+            ofn.nMaxFile = MAX_PATH;
+            
+            ofn.lpstrDefExt = TEXT("wav");
+     
+            if ( GetSaveFileName ( &ofn )) 
+            {
+                write_wav( file_path );
 
 
-                               isnew = TRUE;
+                EnableMenuItem( GetMenu( hWnd ), ID_FILE_SAVE, MF_ENABLED );
+            }
 
 
-                               ZeroMemory( file_path, MAX_PATH );
+            break;
 
 
-                               EnableWindow( slider, FALSE );
+        case ID_EXIT:
+            DestroyWindow( hWnd );
+            break;
 
 
-                       }
 
 
+            //
+            // Sndrec32 buttons routines
+            //
 
 
+        case BUTSTART_ID:
 
 
-                       break;
+            AUD_BUF->set_position_start();
 
 
+            slider_pos = 0;
 
 
+            SendMessage( slider, TBM_SETPOS, (WPARAM) TRUE, (LPARAM) slider_pos );
 
 
+            break;
 
 
-               case ID_FILE_OPEN:
 
 
-                       ZeroMemory( &ofn, sizeof( ofn ));
+        case BUTEND_ID:
+            DestroyWindow( hWnd );
+            break;
 
 
-                       ofn.lStructSize = sizeof( ofn );
-                       ofn.hwndOwner = hWnd;
-                       ofn.lpstrFilter = TEXT("Audio Files (*.wav)\0*.wav\0All Files (*.*)\0*.*\0");
-                       ofn.lpstrFile = file_path;
-                       ofn.nMaxFile = MAX_PATH;
-                       ofn.Flags = OFN_EXPLORER | OFN_FILEMUSTEXIST | OFN_HIDEREADONLY;
-                       ofn.lpstrDefExt = TEXT("wav");
+        case BUTPLAY_ID:
+            
+            if ( wout_first == false )
+            {
+                AUD_OUT->open();
+                wout_first = true;
+            }
 
 
-                       if( GetOpenFileName( &ofn ))
-                       {
-                               open_wav( file_path );
-                               EnableMenuItem( GetMenu( hWnd ), ID_FILE_SAVE, MF_ENABLED );
-                               EnableMenuItem( GetMenu( hWnd ), ID_FILE_SAVEAS, MF_ENABLED );
 
 
-                               EnableWindow( slider, TRUE );
+            AUD_OUT->play();
 
 
-                       }
+            disable_but( BUTSTART_ID );
+            disable_but( BUTEND_ID );
+            disable_but( BUTREC_ID );
+            disable_but( BUTPLAY_ID );
 
 
-                       break;
 
 
+            SetTimer( hWnd, 1, 250, 0 );
+            SetTimer( hWnd, WAVEBAR_TIMERID, WAVEBAR_TIMERTIME, 0 );
 
 
+            break;
 
 
+        case BUTSTOP_ID:
+            if ( s_recording )
+            {
+                s_recording = FALSE;
 
 
-               case ID__ABOUT:
+                AUD_IN->stop_recording();
 
 
+                
 
 
+                //
+                // Resetting slider position
+                //
+                
+                slider_pos = 0;
+                SendMessage(slider, TBM_SETPOS, (WPARAM) TRUE, (LPARAM) slider_pos);
 
 
-                       break;
 
 
+                samples_max = AUD_BUF->samples_received();
 
 
-               case ID_FILE_SAVEAS:
+                EnableMenuItem((HMENU)IDR_MENU1, ID_FILE_SAVEAS, MF_ENABLED );
 
 
-                       ZeroMemory( &ofn, sizeof( ofn ));
 
 
-                       ofn.lStructSize = sizeof( ofn );
-                       ofn.hwndOwner         = hWnd ;
-                       ofn.Flags             = OFN_OVERWRITEPROMPT;
-                       ofn.lpstrFilter = TEXT("Audio Files (*.wav)\0*.wav\0All Files (*.*)\0*.*\0");
-                       ofn.lpstrFile = file_path;
-                       ofn.nMaxFile = MAX_PATH;
+                enable_but( BUTSTART_ID );
+                enable_but( BUTEND_ID );
+                enable_but( BUTREC_ID );
+                enable_but( BUTPLAY_ID );
 
 
-                       ofn.lpstrDefExt = TEXT("wav");
+                EnableMenuItem( GetMenu( hWnd ), ID_FILE_SAVEAS, MF_ENABLED );
+                EnableWindow( slider, TRUE );
 
 
-                       if ( GetSaveFileName ( &ofn ))
-                       {
-                               write_wav( file_path );
+                display_dur = FALSE;
 
 
-                               EnableMenuItem( GetMenu( hWnd ), ID_FILE_SAVE, MF_ENABLED );
-                       }
+                AUD_BUF->truncate();
 
 
-                       break;
+                InvalidateRect( hWnd, &text_rect, TRUE );
+                InvalidateRect( wave_win, 0, TRUE );
 
 
-               case ID_EXIT:
-                       DestroyWindow( hWnd );
-                       break;
 
 
+            } else {
 
 
-                       //
-                       // Sndrec32 buttons routines
-                       //
+                AUD_OUT->pause();
 
 
-               case BUTSTART_ID:
+                enable_but( BUTSTART_ID );
+                enable_but( BUTEND_ID );
+                enable_but( BUTREC_ID );
+                enable_but( BUTPLAY_ID );
 
 
-                       AUD_BUF->set_position_start();
+            }
 
 
-                       slider_pos = 0;
+            KillTimer( hWnd, 1 );
+            KillTimer( hWnd, WAVEBAR_TIMERID );
 
 
-                       SendMessage( slider, TBM_SETPOS, (WPARAM) TRUE, (LPARAM) slider_pos );
+            InvalidateRect( hWnd, &text_rect, TRUE );
+            
+            break;
 
 
-                       break;
+        case BUTREC_ID:
 
 
+            if ( win_first == false )
+            {
+                AUD_IN->open();
+                win_first = true;
+            }
 
 
-               case BUTEND_ID:
-                       //Beep(300,200);
-                       break;
+            s_recording = TRUE;
 
 
-               case BUTPLAY_ID:
+            samples_max = AUD_BUF->total_samples();
 
 
-                       AUD_OUT->play();
+            AUD_IN->start_recording();
 
 
-                       disable_but( BUTSTART_ID );
-                       disable_but( BUTEND_ID );
-                       disable_but( BUTREC_ID );
-                       disable_but( BUTPLAY_ID );
+            enable_but( BUTSTOP_ID );
 
 
+            disable_but( BUTSTART_ID );
+            disable_but( BUTEND_ID );
+            disable_but( BUTREC_ID );
+            disable_but( BUTPLAY_ID );
 
 
-                       SetTimer( hWnd, 1, 250, 0 );
+            isnew = FALSE;
 
 
-                       break;
+            EnableWindow( slider, FALSE );
 
 
-               case BUTSTOP_ID:
-                       if ( s_recording )
-                       {
-                               s_recording = FALSE;
+            SetTimer( hWnd, 1, 150, 0 );
 
 
-                               AUD_IN->stop_recording();
+            SetTimer( hWnd, WAVEBAR_TIMERID, WAVEBAR_TIMERTIME, 0 );
 
 
+            break;
 
 
 
 
-                               //
-                               // Resetting slider position
-                               //
+        default:
+            return DefWindowProc(hWnd, message, wParam, lParam);
+        }
+        break;
 
 
-                               slider_pos = 0;
-                               SendMessage(slider, TBM_SETPOS, (WPARAM) TRUE, (LPARAM) slider_pos);
 
 
+    case WM_TIMER:
 
 
-                               samples_max = AUD_BUF->samples_received();
+        switch ( wParam )
+        {
 
 
-                               EnableMenuItem((HMENU)IDR_MENU1, ID_FILE_SAVEAS, MF_ENABLED );
+        case 1: 
+            if ( stopped_flag )
+            {
+                KillTimer( hWnd, 1 );
+                KillTimer( hWnd, WAVEBAR_TIMERID );
+                slider_pos = 0;
 
 
+                enable_but( BUTPLAY_ID );
 
 
-                               enable_but( BUTSTART_ID );
-                               enable_but( BUTEND_ID );
-                               enable_but( BUTREC_ID );
-                               enable_but( BUTPLAY_ID );
+                stopped_flag = FALSE;
+            }
 
 
-                               EnableMenuItem( GetMenu( hWnd ), ID_FILE_SAVEAS, MF_ENABLED );
-                               EnableWindow( slider, TRUE );
 
 
 
 
+            SendMessage( 
+                        slider, 
+                        TBM_SETPOS, 
+                        ( WPARAM ) TRUE, 
+                        ( LPARAM ) slider_pos 
+                    );
 
 
-                       } else {
+            InvalidateRect( hWnd, &text_rect, TRUE );
+            break;
 
 
-                               AUD_OUT->pause();
 
 
-                               enable_but( BUTSTART_ID );
-                               enable_but( BUTEND_ID );
-                               enable_but( BUTREC_ID );
-                               enable_but( BUTPLAY_ID );
 
 
-                       }
+        case WAVEBAR_TIMERID:
+            InvalidateRect( wave_win, 0, TRUE );
+            SendMessage( wave_win, WM_USER, 0, 0 );
+            break;
 
 
-                       KillTimer( hWnd, 1 );
+        }
 
 
-                       break;
+        break;
 
 
-               case BUTREC_ID:
 
 
-                       s_recording = TRUE;
 
 
-                       samples_max = AUD_BUF->total_samples();
+    case WM_PAINT:
 
 
-                       AUD_IN->start_recording();
 
 
-                       enable_but( BUTSTOP_ID );
+        hdc = BeginPaint(hWnd, &ps);
 
 
-                       disable_but( BUTSTART_ID );
-                       disable_but( BUTEND_ID );
-                       disable_but( BUTREC_ID );
-                       disable_but( BUTPLAY_ID );
 
 
-                       isnew = FALSE;
+        font = CreateFontIndirect( &s_info.lfMenuFont );
 
 
-                       EnableWindow( slider, FALSE );
 
 
-                       SetTimer( hWnd, 1, 150, 0 );
+        SelectObject( hdc, font );
 
 
-                       break;
+        SetBkMode( hdc, TRANSPARENT );
 
 
 
 
-               default:
-                       return DefWindowProc(hWnd, message, wParam, lParam);
-               }
-               break;
+        if ( AUD_IN->current_status() == snd::WAVEIN_RECORDING )
+        {
+            gprintf(
+                    str_tmp,
+                    MAX_LOADSTRING,
+                    str_pos,
+                    ( float )(( float )AUD_BUF->bytes_recorded( ) / ( float )AUD_BUF->audinfo().byte_rate( ))
+                );
 
 
+        } else if ( AUD_OUT->current_status() == snd::WAVEOUT_PLAYING ) {
 
 
-       case WM_TIMER:
+            gprintf(
+                    str_tmp,
+                    MAX_LOADSTRING,
+                    str_pos,
+                    ( float )(( float )AUD_BUF->bytes_played() / ( float )AUD_BUF->audinfo().byte_rate( ))
+                );
 
 
-               if ( stopped_flag )
-               {
-                       KillTimer(hWnd, 1);
-                       slider_pos = 0;
+        } else {
 
 
-                       enable_but( BUTPLAY_ID );
+            gprintf(
+                    str_tmp,
+                    MAX_LOADSTRING,
+                    str_pos,
+                    ( float )(((( float )slider_pos * ( float )samples_max ) / ( float )slider_max ) / ( float )AUD_BUF->audinfo().sample_rate())
+                );
+        }
 
 
-                       stopped_flag = FALSE;
-               }
 
 
-               SendMessage( slider, TBM_SETPOS, (WPARAM) TRUE, (LPARAM) slider_pos );
+        ExtTextOut( hdc, STRPOS_X, STRPOS_Y, ETO_OPAQUE, 
+                    0, str_tmp, _tcslen( str_tmp ), 0 );
 
 
 
 
+        if ( display_dur )
+        {
 
 
-               break;
+            gprintf( str_tmp, MAX_LOADSTRING, str_dur, 
+                                AUD_BUF->fseconds_total( ));
+        
+        } else {
 
 
 
 
+            gprintf( str_tmp, MAX_LOADSTRING, str_dur, 
+                                AUD_BUF->fseconds_recorded( ));
+        }
 
 
-       case WM_PAINT:
 
 
-               InvalidateRect( hWnd, &rect, TRUE );
-               hdc = BeginPaint(hWnd, &ps);
 
 
-               EndPaint(hWnd, &ps);
-               break;
-       case WM_DESTROY:
-               PostQuitMessage(0);
-               break;
-       default:
-               return DefWindowProc(hWnd, message, wParam, lParam);
-       }
-       return 0;
+        ExtTextOut( hdc, STRDUR_X, STRDUR_Y, ETO_OPAQUE, 
+                    0, str_tmp, _tcslen( str_tmp ), 0 );
+       
+
+
+        gprintf(
+                    str_tmp,
+                    MAX_LOADSTRING,
+                    str_buf,
+                    ( float )(( float )AUD_BUF->mem_size() / 1024.0f )
+                );
+
+
+        ExtTextOut( hdc, STRBUF_X, STRBUF_Y, ETO_OPAQUE, 
+                    0, str_tmp, _tcslen( str_tmp ), 0 );
+
+
+
+        gprintf(
+                    str_tmp,
+                    MAX_LOADSTRING,
+                    str_fmt,
+                    ( float )(( float )AUD_BUF->audinfo().sample_rate() / 1000.0f ),
+                    AUD_BUF->audinfo().bits(),
+                    AUD_BUF->audinfo().channels() == 2 ? str_mono : str_stereo
+                );
+
+
+        ExtTextOut( hdc, STRFMT_X, STRFMT_Y, ETO_OPAQUE, 
+                    0, str_tmp, _tcslen( str_tmp ), 0 );
+
+
+
+        gprintf(
+                    str_tmp,
+                    MAX_LOADSTRING,
+                    str_chan,
+                    AUD_BUF->audinfo().channels() == 2 ? str_stereo : str_mono
+                );
+
+
+        ExtTextOut( hdc, STRCHAN_X, STRCHAN_Y, ETO_OPAQUE, 
+                    0, str_tmp, _tcslen( str_tmp ), 0 );
+
+        
+
+        DeleteObject( font );
+
+        EndPaint(hWnd, &ps);
+
+
+        break;
+
+
+
+
+    case WM_DESTROY:
+        PostQuitMessage(0);
+        break;
+    default:
+        return DefWindowProc( hWnd, message, wParam, lParam );
+    }
+    return 0;
 }
 
 
 }
 
 
@@ -661,15 +1140,15 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
 void l_play_finished ( void )
 {
 
 void l_play_finished ( void )
 {
 
-       stopped_flag = true;
+    stopped_flag = true;
 
 
 
 
-       enable_but( BUTSTART_ID );
-       enable_but( BUTEND_ID );
-       enable_but( BUTREC_ID );
-       enable_but( BUTPLAY_ID );
-
+    enable_but( BUTSTART_ID );
+    enable_but( BUTEND_ID );
+    enable_but( BUTREC_ID );
+    enable_but( BUTPLAY_ID );
 
 
+    InvalidateRect( wave_win, 0, TRUE );
 
 }
 
 
 }
 
@@ -677,8 +1156,8 @@ void l_audio_arrival ( unsigned int samples_arrival )
 {
 
 
 {
 
 
-       slider_pos += (DWORD) (( slider_max * samples_arrival ) / samples_max );
-
+    slider_pos += ( DWORD ) (( slider_max * samples_arrival ) / samples_max );
+    
 
 }
 
 
 }
 
@@ -694,18 +1173,18 @@ void l_buffer_resized ( unsigned int new_size )
 VOID enable_but( DWORD id )
 {
 
 VOID enable_but( DWORD id )
 {
 
-       butdisabled[ id ] = FALSE;
+    butdisabled[ id ] = FALSE;
 
 
-       SendMessage(buttons[ id ], BM_SETIMAGE, ( WPARAM )IMAGE_BITMAP, ( LPARAM )butbmps[ id ]);
+    SendMessage(buttons[ id ], BM_SETIMAGE, ( WPARAM )IMAGE_BITMAP, ( LPARAM )butbmps[ id ]);
 
 
 }
 VOID disable_but( DWORD id )
 {
 
 
 
 }
 VOID disable_but( DWORD id )
 {
 
-       butdisabled[ id ] = TRUE;
+    butdisabled[ id ] = TRUE;
 
 
-       SendMessage(buttons[ id ], BM_SETIMAGE, ( WPARAM )IMAGE_BITMAP, ( LPARAM )butbmps_dis[ id ]);
+    SendMessage(buttons[ id ], BM_SETIMAGE, ( WPARAM )IMAGE_BITMAP, ( LPARAM )butbmps_dis[ id ]);
 
 }
 
 
 }
 
@@ -728,160 +1207,160 @@ BOOL open_wav( TCHAR * f )
 {
 
 
 {
 
 
-       HANDLE file;
+    HANDLE file;
+    
+    riff_hdr r;
+    wave_hdr w;
+    data_chunk d;
 
 
-       riff_hdr r;
-       wave_hdr w;
-       data_chunk d;
+    BOOL b;
 
 
-       BOOL b;
+    DWORD bytes_recorded_in_wav = 0;
+    DWORD is_read = 0;
 
 
-       DWORD bytes_recorded_in_wav = 0;
-       DWORD is_read = 0;
 
 
+    file = CreateFile( 
+                    f, 
+                    GENERIC_READ, 
+                    0, 0,
+                    OPEN_EXISTING,
+                    FILE_ATTRIBUTE_NORMAL, 
+                    0 
+                );
 
 
-       file = CreateFile(
-                                       f,
-                                       GENERIC_READ,
-                                       0, 0,
-                                       OPEN_EXISTING,
-                                       FILE_ATTRIBUTE_NORMAL,
-                                       0
-                               );
 
 
 
 
+    if ( !file )
+    {
+        MessageBox( 
+                    main_win, 
+                    TEXT("Cannot open file. CreateFile() error."), 
+                    TEXT("ERROR"), 
+                    MB_OK|MB_ICONERROR
+                );
 
 
-       if ( !file )
-       {
-               MessageBox(
-                                       main_win,
-                                       TEXT("Cannot open file. CreateFile() error."),
-                                       TEXT("ERROR"),
-                                       MB_OK|MB_ICONERROR
-                               );
+        return FALSE;
+    }
 
 
-               return FALSE;
-       }
 
 
+    b = ReadFile( file, ( LPVOID ) &r, sizeof ( r ), &is_read, 0 );
 
 
-       b = ReadFile( file, ( LPVOID ) &r, sizeof ( r ), &is_read, 0 );
+    if ( !b )
+    {
+        MessageBox( 
+                    main_win, 
+                    TEXT("Cannot read RIFF header."), 
+                    TEXT("ERROR"), 
+                    MB_OK|MB_ICONERROR
+                );
 
 
-       if ( !b )
-       {
-               MessageBox(
-                                       main_win,
-                                       TEXT("Cannot read RIFF header."),
-                                       TEXT("ERROR"),
-                                       MB_OK|MB_ICONERROR
-                               );
+        CloseHandle( file );
+        return FALSE;
+    }
 
 
-               CloseHandle( file );
-               return FALSE;
-       }
 
 
+    b = ReadFile( file, ( LPVOID ) &w, sizeof ( w ), &is_read, 0 );
 
 
-       b = ReadFile( file, ( LPVOID ) &w, sizeof ( w ), &is_read, 0 );
 
 
+    if ( !b )
+    {
+        MessageBox( 
+                    main_win, 
+                    TEXT("Cannot read WAVE header."), 
+                    TEXT("ERROR"), 
+                    MB_OK|MB_ICONERROR
+                );
 
 
-       if ( !b )
-       {
-               MessageBox(
-                                       main_win,
-                                       TEXT("Cannot read WAVE header."),
-                                       TEXT("ERROR"),
-                                       MB_OK|MB_ICONERROR
-                               );
+        CloseHandle( file );
+        return FALSE;
+    }
 
 
-               CloseHandle( file );
-               return FALSE;
-       }
 
 
 
 
+    b = ReadFile( file, ( LPVOID ) &d, sizeof ( d ), &is_read, 0 );
 
 
-       b = ReadFile( file, ( LPVOID ) &d, sizeof ( d ), &is_read, 0 );
+    if ( !b )
+    {
+        MessageBox( 
+                    main_win, 
+                    TEXT("Cannot read WAVE subchunk."), 
+                    TEXT("ERROR"), 
+                    MB_OK|MB_ICONERROR
+                );
 
 
-       if ( !b )
-       {
-               MessageBox(
-                                       main_win,
-                                       TEXT("Cannot read WAVE subchunk."),
-                                       TEXT("ERROR"),
-                                       MB_OK|MB_ICONERROR
-                               );
+        CloseHandle( file );
+        return FALSE;
+    }
 
 
-               CloseHandle( file );
-               return FALSE;
-       }
+    bytes_recorded_in_wav = r.chunksize - 36;
 
 
-       bytes_recorded_in_wav = r.chunksize - 36;
 
 
+    if ( bytes_recorded_in_wav == 0 )
+    {
+        MessageBox( 
+                    main_win, 
+                    TEXT("Cannot read file. No audio data."), 
+                    TEXT("ERROR"), 
+                    MB_OK|MB_ICONERROR
+                );
 
 
-       if ( bytes_recorded_in_wav == 0 )
-       {
-               MessageBox(
-                                       main_win,
-                                       TEXT("Cannot read file. No audio data."),
-                                       TEXT("ERROR"),
-                                       MB_OK|MB_ICONERROR
-                               );
+        CloseHandle( file );
+        return FALSE;
+    }
 
 
-               CloseHandle( file );
-               return FALSE;
-       }
 
 
+    snd::audio_format openfmt
+        ( w.SampleRate, w.BitsPerSample, w.NumChannels );
 
 
-       snd::audio_format openfmt
-               ( w.SampleRate, w.BitsPerSample, w.NumChannels );
 
 
 
 
+    AUD_BUF->clear();
 
 
-       AUD_BUF->clear();
 
 
+    AUD_BUF->alloc_bytes( bytes_recorded_in_wav );
 
 
-       AUD_BUF->alloc_bytes( bytes_recorded_in_wav );
 
 
+    b = ReadFile(
+                file, 
+                ( LPVOID ) AUD_BUF->audio_buffer(), 
+                bytes_recorded_in_wav,
+                &is_read,
+                0
+            );
 
 
-       b = ReadFile(
-                               file,
-                               ( LPVOID ) AUD_BUF->audio_buffer(),
-                               bytes_recorded_in_wav,
-                               &is_read,
-                               0
-                       );
 
 
+    AUD_BUF->set_b_received( bytes_recorded_in_wav );
 
 
-       AUD_BUF->set_b_received( bytes_recorded_in_wav );
 
 
+    if (( !b ) || ( is_read != bytes_recorded_in_wav ))
+    {
+        MessageBox( 
+                    main_win, 
+                    TEXT("Cannot read file. Error reading audio data."), 
+                    TEXT("ERROR"), 
+                    MB_OK|MB_ICONERROR
+                );
 
 
-       if (( !b ) || ( is_read != bytes_recorded_in_wav ))
-       {
-               MessageBox(
-                                       main_win,
-                                       TEXT("Cannot read file. Error reading audio data."),
-                                       TEXT("ERROR"),
-                                       MB_OK|MB_ICONERROR
-                               );
+        CloseHandle( file );
 
 
-               CloseHandle( file );
+        AUD_BUF->reset();
+        return FALSE;
+    }
 
 
-               AUD_BUF->reset();
-               return FALSE;
-       }
+    CloseHandle( file );
 
 
-       CloseHandle( file );
+    enable_but( BUTPLAY_ID );
+    enable_but( BUTSTOP_ID );
+    enable_but( BUTSTART_ID );
+    enable_but( BUTEND_ID );
+    enable_but( BUTREC_ID );
 
 
-       enable_but( BUTPLAY_ID );
-       enable_but( BUTSTOP_ID );
-       enable_but( BUTSTART_ID );
-       enable_but( BUTEND_ID );
-       enable_but( BUTREC_ID );
 
 
+    samples_max = AUD_BUF->samples_received();
 
 
-       samples_max = AUD_BUF->samples_received();
+    isnew = FALSE;
 
 
-       isnew = FALSE;
-
-       return TRUE;
+    return TRUE;
 
 }
 
 
 }
 
@@ -890,181 +1369,181 @@ BOOL
 write_wav( TCHAR * f )
 {
 
 write_wav( TCHAR * f )
 {
 
-       HANDLE file;
-
-
-       DWORD written;
-       BOOL is_writ;
-       int i;
-       riff_hdr r;
-       wave_hdr w;
-       data_chunk d;
-
-
-
-       file = CreateFile(
-                                       f,
-                                       GENERIC_WRITE,
-                                       0, 0,
-                                       CREATE_NEW,
-                                       FILE_ATTRIBUTE_NORMAL,
-                                       0
-                               );
-
-
-
-       if ( !file )
-       {
-               i = MessageBox(
-                                       main_win,
-                                       TEXT("File already exist. Overwrite it?"),
-                                       TEXT("Warning"),
-                                       MB_YESNO|MB_ICONQUESTION
-                               );
-
-               if ( i == IDYES )
-               {
-
-                       file = CreateFile(
-                                                       f,
-                                                       GENERIC_WRITE,
-                                                       0, 0,
-                                                       CREATE_ALWAYS,
-                                                       FILE_ATTRIBUTE_NORMAL,
-                                                       0
-                                               );
-
-                       if ( !file )
-                       {
-                               MessageBox(
-                                               main_win,
-                                               TEXT("File Error, CreateFile() failed."),
-                                               TEXT("ERROR"),
-                                               MB_OK|MB_ICONERROR
-                                       );
-
-
-                               return FALSE;
+    HANDLE file;
+    
+    
+    DWORD written;
+    BOOL is_writ;
+    int i;
+    riff_hdr r;
+    wave_hdr w;
+    data_chunk d;
 
 
-                       }
 
 
 
 
-               } else
-                       return FALSE;
-       }
+    file = CreateFile( 
+                    f, 
+                    GENERIC_WRITE, 
+                    0, 0,
+                    CREATE_NEW,
+                    FILE_ATTRIBUTE_NORMAL, 
+                    0 
+                );
 
 
 
 
 
 
+    if ( !file )
+    {
+        i = MessageBox( 
+                    main_win, 
+                    TEXT("File already exist. Overwrite it?"), 
+                    TEXT("Warning"), 
+                    MB_YESNO|MB_ICONQUESTION
+                );
 
 
-       r.magic = 0x46464952;
+        if ( i == IDYES )
+        {
 
 
+            file = CreateFile( 
+                            f, 
+                            GENERIC_WRITE, 
+                            0, 0,
+                            CREATE_ALWAYS,
+                            FILE_ATTRIBUTE_NORMAL, 
+                            0 
+                        );
 
 
-       r.format = 0x45564157;
-       r.chunksize = 36 + AUD_BUF->bytes_recorded();
+            if ( !file )
+            {
+                MessageBox( 
+                        main_win, 
+                        TEXT("File Error, CreateFile() failed."), 
+                        TEXT("ERROR"), 
+                        MB_OK|MB_ICONERROR
+                    );
 
 
 
 
-       w.Subchunkid = 0x20746d66;
+                return FALSE;
 
 
-       w.Subchunk1Size = 16;
-       w.AudioFormat = 1;
-       w.NumChannels = AUD_BUF->audinfo().channels();
-       w.SampleRate = AUD_BUF->audinfo().sample_rate();
-       w.ByteRate = AUD_BUF->audinfo().byte_rate();
-       w.BlockAlign = AUD_BUF->audinfo().block_align();
-       w.BitsPerSample = AUD_BUF->audinfo().bits();
+            }
 
 
 
 
-       d.subc = 0x61746164;
-       d.subc_size = AUD_BUF->bytes_recorded();
+        } else
+            return FALSE;
+    }
 
 
 
 
+    
+                        
+    r.magic = 0x46464952;
 
 
-       //
-       // Writing headers
-       //
+                            
+    r.format = 0x45564157;
+    r.chunksize = 36 + AUD_BUF->bytes_recorded();
 
 
+                            
+    w.Subchunkid = 0x20746d66;
 
 
-       is_writ = WriteFile( file, ( LPCVOID ) &r, sizeof ( r ), &written, 0 );
+    w.Subchunk1Size = 16;
+    w.AudioFormat = 1;
+    w.NumChannels = AUD_BUF->audinfo().channels();
+    w.SampleRate = AUD_BUF->audinfo().sample_rate();
+    w.ByteRate = AUD_BUF->audinfo().byte_rate();
+    w.BlockAlign = AUD_BUF->audinfo().block_align();
+    w.BitsPerSample = AUD_BUF->audinfo().bits();
 
 
-       if ( !is_writ )
-       {
-               MessageBox(
-                               main_win,
-                               TEXT("File Error, WriteFile() failed."),
-                               TEXT("ERROR"),
-                               MB_OK|MB_ICONERROR
-                       );
+                            
+    d.subc = 0x61746164;
+    d.subc_size = AUD_BUF->bytes_recorded();
 
 
-               CloseHandle( file );
 
 
-               return FALSE;
 
 
-       }
+    //
+    // Writing headers
+    //
 
 
+    
+    is_writ = WriteFile( file, ( LPCVOID ) &r, sizeof ( r ), &written, 0 );
 
 
-       is_writ = WriteFile( file, ( LPCVOID ) &w, sizeof ( w ), &written, 0 );
+    if ( !is_writ )
+    {
+        MessageBox( 
+                main_win, 
+                TEXT("File Error, WriteFile() failed."), 
+                TEXT("ERROR"), 
+                MB_OK|MB_ICONERROR
+            );
+        
+        CloseHandle( file );
 
 
-       if ( !is_writ )
-       {
-               MessageBox(
-                               main_win,
-                               TEXT("File Error, WriteFile() failed."),
-                               TEXT("ERROR"),
-                               MB_OK|MB_ICONERROR
-                       );
+        return FALSE;
 
 
-               CloseHandle( file );
+    }
 
 
-               return FALSE;
 
 
-       }
+    is_writ = WriteFile( file, ( LPCVOID ) &w, sizeof ( w ), &written, 0 );
 
 
+    if ( !is_writ )
+    {
+        MessageBox( 
+                main_win, 
+                TEXT("File Error, WriteFile() failed."), 
+                TEXT("ERROR"), 
+                MB_OK|MB_ICONERROR
+            );
+        
+        CloseHandle( file );
 
 
-       is_writ = WriteFile( file, ( LPCVOID ) &d, sizeof ( d ), &written, 0 );
+        return FALSE;
 
 
+    }
 
 
-       if ( !is_writ )
-       {
-               MessageBox(
-                               main_win,
-                               TEXT("File Error, WriteFile() failed."),
-                               TEXT("ERROR"),
-                               MB_OK|MB_ICONERROR
-                       );
 
 
-               CloseHandle( file );
+    is_writ = WriteFile( file, ( LPCVOID ) &d, sizeof ( d ), &written, 0 );
 
 
-               return FALSE;
 
 
-       }
+    if ( !is_writ )
+    {
+        MessageBox( 
+                main_win, 
+                TEXT("File Error, WriteFile() failed."), 
+                TEXT("ERROR"), 
+                MB_OK|MB_ICONERROR
+            );
+        
+        CloseHandle( file );
 
 
+        return FALSE;
 
 
+    }
 
 
-       is_writ = WriteFile(
-                                       file,
-                                       ( LPCVOID ) AUD_BUF->audio_buffer(),
-                                       AUD_BUF->bytes_recorded(),
-                                       &written,
-                                       0
-                               );
 
 
-       if ( !is_writ )
-       {
-               MessageBox(
-                               main_win,
-                               TEXT("File Error, WriteFile() failed."),
-                               TEXT("ERROR"),
-                               MB_OK|MB_ICONERROR
-                       );
+    
+    is_writ = WriteFile( 
+                    file, 
+                    ( LPCVOID ) AUD_BUF->audio_buffer(), 
+                    AUD_BUF->bytes_recorded(), 
+                    &written, 
+                    0 
+                );
 
 
-               CloseHandle( file );
+    if ( !is_writ )
+    {
+        MessageBox( 
+                main_win, 
+                TEXT("File Error, WriteFile() failed."), 
+                TEXT("ERROR"), 
+                MB_OK|MB_ICONERROR
+            );
 
 
-               return FALSE;
+        CloseHandle( file );
+        
+        return FALSE;
 
 
-       }
+    }
 
 
 
 
-       CloseHandle( file );
+    CloseHandle( file );
 
 
-       return TRUE;
+    return TRUE;
 }
 }
index a8973f9..2f3dfa4 100644 (file)
@@ -1,3 +1,12 @@
+/* PROJECT:         ReactOS sndrec32
+ * LICENSE:         GPL - See COPYING in the top level directory
+ * FILE:            base/applications/sndrec32/sndrec.h
+ * PURPOSE:         Sound recording
+ * PROGRAMMERS:     Marco Pagliaricci (irc: rendar)
+ */
+
+
+
 #pragma once
 
 #include "resource.h"
 #pragma once
 
 #include "resource.h"
 #define BUTSTOP_ID 3
 #define BUTREC_ID 4
 #define SLIDER_ID 5
 #define BUTSTOP_ID 3
 #define BUTREC_ID 4
 #define SLIDER_ID 5
+#define WAVEBAR_ID 6
 
 #define BUTTONS_H 30
 #define BUTTONS_W 60
 #define BUTTONS_CY 100
 
 #define BUTTONS_H 30
 #define BUTTONS_W 60
 #define BUTTONS_CY 100
-#define BUTTONS_CX CONTROLS_CX
+#define BUTTONS_CX ( CONTROLS_CX )
 #define BUTTONS_SPACE 5
 
 
 #define BUTTONS_SPACE 5
 
 
+
 #define SLIDER_CX CONTROLS_CX
 #define SLIDER_CY 65
 #define SLIDER_H 30
 #define SLIDER_W 320
 
 
 #define SLIDER_CX CONTROLS_CX
 #define SLIDER_CY 65
 #define SLIDER_H 30
 #define SLIDER_W 320
 
 
+#define STRPOS_X 240
+#define STRPOS_Y 5
+
+#define STRDUR_X ( STRPOS_X )
+#define STRDUR_Y ( STRPOS_Y + 13 )
+
+#define STRBUF_X ( STRDUR_X )
+#define STRBUF_Y ( STRDUR_Y + 13 )
+
+
+#define STRFMT_X 10
+#define STRFMT_Y ( STRPOS_Y )
+
+#define STRCHAN_X ( STRFMT_X )
+#define STRCHAN_Y ( STRFMT_Y + 13 )
+
+
+#define WAVEBAR_X ( CONTROLS_CX + 90 )
+#define WAVEBAR_Y ( STRPOS_Y )
+#define WAVEBAR_CX 130
+#define WAVEBAR_CY 50
+
+#define WAVEBAR_TIMERID 2
+#define WAVEBAR_TIMERTIME 80
+
+#define WAVEBAR_COLOR ( RGB( 0, 0, 255 ))
+
+#define REFRESHA_X ( STRPOS_X )
+#define REFRESHA_Y ( STRPOS_Y )
+#define REFRESHA_CX ( REFRESHA_X + 100 )
+#define REFRESHA_CY ( REFRESHA_Y + 55 )
+
+
+#define REFRESHB_X ( STRFMT_X )
+#define REFRESHB_Y ( STRFMT_Y )
+#define REFRESHB_CX ( REFRESHB_X + 85 )
+#define REFRESHB_CY ( REFRESHB_Y + 55 )
 
 
 struct riff_hdr
 {
 
 
 struct riff_hdr
 {
-       DWORD magic;
-       DWORD chunksize;
-       DWORD format;
+    DWORD magic;
+    DWORD chunksize;
+    DWORD format;
 };
 
 
 struct wave_hdr
 {
 };
 
 
 struct wave_hdr
 {
-
-       DWORD Subchunkid;
-       DWORD Subchunk1Size;
-       WORD AudioFormat;
-       WORD NumChannels;
-       DWORD SampleRate;
-       DWORD ByteRate;
-       WORD BlockAlign;
-       WORD BitsPerSample;
+    
+    DWORD Subchunkid;
+    DWORD Subchunk1Size;
+    WORD AudioFormat;
+    WORD NumChannels;
+    DWORD SampleRate;
+    DWORD ByteRate;
+    WORD BlockAlign;
+    WORD BitsPerSample;
 };
 
 struct data_chunk
 {
 };
 
 struct data_chunk
 {
-       DWORD subc;
-       DWORD subc_size;
-       //unsigned char data[];
+    DWORD subc;
+    DWORD subc_size;
+    //unsigned char data[];
 };
 
 
 };
 
 
@@ -71,7 +119,7 @@ struct data_chunk
 //
 // Functions prototypes
 //
 //
 // Functions prototypes
 //
-LRESULT CALLBACK
+LRESULT CALLBACK 
 Buttons_proc(HWND, UINT, WPARAM, LPARAM);
 
 
 Buttons_proc(HWND, UINT, WPARAM, LPARAM);
 
 
@@ -87,11 +135,11 @@ VOID disable_but( DWORD );
 
 
 
 
 
 
-void
+void 
 l_play_finished ( void );
 
 l_play_finished ( void );
 
-void
+void 
 l_audio_arrival ( unsigned int );
 
 l_audio_arrival ( unsigned int );
 
-void
+void 
 l_buffer_resized ( unsigned int );
 l_buffer_resized ( unsigned int );
index 5098c75..f101a14 100644 (file)
@@ -7,6 +7,7 @@
        <library>msacm32</library>
        <library>comctl32</library>
        <library>comdlg32</library>
        <library>msacm32</library>
        <library>comctl32</library>
        <library>comdlg32</library>
+       <library>gdi32</library>
        <file>audio_format.cpp</file>
        <file>audio_membuffer.cpp</file>
        <file>audio_producer.cpp</file>
        <file>audio_format.cpp</file>
        <file>audio_membuffer.cpp</file>
        <file>audio_producer.cpp</file>
index f81c55e..89eb838 100644 (file)
@@ -1,23 +1,23 @@
-// stdafx.h : file di inclusione per file di inclusione di sistema standard
-// o file di inclusione specifici del progetto utilizzati di frequente, ma
-// modificati raramente
-//
-
 #pragma once
 
 #include "targetver.h"
 
 #pragma once
 
 #include "targetver.h"
 
-#define WIN32_LEAN_AND_MEAN             // Escludere gli elementi utilizzati di rado dalle intestazioni di Windows
-// File di intestazione di Windows:
-#include <windows.h>
-#include <commctrl.h>
-#include <commdlg.h>
+#define WIN32_LEAN_AND_MEAN
+
+
+#ifdef _UNICODE
+       #define _sntprintf_s    _snwprintf_s
+#else
+       #define _sntprintf_s    _snprintf_s
+#endif
+
 
 
-// File di intestazione Runtime C
 #include <stdlib.h>
 #include <stdlib.h>
-#include <malloc.h>
-#include <memory.h>
+#include <stdio.h>
 #include <tchar.h>
 #include <tchar.h>
+#include <string.h>
 
 
-
-// TODO: fare riferimento qui alle intestazioni aggiuntive richieste dal programma
+#include <windows.h>
+#include <commctrl.h>
+#include <commdlg.h>
index 66c7da9..400af64 100644 (file)
@@ -1,24 +1,27 @@
+/* PROJECT:         ReactOS sndrec32
+ * LICENSE:         GPL - See COPYING in the top level directory
+ * FILE:            base/applications/sndrec32/targetver.h
+ * PURPOSE:         Sound recording
+ * PROGRAMMERS:     Marco Pagliaricci (irc: rendar)
+ */
+
+
+
 #pragma once
 
 #pragma once
 
-// Le macro seguenti definiscono la piattaforma minima richiesta. La piattaforma minima richiesta
-// è costituita dalla versione meno recente di Windows, Internet Explorer e così via contenenti le funzionalità necessarie per eseguire
-// l'applicazione. Le macro consentono di attivare tutte le funzionalità disponibili nelle versioni delle piattaforme fino
-// alla versione specificata compresa.
 
 
-// Modificare le seguenti definizioni se è necessario utilizzare come destinazione una piattaforma prima di quelle specificate di seguito.
-// Fare riferimento a MSDN per informazioni aggiornate sui valori corrispondenti per le differenti piattaforme.
-#ifndef WINVER                          // Specifica che la piattaforma minima richiesta è Windows Vista.
-#define WINVER 0x0600           // Modificare il valore con quello appropriato per altre versioni di Windows.
+#ifndef WINVER                         
+#define WINVER 0x0600           
 #endif
 
 #endif
 
-#ifndef _WIN32_WINNT            // Specifica che la piattaforma minima richiesta è Windows Vista.
-#define _WIN32_WINNT 0x0600     // Modificare il valore con quello appropriato per altre versioni di Windows.
+#ifndef _WIN32_WINNT         
+#define _WIN32_WINNT 0x0600
 #endif
 
 #endif
 
-#ifndef _WIN32_WINDOWS          // Specifica che la piattaforma minima richiesta è Windows 98.
-#define _WIN32_WINDOWS 0x0410 // Modificare il valore con quello appropriato per Windows Me o versioni successive.
+#ifndef _WIN32_WINDOWS
+#define _WIN32_WINDOWS 0x0410
 #endif
 
 #endif
 
-#ifndef _WIN32_IE                       // Specifica che la piattaforma minima richiesta è Internet Explorer 7.0.
-#define _WIN32_IE 0x0700        // Modificare il valore con quello appropriato per altre versioni di IE.
+#ifndef _WIN32_IE
+#define _WIN32_IE 0x0700
 #endif
 #endif