[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_END_ };
//
// Platform depend stuff
//

View file

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

View file

@ -19,7 +19,7 @@ _AUDIO_NAMESPACE_START_
class audio_format
{
protected:
unsigned int samples_psec;
unsigned short int bits_psample;
@ -27,13 +27,13 @@ class audio_format
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 ),
@ -71,7 +71,7 @@ class audio_format
// 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 ));
}

View file

@ -9,6 +9,8 @@
#include "stdafx.h"
#include "audio_membuffer.hpp"
_AUDIO_NAMESPACE_START_
@ -19,50 +21,50 @@ _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;
@ -70,169 +72,169 @@ void
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.
//
}
}
}
@ -250,97 +252,97 @@ void
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 )
);
}
@ -359,150 +361,151 @@ void
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_

View file

@ -19,7 +19,7 @@ class audio_membuffer : public audio_receiver, public audio_producer
{
protected:
@ -58,11 +58,11 @@ class audio_membuffer : public audio_receiver, public audio_producer
public:
void ( * audio_arrival )( unsigned int );
void ( * buffer_resized ) ( unsigned int );
//
// Ctors
//
@ -70,8 +70,8 @@ class audio_membuffer : public audio_receiver, public audio_producer
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.
@ -82,7 +82,7 @@ class audio_membuffer : public audio_receiver, public audio_producer
alloc_mem_( init_size );
}
@ -90,8 +90,8 @@ class audio_membuffer : public audio_receiver, public audio_producer
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.
@ -101,7 +101,7 @@ class audio_membuffer : public audio_receiver, public audio_producer
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_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 );
}
@ -126,18 +126,18 @@ class audio_membuffer : public audio_receiver, public audio_producer
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 );
}
@ -146,14 +146,14 @@ class audio_membuffer : public audio_receiver, public audio_producer
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 );
}
@ -164,14 +164,14 @@ class audio_membuffer : public audio_receiver, public audio_producer
//
virtual ~audio_membuffer( void )
{
{
//
// Frees memory and reset values.
//
clear();
}
@ -214,14 +214,14 @@ class audio_membuffer : public audio_receiver, public audio_producer
//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()); }
@ -270,26 +270,26 @@ class audio_membuffer : public audio_receiver, public audio_producer
//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 );
@ -300,8 +300,8 @@ class audio_membuffer : public audio_receiver, public audio_producer
//
// Inherited Functions from `audio_receiver'
//
@ -310,7 +310,7 @@ class audio_membuffer : public audio_receiver, public audio_producer
//
// Inherited Functions from `audio_buffer'
//
@ -318,7 +318,7 @@ class audio_membuffer : public audio_receiver, public audio_producer
unsigned int read( BYTE *, unsigned int );
bool finished( void );
};

View file

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

View file

@ -25,7 +25,7 @@ class audio_receiver
//
// 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.
@ -47,8 +47,8 @@ class audio_receiver
public:
//
// Ctors
//
@ -70,13 +70,13 @@ class audio_receiver
//
// Public Functions
//
virtual void audio_receive( unsigned char *, unsigned int ) = 0;
//virtual void start_rec( void ) = 0;
//virtual void stop_rec( void ) = 0;

View file

@ -9,67 +9,69 @@
#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
//
}
@ -90,72 +92,72 @@ _AUDIO_NAMESPACE_START_
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;
@ -169,29 +171,29 @@ void
//
// Give ACMSTREAMHEADER initialized correctly to the
// driver.
//
//
// Give ACMSTREAMHEADER initialized correctly to the
// driver.
//
err = acmStreamPrepareHeader( acm_stream, &acm_header, 0L );
err = acmStreamPrepareHeader( acm_stream, &acm_header, 0L );
if ( err != MMSYSERR_NOERROR )
{
//TODO: throw error
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;
}
@ -199,135 +201,135 @@ 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;
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.
//
}
@ -335,62 +337,63 @@ void
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_

View file

@ -54,18 +54,18 @@ class audio_resampler_acm : public audio_receiver
stream_opened( false ), audfmt_in( fmt_in ), audfmt_out( fmt_out ),
buf_secs( _AUDIO_DEFAULT_BUFSECS )
{
{
init_();
}
//
// 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_STOP, WAVEIN_FLUSHING
};
@ -67,14 +67,14 @@ class audio_wavein
audio_format aud_info;
audio_receiver & audio_rcvd;
//
// Audio Recorder Thread id
//
@ -82,7 +82,7 @@ class audio_wavein
DWORD recthread_id;
//
// Object status
@ -99,7 +99,7 @@ class audio_wavein
//
// How many seconds of audio
// can record the internal buffer
// before flushing audio data
// before flushing audio data
// to the `audio_receiver' class?
//
@ -154,7 +154,7 @@ class audio_wavein
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 )
{
@ -162,8 +162,8 @@ class audio_wavein
//
// Initializing internal wavein data
//
init_();
aud_info = a_info;
@ -181,7 +181,7 @@ class audio_wavein
~audio_wavein( void )
{
//close(); TODO!
}
@ -211,7 +211,7 @@ class audio_wavein
void buffer_secs( float bsecs )
{
{
//
// Some checking
//
@ -225,7 +225,7 @@ class audio_wavein
// buffer.
//
buf_secs = bsecs;
buf_secs = bsecs;
}
@ -244,7 +244,7 @@ class audio_wavein
if ( tot_bufs == 0 )
return;
//
// Sets the number of total buffers.
//
@ -257,7 +257,7 @@ class audio_wavein
{ return aud_info; }
};

File diff suppressed because it is too large Load diff

View file

@ -10,13 +10,20 @@
_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
{
@ -30,28 +37,28 @@ 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;
@ -91,7 +98,7 @@ class audio_waveout
unsigned int buffers;
@ -110,7 +117,7 @@ class audio_waveout
@ -124,7 +131,7 @@ class audio_waveout
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 )
{
@ -132,17 +139,17 @@ class audio_waveout
//
// Initializing internal wavein data
//
init_();
}
//
// Dtor
//

View file

@ -39,7 +39,7 @@
#define IDC_STATIC -1
// Next default values for new objects
//
//
#ifdef APSTUDIO_INVOKED
#ifndef APSTUDIO_READONLY_SYMBOLS
#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
{
DWORD Subchunkid;
DWORD Subchunk1Size;
WORD AudioFormat;
@ -71,7 +71,7 @@ struct data_chunk
//
// Functions prototypes
//
LRESULT CALLBACK
LRESULT CALLBACK
Buttons_proc(HWND, UINT, WPARAM, LPARAM);
@ -87,11 +87,11 @@ VOID disable_but( DWORD );
void
void
l_play_finished ( void );
void
void
l_audio_arrival ( unsigned int );
void
void
l_buffer_resized ( unsigned int );

View file

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

View file

@ -1,8 +1,8 @@
#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.