mirror of
https://github.com/reactos/reactos.git
synced 2025-08-06 00:12:57 +00:00
[FORMATTING] SndRec32 patch by Marco Pagliaricci, bug #4978.
svn path=/trunk/; revision=44387
This commit is contained in:
parent
f558c83b1c
commit
99f27439b5
18 changed files with 2053 additions and 2045 deletions
|
@ -25,6 +25,7 @@
|
|||
|
||||
#define _AUDIO_NAMESPACE_START_ namespace snd {
|
||||
#define _AUDIO_NAMESPACE_END_ };
|
||||
|
||||
//
|
||||
// Platform depend stuff
|
||||
//
|
||||
|
|
|
@ -6,7 +6,6 @@
|
|||
* PROGRAMMERS: Marco Pagliaricci <ms_blue (at) hotmail (dot) it>
|
||||
*/
|
||||
|
||||
|
||||
#include "stdafx.h"
|
||||
#include "audio_format.hpp"
|
||||
|
||||
|
|
|
@ -9,6 +9,8 @@
|
|||
#include "stdafx.h"
|
||||
#include "audio_membuffer.hpp"
|
||||
|
||||
|
||||
|
||||
_AUDIO_NAMESPACE_START_
|
||||
|
||||
|
||||
|
@ -20,49 +22,49 @@ _AUDIO_NAMESPACE_START_
|
|||
|
||||
|
||||
void
|
||||
audio_membuffer::alloc_mem_( unsigned int bytes )
|
||||
audio_membuffer::alloc_mem_( unsigned int bytes )
|
||||
{
|
||||
|
||||
//
|
||||
// Some checking
|
||||
//
|
||||
//
|
||||
// Some checking
|
||||
//
|
||||
|
||||
if ( bytes == 0 )
|
||||
return;
|
||||
if ( bytes == 0 )
|
||||
return;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
//
|
||||
// Checks previsiously alloc'd memory
|
||||
// and frees it.
|
||||
//
|
||||
//
|
||||
// Checks previsiously alloc'd memory
|
||||
// and frees it.
|
||||
//
|
||||
|
||||
if ( audio_data )
|
||||
delete[] audio_data;
|
||||
if ( audio_data )
|
||||
delete[] audio_data;
|
||||
|
||||
|
||||
|
||||
//
|
||||
// Allocs new memory and zeros it.
|
||||
//
|
||||
//
|
||||
// Allocs new memory and zeros it.
|
||||
//
|
||||
|
||||
audio_data = new BYTE[ bytes ];
|
||||
audio_data = new BYTE[ bytes ];
|
||||
|
||||
|
||||
memset( audio_data, 0, bytes * sizeof( BYTE ));
|
||||
memset( audio_data, 0, bytes * sizeof( BYTE ));
|
||||
|
||||
|
||||
|
||||
//
|
||||
// Sets the correct buffer size
|
||||
//
|
||||
//
|
||||
// Sets the correct buffer size
|
||||
//
|
||||
|
||||
buf_size = bytes;
|
||||
buf_size = bytes;
|
||||
|
||||
|
||||
init_size = bytes;
|
||||
init_size = bytes;
|
||||
|
||||
|
||||
|
||||
|
@ -70,102 +72,102 @@ 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 );
|
||||
|
||||
}
|
||||
|
||||
|
@ -173,66 +175,66 @@ void
|
|||
|
||||
|
||||
void
|
||||
audio_membuffer::truncate_( void )
|
||||
audio_membuffer::truncate_( void )
|
||||
{
|
||||
|
||||
//
|
||||
// If `buf_size' is already = to the
|
||||
// `bytes_received' of audio data, then
|
||||
// this operation is useless; simply return.
|
||||
//
|
||||
//
|
||||
// If `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,45 +252,45 @@ 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 )
|
||||
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 )
|
||||
audio_membuffer::alloc_bytes( unsigned int bytes )
|
||||
{
|
||||
|
||||
alloc_mem_( bytes );
|
||||
alloc_mem_( bytes );
|
||||
|
||||
}
|
||||
|
||||
|
@ -296,19 +298,19 @@ 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
|
||||
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 ));
|
||||
|
||||
}
|
||||
|
||||
|
@ -316,31 +318,31 @@ void
|
|||
|
||||
|
||||
void
|
||||
audio_membuffer::resize_bytes( unsigned int bytes )
|
||||
audio_membuffer::resize_bytes( unsigned int bytes )
|
||||
{
|
||||
|
||||
resize_mem_( bytes );
|
||||
resize_mem_( bytes );
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
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
|
||||
audio_membuffer::resize_seconds( float secs )
|
||||
audio_membuffer::resize_seconds( float secs )
|
||||
{
|
||||
|
||||
resize_mem_(( unsigned int )
|
||||
(( float )aud_info.byte_rate() * secs )
|
||||
);
|
||||
resize_mem_(( unsigned int )
|
||||
(( float )aud_info.byte_rate() * secs )
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
|
@ -360,81 +362,81 @@ void
|
|||
|
||||
|
||||
void
|
||||
audio_membuffer::audio_receive
|
||||
( unsigned char * data, unsigned int size )
|
||||
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 ));
|
||||
|
||||
|
||||
|
||||
|
@ -442,67 +444,68 @@ void
|
|||
|
||||
|
||||
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 )
|
||||
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_
|
||||
|
|
|
@ -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.
|
||||
//
|
||||
|
||||
|
||||
}
|
||||
|
@ -336,61 +338,62 @@ void
|
|||
|
||||
|
||||
void
|
||||
audio_resampler_acm::audio_receive( unsigned char * data, unsigned int size )
|
||||
audio_resampler_acm::audio_receive( unsigned char * data, unsigned int size )
|
||||
{
|
||||
|
||||
MMRESULT err;
|
||||
MMRESULT err;
|
||||
|
||||
//
|
||||
// Checking for acm stream opened
|
||||
//
|
||||
//
|
||||
// Checking for acm stream opened
|
||||
//
|
||||
|
||||
if ( stream_opened )
|
||||
{
|
||||
if ( stream_opened )
|
||||
{
|
||||
|
||||
|
||||
//
|
||||
// Copy audio data from extern to
|
||||
// internal source buffer
|
||||
//
|
||||
//
|
||||
// Copy audio data from extern to
|
||||
// internal source buffer
|
||||
//
|
||||
|
||||
memcpy( acm_header.pbSrc, data, size );
|
||||
memcpy( acm_header.pbSrc, data, size );
|
||||
|
||||
|
||||
acm_header.cbSrcLength = size;
|
||||
acm_header.cbDstLengthUsed = 0;
|
||||
acm_header.cbSrcLength = size;
|
||||
acm_header.cbDstLengthUsed = 0;
|
||||
|
||||
err = acmStreamConvert( acm_stream, &acm_header, ACM_STREAMCONVERTF_BLOCKALIGN );
|
||||
err = acmStreamConvert( acm_stream, &acm_header, ACM_STREAMCONVERTF_BLOCKALIGN );
|
||||
|
||||
if ( err != MMSYSERR_NOERROR )
|
||||
{
|
||||
//TODO: throw error
|
||||
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_
|
||||
|
|
File diff suppressed because it is too large
Load diff
File diff suppressed because it is too large
Load diff
|
@ -10,6 +10,10 @@
|
|||
|
||||
_AUDIO_NAMESPACE_START_
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
enum audio_waveout_status { WAVEOUT_NOTREADY, WAVEOUT_READY,
|
||||
WAVEOUT_PLAYING, WAVEOUT_ERR,
|
||||
WAVEOUT_PAUSED, WAVEOUT_STOP
|
||||
|
@ -17,6 +21,9 @@ enum audio_waveout_status { WAVEOUT_NOTREADY, WAVEOUT_READY,
|
|||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
class audio_waveout
|
||||
{
|
||||
|
||||
|
|
File diff suppressed because it is too large
Load diff
Loading…
Add table
Add a link
Reference in a new issue