#define _AUDIO_NAMESPACE_START_ namespace snd {
#define _AUDIO_NAMESPACE_END_ };
+
//
// Platform depend stuff
//
* PROGRAMMERS: Marco Pagliaricci <ms_blue (at) hotmail (dot) it>
*/
-
#include "stdafx.h"
#include "audio_format.hpp"
class audio_format
{
protected:
-
+
unsigned int samples_psec;
unsigned short int bits_psample;
public:
-
-
+
+
//
// Ctors
//
- audio_format( unsigned int samples_per_second,
+ 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 ),
// bit per sample, and channels mono/stereo are equal.
//
- return (( samples_psec == eq.samples_psec )
+ return (( samples_psec == eq.samples_psec )
&& ( bits_psample == eq.bits_psample ) && ( chan == eq.chan ));
}
#include "stdafx.h"
#include "audio_membuffer.hpp"
+
+
_AUDIO_NAMESPACE_START_
//////////////////////////////////////
-void
- audio_membuffer::alloc_mem_( unsigned int bytes )
+void
+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;
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;
}
void
- audio_membuffer::resize_mem_( unsigned int new_size )
+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
- audio_membuffer::truncate_( void )
+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 `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 ( 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.
+ //
- }
+ }
}
void
- audio_membuffer::clear( void )
+audio_membuffer::clear( void )
{
- free_mem_();
+ free_mem_();
- bytes_received = 0;
+ bytes_received = 0;
}
-void
- audio_membuffer::reset( void )
+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
- audio_membuffer::alloc_bytes( unsigned int bytes )
+void
+audio_membuffer::alloc_bytes( unsigned int bytes )
{
- alloc_mem_( bytes );
+ alloc_mem_( bytes );
}
-void
- audio_membuffer::alloc_seconds( unsigned int secs )
+void
+audio_membuffer::alloc_seconds( unsigned int secs )
{
- alloc_mem_( aud_info.byte_rate() * secs );
+ alloc_mem_( aud_info.byte_rate() * secs );
}
-void
- audio_membuffer::alloc_seconds( float secs )
+void
+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
- audio_membuffer::resize_bytes( unsigned int bytes )
+void
+audio_membuffer::resize_bytes( unsigned int bytes )
{
- resize_mem_( bytes );
+ resize_mem_( bytes );
}
-void
- audio_membuffer::resize_seconds( unsigned int secs )
+void
+audio_membuffer::resize_seconds( unsigned int secs )
{
- resize_mem_( aud_info.byte_rate() * secs );
+ resize_mem_( aud_info.byte_rate() * secs );
}
-void
- audio_membuffer::resize_seconds( float secs )
+void
+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 )
+ );
}
-void
- audio_membuffer::audio_receive
- ( unsigned char * data, unsigned int size )
+void
+audio_membuffer::audio_receive
+ ( 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 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 (( audio_data == 0 ) || ( buf_size == 0 ))
+ {
+ alloc_mem_( size * 2 );
- memcpy( audio_data, data, size );
+ memcpy( audio_data, data, size );
- return;
+ 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'.
- //
+ //
+ // 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;
+ unsigned int tot_mem = buf_size,
+ free_mem = buf_size - bytes_received;
- if ( free_mem < size )
- {
+ if ( free_mem < size )
+ {
- //
- // Calcs new buffer size.
- // TODO: flags for other behaviour?
+ //
+ // Calcs new buffer size.
+ // TODO: flags for other behaviour?
- while ( free_mem < size )
- {
- tot_mem *= 2;
+ while ( free_mem < size )
+ {
+ tot_mem *= 2;
- free_mem = tot_mem - bytes_received;
- }
+ free_mem = tot_mem - bytes_received;
+ }
- //
- // Resize buffer memory.
- //
+ //
+ // Resize buffer memory.
+ //
- resize_mem_( tot_mem );
+ 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
- audio_membuffer::read( BYTE * out_buf, unsigned int bytes )
+unsigned int
+audio_membuffer::read( BYTE * out_buf, unsigned int bytes )
{
- //
- // Some checking
- //
+ //
+ // Some checking
+ //
- if ( !audio_data )
- return 0;
+ if ( !audio_data )
+ return 0;
- if ( bytes_played_ >= bytes_received )
- return 0;
+ if ( bytes_played_ >= bytes_received )
+ return 0;
- unsigned int to_play =
- bytes_received - bytes_played_;
+ unsigned int to_play =
+ bytes_received - bytes_played_;
- unsigned int to_copy =
- bytes > to_play ? to_play : bytes;
+ unsigned int to_copy =
+ bytes > to_play ? to_play : bytes;
- //
- // Copies the audio data out.
- //
+ //
+ // Copies the audio data out.
+ //
- if (( out_buf ) && ( to_copy ) && ( audio_data ))
- memcpy( out_buf, audio_data + bytes_played_, to_copy );
+ 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).
- //
+ //
+ // Increments the number of total bytes
+ // played (audio data gone out from the
+ // `audio_producer' object).
+ //
- bytes_played_ += bytes;
+ bytes_played_ += bytes;
- if ( audio_arrival )
- audio_arrival( aud_info.samples_in_bytes( bytes ));
+ if ( audio_arrival )
+ audio_arrival( aud_info.samples_in_bytes( bytes ));
- //
- // Returns the exact size of audio data
- // produced.
- //
+ //
+ // Returns the exact size of audio data
+ // produced.
+ //
- return to_copy;
+ return to_copy;
}
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;
}
+
_AUDIO_NAMESPACE_END_
{
-
+
protected:
public:
-
+
void ( * audio_arrival )( unsigned int );
void ( * buffer_resized ) ( unsigned int );
-
+
//
// 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.
alloc_mem_( init_size );
-
+
}
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.
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( 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() *
+ init_size = ( unsigned int )(( float ) aud_info.byte_rate() *
seconds <= 0 ? 1 : 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 );
-
+
}
//
virtual ~audio_membuffer( void )
- {
-
+ {
+
//
// Frees memory and reset values.
//
clear();
-
+
}
//returns the float number of seconds
//that the buffer can record
float fseconds_total( void ) const
- { return ( float )(( float ) buf_size /
+ { return ( float )(( float ) buf_size /
( float ) aud_info.byte_rate()); }
//returns the float number of seconds
//that has been recorded
float fseconds_recorded( void ) const
- { return ( float )(( float ) bytes_received /
+ { return ( float )(( float ) bytes_received /
( float ) aud_info.byte_rate()); }
//if there is a buffer, discards current buffer
- //memory and realloc a new memory buffer with a
+ //memory and realloc a new memory buffer with a
//new size expressed in bytes.
void alloc_bytes( unsigned int );
//if there is a buffer, discards current buffer
- //memory and realloc a new memory buffer with a
+ //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 bytes the current buffer,
+ //resizes in bytes the current buffer,
//without discarding previsiously audio data received.
void resize_bytes( unsigned int );
- //resizes in seconds the current buffer,
+ //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'
//
-
+
//
// Inherited Functions from `audio_buffer'
//
unsigned int read( BYTE *, unsigned int );
bool finished( void );
-
+
};
protected:
-
-
+
+
unsigned int bytes_played_;
{ }
-
-
+
+
//
// Dtor
//
//
// The `audio_wavein' class, while is
- // recording audio, has to access to
+ // recording audio, has to access to
// protected members of `audio_receiver'
// such as `bytes_received' protected
// variable.
public:
-
-
+
+
//
// Ctors
//
-
+
//
// Public Functions
//
virtual void audio_receive( unsigned char *, unsigned int ) = 0;
-
+
//virtual void start_rec( void ) = 0;
//virtual void stop_rec( void ) = 0;
#include "stdafx.h"
#include "audio_resampler_acm.hpp"
+
+
_AUDIO_NAMESPACE_START_
- /////////////////////////////////////////
- /////// Private Functions ////////
- /////////////////////////////////////////
+/////////////////////////////////////////
+/////// Private Functions ////////
+/////////////////////////////////////////
- void
- audio_resampler_acm::init_( void )
+void
+audio_resampler_acm::init_( void )
{
- //
- // Zeroing structures
- //
+ //
+ // Zeroing structures
+ //
- ZeroMemory( &acm_header, sizeof( ACMSTREAMHEADER ));
- ZeroMemory( &wformat_src, sizeof( WAVEFORMATEX ));
- ZeroMemory( &wformat_dst, sizeof( WAVEFORMATEX ));
+ 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
+ //
}
void
- audio_resampler_acm::open( void )
+audio_resampler_acm::open( void )
{
- MMRESULT err;
+ MMRESULT err;
- //
- // Opens ACM stream
- //
+ //
+ // Opens ACM stream
+ //
- err = acmStreamOpen( &acm_stream, 0, &wformat_src, &wformat_dst,
- 0, 0, 0, ACM_STREAMOPENF_NONREALTIME );
+ err = acmStreamOpen( &acm_stream, 0, &wformat_src, &wformat_dst,
+ 0, 0, 0, ACM_STREAMOPENF_NONREALTIME );
- if ( err != MMSYSERR_NOERROR )
- {
- //TODO: throw error
+ if ( err != MMSYSERR_NOERROR )
+ {
+ //TODO: throw error
MessageBox( 0, _T("acmOpen error: %i"), _T("ERROR"), MB_ICONERROR );
- }
+ }
- //
- // Calcs source buffer lenght
- //
+ //
+ // Calcs source buffer lenght
+ //
- src_buflen = ( unsigned int )
- (( float )audfmt_in.byte_rate() * ( float )buf_secs );
+ src_buflen = ( unsigned int )
+ (( float )audfmt_in.byte_rate() * ( float )buf_secs );
- //
- // Calcs destination source buffer lenght
- // with help of ACM apis
- //
+ //
+ // Calcs destination source buffer lenght
+ // with help of ACM apis
+ //
- err = acmStreamSize( acm_stream,
- src_buflen, &dst_buflen, ACM_STREAMSIZEF_SOURCE );
+ err = acmStreamSize( acm_stream,
+ src_buflen, &dst_buflen, ACM_STREAMSIZEF_SOURCE );
- if ( err != MMSYSERR_NOERROR )
- {
- //TODO: throw error
+ 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.
- //
+ //
+ // Initialize ACMSTREAMHEADER structure,
+ // and alloc memory for source and destination
+ // buffers.
+ //
- acm_header.fdwStatus = 0;
- acm_header.dwUser = 0;
+ 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;
- //
- // 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
+ 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;
}
void
- audio_resampler_acm::close( void )
+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 );
- 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("acmStreamUnPrepareHeader error"), _T("ERROR"), MB_ICONERROR );
- }
- }
+ }
+ }
- err = acmStreamClose( acm_stream, 0 );
+ err = acmStreamClose( 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 );
- }
+ }
- }//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.
+ //
}
-void
- audio_resampler_acm::audio_receive( unsigned char * data, unsigned int size )
+void
+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
+ 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.
- //
+ //
+ // Copy resampled audio, to destination buffer.
+ //
- //memcpy( pbOutputData, acm_header.pbDst, acm_header.cbDstLengthUsed );
+ //memcpy( pbOutputData, acm_header.pbDst, acm_header.cbDstLengthUsed );
- }
+ }
}
+
_AUDIO_NAMESPACE_END_
stream_opened( false ), audfmt_in( fmt_in ), audfmt_out( fmt_out ),
buf_secs( _AUDIO_DEFAULT_BUFSECS )
- {
-
+ {
+
init_();
-
-
+
+
}
-
-
+
+
//
// Dtor
//
/*
-* PROJECT: ReactOS Sound Record Application
-* 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>
-*/
+ * PROJECT: ReactOS Sound Record Application
+ * 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>
+ */
#include "stdafx.h"
#include "audio_wavein.hpp"
_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;
- buf_secs = _AUDIO_DEFAULT_WAVEINBUFSECS;
+ buf_secs = _AUDIO_DEFAULT_WAVEINBUFSECS;
- status = WAVEIN_NOTREADY;
+ status = WAVEIN_NOTREADY;
}
void
- audio_wavein::alloc_buffers_mem_( unsigned int buffs, float secs )
+audio_wavein::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
- //
+ //
+ // Release old 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;
- //
- // Calcs size of the buffers
- //
+ //
+ // Calcs size of the buffers
+ //
- onebuf_size = ( unsigned int )
- (( float )aud_info.byte_rate() * secs );
+ 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
- //
+ //
+ // 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
- audio_wavein::free_buffers_mem_( void )
+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
- audio_wavein::init_headers_( void )
+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
- audio_wavein::prep_headers_( void )
+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
- audio_wavein::unprep_headers_( void )
+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 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 = 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
- audio_wavein::add_buffers_to_driver_( void )
+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 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 = 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
- 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_();
}
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
- //
+ //
+ // Checkin the status of the object
+ //
- if ( status != WAVEIN_NOTREADY )
- {} //TODO: throw error
+ if ( status != WAVEIN_NOTREADY )
+ {} //TODO: throw error
- //
- // Creating the EVENT object that will be signaled
- // when the recording thread has to wake up.
- //
+ //
+ // Creating the EVENT object that will be signaled
+ // when the recording thread has to wake up.
+ //
- wakeup_recthread =
- CreateEvent( 0, FALSE, FALSE, 0 );
+ 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;
+ status = WAVEIN_ERR;
- MessageBox( 0, TEXT("Thread Error."), 0, 0 );
+ MessageBox( 0, TEXT("Thread Error."), 0, 0 );
- //TODO: throw error
- }
+ //TODO: throw error
+ }
- //
- // Inialize buffers for recording audio
- // data from the wavein audio line.
- //
+ //
+ // Inialize buffers for recording audio
+ // data from the wavein audio line.
+ //
- alloc_buffers_mem_( buffers, buf_secs );
- init_headers_();
+ alloc_buffers_mem_( buffers, buf_secs );
+ init_headers_();
- //
- // Sound format that will be captured by wavein
- //
+ //
+ // Sound format that will be captured by wavein
+ //
- wave_format.wFormatTag = WAVE_FORMAT_PCM;
+ 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();
+ 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
- //
+ //
+ // Creating the recording thread
+ //
- recthread_handle =
- CreateThread( NULL,
- 0,
- audio_wavein::recording_procedure,
- ( PVOID ) this,
- 0,
- &recthread_id
- );
+ 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!
+ //
}
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
- //
+ //
+ // Updating to the recording status
+ //
- status = WAVEIN_RECORDING;
+ status = WAVEIN_RECORDING;
- //
- // Let's prepare header of type WAVEHDR that
- // we will pass to the driver with our
- // audio informations, and buffer informations.
- //
+ //
+ // Let's prepare header of type WAVEHDR that
+ // we will pass to the driver with our
+ // audio informations, and buffer informations.
+ //
- prep_headers_();
+ 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.
- //
+ //
+ // 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_();
+ add_buffers_to_driver_();
- //
- // Signaling event for waking up
- // the recorder thread.
- //
+ //
+ // Signaling event for waking up
+ // the recorder thread.
+ //
- ev = SetEvent( wakeup_recthread );
+ 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 )
- {
+ if ( err != MMSYSERR_NOERROR )
+ {
- //
- // Updating status
- //
+ //
+ // Updating status
+ //
- status = WAVEIN_ERR;
+ status = WAVEIN_ERR;
- MessageBox( 0, TEXT("waveInStart Error."), 0, 0 );
+ MessageBox( 0, TEXT("waveInStart Error."), 0, 0 );
- //TODO: throw error
+ //TODO: throw error
- }
+ }
}
void
- audio_wavein::stop_recording( 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;
- if ( data_flushed_event )
- wait = WaitForSingleObject(
- data_flushed_event, INFINITE
- );
+ if ( data_flushed_event )
+ wait = WaitForSingleObject(
+ data_flushed_event, INFINITE
+ );
- //
- // waveInReset will make all pending buffer as done.
- //
+ //
+ // waveInReset will make all pending buffer as done.
+ //
- err = waveInReset( wavein_handle );
+ err = waveInReset( wavein_handle );
- if ( err != MMSYSERR_NOERROR )
- {
+ if ( err != MMSYSERR_NOERROR )
+ {
- //TODO: throw error
+ //TODO: throw error
- MessageBox( 0, TEXT("waveInReset Error."), 0, 0 );
+ MessageBox( 0, TEXT("waveInReset Error."), 0, 0 );
- }
+ }
- //
- // 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
- audio_wavein::recording_procedure( LPVOID arg )
+DWORD WINAPI
+audio_wavein::recording_procedure( LPVOID arg )
{
- MSG msg;
- WAVEHDR * phdr;
- DWORD wait;
- audio_wavein * _this = ( audio_wavein * ) arg;
+ MSG msg;
+ WAVEHDR * phdr;
+ DWORD wait;
+ audio_wavein * _this = ( audio_wavein * ) arg;
- //
- // Check the arg pointer
- //
+ //
+ // Check the arg pointer
+ //
- if ( _this == 0 )
- return 0;
+ 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.
- //
+ //
+ // 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 ( _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 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;
+ if (( _this->status != WAVEIN_READY ) &&
+ ( _this->status != WAVEIN_RECORDING ))
+ return 0;
- //
- // Entering main polling loop
- //
+ //
+ // Entering main polling loop
+ //
- while ( GetMessage( &msg, 0, 0, 0 ))
- {
+ while ( GetMessage( &msg, 0, 0, 0 ))
+ {
- switch ( msg.message )
- {
+ switch ( msg.message )
+ {
- case MM_WIM_DATA:
+ case MM_WIM_DATA:
- phdr = ( WAVEHDR * ) msg.lParam;
+ phdr = ( WAVEHDR * ) msg.lParam;
- if (( _this->status == WAVEIN_RECORDING )
- || ( _this->status == WAVEIN_FLUSHING ))
- {
+ if (( _this->status == WAVEIN_RECORDING )
+ || ( _this->status == WAVEIN_FLUSHING ))
+ {
- //
- // Flushes recorded audio data to
- // the `audio_receiver' object.
- //
+ //
+ // Flushes recorded audio data to
+ // the `audio_receiver' object.
+ //
- _this->audio_rcvd.audio_receive(
- ( unsigned char * )phdr->lpData,
- phdr->dwBytesRecorded
- );
+ _this->audio_rcvd.audio_receive(
+ ( unsigned char * )phdr->lpData,
+ phdr->dwBytesRecorded
+ );
- //
- // Updating `audio_receiver' total
- // bytes received _AFTER_ calling
- // `audio_receive' function.
- //
+ //
+ // Updating `audio_receiver' total
+ // bytes received _AFTER_ calling
+ // `audio_receive' function.
+ //
- _this->audio_rcvd.bytes_received +=
- phdr->dwBytesRecorded;
+ _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 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 )
- {
+ if ( _this->status != WAVEIN_FLUSHING )
+ {
- //
- // Let the audio driver reuse the buffer
- //
+ //
+ // Let the audio driver reuse the buffer
+ //
- waveInAddBuffer( _this->wavein_handle,
- phdr, sizeof( WAVEHDR ));
+ waveInAddBuffer( _this->wavein_handle,
+ phdr, sizeof( WAVEHDR ));
- } else {
+ } else {
- //
- // 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.
- //
+ //
+ // 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.
+ //
- phdr->dwFlags = 0;
+ phdr->dwFlags = 0;
- SetEvent( _this->data_flushed_event );
+ SetEvent( _this->data_flushed_event );
- //
- // The recording is gooing to stop, so the
- // recording thread can go to sleep!
- //
+ //
+ // The recording is gooing to stop, so the
+ // recording thread can go to sleep!
+ //
- wait = WaitForSingleObject(
- _this->wakeup_recthread, INFINITE );
+ wait = WaitForSingleObject(
+ _this->wakeup_recthread, INFINITE );
- }
+ }
- }//if WAVEIN_RECORDING || WAVEIN_FLUSHING
+ }//if WAVEIN_RECORDING || WAVEIN_FLUSHING
- break;
+ break;
- case MM_WIM_CLOSE:
+ case MM_WIM_CLOSE:
- //
- // The thread can exit now.
- //
+ //
+ // The thread can exit now.
+ //
- return 0;
+ return 0;
- break;
+ break;
- } //end switch( msg.message )
+ } //end switch( msg.message )
- } //end while( GetMessage( ... ))
+ } //end while( GetMessage( ... ))
- return 0;
+ return 0;
}
-enum audio_wavein_status { WAVEIN_NOTREADY, WAVEIN_READY,
+enum audio_wavein_status { WAVEIN_NOTREADY, WAVEIN_READY,
WAVEIN_RECORDING, WAVEIN_ERR,
WAVEIN_STOP, WAVEIN_FLUSHING
-
+
};
-
+
audio_format aud_info;
-
+
audio_receiver & audio_rcvd;
-
+
//
// Audio Recorder Thread id
//
DWORD recthread_id;
-
+
//
// Object status
//
// How many seconds of audio
// can record the internal buffer
- // before flushing audio data
+ // before flushing audio data
// to the `audio_receiver' class?
//
const audio_format & a_info, audio_receiver & a_receiver )
: wave_headers( 0 ),
- aud_info( a_info ), audio_rcvd( a_receiver ),
+ 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_();
aud_info = a_info;
~audio_wavein( void )
{
-
+
//close(); TODO!
}
void buffer_secs( float bsecs )
- {
+ {
//
// Some checking
//
// buffer.
//
- buf_secs = bsecs;
+ buf_secs = bsecs;
}
if ( tot_bufs == 0 )
return;
-
+
//
// Sets the number of total buffers.
//
{ return aud_info; }
-
+
};
* PROGRAMMERS: Marco Pagliaricci <ms_blue (at) hotmail (dot) it>
*/
-
#include "stdafx.h"
#include "audio_waveout.hpp"
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 )
{
- 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.
- //
- mb_size = tot_size;
+ //
+ // Updates total size of the buffers.
+ //
+
+ mb_size = tot_size;
}
-void
+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
+ //
+ DWORD buf_sz = mb_size / buffers;
- //
- // This is the size for one buffer
- //
- DWORD buf_sz = mb_size / buffers;
+ //
+ // This is the base address for one buffer
+ //
+ BYTE * buf_addr = main_buffer;
- //
- // This is the base address for one 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 )
+ {
- for ( unsigned int i = 0; i < buffers; ++i )
- {
-
- //
- // Sets the correct base address and
- // lenght for the little buffer.
- //
+ //
+ // Sets the correct base address and
+ // lenght for the little buffer.
+ //
- wave_headers[ i ].dwBufferLength = mb_size / buffers;
- wave_headers[ i ].lpData = ( LPSTR ) buf_addr;
+ wave_headers[ i ].dwBufferLength = mb_size / buffers;
+ wave_headers[ i ].lpData = ( LPSTR ) buf_addr;
- //
- // Unsets the WHDR_DONE flag.
- //
+ //
+ // Unsets the WHDR_DONE flag.
+ //
- wave_headers[ i ].dwFlags &= ~WHDR_DONE;
+ wave_headers[ i ].dwFlags &= ~WHDR_DONE;
-
- //
- // Sets the WAVEHDR user data with an
- // unique little buffer ID#
- //
- wave_headers[ i ].dwUser = ( unsigned int ) i;
+ //
+ // Sets the WAVEHDR user data with an
+ // unique little buffer ID#
+ //
-
-
- //
- // Increments little buffer base address.
- //
+ wave_headers[ i ].dwUser = ( unsigned int ) i;
- buf_addr += buf_sz;
- }
+
+
+ //
+ // Increments little buffer base address.
+ //
+
+ buf_addr += buf_sz;
+ }
}
-void
+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 )
{
- 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 = 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
}
-void
+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;
-void
+void
audio_waveout::open( void )
{
- MMRESULT err;
- HANDLE playthread_handle = 0;
+ MMRESULT err;
+ HANDLE playthread_handle = 0;
+
+ //
+ // Checkin the status of the object
+ //
- //
- // Checkin the status of the object
- //
+ if ( status != WAVEOUT_NOTREADY )
+ {} //TODO: throw error
- if ( status != WAVEOUT_NOTREADY )
- {} //TODO: throw error
+ //
+ // Creating the EVENT object that will be signaled
+ // when the playing thread has to wake up.
+ //
- //
- // Creating the EVENT object that will be signaled
- // when the playing thread has to wake up.
- //
+ wakeup_playthread =
+ CreateEvent( 0, FALSE, FALSE, 0 );
- wakeup_playthread =
- CreateEvent( 0, FALSE, FALSE, 0 );
+ if ( !wakeup_playthread )
+ {
- if ( !wakeup_playthread )
- {
+ status = WAVEOUT_ERR;
- status = WAVEOUT_ERR;
+ //TODO: throw error
+ }
- //TODO: throw error
- }
+ //
+ // Inialize buffers for recording audio
+ // data from the wavein audio line.
+ //
- //
- // Inialize buffers for recording audio
- // data from the wavein audio line.
- //
+ alloc_buffers_mem_( buffers, buf_secs );
+ init_headers_();
- alloc_buffers_mem_( buffers, buf_secs );
- init_headers_();
+ //
+ // Sound format that will be captured by wavein
+ //
- //
- // Sound format that will be captured by wavein
- //
+ wave_format.wFormatTag = WAVE_FORMAT_PCM;
- 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();
- 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
+ //
- //
- // Creating the recording thread
- //
+ playthread_handle =
+ CreateThread( NULL,
+ 0,
+ audio_waveout::playing_procedure,
+ ( PVOID ) this,
+ 0,
+ &playthread_id
+ );
- 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 )
{
- MMRESULT err;
- unsigned int i;
- BOOL ev;
+ MMRESULT err;
+ unsigned int i;
+ BOOL ev;
+
+ if ( !main_buffer )
+ { return; } //TODO; throw error, or assert
- 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 )
+ {
- //
- // If the status is PAUSED, we have to
- // resume the audio playing.
- //
- if ( status == WAVEOUT_PAUSED )
- {
+ //
+ // Updates status.
+ //
- //
- // Updates status.
- //
+ status = WAVEOUT_PLAYING;
- status = WAVEOUT_PLAYING;
+ //
+ // Tells to the driver to resume
+ // audio playing.
+ //
- //
- // Tells to the driver to resume
- // audio playing.
- //
+ waveOutRestart( waveout_handle );
- waveOutRestart( waveout_handle );
-
- //
- // Wakeup playing thread.
- //
+ //
+ // Wakeup playing thread.
+ //
- ev = SetEvent( wakeup_playthread );
+ ev = SetEvent( wakeup_playthread );
- return;
+ return;
- } //if status == WAVEOUT_PAUSED
+ } //if status == WAVEOUT_PAUSED
- if ( status != WAVEOUT_READY )
- return;
-
+ if ( status != WAVEOUT_READY )
+ return;
- //
- // Prepares WAVEHDR structures.
- //
- prep_headers_();
+ //
+ // Prepares WAVEHDR structures.
+ //
+ prep_headers_();
- //
- // Sets correct status.
- //
- status = WAVEOUT_PLAYING;
-
-
+ //
+ // Sets correct status.
+ //
- //
- // Reads the audio from the start.
- //
+ status = WAVEOUT_PLAYING;
+
+
+
+ //
+ // 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 );
+ //
+ // Wakeup the playing thread.
+ //
+ ev = SetEvent( wakeup_playthread );
- //
- // 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 ));
- if ( err != MMSYSERR_NOERROR )
- {
-
+ //
+ // Sends all the little buffers to the
+ // audio driver, so it can play the sound
+ // data.
+ //
- MessageBox(0, _T("waveOutWrite Error"), 0, 0);
-
- //TODO: throw error
- }
+ for ( i = 0; i < buffers; ++ i )
+ {
- }
+
+ err = waveOutWrite( waveout_handle, &wave_headers[ i ], sizeof( WAVEHDR ));
+
+ if ( err != MMSYSERR_NOERROR )
+ {
+
+
+ MessageBox(0, _T("waveOutWrite Error"), 0, 0);
+
+ //TODO: throw error
+ }
+
+ }
}
-void
+void
audio_waveout::pause( void )
{
- MMRESULT err;
+ MMRESULT err;
- //
- // If the waveout object is not playing audio,
- // do nothing.
- //
-
- if ( status == WAVEOUT_PLAYING )
- {
+ //
+ // If the waveout object is not playing audio,
+ // do nothing.
+ //
- //
- // Updating status.
- //
+ if ( status == WAVEOUT_PLAYING )
+ {
- status = WAVEOUT_PAUSED;
+ //
+ // Updating status.
+ //
+ status = WAVEOUT_PAUSED;
- //
- // Tells to audio driver to pause audio.
- //
- err = waveOutPause( waveout_handle );
+ //
+ // Tells to audio driver to pause audio.
+ //
+ err = waveOutPause( waveout_handle );
- if ( err != MMSYSERR_NOERROR )
- {
- MessageBox(0, _T("waveOutPause Error"), 0, 0);
- //TODO: throw error
+ if ( err != MMSYSERR_NOERROR )
+ {
- }
+ MessageBox(0, _T("waveOutPause Error"), 0, 0);
+ //TODO: throw error
- }
+ }
+
+ }
}
-void
+void
audio_waveout::stop( void )
{
- MMRESULT err;
+ MMRESULT err;
- status = WAVEOUT_STOP;
+ status = WAVEOUT_STOP;
- 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
+ //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_();
+ unprep_headers_();
- init_headers_();
+ init_headers_();
- status = WAVEOUT_READY;
+ status = WAVEOUT_READY;
}
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 (( status == WAVEOUT_PLAYING )
+ || ( status== WAVEOUT_PAUSED ))
+ {
- //
- // 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();
+ stop();
- }
+ }
- //
- // When we have flushed all pending buffers,
- // the wave out handle can be successfully closed.
- //
+ //
+ // When we have flushed all pending buffers,
+ // the wave out handle can be successfully closed.
+ //
- err = waveOutClose( waveout_handle );
+ err = waveOutClose( waveout_handle );
- if ( err != MMSYSERR_NOERROR )
- {
+ if ( err != MMSYSERR_NOERROR )
+ {
- MessageBox(0, _T("waveOutClose Error"), 0, 0);
- //TODO: throw error
+ 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 )
{
- 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;
+ 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 ))
+ {
- //
- // If the status of the `wave_out' object
- // is different than playing, then the thread
- // can go to sleep.
- //
+ switch ( msg.message )
+ {
- if (( _this->status != WAVEOUT_PLAYING )
- && ( _this->wakeup_playthread ))
- {
-
- wait = WaitForSingleObject(
- _this->wakeup_playthread,
- INFINITE
- );
- }
-
- //TODO: quando il thread si risveglia, deve
- //entrare nel prossimo if o no? o metter un else { ?
+ case MM_WOM_DONE:
+ phdr = ( WAVEHDR * ) msg.lParam;
-
- if ( phdr->dwFlags & WHDR_DONE )
- {
-
- read_size =
- _this->audio_buf.read(
- ( BYTE * ) phdr->lpData,
- phdr->dwBufferLength
- );
-
- if ( read_size )
- {
- phdr->dwBufferLength = read_size;
+ //
+ // If the status of the `wave_out' object
+ // is different than playing, then the thread
+ // can go to sleep.
+ //
- phdr->dwFlags &= ~WHDR_DONE;
+ if (( _this->status != WAVEOUT_PLAYING )
+ && ( _this->wakeup_playthread ))
+ {
- err = waveOutWrite(
- _this->waveout_handle,
- phdr,
- sizeof( WAVEHDR )
- );
+ wait = WaitForSingleObject(
+ _this->wakeup_playthread,
+ INFINITE
+ );
+ }
- if ( err != MMSYSERR_NOERROR )
- {
- MessageBox(0, _T("waveOutWrite Error"), 0, 0);
- //TODO: throw error
- }
+ //TODO: quando il thread si risveglia, deve
+ //entrare nel prossimo if o no? o metter un else { ?
- } else {
- //
- // Here `read_sizep' is 0
- //
+ if ( phdr->dwFlags & WHDR_DONE )
+ {
- if ( phdr->dwUser == ( _this->buffers - 1 ))
- {
+ read_size =
+ _this->audio_buf.read(
+ ( BYTE * ) phdr->lpData,
+ phdr->dwBufferLength
+ );
- //
- // 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 ( read_size )
+ {
+ phdr->dwBufferLength = read_size;
- _this->stop();
-
- //
- // Let the thread go to sleep.
- //
+ phdr->dwFlags &= ~WHDR_DONE;
- if ( _this->audio_buf.play_finished )
- _this->audio_buf.play_finished();
-
+ err = waveOutWrite(
+ _this->waveout_handle,
+ phdr,
+ sizeof( WAVEHDR )
+ );
- if ( _this->wakeup_playthread )
- wait = WaitForSingleObject(
- _this->wakeup_playthread,
- INFINITE
- );
+ if ( err != MMSYSERR_NOERROR )
+ {
+ MessageBox(0, _T("waveOutWrite Error"), 0, 0);
+ //TODO: throw error
+ }
- }
- } //if read_size != 0
+ } else {
- } //( phdr->dwFlags & WHDR_DONE )
-
+ //
+ // Here `read_sizep' is 0
+ //
- break; // end case
+ if ( phdr->dwUser == ( _this->buffers - 1 ))
+ {
+ //
+ // 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.
+ //
- case MM_WOM_CLOSE:
- //
- // The thread can exit now.
- //
+ _this->stop();
- return 0;
+ //
+ // Let the thread go to sleep.
+ //
- break;
+ if ( _this->audio_buf.play_finished )
+ _this->audio_buf.play_finished();
- case MM_WOM_OPEN:
-
- //
- // Do nothing.
- //
+ if ( _this->wakeup_playthread )
+ wait = WaitForSingleObject(
+ _this->wakeup_playthread,
+ INFINITE
+ );
- break;
+ }
+ } //if read_size != 0
- } //end switch( msg.message )
-
- } //end while( GetMessage( ... ))
+ } //( phdr->dwFlags & WHDR_DONE )
- return 0;
+
+ break; // end case
+
+
+
+ case MM_WOM_CLOSE:
+ //
+ // The thread can exit now.
+ //
+
+ return 0;
+
+ break;
+
+
+ case MM_WOM_OPEN:
+
+ //
+ // Do nothing.
+ //
+
+ break;
+
+
+ } //end switch( msg.message )
+
+ } //end while( GetMessage( ... ))
+
+ return 0;
}
+
_AUDIO_NAMESPACE_END_
_AUDIO_NAMESPACE_START_
-enum audio_waveout_status { WAVEOUT_NOTREADY, WAVEOUT_READY,
+
+
+
+
+enum audio_waveout_status { WAVEOUT_NOTREADY, WAVEOUT_READY,
WAVEOUT_PLAYING, WAVEOUT_ERR,
WAVEOUT_PAUSED, WAVEOUT_STOP
-
+
};
+
+
+
class audio_waveout
{
static DWORD WINAPI playing_procedure( LPVOID );
-
+
HANDLE wakeup_playthread;
-
+
protected:
-
+
WAVEFORMATEX wave_format;
WAVEHDR * wave_headers;
HWAVEOUT waveout_handle;
-
-
-
+
+
+
const audio_format & aud_info;
audio_producer & audio_buf;
-
+
unsigned int buffers;
-
+
-
+
audio_producer & a_buf )
: wave_headers( 0 ), aud_info( aud_fmt ),
- audio_buf( a_buf ), status( WAVEOUT_NOTREADY ),
+ audio_buf( a_buf ), status( WAVEOUT_NOTREADY ),
main_buffer( 0 ), mb_size( 0 ),
buffers( _AUDIO_DEFAULT_WAVEOUTBUFFERS )
{
//
// Initializing internal wavein data
//
-
-
+
+
init_();
}
-
-
+
+
//
// Dtor
//
#define IDC_STATIC -1
// Next default values for new objects
-//
+//
#ifdef APSTUDIO_INVOKED
#ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_NO_MFC 1
/*
-* PROJECT: ReactOS Sound Record Application
-* 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>
-*/
-
-
+ * PROJECT: ReactOS Sound Record Application
+ * 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>
+ */
#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);
+ATOM MyRegisterClass(HINSTANCE hInstance);
+BOOL InitInstance(HINSTANCE, int);
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
INT_PTR CALLBACK About(HWND, UINT, WPARAM, LPARAM);
BOOL s_recording;
+
int APIENTRY _tWinMain(HINSTANCE hInstance,
- HINSTANCE hPrevInstance,
- LPTSTR lpCmdLine,
- int nCmdShow)
+ HINSTANCE hPrevInstance,
+ LPTSTR lpCmdLine,
+ int nCmdShow)
{
- UNREFERENCED_PARAMETER(hPrevInstance);
- UNREFERENCED_PARAMETER(lpCmdLine);
-
-
- MSG msg;
- HACCEL hAccelTable;
+ UNREFERENCED_PARAMETER(hPrevInstance);
+ UNREFERENCED_PARAMETER(lpCmdLine);
- InitCommonControls();
+ MSG msg;
+ HACCEL hAccelTable;
+ InitCommonControls();
-
-
-
-
- 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 ));
+ 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 ));
butbmps_dis[0] = LoadBitmap( hInstance, MAKEINTRESOURCE( IDB_BITMAP2_START_DIS ));
butbmps_dis[1] = LoadBitmap( hInstance, MAKEINTRESOURCE( IDB_BITMAP2_END_DIS ));
butbmps_dis[4] = LoadBitmap( hInstance, MAKEINTRESOURCE( IDB_BITMAP2_REC_DIS ));
- 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;
+ 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.alloc_seconds( INITIAL_BUFREC_SECONDS );
+ AUD_buffer.play_finished = l_play_finished;
+ AUD_buffer.audio_arrival = l_audio_arrival;
+ AUD_buffer.buffer_resized = l_buffer_resized;
- AUD_IN = &AUD_wavein;
- AUD_OUT = &AUD_waveout;
- AUD_BUF = &AUD_buffer;
+ AUD_buffer.alloc_seconds( INITIAL_BUFREC_SECONDS );
+ AUD_IN = &AUD_wavein;
+ AUD_OUT = &AUD_waveout;
+ AUD_BUF = &AUD_buffer;
- slider_pos = 0;
- slider_min = 0;
- slider_max = 32767;
+ slider_pos = 0;
+ slider_min = 0;
+ slider_max = 32767;
- stopped_flag = FALSE;
- path_set = FALSE;
- isnew = TRUE;
+ stopped_flag = FALSE;
+ path_set = FALSE;
+ isnew = TRUE;
- samples_max = AUD_buffer.total_samples();
+ samples_max = AUD_buffer.total_samples();
- LoadString(hInstance,
+ LoadString(hInstance,
IDS_APP_TITLE, szTitle, MAX_LOADSTRING);
- LoadString(hInstance,
+ LoadString(hInstance,
IDC_REACTOS_SNDREC32, szWindowClass, MAX_LOADSTRING);
- MyRegisterClass(hInstance);
+ MyRegisterClass(hInstance);
- if (!InitInstance (hInstance, nCmdShow))
- {
- MessageBox(0, 0, TEXT("CreateWindow() Error!"), 0);
- return FALSE;
- }
+ if (!InitInstance (hInstance, nCmdShow))
+ {
+ MessageBox(0, 0, TEXT("CreateWindow() Error!"), 0);
+ return FALSE;
+ }
- hAccelTable = LoadAccelerators(hInstance,
+ hAccelTable = LoadAccelerators(hInstance,
MAKEINTRESOURCE( IDC_REACTOS_SNDREC32 ));
- s_recording = false;
+ s_recording = false;
- AUD_wavein.open();
- AUD_waveout.open();
+ AUD_wavein.open();
+ AUD_waveout.open();
- while (GetMessage(&msg, NULL, 0, 0))
- {
- if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg))
- {
- TranslateMessage(&msg);
- DispatchMessage(&msg);
- }
- }
+ while (GetMessage(&msg, NULL, 0, 0))
+ {
+ if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg))
+ {
+ TranslateMessage(&msg);
+ DispatchMessage(&msg);
+ }
+ }
- AUD_waveout.close();
- AUD_wavein.close();
+ AUD_waveout.close();
+ AUD_wavein.close();
- AUD_buffer.clear();
+ AUD_buffer.clear();
- return (int) msg.wParam;
+ return (int) msg.wParam;
}
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.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.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(
- szWindowClass,
- szTitle,
- WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX,
- CW_USEDEFAULT,
- CW_USEDEFAULT,
- MAINWINDOW_W,
- MAINWINDOW_H,
- NULL, NULL,
- hInstance, NULL
- );
+ 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
+ );
- if (!hWnd)
- {
- return FALSE;
- }
+ if (!hWnd)
+ {
+ return FALSE;
+ }
- ShowWindow(hWnd, nCmdShow);
- UpdateWindow(hWnd);
+ ShowWindow(hWnd, nCmdShow);
+ UpdateWindow(hWnd);
- main_win = hWnd;
+ main_win = hWnd;
- return TRUE;
+ return TRUE;
}
//
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
- int wmId, wmEvent;
- RECT rect;
- PAINTSTRUCT ps;
- HDC hdc;
+ int wmId, wmEvent;
+ RECT rect;
+ PAINTSTRUCT ps;
+ HDC hdc;
- //
- // Checking for global pointers to buffer and
- // io audio devices.
- //
+ //
+ // 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;
- }
+ if (( !AUD_IN ) || ( !AUD_OUT ) || ( !AUD_BUF ))
+ {
+ MessageBox( 0, TEXT("Buffer Error"), 0, 0 );
+ return 1;
+ }
- switch (message)
- {
+ switch (message)
+ {
- case WM_CREATE:
+ case WM_CREATE:
- //
- // Creating ALL the buttons
- //
+ //
+ // Creating ALL the buttons
+ //
- for ( int i = 0; i < 5; ++ i )
- {
+ 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
- );
+ 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;
+ if ( !buttons[i] )
+ {
+ MessageBox(0, 0, TEXT("CreateWindow() Error!"), 0);
+ return FALSE;
- }
+ }
- //
- // Realize the button bmp image
- //
+ //
+ // Realize the button bmp image
+ //
- SendMessage(buttons[i], BM_SETIMAGE, ( WPARAM )IMAGE_BITMAP, ( LPARAM )butbmps[i]);
+ SendMessage(buttons[i], BM_SETIMAGE, ( WPARAM )IMAGE_BITMAP, ( LPARAM )butbmps[i]);
- UpdateWindow( buttons[i] );
+ UpdateWindow( buttons[i] );
disable_but( i );
- }
+ }
- //
- // Creating the SLIDER window
- //
+ //
+ // 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
- );
+ 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;
+ if ( !slider )
+ {
+ MessageBox(0, 0, TEXT("CreateWindow() Error!"), 0);
+ return FALSE;
- }
+ }
- //
- // Sets slider limits
- //
+ //
+ // Sets slider limits
+ //
- SendMessage(
- slider,
- TBM_SETRANGE,
- (WPARAM)TRUE,
- (LPARAM)MAKELONG(slider_min,slider_max)
- );
+ SendMessage(
+ slider,
+ TBM_SETRANGE,
+ (WPARAM)TRUE,
+ (LPARAM)MAKELONG(slider_min,slider_max)
+ );
- UpdateWindow( slider );
+ UpdateWindow( slider );
enable_but( BUTREC_ID );
- break;
+ break;
- //
- // Implements slider logic
- //
+ //
+ // Implements slider logic
+ //
- case WM_HSCROLL :
- {
- switch( LOWORD( wParam ))
- {
+ case WM_HSCROLL :
+ {
+ switch( LOWORD( wParam ))
+ {
- case SB_ENDSCROLL:
- break;
+ case SB_ENDSCROLL:
+ break;
- case SB_PAGERIGHT:
- case SB_PAGELEFT:
- case TB_THUMBTRACK:
+ case SB_PAGERIGHT:
+ case SB_PAGELEFT:
+ case TB_THUMBTRACK:
//
//
- slider_pos = SendMessage(slider, TBM_GETPOS, 0, 0);
+ slider_pos = SendMessage( slider, TBM_GETPOS, 0, 0 );
AUD_BUF->set_position(
(( slider_pos * samples_max ) / slider_max )
)
);
-
- break;
- }
+ break;
- break;
- }
+ }
+ break;
+ }
- case WM_COMMAND:
- wmId = LOWORD(wParam);
- wmEvent = HIWORD(wParam);
+ case WM_COMMAND:
- if (( wmId >= 0 ) && ( wmId < 5 ) && (butdisabled[wmId] == TRUE))
- break;
+ wmId = LOWORD( wParam );
+ wmEvent = HIWORD( wParam );
- switch (wmId)
- {
+ if (( wmId >= 0 ) && ( wmId < 5 ) && ( butdisabled[wmId] == TRUE ))
+ break;
- case ID_NEW:
+ switch (wmId)
+ {
- if ( !isnew )
- {
+ case ID_NEW:
- if ( AUD_IN->current_status() == snd::WAVEIN_RECORDING )
- AUD_IN->stop_recording();
+ if ( !isnew )
+ {
+ if ( AUD_IN->current_status() == snd::WAVEIN_RECORDING )
+ AUD_IN->stop_recording();
- if (( AUD_OUT->current_status() == snd::WAVEOUT_PLAYING ) ||
- ( AUD_OUT->current_status() == snd::WAVEOUT_PAUSED ))
- AUD_OUT->stop();
+ if (( AUD_OUT->current_status() == snd::WAVEOUT_PLAYING ) ||
+ ( AUD_OUT->current_status() == snd::WAVEOUT_PAUSED ))
+ AUD_OUT->stop();
- AUD_BUF->reset();
+
+ AUD_BUF->reset();
enable_but( BUTREC_ID );
disable_but( BUTSTART_ID );
disable_but( BUTPLAY_ID );
- samples_max = AUD_BUF->total_samples();
- slider_pos = 0;
+ samples_max = AUD_BUF->total_samples();
+ slider_pos = 0;
- SendMessage(slider, TBM_SETPOS, (WPARAM) TRUE, (LPARAM) slider_pos);
+ 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 );
EnableWindow( slider, FALSE );
- }
+ }
- break;
+ break;
- case ID_FILE_OPEN:
+ case ID_FILE_OPEN:
- ZeroMemory( &ofn, sizeof( ofn ));
+ ZeroMemory( &ofn, sizeof( ofn ));
- 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");
+ 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( GetOpenFileName( &ofn ))
- {
- open_wav( file_path );
+ 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 );
- }
+ }
- break;
+ break;
- case ID__ABOUT:
+ case ID__ABOUT:
- break;
+ break;
- case ID_FILE_SAVEAS:
+ case ID_FILE_SAVEAS:
- ZeroMemory( &ofn, sizeof( ofn ));
+ 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;
+ 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");
+ ofn.lpstrDefExt = TEXT("wav");
- if ( GetSaveFileName ( &ofn ))
- {
- write_wav( file_path );
+ if ( GetSaveFileName ( &ofn ))
+ {
+ write_wav( file_path );
EnableMenuItem( GetMenu( hWnd ), ID_FILE_SAVE, MF_ENABLED );
- }
+ }
- break;
+ break;
- case ID_EXIT:
- DestroyWindow( hWnd );
- break;
+ case ID_EXIT:
+ DestroyWindow( hWnd );
+ break;
- //
- // Sndrec32 buttons routines
- //
+ //
+ // Sndrec32 buttons routines
+ //
- case BUTSTART_ID:
+ case BUTSTART_ID:
AUD_BUF->set_position_start();
SendMessage( slider, TBM_SETPOS, (WPARAM) TRUE, (LPARAM) slider_pos );
- break;
+ break;
- case BUTEND_ID:
+ case BUTEND_ID:
//Beep(300,200);
- break;
+ break;
- case BUTPLAY_ID:
+ case BUTPLAY_ID:
- AUD_OUT->play();
+ AUD_OUT->play();
disable_but( BUTSTART_ID );
disable_but( BUTEND_ID );
disable_but( BUTPLAY_ID );
- SetTimer( hWnd, 1, 250, 0 );
+ SetTimer( hWnd, 1, 250, 0 );
- break;
+ break;
- case BUTSTOP_ID:
- if ( s_recording )
- {
- s_recording = FALSE;
+ case BUTSTOP_ID:
+ if ( s_recording )
+ {
+ s_recording = FALSE;
- AUD_IN->stop_recording();
+ AUD_IN->stop_recording();
- //
- // Resetting slider position
- //
+ //
+ // Resetting slider position
+ //
- slider_pos = 0;
- SendMessage(slider, TBM_SETPOS, (WPARAM) TRUE, (LPARAM) slider_pos);
+ slider_pos = 0;
+ SendMessage(slider, TBM_SETPOS, (WPARAM) TRUE, (LPARAM) slider_pos);
- samples_max = AUD_BUF->samples_received();
+ samples_max = AUD_BUF->samples_received();
- EnableMenuItem((HMENU)IDR_MENU1, ID_FILE_SAVEAS, MF_ENABLED );
+ EnableMenuItem((HMENU)IDR_MENU1, ID_FILE_SAVEAS, MF_ENABLED );
enable_but( BUTSTART_ID );
- } else {
+ } else {
- AUD_OUT->pause();
+ AUD_OUT->pause();
enable_but( BUTSTART_ID );
enable_but( BUTEND_ID );
enable_but( BUTREC_ID );
enable_but( BUTPLAY_ID );
- }
+ }
- KillTimer( hWnd, 1 );
+ KillTimer( hWnd, 1 );
- break;
+ break;
- case BUTREC_ID:
+ case BUTREC_ID:
- s_recording = TRUE;
+ s_recording = TRUE;
- samples_max = AUD_BUF->total_samples();
+ samples_max = AUD_BUF->total_samples();
- AUD_IN->start_recording();
+ AUD_IN->start_recording();
enable_but( BUTSTOP_ID );
EnableWindow( slider, FALSE );
- SetTimer( hWnd, 1, 150, 0 );
+ SetTimer( hWnd, 1, 150, 0 );
- break;
+ break;
- default:
- return DefWindowProc(hWnd, message, wParam, lParam);
- }
- break;
+ default:
+ return DefWindowProc(hWnd, message, wParam, lParam);
+ }
+ break;
- case WM_TIMER:
+ case WM_TIMER:
- if ( stopped_flag )
- {
- KillTimer(hWnd, 1);
- slider_pos = 0;
+ if ( stopped_flag )
+ {
+ KillTimer(hWnd, 1);
+ slider_pos = 0;
enable_but( BUTPLAY_ID );
- stopped_flag = FALSE;
- }
+ stopped_flag = FALSE;
+ }
- SendMessage(slider, TBM_SETPOS, (WPARAM) TRUE, (LPARAM) slider_pos);
+ SendMessage( slider, TBM_SETPOS, (WPARAM) TRUE, (LPARAM) slider_pos );
- break;
+ break;
- case WM_PAINT:
+ case WM_PAINT:
- InvalidateRect( hWnd, &rect, TRUE );
- hdc = BeginPaint(hWnd, &ps);
+ 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;
+ EndPaint(hWnd, &ps);
+ break;
+ case WM_DESTROY:
+ PostQuitMessage(0);
+ break;
+ default:
+ return DefWindowProc(hWnd, message, wParam, lParam);
+ }
+ return 0;
}
enable_but( BUTREC_ID );
enable_but( BUTPLAY_ID );
-
+
}
slider_pos += (DWORD) (( slider_max * samples_arrival ) / samples_max );
-
+
}
}
-BOOL open_wav( TCHAR * f )
-{
- HANDLE file;
- riff_hdr r;
- wave_hdr w;
- data_chunk d;
- BOOL b;
- DWORD bytes_recorded_in_wav = 0;
- DWORD is_read = 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
- );
- return FALSE;
- }
+BOOL open_wav( TCHAR * f )
+{
- b = ReadFile( file, ( LPVOID ) &r, sizeof ( r ), &is_read, 0 );
+ HANDLE file;
- if ( !b )
- {
- MessageBox(
- main_win,
- TEXT("Cannot read RIFF header."),
- TEXT("ERROR"),
- MB_OK|MB_ICONERROR
- );
+ riff_hdr r;
+ wave_hdr w;
+ data_chunk d;
- CloseHandle( file );
- return FALSE;
+ BOOL b;
- }
+ DWORD bytes_recorded_in_wav = 0;
+ DWORD is_read = 0;
- b = ReadFile( file, ( LPVOID ) &w, sizeof ( w ), &is_read, 0 );
+ file = CreateFile(
+ f,
+ GENERIC_READ,
+ 0, 0,
+ OPEN_EXISTING,
+ FILE_ATTRIBUTE_NORMAL,
+ 0
+ );
- if ( !b )
- {
- MessageBox(
- main_win,
- TEXT("Cannot read WAVE header."),
- TEXT("ERROR"),
- MB_OK|MB_ICONERROR
- );
+ if ( !file )
+ {
+ MessageBox(
+ main_win,
+ TEXT("Cannot open file. CreateFile() error."),
+ TEXT("ERROR"),
+ MB_OK|MB_ICONERROR
+ );
- CloseHandle( file );
- return FALSE;
+ return FALSE;
+ }
- }
+ 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
+ );
- b = ReadFile( file, ( LPVOID ) &d, sizeof ( d ), &is_read, 0 );
+ CloseHandle( file );
+ return FALSE;
+ }
- if ( !b )
- {
- MessageBox(
- main_win,
- TEXT("Cannot read WAVE subchunk."),
- TEXT("ERROR"),
- MB_OK|MB_ICONERROR
- );
+ b = ReadFile( file, ( LPVOID ) &w, sizeof ( w ), &is_read, 0 );
- CloseHandle( file );
- return FALSE;
- }
+ if ( !b )
+ {
+ MessageBox(
+ main_win,
+ TEXT("Cannot read WAVE header."),
+ TEXT("ERROR"),
+ MB_OK|MB_ICONERROR
+ );
- bytes_recorded_in_wav = r.chunksize - 36;
+ CloseHandle( file );
+ return FALSE;
+ }
- 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;
+ 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
+ );
+
+ CloseHandle( file );
+ return FALSE;
+ }
+ bytes_recorded_in_wav = r.chunksize - 36;
- snd::audio_format openfmt
- ( w.SampleRate, w.BitsPerSample, w.NumChannels );
+ 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;
+ }
- AUD_BUF->clear();
+ snd::audio_format openfmt
+ ( w.SampleRate, w.BitsPerSample, w.NumChannels );
- AUD_BUF->alloc_bytes( bytes_recorded_in_wav );
- b = ReadFile(
- file,
- ( LPVOID ) AUD_BUF->audio_buffer(),
- bytes_recorded_in_wav,
- &is_read,
- 0
- );
+ AUD_BUF->clear();
- AUD_BUF->set_b_received( bytes_recorded_in_wav );
+ AUD_BUF->alloc_bytes( bytes_recorded_in_wav );
- if (( !b ) || ( is_read != bytes_recorded_in_wav ))
- {
+ b = ReadFile(
+ file,
+ ( LPVOID ) AUD_BUF->audio_buffer(),
+ bytes_recorded_in_wav,
+ &is_read,
+ 0
+ );
- MessageBox(
- main_win,
- TEXT("Cannot read file. Error reading audio data."),
- TEXT("ERROR"),
- MB_OK|MB_ICONERROR
- );
- CloseHandle( file );
+ AUD_BUF->set_b_received( bytes_recorded_in_wav );
- AUD_BUF->reset();
- return FALSE;
- }
+ 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;
+ }
+
+ CloseHandle( file );
enable_but( BUTPLAY_ID );
enable_but( BUTSTOP_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;
}
BOOL
- write_wav( TCHAR * f )
+write_wav( TCHAR * f )
{
- HANDLE file;
+ HANDLE file;
- DWORD written;
- BOOL is_writ;
- int i;
- riff_hdr r;
- wave_hdr w;
- data_chunk d;
+ 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
- );
+ 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 ( !file )
+ {
+ i = MessageBox(
+ main_win,
+ TEXT("File already exist. Overwrite it?"),
+ TEXT("Warning"),
+ MB_YESNO|MB_ICONQUESTION
+ );
- if ( i == IDYES )
- {
+ if ( i == IDYES )
+ {
- file = CreateFile(
- f,
- GENERIC_WRITE,
- 0, 0,
- CREATE_ALWAYS,
- FILE_ATTRIBUTE_NORMAL,
- 0
- );
+ 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
- );
+ if ( !file )
+ {
+ MessageBox(
+ main_win,
+ TEXT("File Error, CreateFile() failed."),
+ TEXT("ERROR"),
+ MB_OK|MB_ICONERROR
+ );
- return FALSE;
+ return FALSE;
- }
+ }
- } else
- return FALSE;
- }
+ } else
+ return FALSE;
+ }
- r.magic = 0x46464952;
+ r.magic = 0x46464952;
- r.format = 0x45564157;
- r.chunksize = 36 + AUD_BUF->bytes_recorded();
+ r.format = 0x45564157;
+ r.chunksize = 36 + AUD_BUF->bytes_recorded();
- w.Subchunkid = 0x20746d66;
+ w.Subchunkid = 0x20746d66;
- 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();
+ 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();
+ d.subc = 0x61746164;
+ d.subc_size = AUD_BUF->bytes_recorded();
- //
- // Writing headers
- //
+ //
+ // Writing headers
+ //
- is_writ = WriteFile( file, ( LPCVOID ) &r, sizeof ( r ), &written, 0 );
+ is_writ = WriteFile( file, ( LPCVOID ) &r, sizeof ( r ), &written, 0 );
- if ( !is_writ )
- {
- MessageBox(
- main_win,
- TEXT("File Error, WriteFile() failed."),
- TEXT("ERROR"),
- MB_OK|MB_ICONERROR
- );
+ if ( !is_writ )
+ {
+ MessageBox(
+ main_win,
+ TEXT("File Error, WriteFile() failed."),
+ TEXT("ERROR"),
+ MB_OK|MB_ICONERROR
+ );
- CloseHandle( file );
+ CloseHandle( file );
- return FALSE;
+ return FALSE;
- }
+ }
- is_writ = WriteFile( file, ( LPCVOID ) &w, sizeof ( w ), &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
- );
+ if ( !is_writ )
+ {
+ MessageBox(
+ main_win,
+ TEXT("File Error, WriteFile() failed."),
+ TEXT("ERROR"),
+ MB_OK|MB_ICONERROR
+ );
- CloseHandle( file );
+ CloseHandle( file );
- return FALSE;
+ return FALSE;
- }
+ }
- is_writ = WriteFile( file, ( LPCVOID ) &d, sizeof ( d ), &written, 0 );
+ is_writ = WriteFile( file, ( LPCVOID ) &d, sizeof ( d ), &written, 0 );
- if ( !is_writ )
- {
- MessageBox(
- main_win,
- TEXT("File Error, WriteFile() failed."),
- TEXT("ERROR"),
- MB_OK|MB_ICONERROR
- );
+ if ( !is_writ )
+ {
+ MessageBox(
+ main_win,
+ TEXT("File Error, WriteFile() failed."),
+ TEXT("ERROR"),
+ MB_OK|MB_ICONERROR
+ );
- CloseHandle( file );
+ CloseHandle( file );
- return FALSE;
+ return FALSE;
- }
+ }
- is_writ = WriteFile(
- file,
- ( LPCVOID ) AUD_BUF->audio_buffer(),
- AUD_BUF->bytes_recorded(),
- &written,
- 0
- );
+ 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
- );
+ if ( !is_writ )
+ {
+ MessageBox(
+ main_win,
+ TEXT("File Error, WriteFile() failed."),
+ TEXT("ERROR"),
+ MB_OK|MB_ICONERROR
+ );
- CloseHandle( file );
+ CloseHandle( file );
- return FALSE;
+ return FALSE;
- }
+ }
- CloseHandle( file );
+ CloseHandle( file );
- return TRUE;
+ return TRUE;
}
struct wave_hdr
{
-
+
DWORD Subchunkid;
DWORD Subchunk1Size;
WORD AudioFormat;
//
// Functions prototypes
//
-LRESULT CALLBACK
+LRESULT CALLBACK
Buttons_proc(HWND, UINT, WPARAM, LPARAM);
-void
+void
l_play_finished ( void );
-void
+void
l_audio_arrival ( unsigned int );
-void
+void
l_buffer_resized ( unsigned int );
// Accelerator
//
-IDC_REACTOS_SNDREC32 ACCELERATORS
+IDC_REACTOS_SNDREC32 ACCELERATORS
BEGIN
"?", IDM_ABOUT, ASCII, ALT
"/", IDM_ABOUT, ASCII, ALT
//
#ifdef APSTUDIO_INVOKED
-GUIDELINES DESIGNINFO
+GUIDELINES DESIGNINFO
BEGIN
IDD_ABOUTBOX, DIALOG
BEGIN
// TEXTINCLUDE
//
-1 TEXTINCLUDE
+1 TEXTINCLUDE
BEGIN
"resource.h\0"
END
-2 TEXTINCLUDE
+2 TEXTINCLUDE
BEGIN
"#ifndef APSTUDIO_INVOKED\r\n"
"#include ""targetver.h""\r\n"
"\0"
END
-3 TEXTINCLUDE
+3 TEXTINCLUDE
BEGIN
"\r\n"
"\0"
// Menu
//
-IDR_MENU1 MENU
+IDR_MENU1 MENU
BEGIN
POPUP "File"
BEGIN
// String Table
//
-STRINGTABLE
+STRINGTABLE
BEGIN
IDS_APP_TITLE "reactOS_sndrec32"
IDC_REACTOS_SNDREC32 "REACTOS_SNDREC32"
#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
+// è 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.