[FORMATTING] SndRec32 patch by Marco Pagliaricci, bug #4978.

svn path=/trunk/; revision=44387
This commit is contained in:
Dmitry Gorbachev 2009-12-03 19:00:41 +00:00
parent f558c83b1c
commit 99f27439b5
18 changed files with 2053 additions and 2045 deletions

View file

@ -25,6 +25,7 @@
#define _AUDIO_NAMESPACE_START_ namespace snd { #define _AUDIO_NAMESPACE_START_ namespace snd {
#define _AUDIO_NAMESPACE_END_ }; #define _AUDIO_NAMESPACE_END_ };
// //
// Platform depend stuff // Platform depend stuff
// //

View file

@ -6,7 +6,6 @@
* PROGRAMMERS: Marco Pagliaricci <ms_blue (at) hotmail (dot) it> * PROGRAMMERS: Marco Pagliaricci <ms_blue (at) hotmail (dot) it>
*/ */
#include "stdafx.h" #include "stdafx.h"
#include "audio_format.hpp" #include "audio_format.hpp"

View file

@ -19,7 +19,7 @@ _AUDIO_NAMESPACE_START_
class audio_format class audio_format
{ {
protected: protected:
unsigned int samples_psec; unsigned int samples_psec;
unsigned short int bits_psample; unsigned short int bits_psample;
@ -27,13 +27,13 @@ class audio_format
public: public:
// //
// Ctors // 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 ) unsigned short int bits_per_sample, unsigned short int channels )
: samples_psec( samples_per_second ), bits_psample( bits_per_sample ), : samples_psec( samples_per_second ), bits_psample( bits_per_sample ),
@ -71,7 +71,7 @@ class audio_format
// bit per sample, and channels mono/stereo are equal. // 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 )); && ( bits_psample == eq.bits_psample ) && ( chan == eq.chan ));
} }

View file

@ -9,6 +9,8 @@
#include "stdafx.h" #include "stdafx.h"
#include "audio_membuffer.hpp" #include "audio_membuffer.hpp"
_AUDIO_NAMESPACE_START_ _AUDIO_NAMESPACE_START_
@ -19,50 +21,50 @@ _AUDIO_NAMESPACE_START_
////////////////////////////////////// //////////////////////////////////////
void void
audio_membuffer::alloc_mem_( unsigned int bytes ) audio_membuffer::alloc_mem_( unsigned int bytes )
{ {
// //
// Some checking // Some checking
// //
if ( bytes == 0 ) if ( bytes == 0 )
return; return;
// //
// Checks previsiously alloc'd memory // Checks previsiously alloc'd memory
// and frees it. // and frees it.
// //
if ( audio_data ) if ( audio_data )
delete[] 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;
@ -70,169 +72,169 @@ void
void void
audio_membuffer::free_mem_( void ) audio_membuffer::free_mem_( void )
{ {
if ( audio_data ) if ( audio_data )
delete[] audio_data; delete[] audio_data;
buf_size = 0; buf_size = 0;
audio_data = 0; audio_data = 0;
} }
void void
audio_membuffer::resize_mem_( unsigned int new_size ) audio_membuffer::resize_mem_( unsigned int new_size )
{ {
if ( new_size == 0 ) if ( new_size == 0 )
return; return;
// //
// The new_size, cannot be <= of the // The new_size, cannot be <= of the
// `bytes_received' member value of the // `bytes_received' member value of the
// parent class `audio_receiver'. // parent class `audio_receiver'.
// We cannot touch received audio data, // We cannot touch received audio data,
// so we have to alloc at least // so we have to alloc at least
// bytes_received+1 bytes. // bytes_received+1 bytes.
// //
// But we can truncate unused memory, so // But we can truncate unused memory, so
// `new_size' can be < of `buf_size'. // `new_size' can be < of `buf_size'.
// //
if ( new_size <= bytes_received ) if ( new_size <= bytes_received )
return; 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 // Copies received audio data, and discard
// unused memory. // 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; audio_data = new_mem;
buf_size = new_size; buf_size = new_size;
} else { } else {
audio_data = new_mem; audio_data = new_mem;
buf_size = new_size; buf_size = new_size;
} }
if ( buffer_resized ) if ( buffer_resized )
buffer_resized( new_size ); buffer_resized( new_size );
} }
void void
audio_membuffer::truncate_( void ) audio_membuffer::truncate_( void )
{ {
// //
// If `buf_size' is already = to the // If `buf_size' is already = to the
// `bytes_received' of audio data, then // `bytes_received' of audio data, then
// this operation is useless; simply return. // this operation is useless; simply return.
// //
if ( bytes_received == buf_size ) if ( bytes_received == buf_size )
return; 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; audio_data = newbuf;
buf_size = bytes_received; buf_size = bytes_received;
// //
// Buffer truncation successfull. // Buffer truncation successfull.
// Now the buffer size is exactly big // Now the buffer size is exactly big
// as much audio data was received. // as much audio data was received.
// //
} }
} }
@ -250,97 +252,97 @@ void
void void
audio_membuffer::clear( void ) audio_membuffer::clear( void )
{ {
free_mem_(); free_mem_();
bytes_received = 0; bytes_received = 0;
} }
void void
audio_membuffer::reset( void ) audio_membuffer::reset( void )
{ {
// //
// Frees memory and reset // Frees memory and reset
// to initial state. // to initial state.
// //
clear(); clear();
// //
// Alloc memory of size specified // Alloc memory of size specified
// at the constructor. // at the constructor.
// //
alloc_mem_( init_size ); alloc_mem_( init_size );
} }
void void
audio_membuffer::alloc_bytes( unsigned int bytes ) audio_membuffer::alloc_bytes( unsigned int bytes )
{ {
alloc_mem_( bytes ); alloc_mem_( bytes );
} }
void void
audio_membuffer::alloc_seconds( unsigned int secs ) audio_membuffer::alloc_seconds( unsigned int secs )
{ {
alloc_mem_( aud_info.byte_rate() * secs ); alloc_mem_( aud_info.byte_rate() * secs );
} }
void void
audio_membuffer::alloc_seconds( float secs ) audio_membuffer::alloc_seconds( float secs )
{ {
alloc_mem_(( unsigned int )(( float ) aud_info.byte_rate() * secs )); alloc_mem_(( unsigned int )(( float ) aud_info.byte_rate() * secs ));
} }
void void
audio_membuffer::resize_bytes( unsigned int bytes ) audio_membuffer::resize_bytes( unsigned int bytes )
{ {
resize_mem_( bytes ); resize_mem_( bytes );
} }
void void
audio_membuffer::resize_seconds( unsigned int secs ) audio_membuffer::resize_seconds( unsigned int secs )
{ {
resize_mem_( aud_info.byte_rate() * secs ); resize_mem_( aud_info.byte_rate() * secs );
} }
void void
audio_membuffer::resize_seconds( float secs ) audio_membuffer::resize_seconds( float secs )
{ {
resize_mem_(( unsigned int ) resize_mem_(( unsigned int )
(( float )aud_info.byte_rate() * secs ) (( float )aud_info.byte_rate() * secs )
); );
} }
@ -359,150 +361,151 @@ void
void void
audio_membuffer::audio_receive audio_membuffer::audio_receive
( unsigned char * data, unsigned int size ) ( unsigned char * data, unsigned int size )
{ {
// //
// If there isn't a buffer, allocs memory for // If there isn't a buffer, allocs memory for
// it of size*2, and copies audio data arrival. // it of size*2, and copies audio data arrival.
// //
if (( audio_data == 0 ) || ( buf_size == 0 )) if (( audio_data == 0 ) || ( buf_size == 0 ))
{ {
alloc_mem_( size * 2 ); alloc_mem_( size * 2 );
memcpy( audio_data, data, size ); memcpy( audio_data, data, size );
return; return;
} }
// //
// If buffer's free memory is < of `size', // If buffer's free memory is < of `size',
// we have to realloc buffer memory of // we have to realloc buffer memory of
// buf_size*2, while free memory is enough // buf_size*2, while free memory is enough
// to contain `size' bytes. // to contain `size' bytes.
// //
// In this case free memory is represented // In this case free memory is represented
// by `buf_size - bytes_recorded'. // by `buf_size - bytes_recorded'.
// //
unsigned int tot_mem = buf_size, unsigned int tot_mem = buf_size,
free_mem = buf_size - bytes_received; free_mem = buf_size - bytes_received;
if ( free_mem < size ) if ( free_mem < size )
{ {
// //
// Calcs new buffer size. // Calcs new buffer size.
// TODO: flags for other behaviour? // TODO: flags for other behaviour?
while ( free_mem < size ) while ( free_mem < size )
{ {
tot_mem *= 2; 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 // Now we have enough free space in the
// buffer, so let's copy audio data arrivals. // 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 ) if ( audio_arrival )
audio_arrival( aud_info.samples_in_bytes( size )); audio_arrival( aud_info.samples_in_bytes( size ));
} }
unsigned int unsigned int
audio_membuffer::read( BYTE * out_buf, unsigned int bytes ) audio_membuffer::read( BYTE * out_buf, unsigned int bytes )
{ {
// //
// Some checking // Some checking
// //
if ( !audio_data ) if ( !audio_data )
return 0; return 0;
if ( bytes_played_ >= bytes_received ) if ( bytes_played_ >= bytes_received )
return 0; return 0;
unsigned int to_play = unsigned int to_play =
bytes_received - bytes_played_; bytes_received - bytes_played_;
unsigned int to_copy = unsigned int to_copy =
bytes > to_play ? to_play : bytes; bytes > to_play ? to_play : bytes;
// //
// Copies the audio data out. // Copies the audio data out.
// //
if (( out_buf ) && ( to_copy ) && ( audio_data )) if (( out_buf ) && ( to_copy ) && ( audio_data ))
memcpy( out_buf, audio_data + bytes_played_, to_copy ); memcpy( out_buf, audio_data + bytes_played_, to_copy );
// //
// Increments the number of total bytes // Increments the number of total bytes
// played (audio data gone out from the // played (audio data gone out from the
// `audio_producer' object). // `audio_producer' object).
// //
bytes_played_ += bytes; bytes_played_ += bytes;
if ( audio_arrival ) if ( audio_arrival )
audio_arrival( aud_info.samples_in_bytes( bytes )); audio_arrival( aud_info.samples_in_bytes( bytes ));
// //
// Returns the exact size of audio data // Returns the exact size of audio data
// produced. // produced.
// //
return to_copy; return to_copy;
} }
bool bool
audio_membuffer::finished( void ) audio_membuffer::finished( void )
{ {
if ( bytes_played_ < bytes_received ) if ( bytes_played_ < bytes_received )
return false; return false;
else else
return true; return true;
} }
_AUDIO_NAMESPACE_END_ _AUDIO_NAMESPACE_END_

View file

@ -19,7 +19,7 @@ class audio_membuffer : public audio_receiver, public audio_producer
{ {
protected: protected:
@ -58,11 +58,11 @@ class audio_membuffer : public audio_receiver, public audio_producer
public: public:
void ( * audio_arrival )( unsigned int ); void ( * audio_arrival )( unsigned int );
void ( * buffer_resized ) ( unsigned int ); void ( * buffer_resized ) ( unsigned int );
// //
// Ctors // Ctors
// //
@ -70,8 +70,8 @@ class audio_membuffer : public audio_receiver, public audio_producer
audio_membuffer( void ) audio_membuffer( void )
: audio_data( 0 ), aud_info( _AUDIO_DEFAULT_FORMAT ), : audio_data( 0 ), aud_info( _AUDIO_DEFAULT_FORMAT ),
buf_size( 0 ), init_size( 0 ) buf_size( 0 ), init_size( 0 )
{ {
// //
// Allocs memory for at least 1 or some seconds // Allocs memory for at least 1 or some seconds
// of recording. // of recording.
@ -82,7 +82,7 @@ class audio_membuffer : public audio_receiver, public audio_producer
alloc_mem_( init_size ); alloc_mem_( init_size );
} }
@ -90,8 +90,8 @@ class audio_membuffer : public audio_receiver, public audio_producer
audio_membuffer( audio_format aud_fmt ) audio_membuffer( audio_format aud_fmt )
: audio_data( 0 ), aud_info( aud_fmt ), buf_size( 0 ), : audio_data( 0 ), aud_info( aud_fmt ), buf_size( 0 ),
init_size( 0 ) init_size( 0 )
{ {
// //
// Allocs memory for at least 1 or some seconds // Allocs memory for at least 1 or some seconds
// of recording. // of recording.
@ -101,7 +101,7 @@ class audio_membuffer : public audio_receiver, public audio_producer
alloc_mem_( init_size ); alloc_mem_( init_size );
} }
@ -110,15 +110,15 @@ class audio_membuffer : public audio_receiver, public audio_producer
audio_membuffer( audio_format aud_fmt, unsigned int seconds ) audio_membuffer( audio_format aud_fmt, unsigned int seconds )
: audio_data( 0 ), aud_info( aud_fmt ), buf_size( 0 ), : audio_data( 0 ), aud_info( aud_fmt ), buf_size( 0 ),
init_size( 0 ) init_size( 0 )
{ {
// //
// Allocs memory for audio recording // Allocs memory for audio recording
// the specified number of seconds. // the specified number of seconds.
// //
init_size = aud_info.byte_rate() * seconds; init_size = aud_info.byte_rate() * seconds;
alloc_mem_( init_size ); alloc_mem_( init_size );
} }
@ -126,18 +126,18 @@ class audio_membuffer : public audio_receiver, public audio_producer
audio_membuffer( audio_format aud_fmt, float seconds ) audio_membuffer( audio_format aud_fmt, float seconds )
: audio_data( 0 ), aud_info( aud_fmt ), buf_size( 0 ), : audio_data( 0 ), aud_info( aud_fmt ), buf_size( 0 ),
init_size( 0 ) init_size( 0 )
{ {
// //
// Allocs memory for audio recording // Allocs memory for audio recording
// the specified number of seconds. // 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 ); seconds <= 0 ? 1 : seconds );
alloc_mem_( init_size ); alloc_mem_( init_size );
} }
@ -146,14 +146,14 @@ class audio_membuffer : public audio_receiver, public audio_producer
audio_membuffer( unsigned int bytes ) audio_membuffer( unsigned int bytes )
: audio_data( 0 ), aud_info( _AUDIO_DEFAULT_FORMAT ), : audio_data( 0 ), aud_info( _AUDIO_DEFAULT_FORMAT ),
buf_size( 0 ), init_size( 0 ) buf_size( 0 ), init_size( 0 )
{ {
// //
// Allocs memory for the specified bytes // Allocs memory for the specified bytes
// //
init_size = bytes; init_size = bytes;
alloc_mem_( init_size ); alloc_mem_( init_size );
} }
@ -164,14 +164,14 @@ class audio_membuffer : public audio_receiver, public audio_producer
// //
virtual ~audio_membuffer( void ) virtual ~audio_membuffer( void )
{ {
// //
// Frees memory and reset values. // Frees memory and reset values.
// //
clear(); clear();
} }
@ -214,14 +214,14 @@ class audio_membuffer : public audio_receiver, public audio_producer
//returns the float number of seconds //returns the float number of seconds
//that the buffer can record //that the buffer can record
float fseconds_total( void ) const float fseconds_total( void ) const
{ return ( float )(( float ) buf_size / { return ( float )(( float ) buf_size /
( float ) aud_info.byte_rate()); } ( float ) aud_info.byte_rate()); }
//returns the float number of seconds //returns the float number of seconds
//that has been recorded //that has been recorded
float fseconds_recorded( void ) const float fseconds_recorded( void ) const
{ return ( float )(( float ) bytes_received / { return ( float )(( float ) bytes_received /
( float ) aud_info.byte_rate()); } ( float ) aud_info.byte_rate()); }
@ -270,26 +270,26 @@ class audio_membuffer : public audio_receiver, public audio_producer
//if there is a buffer, discards current buffer //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. //new size expressed in bytes.
void alloc_bytes( unsigned int ); void alloc_bytes( unsigned int );
//if there is a buffer, discards current buffer //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. //new size expressed in seconds, integer and float.
void alloc_seconds( unsigned int ); void alloc_seconds( unsigned int );
void alloc_seconds( float ); void alloc_seconds( float );
//resizes in bytes the current buffer, //resizes in bytes the current buffer,
//without discarding previsiously audio data received. //without discarding previsiously audio data received.
void resize_bytes( unsigned int ); void resize_bytes( unsigned int );
//resizes in seconds the current buffer, //resizes in seconds the current buffer,
//without discarding previsiously audio data received. //without discarding previsiously audio data received.
void resize_seconds( unsigned int ); void resize_seconds( unsigned int );
void resize_seconds( float ); void resize_seconds( float );
@ -300,8 +300,8 @@ class audio_membuffer : public audio_receiver, public audio_producer
// //
// Inherited Functions from `audio_receiver' // Inherited Functions from `audio_receiver'
// //
@ -310,7 +310,7 @@ class audio_membuffer : public audio_receiver, public audio_producer
// //
// Inherited Functions from `audio_buffer' // Inherited Functions from `audio_buffer'
// //
@ -318,7 +318,7 @@ class audio_membuffer : public audio_receiver, public audio_producer
unsigned int read( BYTE *, unsigned int ); unsigned int read( BYTE *, unsigned int );
bool finished( void ); bool finished( void );
}; };

View file

@ -14,8 +14,8 @@ class audio_producer
protected: protected:
unsigned int bytes_played_; unsigned int bytes_played_;
@ -33,13 +33,13 @@ class audio_producer
{ } { }
// //
// Dtor // Dtor
// //

View file

@ -25,7 +25,7 @@ class audio_receiver
// //
// The `audio_wavein' class, while is // The `audio_wavein' class, while is
// recording audio, has to access to // recording audio, has to access to
// protected members of `audio_receiver' // protected members of `audio_receiver'
// such as `bytes_received' protected // such as `bytes_received' protected
// variable. // variable.
@ -47,8 +47,8 @@ class audio_receiver
public: public:
// //
// Ctors // Ctors
// //
@ -70,13 +70,13 @@ class audio_receiver
// //
// Public Functions // Public Functions
// //
virtual void audio_receive( unsigned char *, unsigned int ) = 0; virtual void audio_receive( unsigned char *, unsigned int ) = 0;
//virtual void start_rec( void ) = 0; //virtual void start_rec( void ) = 0;
//virtual void stop_rec( void ) = 0; //virtual void stop_rec( void ) = 0;

View file

@ -9,67 +9,69 @@
#include "stdafx.h" #include "stdafx.h"
#include "audio_resampler_acm.hpp" #include "audio_resampler_acm.hpp"
_AUDIO_NAMESPACE_START_ _AUDIO_NAMESPACE_START_
///////////////////////////////////////// /////////////////////////////////////////
/////// Private Functions //////// /////// Private Functions ////////
///////////////////////////////////////// /////////////////////////////////////////
void void
audio_resampler_acm::init_( void ) audio_resampler_acm::init_( void )
{ {
// //
// Zeroing structures // Zeroing structures
// //
ZeroMemory( &acm_header, sizeof( ACMSTREAMHEADER )); ZeroMemory( &acm_header, sizeof( ACMSTREAMHEADER ));
ZeroMemory( &wformat_src, sizeof( WAVEFORMATEX )); ZeroMemory( &wformat_src, sizeof( WAVEFORMATEX ));
ZeroMemory( &wformat_dst, sizeof( WAVEFORMATEX )); ZeroMemory( &wformat_dst, sizeof( WAVEFORMATEX ));
// //
// Setting structures sizes // Setting structures sizes
// //
acm_header.cbStruct = sizeof( ACMSTREAMHEADER ); acm_header.cbStruct = sizeof( ACMSTREAMHEADER );
wformat_src.cbSize = sizeof( WAVEFORMATEX ); wformat_src.cbSize = sizeof( WAVEFORMATEX );
wformat_dst.cbSize = sizeof( WAVEFORMATEX ); wformat_dst.cbSize = sizeof( WAVEFORMATEX );
// //
// Setting WAVEFORMATEX structure parameters // Setting WAVEFORMATEX structure parameters
// according to `audio_format' in/out classes // according to `audio_format' in/out classes
// //
wformat_src.wFormatTag = WAVE_FORMAT_PCM; wformat_src.wFormatTag = WAVE_FORMAT_PCM;
wformat_src.nSamplesPerSec = audfmt_in.sample_rate(); wformat_src.nSamplesPerSec = audfmt_in.sample_rate();
wformat_src.nChannels = audfmt_in.channels(); wformat_src.nChannels = audfmt_in.channels();
wformat_src.wBitsPerSample = audfmt_in.bits(); wformat_src.wBitsPerSample = audfmt_in.bits();
wformat_src.nAvgBytesPerSec = audfmt_in.byte_rate(); wformat_src.nAvgBytesPerSec = audfmt_in.byte_rate();
wformat_src.nBlockAlign = audfmt_in.block_align(); wformat_src.nBlockAlign = audfmt_in.block_align();
wformat_dst.wFormatTag = WAVE_FORMAT_PCM; wformat_dst.wFormatTag = WAVE_FORMAT_PCM;
wformat_dst.nSamplesPerSec = audfmt_out.sample_rate(); wformat_dst.nSamplesPerSec = audfmt_out.sample_rate();
wformat_dst.nChannels = audfmt_out.channels(); wformat_dst.nChannels = audfmt_out.channels();
wformat_dst.wBitsPerSample = audfmt_out.bits(); wformat_dst.wBitsPerSample = audfmt_out.bits();
wformat_dst.nAvgBytesPerSec = audfmt_out.byte_rate(); wformat_dst.nAvgBytesPerSec = audfmt_out.byte_rate();
wformat_dst.nBlockAlign = audfmt_out.block_align(); wformat_dst.nBlockAlign = audfmt_out.block_align();
// //
// Init acm structures completed successfull // Init acm structures completed successfull
// //
} }
@ -90,72 +92,72 @@ _AUDIO_NAMESPACE_START_
void 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, err = acmStreamOpen( &acm_stream, 0, &wformat_src, &wformat_dst,
0, 0, 0, ACM_STREAMOPENF_NONREALTIME ); 0, 0, 0, ACM_STREAMOPENF_NONREALTIME );
if ( err != MMSYSERR_NOERROR ) if ( err != MMSYSERR_NOERROR )
{ {
//TODO: throw error //TODO: throw error
MessageBox( 0, _T("acmOpen error: %i"), _T("ERROR"), MB_ICONERROR ); MessageBox( 0, _T("acmOpen error: %i"), _T("ERROR"), MB_ICONERROR );
} }
// //
// Calcs source buffer lenght // Calcs source buffer lenght
// //
src_buflen = ( unsigned int ) src_buflen = ( unsigned int )
(( float )audfmt_in.byte_rate() * ( float )buf_secs ); (( float )audfmt_in.byte_rate() * ( float )buf_secs );
// //
// Calcs destination source buffer lenght // Calcs destination source buffer lenght
// with help of ACM apis // with help of ACM apis
// //
err = acmStreamSize( acm_stream, err = acmStreamSize( acm_stream,
src_buflen, &dst_buflen, ACM_STREAMSIZEF_SOURCE ); src_buflen, &dst_buflen, ACM_STREAMSIZEF_SOURCE );
if ( err != MMSYSERR_NOERROR ) if ( err != MMSYSERR_NOERROR )
{ {
//TODO: throw error //TODO: throw error
MessageBox( 0, _T("acmStreamSize error"), _T("ERROR"), MB_ICONERROR ); MessageBox( 0, _T("acmStreamSize error"), _T("ERROR"), MB_ICONERROR );
} }
// //
// Initialize ACMSTREAMHEADER structure, // Initialize ACMSTREAMHEADER structure,
// and alloc memory for source and destination // and alloc memory for source and destination
// buffers. // buffers.
// //
acm_header.fdwStatus = 0; acm_header.fdwStatus = 0;
acm_header.dwUser = 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.cbSrcLength = src_buflen;
acm_header.cbSrcLengthUsed = 0; acm_header.cbSrcLengthUsed = 0;
acm_header.dwSrcUser = src_buflen; acm_header.dwSrcUser = src_buflen;
@ -169,29 +171,29 @@ void
// //
// Give ACMSTREAMHEADER initialized correctly to the // Give ACMSTREAMHEADER initialized correctly to the
// driver. // driver.
// //
err = acmStreamPrepareHeader( acm_stream, &acm_header, 0L ); err = acmStreamPrepareHeader( acm_stream, &acm_header, 0L );
if ( err != MMSYSERR_NOERROR ) if ( err != MMSYSERR_NOERROR )
{ {
//TODO: throw error //TODO: throw error
MessageBox( 0, _T("acmStreamPrepareHeader error"), _T("ERROR"), MB_ICONERROR ); MessageBox( 0, _T("acmStreamPrepareHeader error"), _T("ERROR"), MB_ICONERROR );
} }
// //
// ACM stream successfully opened. // ACM stream successfully opened.
// //
stream_opened = true; stream_opened = true;
} }
@ -199,135 +201,135 @@ void
void 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; acm_header.cbDstLength = dst_buflen;
err = acmStreamUnprepareHeader( acm_stream, &acm_header, 0L ); 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 ) if ( acm_header.pbSrc != 0 )
delete[] acm_header.pbSrc; delete[] acm_header.pbSrc;
if ( acm_header.pbDst != 0 ) if ( acm_header.pbDst != 0 )
delete[] acm_header.pbDst; 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 ); MessageBox( 0, _T("acmStreamUnPrepareHeader error"), _T("ERROR"), MB_ICONERROR );
} }
} }
err = acmStreamClose( acm_stream, 0 ); err = acmStreamClose( acm_stream, 0 );
acm_stream = 0; acm_stream = 0;
if ( err != MMSYSERR_NOERROR ) if ( err != MMSYSERR_NOERROR )
{ {
// //
// Free buffer memory // Free buffer memory
// //
if ( acm_header.pbSrc != 0 ) if ( acm_header.pbSrc != 0 )
delete[] acm_header.pbSrc; delete[] acm_header.pbSrc;
if ( acm_header.pbDst != 0 ) if ( acm_header.pbDst != 0 )
delete[] acm_header.pbDst; delete[] acm_header.pbDst;
// //
// Re-init structures // Re-init structures
// //
init_(); init_();
// //
// Updating status // Updating status
// //
stream_opened = false; stream_opened = false;
//TODO: throw error! //TODO: throw error!
MessageBox( 0, _T("acmStreamClose error"), _T("ERROR"), MB_ICONERROR ); MessageBox( 0, _T("acmStreamClose error"), _T("ERROR"), MB_ICONERROR );
} }
}//if acm_stream != 0 }//if acm_stream != 0
// //
// Free buffer memory // Free buffer memory
// //
if ( acm_header.pbSrc != 0 ) if ( acm_header.pbSrc != 0 )
delete[] acm_header.pbSrc; delete[] acm_header.pbSrc;
if ( acm_header.pbDst != 0 ) if ( acm_header.pbDst != 0 )
delete[] acm_header.pbDst; 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.
// //
} }
@ -335,62 +337,63 @@ void
void void
audio_resampler_acm::audio_receive( unsigned char * data, unsigned int size ) audio_resampler_acm::audio_receive( unsigned char * data, unsigned int size )
{ {
MMRESULT err; MMRESULT err;
// //
// Checking for acm stream opened // Checking for acm stream opened
// //
if ( stream_opened ) if ( stream_opened )
{ {
// //
// Copy audio data from extern to // Copy audio data from extern to
// internal source buffer // internal source buffer
// //
memcpy( acm_header.pbSrc, data, size ); memcpy( acm_header.pbSrc, data, size );
acm_header.cbSrcLength = size; acm_header.cbSrcLength = size;
acm_header.cbDstLengthUsed = 0; 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 ) if ( err != MMSYSERR_NOERROR )
{ {
//TODO: throw error //TODO: throw error
MessageBox( 0, _T("acmStreamConvert error"), _T("ERROR"), MB_ICONERROR ); 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 ); //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_ _AUDIO_NAMESPACE_END_

View file

@ -54,18 +54,18 @@ class audio_resampler_acm : public audio_receiver
stream_opened( false ), audfmt_in( fmt_in ), audfmt_out( fmt_out ), stream_opened( false ), audfmt_in( fmt_in ), audfmt_out( fmt_out ),
buf_secs( _AUDIO_DEFAULT_BUFSECS ) buf_secs( _AUDIO_DEFAULT_BUFSECS )
{ {
init_(); init_();
} }
// //
// Dtor // Dtor
// //

File diff suppressed because it is too large Load diff

View file

@ -14,10 +14,10 @@ _AUDIO_NAMESPACE_START_
enum audio_wavein_status { WAVEIN_NOTREADY, WAVEIN_READY, enum audio_wavein_status { WAVEIN_NOTREADY, WAVEIN_READY,
WAVEIN_RECORDING, WAVEIN_ERR, WAVEIN_RECORDING, WAVEIN_ERR,
WAVEIN_STOP, WAVEIN_FLUSHING WAVEIN_STOP, WAVEIN_FLUSHING
}; };
@ -67,14 +67,14 @@ class audio_wavein
audio_format aud_info; audio_format aud_info;
audio_receiver & audio_rcvd; audio_receiver & audio_rcvd;
// //
// Audio Recorder Thread id // Audio Recorder Thread id
// //
@ -82,7 +82,7 @@ class audio_wavein
DWORD recthread_id; DWORD recthread_id;
// //
// Object status // Object status
@ -99,7 +99,7 @@ class audio_wavein
// //
// How many seconds of audio // How many seconds of audio
// can record the internal buffer // can record the internal buffer
// before flushing audio data // before flushing audio data
// to the `audio_receiver' class? // to the `audio_receiver' class?
// //
@ -154,7 +154,7 @@ class audio_wavein
const audio_format & a_info, audio_receiver & a_receiver ) const audio_format & a_info, audio_receiver & a_receiver )
: wave_headers( 0 ), : 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 ), status( WAVEIN_NOTREADY ), main_buffer( 0 ), mb_size( 0 ),
buffers( _AUDIO_DEFAULT_WAVEINBUFFERS ) buffers( _AUDIO_DEFAULT_WAVEINBUFFERS )
{ {
@ -162,8 +162,8 @@ class audio_wavein
// //
// Initializing internal wavein data // Initializing internal wavein data
// //
init_(); init_();
aud_info = a_info; aud_info = a_info;
@ -181,7 +181,7 @@ class audio_wavein
~audio_wavein( void ) ~audio_wavein( void )
{ {
//close(); TODO! //close(); TODO!
} }
@ -211,7 +211,7 @@ class audio_wavein
void buffer_secs( float bsecs ) void buffer_secs( float bsecs )
{ {
// //
// Some checking // Some checking
// //
@ -225,7 +225,7 @@ class audio_wavein
// buffer. // buffer.
// //
buf_secs = bsecs; buf_secs = bsecs;
} }
@ -244,7 +244,7 @@ class audio_wavein
if ( tot_bufs == 0 ) if ( tot_bufs == 0 )
return; return;
// //
// Sets the number of total buffers. // Sets the number of total buffers.
// //
@ -257,7 +257,7 @@ class audio_wavein
{ return aud_info; } { return aud_info; }
}; };

File diff suppressed because it is too large Load diff

View file

@ -10,13 +10,20 @@
_AUDIO_NAMESPACE_START_ _AUDIO_NAMESPACE_START_
enum audio_waveout_status { WAVEOUT_NOTREADY, WAVEOUT_READY,
enum audio_waveout_status { WAVEOUT_NOTREADY, WAVEOUT_READY,
WAVEOUT_PLAYING, WAVEOUT_ERR, WAVEOUT_PLAYING, WAVEOUT_ERR,
WAVEOUT_PAUSED, WAVEOUT_STOP WAVEOUT_PAUSED, WAVEOUT_STOP
}; };
class audio_waveout class audio_waveout
{ {
@ -30,28 +37,28 @@ class audio_waveout
static DWORD WINAPI playing_procedure( LPVOID ); static DWORD WINAPI playing_procedure( LPVOID );
HANDLE wakeup_playthread; HANDLE wakeup_playthread;
protected: protected:
WAVEFORMATEX wave_format; WAVEFORMATEX wave_format;
WAVEHDR * wave_headers; WAVEHDR * wave_headers;
HWAVEOUT waveout_handle; HWAVEOUT waveout_handle;
const audio_format & aud_info; const audio_format & aud_info;
audio_producer & audio_buf; audio_producer & audio_buf;
@ -91,7 +98,7 @@ class audio_waveout
unsigned int buffers; unsigned int buffers;
@ -110,7 +117,7 @@ class audio_waveout
@ -124,7 +131,7 @@ class audio_waveout
audio_producer & a_buf ) audio_producer & a_buf )
: wave_headers( 0 ), aud_info( aud_fmt ), : 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 ), main_buffer( 0 ), mb_size( 0 ),
buffers( _AUDIO_DEFAULT_WAVEOUTBUFFERS ) buffers( _AUDIO_DEFAULT_WAVEOUTBUFFERS )
{ {
@ -132,17 +139,17 @@ class audio_waveout
// //
// Initializing internal wavein data // Initializing internal wavein data
// //
init_(); init_();
} }
// //
// Dtor // Dtor
// //

View file

@ -39,7 +39,7 @@
#define IDC_STATIC -1 #define IDC_STATIC -1
// Next default values for new objects // Next default values for new objects
// //
#ifdef APSTUDIO_INVOKED #ifdef APSTUDIO_INVOKED
#ifndef APSTUDIO_READONLY_SYMBOLS #ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_NO_MFC 1 #define _APS_NO_MFC 1

File diff suppressed because it is too large Load diff

View file

@ -48,7 +48,7 @@ struct riff_hdr
struct wave_hdr struct wave_hdr
{ {
DWORD Subchunkid; DWORD Subchunkid;
DWORD Subchunk1Size; DWORD Subchunk1Size;
WORD AudioFormat; WORD AudioFormat;
@ -71,7 +71,7 @@ struct data_chunk
// //
// Functions prototypes // Functions prototypes
// //
LRESULT CALLBACK LRESULT CALLBACK
Buttons_proc(HWND, UINT, WPARAM, LPARAM); Buttons_proc(HWND, UINT, WPARAM, LPARAM);
@ -87,11 +87,11 @@ VOID disable_but( DWORD );
void void
l_play_finished ( void ); l_play_finished ( void );
void void
l_audio_arrival ( unsigned int ); l_audio_arrival ( unsigned int );
void void
l_buffer_resized ( unsigned int ); l_buffer_resized ( unsigned int );

View file

@ -40,7 +40,7 @@ IDI_SNDREC32 ICON "reactOS_sndrec32.ico"
// Accelerator // Accelerator
// //
IDC_REACTOS_SNDREC32 ACCELERATORS IDC_REACTOS_SNDREC32 ACCELERATORS
BEGIN BEGIN
"?", IDM_ABOUT, ASCII, ALT "?", IDM_ABOUT, ASCII, ALT
"/", IDM_ABOUT, ASCII, ALT "/", IDM_ABOUT, ASCII, ALT
@ -70,7 +70,7 @@ END
// //
#ifdef APSTUDIO_INVOKED #ifdef APSTUDIO_INVOKED
GUIDELINES DESIGNINFO GUIDELINES DESIGNINFO
BEGIN BEGIN
IDD_ABOUTBOX, DIALOG IDD_ABOUTBOX, DIALOG
BEGIN BEGIN
@ -89,12 +89,12 @@ END
// TEXTINCLUDE // TEXTINCLUDE
// //
1 TEXTINCLUDE 1 TEXTINCLUDE
BEGIN BEGIN
"resource.h\0" "resource.h\0"
END END
2 TEXTINCLUDE 2 TEXTINCLUDE
BEGIN BEGIN
"#ifndef APSTUDIO_INVOKED\r\n" "#ifndef APSTUDIO_INVOKED\r\n"
"#include ""targetver.h""\r\n" "#include ""targetver.h""\r\n"
@ -105,7 +105,7 @@ BEGIN
"\0" "\0"
END END
3 TEXTINCLUDE 3 TEXTINCLUDE
BEGIN BEGIN
"\r\n" "\r\n"
"\0" "\0"
@ -135,7 +135,7 @@ IDB_BITMAP2_STOP_DIS BITMAP "but_stop_dis.bmp"
// Menu // Menu
// //
IDR_MENU1 MENU IDR_MENU1 MENU
BEGIN BEGIN
POPUP "File" POPUP "File"
BEGIN BEGIN
@ -160,7 +160,7 @@ END
// String Table // String Table
// //
STRINGTABLE STRINGTABLE
BEGIN BEGIN
IDS_APP_TITLE "reactOS_sndrec32" IDS_APP_TITLE "reactOS_sndrec32"
IDC_REACTOS_SNDREC32 "REACTOS_SNDREC32" IDC_REACTOS_SNDREC32 "REACTOS_SNDREC32"

View file

@ -1,8 +1,8 @@
#pragma once #pragma once
// Le macro seguenti definiscono la piattaforma minima richiesta. La piattaforma minima richiesta // 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 // è 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 // l'applicazione. Le macro consentono di attivare tutte le funzionalità disponibili nelle versioni delle piattaforme fino
// alla versione specificata compresa. // alla versione specificata compresa.
// Modificare le seguenti definizioni se è necessario utilizzare come destinazione una piattaforma prima di quelle specificate di seguito. // Modificare le seguenti definizioni se è necessario utilizzare come destinazione una piattaforma prima di quelle specificate di seguito.