Index: audio_api.hpp =================================================================== --- audio_api.hpp (revision 0) +++ audio_api.hpp (revision 0) @@ -0,0 +1,15 @@ +#ifndef __AUDIO_API__ +#define __AUDIO_API__ + +#include "audio_def.hpp" + +#include "audio_format.hpp" +#include "audio_membuffer.hpp" +#include "audio_producer.hpp" +#include "audio_receiver.hpp" +#include "audio_resampler_acm.hpp" +#include "audio_wavein.hpp" +#include "audio_waveout.hpp" + + +#endif Index: audio_resampler_acm.hpp =================================================================== --- audio_resampler_acm.hpp (revision 44362) +++ audio_resampler_acm.hpp (working copy) @@ -10,6 +10,7 @@ + _AUDIO_NAMESPACE_START_ Index: but_start_dis.bmp =================================================================== Cannot display: file marked as a binary type. svn:mime-type = application/octet-stream Property changes on: but_start_dis.bmp ___________________________________________________________________ Added: svn:mime-type + application/octet-stream Index: sndrec32.rc =================================================================== --- sndrec32.rc (revision 44362) +++ sndrec32.rc (working copy) @@ -33,8 +33,7 @@ // Icon with lowest ID value placed first to ensure application icon // remains consistent on all systems. -IDI_REACTOS_SNDREC32LL ICON "reactOS_sndrec32.ico" -IDI_SMALL ICON "small.ico" +IDI_SNDREC32 ICON "reactOS_sndrec32.ico" ///////////////////////////////////////////////////////////////////////////// // @@ -125,6 +124,11 @@ IDB_BITMAP2_PLAY BITMAP "but_play.bmp" IDB_BITMAP2_STOP BITMAP "but_stop.bmp" IDB_BITMAP2_REC BITMAP "but_rec.bmp" +IDB_BITMAP2_END_DIS BITMAP "but_end_dis.bmp" +IDB_BITMAP2_PLAY_DIS BITMAP "but_play_dis.bmp" +IDB_BITMAP2_REC_DIS BITMAP "but_rec_dis.bmp" +IDB_BITMAP2_START_DIS BITMAP "but_start_dis.bmp" +IDB_BITMAP2_STOP_DIS BITMAP "but_stop_dis.bmp" ///////////////////////////////////////////////////////////////////////////// // @@ -138,7 +142,7 @@ MENUITEM "New", ID_NEW MENUITEM "Open...", ID_FILE_OPEN MENUITEM "Save", ID_FILE_SAVE, GRAYED - MENUITEM "Save As...", ID_FILE_SAVEAS + MENUITEM "Save As...", ID_FILE_SAVEAS, GRAYED MENUITEM SEPARATOR MENUITEM "Exit", ID_EXIT END Index: audio_format.cpp =================================================================== --- audio_format.cpp (revision 44362) +++ audio_format.cpp (working copy) @@ -1,17 +1,13 @@ -/* - * PROJECT: ReactOS Sound Record Application - * LICENSE: GPL - See COPYING in the top level directory - * FILE: base/applications/sndrec32/audio_format.cpp - * PURPOSE: Audio Format - * PROGRAMMERS: Marco Pagliaricci - */ - - #include "stdafx.h" #include "audio_format.hpp" + + + _AUDIO_NAMESPACE_START_ + + // // Standard audio formats (declared as // externs in `audio_format.hpp') @@ -20,5 +16,15 @@ audio_format UNNKOWN_FORMAT( 0, 0, 0); audio_format A44100_16BIT_STEREO( 44100, 16, 2 ); + + + + + + + + + + _AUDIO_NAMESPACE_END_ Index: but_end_dis.bmp =================================================================== Cannot display: file marked as a binary type. svn:mime-type = application/octet-stream Property changes on: but_end_dis.bmp ___________________________________________________________________ Added: svn:mime-type + application/octet-stream Index: audio_format.hpp =================================================================== --- audio_format.hpp (revision 44362) +++ audio_format.hpp (working copy) @@ -122,6 +122,13 @@ } + unsigned int bytes_in_samples( unsigned int samples ) const + { + + return (( samples * ( bits_psample / 8 )) * chan ); + + } + }; Index: audio_def.hpp =================================================================== --- audio_def.hpp (revision 44362) +++ audio_def.hpp (working copy) @@ -4,31 +4,58 @@ #include + + // // Defaults // + + #define _AUDIO_DEFAULT_FORMAT A44100_16BIT_STEREO + #define _AUDIO_DEFAULT_WAVEINBUFFERS 8 #define _AUDIO_DEFAULT_WAVEINBUFSECS 0.1f -#define _AUDIO_DEFAULT_WAVEOUTBUFFERS 8 -#define _AUDIO_DEFAULT_WAVEOUTBUFSECS 0.1f + +#define _AUDIO_DEFAULT_WAVEOUTBUFFERS 2 +#define _AUDIO_DEFAULT_WAVEOUTBUFSECS 1.0f + #define _AUDIO_DEFAULT_BUFSECS 1.0f + // // Namespace stuff // #define _AUDIO_NAMESPACE_START_ namespace snd { #define _AUDIO_NAMESPACE_END_ }; + + + // // Platform depend stuff // + + #include #include //Windows MultiMedia (WINMM) audio apis #include //codecs stuff -#include //codecs stuff +#include //codecs stuff + + +//#pragma comment(lib, "winmm.lib") +//#pragma comment(lib, "msacm32.lib") + + + + + + + + + + #endif //ifdef _AUDIO_DEF__H_ Index: audio_receiver.cpp =================================================================== --- audio_receiver.cpp (revision 44362) +++ audio_receiver.cpp (working copy) @@ -1,11 +1,3 @@ -/* - * PROJECT: ReactOS Sound Record Application - * LICENSE: GPL - See COPYING in the top level directory - * FILE: base/applications/sndrec32/audio_producer.cpp - * PURPOSE: Audio Format - * PROGRAMMERS: Marco Pagliaricci - */ - #include "stdafx.h" #include "audio_receiver.hpp" @@ -14,4 +6,18 @@ _AUDIO_NAMESPACE_START_ + + + + + + + + + + + + + _AUDIO_NAMESPACE_END_ + Index: sndrec32.h =================================================================== --- sndrec32.h (revision 44362) +++ sndrec32.h (working copy) @@ -1,6 +1,7 @@ #pragma once #include "resource.h" +#include "audio_api.hpp" @@ -94,3 +95,6 @@ void l_buffer_resized ( unsigned int ); + + + Index: but_stop_dis.bmp =================================================================== Cannot display: file marked as a binary type. svn:mime-type = application/octet-stream Property changes on: but_stop_dis.bmp ___________________________________________________________________ Added: svn:mime-type + application/octet-stream Index: resource.h =================================================================== --- resource.h (revision 44362) +++ resource.h (working copy) @@ -3,12 +3,14 @@ // Used by reactOS_sndrec32.rc // #define IDC_MYICON 2 +#define IDB_BITMAP2_STOP_DIS 8 #define IDD_REACTOS_SNDREC32_DIALOG 102 #define IDS_APP_TITLE 103 #define IDD_ABOUTBOX 103 #define IDM_ABOUT 104 #define IDI_REACTOS_SNDREC32 107 #define IDI_REACTOS_SNDREC32LL 107 +#define IDI_SNDREC32 107 #define IDI_SMALL 108 #define IDC_REACTOS_SNDREC32 109 #define IDR_MAINFRAME 128 @@ -21,6 +23,11 @@ #define IDB_BITMAP2_REC 137 #define IDI_ICON1 138 #define IDR_MENU1 139 +#define IDI_ICON2 140 +#define IDB_BITMAP2_END_DIS 141 +#define IDB_BITMAP2_PLAY_DIS 142 +#define IDB_BITMAP2_REC_DIS 143 +#define IDB_BITMAP2_START_DIS 144 #define ID_FILE_NEW 32771 #define ID_FILE_OPEN 32772 #define ID_FILE_SAVE 32773 @@ -36,7 +43,7 @@ #ifdef APSTUDIO_INVOKED #ifndef APSTUDIO_READONLY_SYMBOLS #define _APS_NO_MFC 1 -#define _APS_NEXT_RESOURCE_VALUE 140 +#define _APS_NEXT_RESOURCE_VALUE 145 #define _APS_NEXT_COMMAND_VALUE 32779 #define _APS_NEXT_CONTROL_VALUE 1000 #define _APS_NEXT_SYMED_VALUE 110 Index: audio_producer.cpp =================================================================== --- audio_producer.cpp (revision 44362) +++ audio_producer.cpp (working copy) @@ -1,12 +1,3 @@ -/* - * PROJECT: ReactOS Sound Record Application - * LICENSE: GPL - See COPYING in the top level directory - * FILE: base/applications/sndrec32/audio_producer.cpp - * PURPOSE: Audio Format - * PROGRAMMERS: Marco Pagliaricci - */ - - #include "StdAfx.h" #include "audio_producer.hpp" Index: but_play_dis.bmp =================================================================== Cannot display: file marked as a binary type. svn:mime-type = application/octet-stream Property changes on: but_play_dis.bmp ___________________________________________________________________ Added: svn:mime-type + application/octet-stream Index: audio_wavein.cpp =================================================================== --- audio_wavein.cpp (revision 44362) +++ audio_wavein.cpp (working copy) @@ -1,11 +1,3 @@ -/* -* PROJECT: ReactOS Sound Record Application -* LICENSE: GPL - See COPYING in the top level directory -* FILE: base/applications/sndrec32/audio_wavein.cpp -* PURPOSE: Audio WaveIn -* PROGRAMMERS: Marco Pagliaricci -*/ - #include "stdafx.h" #include "audio_wavein.hpp" @@ -14,862 +6,862 @@ _AUDIO_NAMESPACE_START_ - void - audio_wavein::init_( void ) +void +audio_wavein::init_( void ) { - ZeroMemory(( LPVOID ) &wave_format, - sizeof( WAVEFORMATEX )); + ZeroMemory(( LPVOID ) &wave_format, + sizeof( WAVEFORMATEX )); - wave_format.cbSize = sizeof( WAVEFORMATEX ); + wave_format.cbSize = sizeof( WAVEFORMATEX ); - wavein_handle = 0; - recthread_id = 0; - wakeup_recthread = 0; + wavein_handle = 0; + recthread_id = 0; + wakeup_recthread = 0; - buf_secs = _AUDIO_DEFAULT_WAVEINBUFSECS; + buf_secs = _AUDIO_DEFAULT_WAVEINBUFSECS; - status = WAVEIN_NOTREADY; + status = WAVEIN_NOTREADY; } void - audio_wavein::alloc_buffers_mem_( unsigned int buffs, float secs ) +audio_wavein::alloc_buffers_mem_( unsigned int buffs, float secs ) { - unsigned int - onebuf_size = 0, tot_size = 0; + unsigned int + onebuf_size = 0, tot_size = 0; - // - // Release old memory - // + // + // Release old memory + // - if ( main_buffer ) - delete[] main_buffer; + if ( main_buffer ) + delete[] main_buffer; - if ( wave_headers ) - delete[] wave_headers; + if ( wave_headers ) + delete[] wave_headers; - // - // Calcs size of the buffers - // + // + // Calcs size of the buffers + // - onebuf_size = ( unsigned int ) - (( float )aud_info.byte_rate() * secs ); + onebuf_size = ( unsigned int ) + (( float )aud_info.byte_rate() * secs ); - tot_size = onebuf_size * buffs; + tot_size = onebuf_size * buffs; + + + + // + // Allocs memory for the audio buffers + // + main_buffer = new BYTE [ tot_size ]; - // - // Allocs memory for the audio buffers - // - main_buffer = new BYTE [ tot_size ]; + // + // Allocs memory for the `WAVEHDR' structures. + // + wave_headers = ( WAVEHDR * ) + new BYTE [ sizeof( WAVEHDR ) * buffs ]; - // - // Allocs memory for the `WAVEHDR' structures. - // - wave_headers = ( WAVEHDR * ) - new BYTE [ sizeof( WAVEHDR ) * buffs ]; + // + // Zeros memory. + // + ZeroMemory( main_buffer, tot_size ); + ZeroMemory( wave_headers, + sizeof( WAVEHDR ) * buffs ); - // - // Zeros memory. - // - ZeroMemory( main_buffer, tot_size ); + // + // Updates total size of the buffers. + // - ZeroMemory( wave_headers, - sizeof( WAVEHDR ) * buffs ); + mb_size = tot_size; - - // - // Updates total size of the buffers. - // - - mb_size = tot_size; - } void - audio_wavein::free_buffers_mem_( void ) +audio_wavein::free_buffers_mem_( void ) { - // - // Frees memory - // + // + // Frees memory + // - if ( main_buffer ) - delete[] main_buffer; + if ( main_buffer ) + delete[] main_buffer; - if ( wave_headers ) - delete[] wave_headers; + if ( wave_headers ) + delete[] wave_headers; - main_buffer = 0; - wave_headers = 0; + main_buffer = 0; + wave_headers = 0; } void - audio_wavein::init_headers_( void ) +audio_wavein::init_headers_( void ) { - // - // If there is no memory for memory or - // headers, simply return. - // + // + // If there is no memory for memory or + // headers, simply return. + // - if (( !wave_headers ) || ( !main_buffer )) - return; + if (( !wave_headers ) || ( !main_buffer )) + return; - // - // This is the size for one buffer - // + // + // This is the size for one buffer + // - DWORD buf_sz = mb_size / buffers; + DWORD buf_sz = mb_size / buffers; - // - // This is the base address for one buffer - // + // + // This is the base address for one buffer + // + + BYTE * buf_addr = main_buffer; - BYTE * buf_addr = main_buffer; + // + // Initializes headers. + // - // - // Initializes headers. - // + for ( unsigned int i = 0; i < buffers; ++i ) + { + wave_headers[ i ].dwBufferLength = mb_size / buffers; + wave_headers[ i ].lpData = ( LPSTR ) buf_addr; - for ( unsigned int i = 0; i < buffers; ++i ) - { - wave_headers[ i ].dwBufferLength = mb_size / buffers; - wave_headers[ i ].lpData = ( LPSTR ) buf_addr; + buf_addr += buf_sz; + } - buf_addr += buf_sz; - } - } void - audio_wavein::prep_headers_( void ) +audio_wavein::prep_headers_( void ) { - MMRESULT err; - bool error = false; + MMRESULT err; + bool error = false; - // - // If there is no memory for memory or - // headers, throw error. - // + // + // If there is no memory for memory or + // headers, throw error. + // - if (( !wave_headers ) - || ( !main_buffer ) || ( !wavein_handle )) - {} //TODO: throw error! + if (( !wave_headers ) + || ( !main_buffer ) || ( !wavein_handle )) + {} //TODO: throw error! - for ( unsigned int i = 0; i < buffers; ++i ) - { - err = waveInPrepareHeader( wavein_handle, - &wave_headers[ i ], sizeof( WAVEHDR )); + for ( unsigned int i = 0; i < buffers; ++i ) + { + err = waveInPrepareHeader( wavein_handle, + &wave_headers[ i ], sizeof( WAVEHDR )); - if ( err != MMSYSERR_NOERROR ) - error = true; + if ( err != MMSYSERR_NOERROR ) + error = true; - } + } + + if ( error ) + MessageBox( 0, TEXT("waveInPrepareHeader Error."), 0, 0 ); - if ( error ) - MessageBox( 0, TEXT("waveInPrepareHeader Error."), 0, 0 ); - } void - audio_wavein::unprep_headers_( void ) +audio_wavein::unprep_headers_( void ) { - MMRESULT err; - bool error = false; + MMRESULT err; + bool error = false; - // - // If there is no memory for memory or - // headers, throw error. - // + // + // If there is no memory for memory or + // headers, throw error. + // - if (( !wave_headers ) - || ( !main_buffer ) || ( !wavein_handle )) - {} //TODO: throw error! + if (( !wave_headers ) + || ( !main_buffer ) || ( !wavein_handle )) + {} //TODO: throw error! - for ( unsigned int i = 0; i < buffers; ++i ) - { - err = waveInUnprepareHeader( wavein_handle, - &wave_headers[ i ], sizeof( WAVEHDR )); + for ( unsigned int i = 0; i < buffers; ++i ) + { + err = waveInUnprepareHeader( wavein_handle, + &wave_headers[ i ], sizeof( WAVEHDR )); - if ( err != MMSYSERR_NOERROR ) - error = true; + if ( err != MMSYSERR_NOERROR ) + error = true; - } + } + + if ( error ) + MessageBox( 0, TEXT("waveInUnPrepareHeader Error."), 0, 0 ); - if ( error ) - MessageBox( 0, TEXT("waveInUnPrepareHeader Error."), 0, 0 ); - } void - audio_wavein::add_buffers_to_driver_( void ) +audio_wavein::add_buffers_to_driver_( void ) { - MMRESULT err; - bool error = false; + MMRESULT err; + bool error = false; - // - // If there is no memory for memory or - // headers, throw error. - // + // + // If there is no memory for memory or + // headers, throw error. + // - if (( !wave_headers ) - || ( !main_buffer ) || ( !wavein_handle )) - {} //TODO: throw error! + if (( !wave_headers ) + || ( !main_buffer ) || ( !wavein_handle )) + {} //TODO: throw error! - for ( unsigned int i = 0; i < buffers; ++i ) - { - err = waveInAddBuffer( wavein_handle, - &wave_headers[ i ], sizeof( WAVEHDR )); + for ( unsigned int i = 0; i < buffers; ++i ) + { + err = waveInAddBuffer( wavein_handle, + &wave_headers[ i ], sizeof( WAVEHDR )); - if ( err != MMSYSERR_NOERROR ) - error = true; + if ( err != MMSYSERR_NOERROR ) + error = true; - } + } + + if ( error ) + MessageBox( 0, TEXT("waveInAddBuffer Error."), 0, 0 ); - if ( error ) - MessageBox( 0, TEXT("waveInAddBuffer Error."), 0, 0 ); - } void - audio_wavein::close( void ) +audio_wavein::close( void ) { - // - // If wavein object is already in the status - // NOTREADY, nothing to do. - // + // + // If wavein object is already in the status + // NOTREADY, nothing to do. + // - if ( status == WAVEIN_NOTREADY ) - return; + if ( status == WAVEIN_NOTREADY ) + return; - // - // If the wavein is recording, - // then stop recording and close it. - // + // + // If the wavein is recording, + // then stop recording and close it. + // + + if ( status == WAVEIN_RECORDING ) + stop_recording(); - if ( status == WAVEIN_RECORDING ) - stop_recording(); + // + // Updating status. + // - // - // Updating status. - // + status = WAVEIN_NOTREADY; - status = WAVEIN_NOTREADY; + // + // Wakeing up recording thread, so it + // can receive the `MM_WIM_CLOSE' message + // then dies. + // + if ( wakeup_recthread ) + SetEvent( wakeup_recthread ); - // - // Wakeing up recording thread, so it - // can receive the `MM_WIM_CLOSE' message - // then dies. - // - if ( wakeup_recthread ) - SetEvent( wakeup_recthread ); + // + // Closing wavein stream + // - // - // Closing wavein stream - // + while (( waveInClose( wavein_handle )) + != MMSYSERR_NOERROR ) Sleep( 1 ); - while (( waveInClose( wavein_handle )) - != MMSYSERR_NOERROR ) Sleep( 1 ); + // + // Release buffers memory. + // - // - // Release buffers memory. - // + free_buffers_mem_(); - free_buffers_mem_(); + // + // Re-initialize variables to the + // initial state. + // - // - // Re-initialize variables to the - // initial state. - // - - init_(); - + init_(); + } void - audio_wavein::open( void ) +audio_wavein::open( void ) { - MMRESULT err; - HANDLE recthread_handle = 0; + MMRESULT err; + HANDLE recthread_handle = 0; - // - // Checkin the status of the object - // + // + // Checkin the status of the object + // - if ( status != WAVEIN_NOTREADY ) - {} //TODO: throw error + if ( status != WAVEIN_NOTREADY ) + {} //TODO: throw error - // - // Creating the EVENT object that will be signaled - // when the recording thread has to wake up. - // + // + // Creating the EVENT object that will be signaled + // when the recording thread has to wake up. + // - wakeup_recthread = - CreateEvent( 0, FALSE, FALSE, 0 ); + wakeup_recthread = + CreateEvent( 0, FALSE, FALSE, 0 ); - data_flushed_event = - CreateEvent( 0, FALSE, FALSE, 0 ); + data_flushed_event = + CreateEvent( 0, FALSE, FALSE, 0 ); - if (( !wakeup_recthread ) || ( !data_flushed_event )) - { + if (( !wakeup_recthread ) || ( !data_flushed_event )) + { - status = WAVEIN_ERR; + status = WAVEIN_ERR; - MessageBox( 0, TEXT("Thread Error."), 0, 0 ); + MessageBox( 0, TEXT("Thread Error."), 0, 0 ); - //TODO: throw error - } + //TODO: throw error + } - // - // Inialize buffers for recording audio - // data from the wavein audio line. - // + // + // Inialize buffers for recording audio + // data from the wavein audio line. + // - alloc_buffers_mem_( buffers, buf_secs ); - init_headers_(); + alloc_buffers_mem_( buffers, buf_secs ); + init_headers_(); - // - // Sound format that will be captured by wavein - // + // + // Sound format that will be captured by wavein + // - wave_format.wFormatTag = WAVE_FORMAT_PCM; + wave_format.wFormatTag = WAVE_FORMAT_PCM; - wave_format.nChannels = aud_info.channels(); - wave_format.nSamplesPerSec = aud_info.sample_rate(); - wave_format.wBitsPerSample = aud_info.bits(); - wave_format.nBlockAlign = aud_info.block_align(); - wave_format.nAvgBytesPerSec = aud_info.byte_rate(); + wave_format.nChannels = aud_info.channels(); + wave_format.nSamplesPerSec = aud_info.sample_rate(); + wave_format.wBitsPerSample = aud_info.bits(); + wave_format.nBlockAlign = aud_info.block_align(); + wave_format.nAvgBytesPerSec = aud_info.byte_rate(); - // - // Creating the recording thread - // + // + // Creating the recording thread + // - recthread_handle = - CreateThread( NULL, - 0, - audio_wavein::recording_procedure, - ( PVOID ) this, - 0, - &recthread_id - ); + recthread_handle = + CreateThread( NULL, + 0, + audio_wavein::recording_procedure, + ( PVOID ) this, + 0, + &recthread_id + ); + + // + // Checking thread handle + // - // - // Checking thread handle - // + if ( !recthread_handle ) + { - if ( !recthread_handle ) - { + // + // Updating status + // - // - // Updating status - // + status = WAVEIN_ERR; - status = WAVEIN_ERR; + MessageBox( 0, TEXT("Thread Error."), 0, 0 ); + //TODO: throw error - MessageBox( 0, TEXT("Thread Error."), 0, 0 ); - //TODO: throw error + } - } + // + // We don't need the thread handle anymore, + // so we can close it from now. (We'll just + // need the thread ID for the `waveInOpen' API) + // - // - // We don't need the thread handle anymore, - // so we can close it from now. (We'll just - // need the thread ID for the `waveInOpen' API) - // + CloseHandle( recthread_handle ); - CloseHandle( recthread_handle ); + // + // Opening audio line wavein + // - // - // Opening audio line wavein - // + err = waveInOpen( &wavein_handle, + 0, + &wave_format, + recthread_id, + 0, + CALLBACK_THREAD + ); - err = waveInOpen( &wavein_handle, - 0, - &wave_format, - recthread_id, - 0, - CALLBACK_THREAD - ); + if ( err != MMSYSERR_NOERROR ) + { - if ( err != MMSYSERR_NOERROR ) - { + // + // Updating status + // - // - // Updating status - // + status = WAVEIN_ERR; - status = WAVEIN_ERR; + if ( err == WAVERR_BADFORMAT ) + MessageBox( 0, TEXT("waveInOpen Error"), 0, 0 ); - if ( err == WAVERR_BADFORMAT ) - MessageBox( 0, TEXT("waveInOpen Error"), 0, 0 ); + //TODO: throw error + } - //TODO: throw error - } + // + // Update object status + // - // - // Update object status - // + status = WAVEIN_READY; - status = WAVEIN_READY; - - // - // Now `audio_wavein' object is ready - // for audio recording! - // + // + // Now `audio_wavein' object is ready + // for audio recording! + // } void - audio_wavein::start_recording( void ) +audio_wavein::start_recording( void ) { - MMRESULT err; - BOOL ev; + MMRESULT err; + BOOL ev; - if (( status != WAVEIN_READY ) - && ( status != WAVEIN_STOP )) - {} //TODO: throw error + if (( status != WAVEIN_READY ) + && ( status != WAVEIN_STOP )) + {} //TODO: throw error - // - // Updating to the recording status - // + // + // Updating to the recording status + // - status = WAVEIN_RECORDING; + status = WAVEIN_RECORDING; - // - // Let's prepare header of type WAVEHDR that - // we will pass to the driver with our - // audio informations, and buffer informations. - // + // + // Let's prepare header of type WAVEHDR that + // we will pass to the driver with our + // audio informations, and buffer informations. + // + + prep_headers_(); - prep_headers_(); + // + // The waveInAddBuffer function sends an input buffer + // to the given waveform-audio input device. + // When the buffer is filled, the application is notified. + // - // - // The waveInAddBuffer function sends an input buffer - // to the given waveform-audio input device. - // When the buffer is filled, the application is notified. - // + add_buffers_to_driver_(); - add_buffers_to_driver_(); + // + // Signaling event for waking up + // the recorder thread. + // + + ev = SetEvent( wakeup_recthread ); - // - // Signaling event for waking up - // the recorder thread. - // - ev = SetEvent( wakeup_recthread ); + if ( !ev ) + { - if ( !ev ) - { + MessageBox( 0, TEXT("Event Error."), 0, 0 ); + } + - MessageBox( 0, TEXT("Event Error."), 0, 0 ); + // + // Start recording + // - } + + err = waveInStart( wavein_handle ); - // - // Start recording - // + if ( err != MMSYSERR_NOERROR ) + { + // + // Updating status + // - err = waveInStart( wavein_handle ); + status = WAVEIN_ERR; + MessageBox( 0, TEXT("waveInStart Error."), 0, 0 ); - if ( err != MMSYSERR_NOERROR ) - { - // - // Updating status - // + //TODO: throw error - status = WAVEIN_ERR; + } - MessageBox( 0, TEXT("waveInStart Error."), 0, 0 ); - - - //TODO: throw error - - } - } void - audio_wavein::stop_recording( void ) +audio_wavein::stop_recording( void ) { + + MMRESULT err; + DWORD wait; - MMRESULT err; - DWORD wait; + if ( status != WAVEIN_RECORDING ) + return; - if ( status != WAVEIN_RECORDING ) - return; + + status = WAVEIN_FLUSHING; - status = WAVEIN_FLUSHING; + if ( data_flushed_event ) + wait = WaitForSingleObject( + data_flushed_event, INFINITE + ); - if ( data_flushed_event ) - wait = WaitForSingleObject( - data_flushed_event, INFINITE - ); + // + // waveInReset will make all pending buffer as done. + // + err = waveInReset( wavein_handle ); - // - // waveInReset will make all pending buffer as done. - // - err = waveInReset( wavein_handle ); + if ( err != MMSYSERR_NOERROR ) + { + //TODO: throw error - if ( err != MMSYSERR_NOERROR ) - { + MessageBox( 0, TEXT("waveInReset Error."), 0, 0 ); - //TODO: throw error - MessageBox( 0, TEXT("waveInReset Error."), 0, 0 ); + } - } + + // + // Stop recording. + // + err = waveInStop( wavein_handle ); - // - // Stop recording. - // + if ( err != MMSYSERR_NOERROR ) + { - err = waveInStop( wavein_handle ); + //TODO: throw error + MessageBox( 0, TEXT("waveInStop Error."), 0, 0 ); - if ( err != MMSYSERR_NOERROR ) - { - //TODO: throw error - MessageBox( 0, TEXT("waveInStop Error."), 0, 0 ); + } + // + // The waveInUnprepareHeader function cleans up the + // preparation performed by the waveInPrepareHeader function. + // - } + unprep_headers_(); - // - // The waveInUnprepareHeader function cleans up the - // preparation performed by the waveInPrepareHeader function. - // - unprep_headers_(); + + status = WAVEIN_STOP; - - - - status = WAVEIN_STOP; - } DWORD WINAPI - audio_wavein::recording_procedure( LPVOID arg ) +audio_wavein::recording_procedure( LPVOID arg ) { - MSG msg; - WAVEHDR * phdr; - DWORD wait; - audio_wavein * _this = ( audio_wavein * ) arg; + MSG msg; + WAVEHDR * phdr; + DWORD wait; + audio_wavein * _this = ( audio_wavein * ) arg; + + // + // Check the arg pointer + // - // - // Check the arg pointer - // + if ( _this == 0 ) + return 0; - if ( _this == 0 ) - return 0; + + + // + // The thread can go to sleep for now. + // It will be wake up only when there is audio data + // to be recorded. + // + if ( _this->wakeup_recthread ) + wait = WaitForSingleObject( + _this->wakeup_recthread, INFINITE + ); - // - // The thread can go to sleep for now. - // It will be wake up only when there is audio data - // to be recorded. - // - if ( _this->wakeup_recthread ) - wait = WaitForSingleObject( - _this->wakeup_recthread, INFINITE - ); + + // + // If status of the `audio_wavein' object + // is not ready or recording the thread can exit. + // + if (( _this->status != WAVEIN_READY ) && + ( _this->status != WAVEIN_RECORDING )) + return 0; + - // - // If status of the `audio_wavein' object - // is not ready or recording the thread can exit. - // - if (( _this->status != WAVEIN_READY ) && - ( _this->status != WAVEIN_RECORDING )) - return 0; + // + // Entering main polling loop + // + while ( GetMessage( &msg, 0, 0, 0 )) + { + switch ( msg.message ) + { + + case MM_WIM_DATA: + + phdr = ( WAVEHDR * ) msg.lParam; + if (( _this->status == WAVEIN_RECORDING ) + || ( _this->status == WAVEIN_FLUSHING )) + { + // + // Flushes recorded audio data to + // the `audio_receiver' object. + // - // - // Entering main polling loop - // + _this->audio_rcvd.audio_receive( + ( unsigned char * )phdr->lpData, + phdr->dwBytesRecorded + ); - while ( GetMessage( &msg, 0, 0, 0 )) - { + + // + // Updating `audio_receiver' total + // bytes received _AFTER_ calling + // `audio_receive' function. + // - switch ( msg.message ) - { + _this->audio_rcvd.bytes_received += + phdr->dwBytesRecorded; - case MM_WIM_DATA: + - phdr = ( WAVEHDR * ) msg.lParam; + + // + // If status is not flushing data, then + // we can re-add the buffer for reusing it. + // Otherwise, if we are flushing pending data, + // we cannot re-add buffer because we don't need + // it anymore + // - if (( _this->status == WAVEIN_RECORDING ) - || ( _this->status == WAVEIN_FLUSHING )) - { + if ( _this->status != WAVEIN_FLUSHING ) + { - // - // Flushes recorded audio data to - // the `audio_receiver' object. - // + // + // Let the audio driver reuse the buffer + // - _this->audio_rcvd.audio_receive( - ( unsigned char * )phdr->lpData, - phdr->dwBytesRecorded - ); + waveInAddBuffer( _this->wavein_handle, + phdr, sizeof( WAVEHDR )); - // - // Updating `audio_receiver' total - // bytes received _AFTER_ calling - // `audio_receive' function. - // + } else { - _this->audio_rcvd.bytes_received += - phdr->dwBytesRecorded; + // + // If we are flushing pending data, we have + // to prepare to stop recording. + // Set WAVEHDR flag to 0, and fires the event + // `data_flushed_event', that will wake up + // the main thread that is sleeping into + // wavein_in::stop_recording() member function, + // waiting the last `MM_WIM_DATA' message that + // contain pending data. + // + + + phdr->dwFlags = 0; + SetEvent( _this->data_flushed_event ); - // - // If status is not flushing data, then - // we can re-add the buffer for reusing it. - // Otherwise, if we are flushing pending data, - // we cannot re-add buffer because we don't need - // it anymore - // - if ( _this->status != WAVEIN_FLUSHING ) - { + // + // The recording is gooing to stop, so the + // recording thread can go to sleep! + // - // - // Let the audio driver reuse the buffer - // + wait = WaitForSingleObject( + _this->wakeup_recthread, INFINITE ); + + } - waveInAddBuffer( _this->wavein_handle, - phdr, sizeof( WAVEHDR )); + }//if WAVEIN_RECORDING || WAVEIN_FLUSHING - } else { + break; - // - // If we are flushing pending data, we have - // to prepare to stop recording. - // Set WAVEHDR flag to 0, and fires the event - // `data_flushed_event', that will wake up - // the main thread that is sleeping into - // wavein_in::stop_recording() member function, - // waiting the last `MM_WIM_DATA' message that - // contain pending data. - // + + - phdr->dwFlags = 0; - SetEvent( _this->data_flushed_event ); + case MM_WIM_CLOSE: - // - // The recording is gooing to stop, so the - // recording thread can go to sleep! - // + // + // The thread can exit now. + // - wait = WaitForSingleObject( - _this->wakeup_recthread, INFINITE ); + return 0; - } + break; - }//if WAVEIN_RECORDING || WAVEIN_FLUSHING - break; + } //end switch( msg.message ) + + } //end while( GetMessage( ... )) - - - - - - - - - case MM_WIM_CLOSE: - - // - // The thread can exit now. - // - - return 0; - - break; - - - - } //end switch( msg.message ) - - } //end while( GetMessage( ... )) - - return 0; + return 0; } Index: audio_waveout.cpp =================================================================== --- audio_waveout.cpp (revision 44362) +++ audio_waveout.cpp (working copy) @@ -1,13 +1,4 @@ -/* - * PROJECT: ReactOS Sound Record Application - * LICENSE: GPL - See COPYING in the top level directory - * FILE: base/applications/sndrec32/audio_waveout.cpp - * PURPOSE: Audio WaveOut - * PROGRAMMERS: Marco Pagliaricci - */ - - -#include "stdafx.h" +#include "StdAfx.h" #include "audio_waveout.hpp" @@ -19,20 +10,20 @@ audio_waveout::init_( void ) { - ZeroMemory(( LPVOID ) &wave_format, - sizeof( WAVEFORMATEX )); + ZeroMemory(( LPVOID ) &wave_format, + sizeof( WAVEFORMATEX )); - wave_format.cbSize = sizeof( WAVEFORMATEX ); + wave_format.cbSize = sizeof( WAVEFORMATEX ); - waveout_handle = 0; + waveout_handle = 0; - playthread_id = 0; - wakeup_playthread = 0; + playthread_id = 0; + wakeup_playthread = 0; - buf_secs = _AUDIO_DEFAULT_WAVEOUTBUFSECS; + buf_secs = _AUDIO_DEFAULT_WAVEOUTBUFSECS; - status = WAVEOUT_NOTREADY; + status = WAVEOUT_NOTREADY; } @@ -44,68 +35,68 @@ { - unsigned int - onebuf_size = 0, tot_size = 0; + unsigned int + onebuf_size = 0, tot_size = 0; - // - // Release old memory - // + // + // Release old memory + // - if ( main_buffer ) - delete[] main_buffer; + if ( main_buffer ) + delete[] main_buffer; - if ( wave_headers ) - delete[] wave_headers; + if ( wave_headers ) + delete[] wave_headers; - // - // Calcs size of the buffers - // + // + // Calcs size of the buffers + // - onebuf_size = ( unsigned int ) - (( float )aud_info.byte_rate() * secs ); + onebuf_size = ( unsigned int ) + (( float )aud_info.byte_rate() * secs ); - tot_size = onebuf_size * buffs; + tot_size = onebuf_size * buffs; - - - - // - // Allocs memory for the audio buffers - // + + + + // + // Allocs memory for the audio buffers + // - main_buffer = new BYTE [ tot_size ]; + main_buffer = new BYTE [ tot_size ]; - // - // Allocs memory for the `WAVEHDR' structures. - // + // + // Allocs memory for the `WAVEHDR' structures. + // - wave_headers = ( WAVEHDR * ) - new BYTE [ sizeof( WAVEHDR ) * buffs ]; + wave_headers = ( WAVEHDR * ) + new BYTE [ sizeof( WAVEHDR ) * buffs ]; - // - // Zeros memory. - // + // + // Zeros memory. + // - ZeroMemory( main_buffer, tot_size ); + ZeroMemory( main_buffer, tot_size ); - ZeroMemory( wave_headers, - sizeof( WAVEHDR ) * buffs ); + ZeroMemory( wave_headers, + sizeof( WAVEHDR ) * buffs ); - // - // Updates total size of the buffers. - // + // + // Updates total size of the buffers. + // - mb_size = tot_size; + mb_size = tot_size; } @@ -115,72 +106,72 @@ - // - // If there is no memory for memory or - // headers, simply return. - // + // + // If there is no memory for memory or + // headers, simply return. + // - if (( !wave_headers ) || ( !main_buffer )) - return; + if (( !wave_headers ) || ( !main_buffer )) + return; - // - // This is the size for one buffer - // + // + // This is the size for one buffer + // - DWORD buf_sz = mb_size / buffers; + DWORD buf_sz = mb_size / buffers; - // - // This is the base address for one buffer - // - - BYTE * buf_addr = main_buffer; + // + // This is the base address for one buffer + // + + BYTE * buf_addr = main_buffer; - ZeroMemory( wave_headers, sizeof( WAVEHDR ) * buffers ); + ZeroMemory( wave_headers, sizeof( WAVEHDR ) * buffers ); - // - // Initializes headers. - // + // + // Initializes headers. + // - for ( unsigned int i = 0; i < buffers; ++i ) - { - - // - // Sets the correct base address and - // lenght for the little buffer. - // + for ( unsigned int i = 0; i < buffers; ++i ) + { + + // + // Sets the correct base address and + // lenght for the little buffer. + // - wave_headers[ i ].dwBufferLength = mb_size / buffers; - wave_headers[ i ].lpData = ( LPSTR ) buf_addr; + wave_headers[ i ].dwBufferLength = mb_size / buffers; + wave_headers[ i ].lpData = ( LPSTR ) buf_addr; - // - // Unsets the WHDR_DONE flag. - // + // + // Unsets the WHDR_DONE flag. + // - wave_headers[ i ].dwFlags &= ~WHDR_DONE; + wave_headers[ i ].dwFlags &= ~WHDR_DONE; - - // - // Sets the WAVEHDR user data with an - // unique little buffer ID# - // + + // + // Sets the WAVEHDR user data with an + // unique little buffer ID# + // - wave_headers[ i ].dwUser = ( unsigned int ) i; + wave_headers[ i ].dwUser = ( unsigned int ) i; - - - // - // Increments little buffer base address. - // + + + // + // Increments little buffer base address. + // - buf_addr += buf_sz; - } + buf_addr += buf_sz; + } } @@ -188,36 +179,36 @@ void audio_waveout::prep_headers_( void ) { - MMRESULT err; - bool error = false; + MMRESULT err; + bool error = false; - // - // If there is no memory for memory or - // headers, throw error. - // + // + // If there is no memory for memory or + // headers, throw error. + // - if (( !wave_headers ) - || ( !main_buffer ) || ( !waveout_handle )) - {} //TODO: throw error! + if (( !wave_headers ) + || ( !main_buffer ) || ( !waveout_handle )) + {} //TODO: throw error! - for ( unsigned int i = 0; i < buffers; ++i ) - { - err = waveOutPrepareHeader( waveout_handle, - &wave_headers[ i ], sizeof( WAVEHDR )); + for ( unsigned int i = 0; i < buffers; ++i ) + { + err = waveOutPrepareHeader( waveout_handle, + &wave_headers[ i ], sizeof( WAVEHDR )); - if ( err != MMSYSERR_NOERROR ) - error = true; + if ( err != MMSYSERR_NOERROR ) + error = true; - } - + } + - if ( error ) - {} //TODO: throw error indicating which - //header i-th is errorneous + if ( error ) + {} //TODO: throw error indicating which + //header i-th is errorneous @@ -226,37 +217,37 @@ void audio_waveout::unprep_headers_( void ) { - MMRESULT err; - bool error = false; + MMRESULT err; + bool error = false; - // - // If there is no memory for memory or - // headers, throw error. - // + // + // If there is no memory for memory or + // headers, throw error. + // - if (( !wave_headers ) - || ( !main_buffer ) || ( !waveout_handle )) - {} //TODO: throw error! + if (( !wave_headers ) + || ( !main_buffer ) || ( !waveout_handle )) + {} //TODO: throw error! - for ( unsigned int i = 0; i < buffers; ++i ) - { - err = waveOutUnprepareHeader( waveout_handle, - &wave_headers[ i ], sizeof( WAVEHDR )); + for ( unsigned int i = 0; i < buffers; ++i ) + { + err = waveOutUnprepareHeader( waveout_handle, + &wave_headers[ i ], sizeof( WAVEHDR )); - if ( err != MMSYSERR_NOERROR ) - error = true; + if ( err != MMSYSERR_NOERROR ) + error = true; - } - + } + - if ( error ) - {} //TODO: throw error indicating which - //header i-th is errorneous + if ( error ) + {} //TODO: throw error indicating which + //header i-th is errorneous } @@ -274,20 +265,20 @@ - // - // Frees memory - // + // + // Frees memory + // - if ( main_buffer ) - delete[] main_buffer; + if ( main_buffer ) + delete[] main_buffer; - if ( wave_headers ) - delete[] wave_headers; + if ( wave_headers ) + delete[] wave_headers; - main_buffer = 0; - wave_headers = 0; + main_buffer = 0; + wave_headers = 0; @@ -311,142 +302,142 @@ audio_waveout::open( void ) { - MMRESULT err; - HANDLE playthread_handle = 0; + MMRESULT err; + HANDLE playthread_handle = 0; - // - // Checkin the status of the object - // + // + // Checkin the status of the object + // - if ( status != WAVEOUT_NOTREADY ) - {} //TODO: throw error + if ( status != WAVEOUT_NOTREADY ) + {} //TODO: throw error - // - // Creating the EVENT object that will be signaled - // when the playing thread has to wake up. - // + // + // Creating the EVENT object that will be signaled + // when the playing thread has to wake up. + // - wakeup_playthread = - CreateEvent( 0, FALSE, FALSE, 0 ); + wakeup_playthread = + CreateEvent( 0, FALSE, FALSE, 0 ); - if ( !wakeup_playthread ) - { + if ( !wakeup_playthread ) + { - status = WAVEOUT_ERR; + status = WAVEOUT_ERR; - //TODO: throw error - } + //TODO: throw error + } - // - // Inialize buffers for recording audio - // data from the wavein audio line. - // + // + // Inialize buffers for recording audio + // data from the wavein audio line. + // - alloc_buffers_mem_( buffers, buf_secs ); - init_headers_(); + alloc_buffers_mem_( buffers, buf_secs ); + init_headers_(); - // - // Sound format that will be captured by wavein - // + // + // Sound format that will be captured by wavein + // - wave_format.wFormatTag = WAVE_FORMAT_PCM; + wave_format.wFormatTag = WAVE_FORMAT_PCM; - wave_format.nChannels = aud_info.channels(); - wave_format.nSamplesPerSec = aud_info.sample_rate(); - wave_format.wBitsPerSample = aud_info.bits(); - wave_format.nBlockAlign = aud_info.block_align(); - wave_format.nAvgBytesPerSec = aud_info.byte_rate(); + wave_format.nChannels = aud_info.channels(); + wave_format.nSamplesPerSec = aud_info.sample_rate(); + wave_format.wBitsPerSample = aud_info.bits(); + wave_format.nBlockAlign = aud_info.block_align(); + wave_format.nAvgBytesPerSec = aud_info.byte_rate(); - // - // Creating the recording thread - // + // + // Creating the recording thread + // - playthread_handle = - CreateThread( NULL, - 0, - audio_waveout::playing_procedure, - ( PVOID ) this, - 0, - &playthread_id - ); + playthread_handle = + CreateThread( NULL, + 0, + audio_waveout::playing_procedure, + ( PVOID ) this, + 0, + &playthread_id + ); - + - // - // Checking thread handle - // + // + // Checking thread handle + // - if ( !playthread_handle ) - { + if ( !playthread_handle ) + { - // - // Updating status - // + // + // Updating status + // - status = WAVEOUT_ERR; - //TODO: throw error + status = WAVEOUT_ERR; + //TODO: throw error - } + } - // - // We don't need the thread handle anymore, - // so we can close it from now. (We'll just - // need the thread ID for the `waveInOpen' API) - // + // + // We don't need the thread handle anymore, + // so we can close it from now. (We'll just + // need the thread ID for the `waveInOpen' API) + // - CloseHandle( playthread_handle ); + CloseHandle( playthread_handle ); - // - // Reset the `audio_source' to the start - // position. - // + // + // Reset the `audio_source' to the start + // position. + // - audio_buf.set_position_start(); + audio_buf.set_position_start(); - // - // Opens the WAVE_OUT device. - // + // + // Opens the WAVE_OUT device. + // - err = waveOutOpen( - &waveout_handle, - WAVE_MAPPER, - &wave_format, - playthread_id, - 0, - CALLBACK_THREAD | WAVE_ALLOWSYNC - ); + err = waveOutOpen( + &waveout_handle, + WAVE_MAPPER, + &wave_format, + playthread_id, + 0, + CALLBACK_THREAD | WAVE_ALLOWSYNC + ); - if ( err != MMSYSERR_NOERROR ) - { - MessageBox(0, _T("waveOutOpen Error"), 0, 0); - //TODO: throw error + if ( err != MMSYSERR_NOERROR ) + { + MessageBox(0, _T("waveOutOpen Error"), 0, 0); + //TODO: throw error - } + } - status = WAVEOUT_READY; + status = WAVEOUT_READY; } @@ -458,128 +449,128 @@ { - MMRESULT err; - unsigned int i; - BOOL ev; + MMRESULT err; + unsigned int i; + BOOL ev; - if ( !main_buffer ) - { return; } //TODO; throw error, or assert + if ( !main_buffer ) + { return; } //TODO; throw error, or assert - // - // If the status is PAUSED, we have to - // resume the audio playing. - // - if ( status == WAVEOUT_PAUSED ) - { + // + // If the status is PAUSED, we have to + // resume the audio playing. + // + if ( status == WAVEOUT_PAUSED ) + { - // - // Updates status. - // + // + // Updates status. + // - status = WAVEOUT_PLAYING; + status = WAVEOUT_PLAYING; - // - // Tells to the driver to resume - // audio playing. - // + // + // Tells to the driver to resume + // audio playing. + // - waveOutRestart( waveout_handle ); - + waveOutRestart( waveout_handle ); + - // - // Wakeup playing thread. - // + // + // Wakeup playing thread. + // - ev = SetEvent( wakeup_playthread ); + ev = SetEvent( wakeup_playthread ); - return; + return; - } //if status == WAVEOUT_PAUSED + } //if status == WAVEOUT_PAUSED - if ( status != WAVEOUT_READY ) - return; - + if ( status != WAVEOUT_READY ) + return; + - // - // Prepares WAVEHDR structures. - // + // + // Prepares WAVEHDR structures. + // - prep_headers_(); + prep_headers_(); - // - // Sets correct status. - // + // + // Sets correct status. + // - status = WAVEOUT_PLAYING; - - + status = WAVEOUT_PLAYING; + + - // - // Reads the audio from the start. - // + // + // Reads the audio from the start. + // - audio_buf.set_position_start(); + //audio_buf.set_position_start(); - + - - // - // Reads the first N bytes from the audio - // buffer, where N = the total size of all - // little buffers. - // + + // + // Reads the first N bytes from the audio + // buffer, where N = the total size of all + // little buffers. + // - audio_buf.read( main_buffer, mb_size ); + audio_buf.read( main_buffer, mb_size ); - + - - // - // Wakeup the playing thread. - // + + // + // Wakeup the playing thread. + // - ev = SetEvent( wakeup_playthread ); + ev = SetEvent( wakeup_playthread ); - // - // Sends all the little buffers to the - // audio driver, so it can play the sound - // data. - // + // + // Sends all the little buffers to the + // audio driver, so it can play the sound + // data. + // - for ( i = 0; i < buffers; ++ i ) - { + for ( i = 0; i < buffers; ++ i ) + { - - err = waveOutWrite( waveout_handle, &wave_headers[ i ], sizeof( WAVEHDR )); + + err = waveOutWrite( waveout_handle, &wave_headers[ i ], sizeof( WAVEHDR )); - if ( err != MMSYSERR_NOERROR ) - { - + if ( err != MMSYSERR_NOERROR ) + { + - MessageBox(0, _T("waveOutWrite Error"), 0, 0); - - //TODO: throw error - } + MessageBox(0, _T("waveOutWrite Error"), 0, 0); + + //TODO: throw error + } - } + } } @@ -588,40 +579,40 @@ audio_waveout::pause( void ) { - MMRESULT err; + MMRESULT err; - // - // If the waveout object is not playing audio, - // do nothing. - // - - if ( status == WAVEOUT_PLAYING ) - { + // + // If the waveout object is not playing audio, + // do nothing. + // + + if ( status == WAVEOUT_PLAYING ) + { - // - // Updating status. - // + // + // Updating status. + // - status = WAVEOUT_PAUSED; + status = WAVEOUT_PAUSED; - // - // Tells to audio driver to pause audio. - // + // + // Tells to audio driver to pause audio. + // - err = waveOutPause( waveout_handle ); + err = waveOutPause( waveout_handle ); - if ( err != MMSYSERR_NOERROR ) - { + if ( err != MMSYSERR_NOERROR ) + { - MessageBox(0, _T("waveOutPause Error"), 0, 0); - //TODO: throw error + MessageBox(0, _T("waveOutPause Error"), 0, 0); + //TODO: throw error - } + } - } + } } @@ -630,41 +621,41 @@ audio_waveout::stop( void ) { - MMRESULT err; + MMRESULT err; - status = WAVEOUT_STOP; + status = WAVEOUT_STOP; - err = waveOutReset( waveout_handle ); + err = waveOutReset( waveout_handle ); - if ( err != MMSYSERR_NOERROR ) - { + if ( err != MMSYSERR_NOERROR ) + { - MessageBox(0, _T("err waveout reset.\n"),_T("ERROR"), 0); - //TODO: throw error + MessageBox(0, _T("err WaveOutReset.\n"),_T("ERROR"), 0); + //TODO: throw error - } + } - // - // Sets the start position of the audio - // buffer. - // + // + // Sets the start position of the audio + // buffer. + // - audio_buf.set_position_start(); + audio_buf.set_position_start(); - unprep_headers_(); + unprep_headers_(); - init_headers_(); + init_headers_(); - status = WAVEOUT_READY; + status = WAVEOUT_READY; } @@ -672,43 +663,43 @@ audio_waveout::close( void ) { - MMRESULT err; + MMRESULT err; - // - // If the `wave_out' object is playing audio, - // or it is in paused state, we have to call - // the `stop' member function, to flush - // pending buffers. - // - - if (( status == WAVEOUT_PLAYING ) - || ( status== WAVEOUT_PAUSED )) - { - - stop(); + // + // If the `wave_out' object is playing audio, + // or it is in paused state, we have to call + // the `stop' member function, to flush + // pending buffers. + // + + if (( status == WAVEOUT_PLAYING ) + || ( status== WAVEOUT_PAUSED )) + { + + stop(); - } + } - // - // When we have flushed all pending buffers, - // the wave out handle can be successfully closed. - // + // + // When we have flushed all pending buffers, + // the wave out handle can be successfully closed. + // - err = waveOutClose( waveout_handle ); + err = waveOutClose( waveout_handle ); - if ( err != MMSYSERR_NOERROR ) - { + if ( err != MMSYSERR_NOERROR ) + { - MessageBox(0, _T("waveOutClose Error"), 0, 0); - //TODO: throw error + MessageBox(0, _T("waveOutClose Error"), 0, 0); + //TODO: throw error - } + } - free_buffers_mem_(); + free_buffers_mem_(); } @@ -716,174 +707,182 @@ DWORD WINAPI audio_waveout::playing_procedure( LPVOID arg ) { - MSG msg; - WAVEHDR * phdr; - DWORD wait; - MMRESULT err; - audio_waveout * _this = ( audio_waveout * ) arg; - unsigned int read_size; - + MSG msg; + WAVEHDR * phdr; + DWORD wait; + MMRESULT err; + audio_waveout * _this = ( audio_waveout * ) arg; + unsigned int read_size; + - // - // Check the arg pointer - // + // + // Check the arg pointer + // - if ( _this == 0 ) - return 0; + if ( _this == 0 ) + return 0; - - - // - // The thread can go to sleep for now. - // It will be wake up only when there is audio data - // to be recorded. - // + + + // + // The thread can go to sleep for now. + // It will be wake up only when there is audio data + // to be recorded. + // - if ( _this->wakeup_playthread ) - wait = WaitForSingleObject( - _this->wakeup_playthread, INFINITE - ); + if ( _this->wakeup_playthread ) + wait = WaitForSingleObject( + _this->wakeup_playthread, INFINITE + ); - // - // Entering main polling loop - // + // + // Entering main polling loop + // - while ( GetMessage( &msg, 0, 0, 0 )) - { + while ( GetMessage( &msg, 0, 0, 0 )) + { - switch ( msg.message ) - { + switch ( msg.message ) + { - case MM_WOM_DONE: - - phdr = ( WAVEHDR * ) msg.lParam; + case MM_WOM_DONE: + + phdr = ( WAVEHDR * ) msg.lParam; - // - // If the status of the `wave_out' object - // is different than playing, then the thread - // can go to sleep. - // + // + // If the status of the `wave_out' object + // is different than playing, then the thread + // can go to sleep. + // - if (( _this->status != WAVEOUT_PLAYING ) - && ( _this->wakeup_playthread )) - { - - wait = WaitForSingleObject( - _this->wakeup_playthread, - INFINITE - ); - } - - //TODO: quando il thread si risveglia, deve - //entrare nel prossimo if o no? o metter un else { ? + if (( _this->status != WAVEOUT_PLAYING ) + && ( _this->wakeup_playthread )) + { + + wait = WaitForSingleObject( + _this->wakeup_playthread, + INFINITE + ); + } + + //TODO: quando il thread si risveglia, deve + //entrare nel prossimo if o no? o metter un else { ? - - if ( phdr->dwFlags & WHDR_DONE ) - { - - read_size = - _this->audio_buf.read( - ( BYTE * ) phdr->lpData, - phdr->dwBufferLength - ); + + if ( phdr->dwFlags & WHDR_DONE ) + { + + read_size = + _this->audio_buf.read( + ( BYTE * ) phdr->lpData, + phdr->dwBufferLength + ); - - if ( read_size ) - { - phdr->dwBufferLength = read_size; + + if ( read_size ) + { + phdr->dwBufferLength = read_size; - phdr->dwFlags &= ~WHDR_DONE; + phdr->dwFlags &= ~WHDR_DONE; - err = waveOutWrite( - _this->waveout_handle, - phdr, - sizeof( WAVEHDR ) - ); + err = waveOutWrite( + _this->waveout_handle, + phdr, + sizeof( WAVEHDR ) + ); - if ( err != MMSYSERR_NOERROR ) - { - MessageBox(0, _T("waveOutWrite Error"), 0, 0); - //TODO: throw error - } + if ( err != MMSYSERR_NOERROR ) + { + MessageBox(0, _T("waveOutWrite Error"), 0, 0); + //TODO: throw error + } - } else { + } else { - // - // Here `read_sizep' is 0 - // + // + // Here `read_sizep' is 0 + // - if ( phdr->dwUser == ( _this->buffers - 1 )) - { + if ( phdr->dwUser == ( _this->buffers - 1 )) + { - // - // Here `read_size' and the buffer user - // data, that contain a buffer ID#, - // is equal to the number of the total - // buffers - 1. This means that this is the - // _LAST_ little buffer that has been played - // by the audio driver. We can STOP the - // `wave_out' object now, or restart the - // sound playing, if we have a infinite loop. - // + // + // Here `read_size' and the buffer user + // data, that contain a buffer ID#, + // is equal to the number of the total + // buffers - 1. This means that this is the + // _LAST_ little buffer that has been played + // by the audio driver. We can STOP the + // `wave_out' object now, or restart the + // sound playing, if we have a infinite loop. + // - _this->stop(); - - // - // Let the thread go to sleep. - // + _this->stop(); + + // + // Let the thread go to sleep. + // - if ( _this->audio_buf.play_finished ) - _this->audio_buf.play_finished(); - + if ( _this->audio_buf.play_finished ) + _this->audio_buf.play_finished(); + - if ( _this->wakeup_playthread ) - wait = WaitForSingleObject( - _this->wakeup_playthread, - INFINITE - ); + if ( _this->wakeup_playthread ) + wait = WaitForSingleObject( + _this->wakeup_playthread, + INFINITE + ); - } + } - } //if read_size != 0 + } //if read_size != 0 - } //( phdr->dwFlags & WHDR_DONE ) - + } //( phdr->dwFlags & WHDR_DONE ) + - break; // end case + break; // end case - case MM_WOM_CLOSE: - // - // The thread can exit now. - // + case MM_WOM_CLOSE: + // + // The thread can exit now. + // - return 0; + return 0; - break; + break; - case MM_WOM_OPEN: - - // - // Do nothing. - // + case MM_WOM_OPEN: + + // + // Do nothing. + // - break; + break; - } //end switch( msg.message ) - - } //end while( GetMessage( ... )) + } //end switch( msg.message ) + + } //end while( GetMessage( ... )) - return 0; + return 0; } + + + + + + + + _AUDIO_NAMESPACE_END_ Index: but_rec_dis.bmp =================================================================== Cannot display: file marked as a binary type. svn:mime-type = application/octet-stream Property changes on: but_rec_dis.bmp ___________________________________________________________________ Added: svn:mime-type + application/octet-stream Index: audio_waveout.hpp =================================================================== --- audio_waveout.hpp (revision 44362) +++ audio_waveout.hpp (working copy) @@ -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 @@ }; + + + class audio_waveout { Index: sndrec32.cpp =================================================================== --- sndrec32.cpp (revision 44362) +++ sndrec32.cpp (working copy) @@ -1,20 +1,12 @@ -/* -* PROJECT: ReactOS Sound Record Application -* LICENSE: GPL - See COPYING in the top level directory -* FILE: base/applications/sndrec32/sndrec32.cpp -* PURPOSE: Application Startup -* PROGRAMMERS: Marco Pagliaricci -*/ +#include "stdafx.h" +#include "sndrec32.h" -#include "stdafx.h" -#include "sndrec32.h" -#include "kkaudio.hpp" +//#pragma comment(lib, "comctl32.lib") - HINSTANCE hInst; TCHAR szTitle[MAX_LOADSTRING]; TCHAR szWindowClass[MAX_LOADSTRING]; @@ -31,6 +23,7 @@ HWND slider; HWND buttons[5]; HBITMAP butbmps[5]; +HBITMAP butbmps_dis[5]; WNDPROC buttons_std_proc; BOOL butdisabled[5]; @@ -42,136 +35,135 @@ WORD slider_min; WORD slider_max; -long long samples_max; +DWORD samples_max; OPENFILENAME ofn; TCHAR file_path[MAX_PATH]; BOOL path_set; -using snd::audio_membuffer; -using snd::audio_wavein; -using snd::audio_waveout; +snd::audio_membuffer * AUD_BUF; +snd::audio_waveout * AUD_OUT; +snd::audio_wavein * AUD_IN; -audio_membuffer * AUD_BUF; -audio_waveout * AUD_OUT; -audio_wavein * AUD_IN; - BOOL s_recording; + int APIENTRY _tWinMain(HINSTANCE hInstance, - HINSTANCE hPrevInstance, - LPTSTR lpCmdLine, - int nCmdShow) + HINSTANCE hPrevInstance, + LPTSTR lpCmdLine, + int nCmdShow) { - UNREFERENCED_PARAMETER(hPrevInstance); - UNREFERENCED_PARAMETER(lpCmdLine); + UNREFERENCED_PARAMETER(hPrevInstance); + UNREFERENCED_PARAMETER(lpCmdLine); - MSG msg; - HACCEL hAccelTable; + MSG msg; + HACCEL hAccelTable; - InitCommonControls(); + InitCommonControls(); + butbmps[0] = LoadBitmap( hInstance, MAKEINTRESOURCE( IDB_BITMAP2_START )); + butbmps[1] = LoadBitmap( hInstance, MAKEINTRESOURCE( IDB_BITMAP2_END )); + butbmps[2] = LoadBitmap( hInstance, MAKEINTRESOURCE( IDB_BITMAP2_PLAY )); + butbmps[3] = LoadBitmap( hInstance, MAKEINTRESOURCE( IDB_BITMAP2_STOP )); + butbmps[4] = LoadBitmap( hInstance, MAKEINTRESOURCE( IDB_BITMAP2_REC )); + butbmps_dis[0] = LoadBitmap( hInstance, MAKEINTRESOURCE( IDB_BITMAP2_START_DIS )); + butbmps_dis[1] = LoadBitmap( hInstance, MAKEINTRESOURCE( IDB_BITMAP2_END_DIS )); + butbmps_dis[2] = LoadBitmap( hInstance, MAKEINTRESOURCE( IDB_BITMAP2_PLAY_DIS )); + butbmps_dis[3] = LoadBitmap( hInstance, MAKEINTRESOURCE( IDB_BITMAP2_STOP_DIS )); + butbmps_dis[4] = LoadBitmap( hInstance, MAKEINTRESOURCE( IDB_BITMAP2_REC_DIS )); + snd::audio_membuffer AUD_buffer( snd::A44100_16BIT_STEREO ); + snd::audio_waveout AUD_waveout( snd::A44100_16BIT_STEREO, AUD_buffer ); + snd::audio_wavein AUD_wavein( snd::A44100_16BIT_STEREO, AUD_buffer ); + AUD_buffer.play_finished = l_play_finished; + AUD_buffer.audio_arrival = l_audio_arrival; + AUD_buffer.buffer_resized = l_buffer_resized; + AUD_buffer.alloc_seconds( INITIAL_BUFREC_SECONDS ); - butbmps[0] = LoadBitmap( hInstance, MAKEINTRESOURCE( IDB_BITMAP2_START )); - butbmps[1] = LoadBitmap( hInstance, MAKEINTRESOURCE( IDB_BITMAP2_END )); - butbmps[2] = LoadBitmap( hInstance, MAKEINTRESOURCE( IDB_BITMAP2_PLAY )); - butbmps[3] = LoadBitmap( hInstance, MAKEINTRESOURCE( IDB_BITMAP2_STOP )); - butbmps[4] = LoadBitmap( hInstance, MAKEINTRESOURCE( IDB_BITMAP2_REC )); + AUD_IN = &AUD_wavein; + AUD_OUT = &AUD_waveout; + AUD_BUF = &AUD_buffer; + slider_pos = 0; + slider_min = 0; + slider_max = 32767; + stopped_flag = FALSE; + path_set = FALSE; + isnew = TRUE; - snd::audio_membuffer AUD_buffer( snd::A44100_16BIT_STEREO ); - snd::audio_waveout AUD_waveout( snd::A44100_16BIT_STEREO, AUD_buffer ); - snd::audio_wavein AUD_wavein( snd::A44100_16BIT_STEREO, AUD_buffer ); - AUD_buffer.play_finished = l_play_finished; - AUD_buffer.audio_arrival = l_audio_arrival; - AUD_buffer.buffer_resized = l_buffer_resized; + samples_max = AUD_buffer.total_samples(); - AUD_buffer.alloc_seconds( INITIAL_BUFREC_SECONDS ); - AUD_IN = &AUD_wavein; - AUD_OUT = &AUD_waveout; - AUD_BUF = &AUD_buffer; + LoadString(hInstance, + IDS_APP_TITLE, szTitle, MAX_LOADSTRING); - slider_pos = 0; - slider_min = 0; - slider_max = 32767; + LoadString(hInstance, + IDC_REACTOS_SNDREC32, szWindowClass, MAX_LOADSTRING); - stopped_flag = FALSE; - path_set = FALSE; - isnew = TRUE; + MyRegisterClass(hInstance); + + if (!InitInstance (hInstance, nCmdShow)) + { + MessageBox(0, 0, TEXT("CreateWindow() Error!"), 0); + return FALSE; + } - samples_max = AUD_buffer.total_samples(); + hAccelTable = LoadAccelerators(hInstance, + MAKEINTRESOURCE( IDC_REACTOS_SNDREC32 )); + - LoadString(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING); - LoadString(hInstance, IDC_REACTOS_SNDREC32, szWindowClass, MAX_LOADSTRING); - MyRegisterClass(hInstance); + s_recording = false; + - if (!InitInstance (hInstance, nCmdShow)) - { - MessageBox(0, 0, TEXT("CreateWindow() Error!"), 0); - return FALSE; - } + - hAccelTable = LoadAccelerators(hInstance, MAKEINTRESOURCE(IDC_REACTOS_SNDREC32)); + AUD_wavein.open(); + AUD_waveout.open(); + + while (GetMessage(&msg, NULL, 0, 0)) + { + if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg)) + { + TranslateMessage(&msg); + DispatchMessage(&msg); + } + } - s_recording = false; + AUD_waveout.close(); + AUD_wavein.close(); + AUD_buffer.clear(); - - AUD_wavein.open(); - AUD_waveout.open(); - - - - - - - while (GetMessage(&msg, NULL, 0, 0)) - { - if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg)) - { - TranslateMessage(&msg); - DispatchMessage(&msg); - } - } - - AUD_waveout.close(); - AUD_wavein.close(); - - AUD_buffer.clear(); - - - return (int) msg.wParam; + return (int) msg.wParam; } @@ -179,864 +171,892 @@ ATOM MyRegisterClass(HINSTANCE hInstance) { - WNDCLASSEX wcex; + WNDCLASSEX wcex; - wcex.cbSize = sizeof(WNDCLASSEX); + wcex.cbSize = sizeof(WNDCLASSEX); - wcex.style = CS_HREDRAW | CS_VREDRAW; - wcex.lpfnWndProc = WndProc; - wcex.cbClsExtra = 0; - wcex.cbWndExtra = 0; - wcex.hInstance = hInstance; - wcex.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_REACTOS_SNDREC32LL)); - wcex.hCursor = LoadCursor(NULL, IDC_ARROW); - wcex.hbrBackground = (HBRUSH)(16); - wcex.lpszMenuName = MAKEINTRESOURCE(IDR_MENU1); - wcex.lpszClassName = szWindowClass; - wcex.hIconSm = LoadIcon(wcex.hInstance, MAKEINTRESOURCE(IDI_REACTOS_SNDREC32LL)); + wcex.style = CS_HREDRAW | CS_VREDRAW; + wcex.lpfnWndProc = WndProc; + wcex.cbClsExtra = 0; + wcex.cbWndExtra = 0; + wcex.hInstance = hInstance; + wcex.hIcon = LoadIcon( hInstance, MAKEINTRESOURCE( IDI_SNDREC32 )); + wcex.hCursor = LoadCursor( NULL, IDC_ARROW ); + wcex.hbrBackground = (HBRUSH)( 16 ); + wcex.lpszMenuName = MAKEINTRESOURCE( IDR_MENU1 ); + wcex.lpszClassName = szWindowClass; + wcex.hIconSm = LoadIcon( wcex.hInstance, MAKEINTRESOURCE( IDI_SNDREC32 )); - return RegisterClassEx(&wcex); + return RegisterClassEx( &wcex ); } -BOOL InitInstance(HINSTANCE hInstance, int nCmdShow) +BOOL InitInstance( HINSTANCE hInstance, int nCmdShow ) { - HWND hWnd; + HWND hWnd; - hInst = hInstance; + hInst = hInstance; - hWnd = CreateWindow( - szWindowClass, - szTitle, - WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX, - CW_USEDEFAULT, - CW_USEDEFAULT, - MAINWINDOW_W, - MAINWINDOW_H, - NULL, NULL, - hInstance, NULL - ); + hWnd = CreateWindow( + szWindowClass, + szTitle, + WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX, + CW_USEDEFAULT, + CW_USEDEFAULT, + MAINWINDOW_W, + MAINWINDOW_H, + NULL, NULL, + hInstance, NULL + ); - if (!hWnd) - { - return FALSE; - } + if (!hWnd) + { + return FALSE; + } - ShowWindow(hWnd, nCmdShow); - UpdateWindow(hWnd); + ShowWindow(hWnd, nCmdShow); + UpdateWindow(hWnd); - main_win = hWnd; + main_win = hWnd; - return TRUE; + return TRUE; } // LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { - int wmId, wmEvent; - RECT rect; - PAINTSTRUCT ps; - HDC hdc; + int wmId, wmEvent; + RECT rect; + PAINTSTRUCT ps; + HDC hdc; - // - // Checking for global pointers to buffer and - // io audio devices. - // + // + // Checking for global pointers to buffer and + // io audio devices. + // - if (( !AUD_IN ) || ( !AUD_OUT ) || ( !AUD_BUF )) - { - MessageBox( 0, TEXT("Buffer Error"), 0, 0 ); - return 1; - } + if (( !AUD_IN ) || ( !AUD_OUT ) || ( !AUD_BUF )) + { + MessageBox( 0, TEXT("Buffer Error"), 0, 0 ); + return 1; + } + + switch (message) + { - switch (message) - { + case WM_CREATE: - case WM_CREATE: + // + // Creating ALL the buttons + // + + for ( int i = 0; i < 5; ++ i ) + { - // - // Creating ALL the buttons - // + buttons[i] = CreateWindow( + TEXT("button"), + TEXT(""), + WS_CHILD|WS_VISIBLE|BS_BITMAP, + BUTTONS_CX + ( i * (BUTTONS_W+((i == 0)?0:BUTTONS_SPACE))), + BUTTONS_CY, BUTTONS_W, BUTTONS_H, hWnd, + (HMENU)i, hInst, 0 + ); - for ( int i = 0; i < 5; ++ i ) - { + if ( !buttons[i] ) + { + MessageBox(0, 0, TEXT("CreateWindow() Error!"), 0); + return FALSE; - buttons[i] = CreateWindow( - TEXT("button"), - TEXT(""), - WS_CHILD|WS_VISIBLE| BS_BITMAP, - BUTTONS_CX + ( i * (BUTTONS_W+((i == 0)?0:BUTTONS_SPACE))), - BUTTONS_CY, BUTTONS_W, BUTTONS_H, hWnd, - (HMENU)i, hInst, 0 - ); + } - if ( !buttons[i] ) - { - MessageBox(0, 0, TEXT("CreateWindow() Error!"), 0); - return FALSE; - } + // + // Realize the button bmp image + // - butdisabled[ i ] = TRUE; + SendMessage(buttons[i], BM_SETIMAGE, ( WPARAM )IMAGE_BITMAP, ( LPARAM )butbmps[i]); + + UpdateWindow( buttons[i] ); + disable_but( i ); + } - // - // Realize the button bmp image - // - SendMessage(buttons[i], BM_SETIMAGE, ( WPARAM )IMAGE_BITMAP, ( LPARAM )butbmps[i]); + // + // Creating the SLIDER window + // + + slider = CreateWindow( + TRACKBAR_CLASS, + TEXT(""), + WS_CHILD|WS_VISIBLE|TBS_NOTICKS|TBS_HORZ|TBS_ENABLESELRANGE, + SLIDER_CX, SLIDER_CY, SLIDER_W, SLIDER_H, hWnd, + (HMENU)SLIDER_ID, hInst, 0 + ); - UpdateWindow( buttons[i] ); + if ( !slider ) + { + MessageBox(0, 0, TEXT("CreateWindow() Error!"), 0); + return FALSE; - } + } - // - // Creating the SLIDER window - // + // + // Sets slider limits + // - slider = CreateWindow( - TRACKBAR_CLASS, - TEXT(""), - WS_CHILD|WS_VISIBLE|TBS_NOTICKS|TBS_HORZ|TBS_ENABLESELRANGE, - SLIDER_CX, SLIDER_CY, SLIDER_W, SLIDER_H, hWnd, - (HMENU)SLIDER_ID, hInst, 0 - ); + SendMessage( + slider, + TBM_SETRANGE, + (WPARAM)TRUE, + (LPARAM)MAKELONG(slider_min,slider_max) + ); - if ( !slider ) - { - MessageBox(0, 0, TEXT("CreateWindow() Error!"), 0); - return FALSE; - } + UpdateWindow( slider ); + enable_but( BUTREC_ID ); - // - // Sets slider limits - // + EnableWindow( slider, FALSE ); - //slider_min = 0; - //slider_max = 100; - SendMessage( - slider, - TBM_SETRANGE, - (WPARAM)TRUE, - (LPARAM)MAKELONG(slider_min,slider_max) - ); - UpdateWindow( slider ); + break; - // - // Enables REC button. - // - butdisabled[ BUTREC_ID ] = FALSE; + // + // Implements slider logic + // + case WM_HSCROLL : + { + switch( LOWORD( wParam )) + { + + case SB_ENDSCROLL: + break; + case SB_PAGERIGHT: + case SB_PAGELEFT: + case TB_THUMBTRACK: - break; + // + // If the user touch the slider bar, + // set the audio start position properly + // + slider_pos = SendMessage( slider, TBM_GETPOS, 0, 0 ); - // - // Implements slider logic - // - case WM_HSCROLL : - { - switch( LOWORD( wParam )) - { + AUD_BUF->set_position( + AUD_BUF->audinfo().bytes_in_samples( + (( slider_pos * samples_max ) / slider_max ) + ) + ); + - case SB_ENDSCROLL: - break; + break; - case SB_PAGERIGHT: - case SB_PAGELEFT: - case TB_THUMBTRACK: - slider_pos = SendMessage(slider, TBM_GETPOS, 0, 0); - break; + } - } + break; + } - break; - } + case WM_COMMAND: - case WM_COMMAND: + wmId = LOWORD( wParam ); + wmEvent = HIWORD( wParam ); + + if (( wmId >= 0 ) && ( wmId < 5 ) && ( butdisabled[wmId] == TRUE )) + break; - wmId = LOWORD(wParam); - wmEvent = HIWORD(wParam); + switch (wmId) + { - if (( wmId >= 0 ) && ( wmId < 5 ) && (butdisabled[wmId] == TRUE)) - break; + case ID_NEW: - switch (wmId) - { + if ( !isnew ) + { - case ID_NEW: + if ( AUD_IN->current_status() == snd::WAVEIN_RECORDING ) + AUD_IN->stop_recording(); - if ( !isnew ) - { - if ( AUD_IN->current_status() == snd::WAVEIN_RECORDING ) - AUD_IN->stop_recording(); + if (( AUD_OUT->current_status() == snd::WAVEOUT_PLAYING ) || + ( AUD_OUT->current_status() == snd::WAVEOUT_PAUSED )) + AUD_OUT->stop(); - if (( AUD_OUT->current_status() == snd::WAVEOUT_PLAYING ) || - ( AUD_OUT->current_status() == snd::WAVEOUT_PAUSED )) - AUD_OUT->stop(); + AUD_BUF->reset(); + enable_but( BUTREC_ID ); + disable_but( BUTSTART_ID ); + disable_but( BUTEND_ID ); + disable_but( BUTSTOP_ID ); + disable_but( BUTPLAY_ID ); - AUD_BUF->reset(); - butdisabled[ BUTREC_ID ] = FALSE; - butdisabled[ BUTSTART_ID ] = TRUE; - butdisabled[ BUTEND_ID ] = TRUE; - butdisabled[ BUTSTOP_ID ] = TRUE; - butdisabled[ BUTPLAY_ID ] = TRUE; + samples_max = AUD_BUF->total_samples(); + slider_pos = 0; - samples_max = AUD_BUF->total_samples(); - slider_pos = 0; + SendMessage(slider, TBM_SETPOS, (WPARAM) TRUE, (LPARAM) slider_pos); - SendMessage(slider, TBM_SETPOS, (WPARAM) TRUE, (LPARAM) slider_pos); + EnableMenuItem( GetMenu( hWnd ), ID_FILE_SAVEAS, MF_GRAYED ); + EnableMenuItem( GetMenu( hWnd ), ID_FILE_SAVE, MF_GRAYED ); - } + isnew = TRUE; + ZeroMemory( file_path, MAX_PATH ); + EnableWindow( slider, FALSE ); - break; + } + + + break; - case ID_FILE_OPEN: - ZeroMemory( &ofn, sizeof( ofn )); + case ID_FILE_OPEN: - ofn.lStructSize = sizeof( ofn ); - ofn.hwndOwner = hWnd; - ofn.lpstrFilter = TEXT("Audio Files (*.wav)\0*.wav\0All Files (*.*)\0*.*\0"); - ofn.lpstrFile = file_path; - ofn.nMaxFile = MAX_PATH; - ofn.Flags = OFN_EXPLORER | OFN_FILEMUSTEXIST | OFN_HIDEREADONLY; - ofn.lpstrDefExt = TEXT("wav"); + ZeroMemory( &ofn, sizeof( ofn )); - if( GetOpenFileName( &ofn )) - { - open_wav( file_path ); - } + ofn.lStructSize = sizeof( ofn ); + ofn.hwndOwner = hWnd; + ofn.lpstrFilter = TEXT("Audio Files (*.wav)\0*.wav\0All Files (*.*)\0*.*\0"); + ofn.lpstrFile = file_path; + ofn.nMaxFile = MAX_PATH; + ofn.Flags = OFN_EXPLORER | OFN_FILEMUSTEXIST | OFN_HIDEREADONLY; + ofn.lpstrDefExt = TEXT("wav"); - break; + if( GetOpenFileName( &ofn )) + { + open_wav( file_path ); + EnableMenuItem( GetMenu( hWnd ), ID_FILE_SAVE, MF_ENABLED ); + EnableMenuItem( GetMenu( hWnd ), ID_FILE_SAVEAS, MF_ENABLED ); + EnableWindow( slider, TRUE ); + } + break; - case ID__ABOUT: - break; + case ID__ABOUT: + + + break; - case ID_FILE_SAVEAS: - ZeroMemory( &ofn, sizeof( ofn )); + case ID_FILE_SAVEAS: - ofn.lStructSize = sizeof( ofn ); - ofn.hwndOwner = hWnd ; - ofn.Flags = OFN_OVERWRITEPROMPT; - ofn.lpstrFilter = TEXT("Audio Files (*.wav)\0*.wav\0All Files (*.*)\0*.*\0"); - ofn.lpstrFile = file_path; - ofn.nMaxFile = MAX_PATH; + ZeroMemory( &ofn, sizeof( ofn )); - ofn.lpstrDefExt = TEXT("wav"); + ofn.lStructSize = sizeof( ofn ); + ofn.hwndOwner = hWnd ; + ofn.Flags = OFN_OVERWRITEPROMPT; + ofn.lpstrFilter = TEXT("Audio Files (*.wav)\0*.wav\0All Files (*.*)\0*.*\0"); + ofn.lpstrFile = file_path; + ofn.nMaxFile = MAX_PATH; + + ofn.lpstrDefExt = TEXT("wav"); + + if ( GetSaveFileName ( &ofn )) + { + write_wav( file_path ); - if ( GetSaveFileName ( &ofn )) - { + EnableMenuItem( GetMenu( hWnd ), ID_FILE_SAVE, MF_ENABLED ); + } - write_wav( file_path ); + break; - } + case ID_EXIT: + DestroyWindow( hWnd ); + break; - break; - case ID_EXIT: - DestroyWindow( hWnd ); - break; + // + // Sndrec32 buttons routines + // + case BUTSTART_ID: - // - // Sndrec32 buttons routines - // + AUD_BUF->set_position_start(); - case BUTSTART_ID: - Beep(200,200); - break; + slider_pos = 0; + SendMessage( slider, TBM_SETPOS, (WPARAM) TRUE, (LPARAM) slider_pos ); - case BUTEND_ID: - Beep(300,200); - break; + break; - case BUTPLAY_ID: - AUD_OUT->play(); + case BUTEND_ID: + //Beep(300,200); + break; - butdisabled[ BUTSTART_ID ] = TRUE; - butdisabled[ BUTEND_ID ] = TRUE; - butdisabled[ BUTREC_ID ] = TRUE; - butdisabled[ BUTPLAY_ID ] = TRUE; + case BUTPLAY_ID: + + AUD_OUT->play(); - SetTimer( hWnd, 1, 250, 0 ); + disable_but( BUTSTART_ID ); + disable_but( BUTEND_ID ); + disable_but( BUTREC_ID ); + disable_but( BUTPLAY_ID ); - break; - case BUTSTOP_ID: - if ( s_recording ) - { - s_recording = FALSE; + SetTimer( hWnd, 1, 250, 0 ); - AUD_IN->stop_recording(); + break; - butdisabled[ BUTSTART_ID ] = FALSE; - butdisabled[ BUTEND_ID ] = FALSE; - butdisabled[ BUTREC_ID ] = FALSE; - butdisabled[ BUTPLAY_ID ] = FALSE; + case BUTSTOP_ID: + if ( s_recording ) + { + s_recording = FALSE; + AUD_IN->stop_recording(); + - // - // Resetting slider position - // + // + // Resetting slider position + // + + slider_pos = 0; + SendMessage(slider, TBM_SETPOS, (WPARAM) TRUE, (LPARAM) slider_pos); - slider_pos = 0; - SendMessage(slider, TBM_SETPOS, (WPARAM) TRUE, (LPARAM) slider_pos); + samples_max = AUD_BUF->samples_received(); - samples_max = AUD_BUF->samples_received(); + EnableMenuItem((HMENU)IDR_MENU1, ID_FILE_SAVEAS, MF_ENABLED ); - EnableMenuItem((HMENU)IDR_MENU1, ID_FILE_SAVEAS, MF_ENABLED ); - } else { + enable_but( BUTSTART_ID ); + enable_but( BUTEND_ID ); + enable_but( BUTREC_ID ); + enable_but( BUTPLAY_ID ); - AUD_OUT->pause(); + EnableMenuItem( GetMenu( hWnd ), ID_FILE_SAVEAS, MF_ENABLED ); + EnableWindow( slider, TRUE ); - butdisabled[ BUTSTART_ID ] = FALSE; - butdisabled[ BUTEND_ID ] = FALSE; - butdisabled[ BUTREC_ID ] = FALSE; - butdisabled[ BUTPLAY_ID ] = FALSE; - } - KillTimer( hWnd, 1 ); + } else { - break; + AUD_OUT->pause(); - case BUTREC_ID: + enable_but( BUTSTART_ID ); + enable_but( BUTEND_ID ); + enable_but( BUTREC_ID ); + enable_but( BUTPLAY_ID ); - s_recording = TRUE; + } - samples_max = AUD_BUF->total_samples(); + KillTimer( hWnd, 1 ); + + break; - AUD_IN->start_recording(); + case BUTREC_ID: - butdisabled[ BUTSTOP_ID ] = FALSE; - butdisabled[ BUTSTART_ID ] = TRUE; - butdisabled[ BUTEND_ID ] = TRUE; - butdisabled[ BUTREC_ID ] = TRUE; - butdisabled[ BUTPLAY_ID ] = TRUE; + s_recording = TRUE; - isnew = FALSE; + samples_max = AUD_BUF->total_samples(); + AUD_IN->start_recording(); + enable_but( BUTSTOP_ID ); - SetTimer( hWnd, 1, 150, 0 ); + disable_but( BUTSTART_ID ); + disable_but( BUTEND_ID ); + disable_but( BUTREC_ID ); + disable_but( BUTPLAY_ID ); - break; + isnew = FALSE; + EnableWindow( slider, FALSE ); - default: - return DefWindowProc(hWnd, message, wParam, lParam); - } - break; + SetTimer( hWnd, 1, 150, 0 ); + break; - case WM_TIMER: - if ( stopped_flag ) - { - KillTimer(hWnd, 1); - slider_pos = 0; + default: + return DefWindowProc(hWnd, message, wParam, lParam); + } + break; - butdisabled[ BUTPLAY_ID ] = FALSE; - stopped_flag = FALSE; - } + case WM_TIMER: - SendMessage(slider, TBM_SETPOS, (WPARAM) TRUE, (LPARAM) slider_pos); + if ( stopped_flag ) + { + KillTimer(hWnd, 1); + slider_pos = 0; + enable_but( BUTPLAY_ID ); + stopped_flag = FALSE; + } - break; + SendMessage( slider, TBM_SETPOS, (WPARAM) TRUE, (LPARAM) slider_pos ); - case WM_PAINT: + break; - InvalidateRect( hWnd, &rect, TRUE ); - hdc = BeginPaint(hWnd, &ps); - EndPaint(hWnd, &ps); - break; - case WM_DESTROY: - PostQuitMessage(0); - break; - default: - return DefWindowProc(hWnd, message, wParam, lParam); - } - return 0; -} + case WM_PAINT: -BOOL open_wav( TCHAR * f ) -{ + InvalidateRect( hWnd, &rect, TRUE ); + hdc = BeginPaint(hWnd, &ps); + + EndPaint(hWnd, &ps); + break; + case WM_DESTROY: + PostQuitMessage(0); + break; + default: + return DefWindowProc(hWnd, message, wParam, lParam); + } + return 0; +} - HANDLE file; - riff_hdr r; - wave_hdr w; - data_chunk d; - BOOL b; - DWORD bytes_recorded_in_wav = 0; - DWORD is_read = 0; +void l_play_finished ( void ) +{ + stopped_flag = true; + enable_but( BUTSTART_ID ); + enable_but( BUTEND_ID ); + enable_but( BUTREC_ID ); + enable_but( BUTPLAY_ID ); - file = CreateFile( - f, - GENERIC_READ, - 0, 0, - OPEN_EXISTING, - FILE_ATTRIBUTE_NORMAL, - 0 - ); + +} +void l_audio_arrival ( unsigned int samples_arrival ) +{ - if ( !file ) - { - MessageBox( - main_win, - TEXT("Cannot open file. CreateFile() error."), - TEXT("ERROR"), - MB_OK|MB_ICONERROR - ); - return FALSE; + slider_pos += (DWORD) (( slider_max * samples_arrival ) / samples_max ); + - } +} +void l_buffer_resized ( unsigned int new_size ) +{ - b = ReadFile( file, ( LPVOID ) &r, sizeof ( r ), &is_read, 0 ); - if ( !b ) - { - DWORD t = GetLastError(); - TCHAR p[100]; - wsprintf(p,TEXT("Errore n: %i"),t); - MessageBox( - main_win, - //TEXT("Cannot read RIFF header."), - p, - TEXT("ERROR"), - MB_OK|MB_ICONERROR - ); - CloseHandle( file ); - return FALSE; - } +} +VOID enable_but( DWORD id ) +{ - b = ReadFile( file, ( LPVOID ) &w, sizeof ( w ), &is_read, 0 ); + butdisabled[ id ] = FALSE; + SendMessage(buttons[ id ], BM_SETIMAGE, ( WPARAM )IMAGE_BITMAP, ( LPARAM )butbmps[ id ]); - if ( !b ) - { - MessageBox( - main_win, - TEXT("Cannot read WAVE header."), - TEXT("ERROR"), - MB_OK|MB_ICONERROR - ); +} +VOID disable_but( DWORD id ) +{ - CloseHandle( file ); - return FALSE; + butdisabled[ id ] = TRUE; - } + SendMessage(buttons[ id ], BM_SETIMAGE, ( WPARAM )IMAGE_BITMAP, ( LPARAM )butbmps_dis[ id ]); +} - b = ReadFile( file, ( LPVOID ) &d, sizeof ( d ), &is_read, 0 ); - if ( !b ) - { - MessageBox( - main_win, - TEXT("Cannot read WAVE subchunk."), - TEXT("ERROR"), - MB_OK|MB_ICONERROR - ); - CloseHandle( file ); - return FALSE; - } - bytes_recorded_in_wav = r.chunksize - 36; - /* - unsigned char * gg = (unsigned char*)&bytes_recorded_in_wav; - gg[0] = gg[3]; - gg[1] = gg[2]; - bytes_recorded_in_wav = (DWORD) *gg; - TCHAR p [100]; - wsprintf(p,TEXT("bytes: %i"),bytes_recorded_in_wav); - MessageBox(0,p,0,0); - */ - if ( bytes_recorded_in_wav == 0 ) - { +BOOL open_wav( TCHAR * f ) +{ - MessageBox( - main_win, - TEXT("Cannot read file. No audio data."), - TEXT("ERROR"), - MB_OK|MB_ICONERROR - ); - CloseHandle( file ); - return FALSE; + HANDLE file; + + riff_hdr r; + wave_hdr w; + data_chunk d; - } + BOOL b; + DWORD bytes_recorded_in_wav = 0; + DWORD is_read = 0; - snd::audio_format openfmt - ( w.SampleRate, w.BitsPerSample, w.NumChannels ); + file = CreateFile( + f, + GENERIC_READ, + 0, 0, + OPEN_EXISTING, + FILE_ATTRIBUTE_NORMAL, + 0 + ); - AUD_BUF->clear(); + if ( !file ) + { + MessageBox( + main_win, + TEXT("Cannot open file. CreateFile() error."), + TEXT("ERROR"), + MB_OK|MB_ICONERROR + ); - AUD_BUF->alloc_bytes( bytes_recorded_in_wav ); + return FALSE; + } - b = ReadFile( - file, - ( LPVOID ) AUD_BUF->audio_buffer(), - bytes_recorded_in_wav, - &is_read, - 0 - ); + b = ReadFile( file, ( LPVOID ) &r, sizeof ( r ), &is_read, 0 ); + if ( !b ) + { + MessageBox( + main_win, + TEXT("Cannot read RIFF header."), + TEXT("ERROR"), + MB_OK|MB_ICONERROR + ); - AUD_BUF->set_b_received( bytes_recorded_in_wav ); + CloseHandle( file ); + return FALSE; + } - if (( !b ) || ( is_read != bytes_recorded_in_wav )) - { + b = ReadFile( file, ( LPVOID ) &w, sizeof ( w ), &is_read, 0 ); - MessageBox( - main_win, - TEXT("Cannot read file. Error reading audio data."), - TEXT("ERROR"), - MB_OK|MB_ICONERROR - ); - CloseHandle( file ); + if ( !b ) + { + MessageBox( + main_win, + TEXT("Cannot read WAVE header."), + TEXT("ERROR"), + MB_OK|MB_ICONERROR + ); - AUD_BUF->reset(); - return FALSE; + CloseHandle( file ); + return FALSE; + } - } - CloseHandle( file ); - butdisabled[ BUTPLAY_ID ] = FALSE; - butdisabled[ BUTSTOP_ID ] = FALSE; - butdisabled[ BUTEND_ID ] = FALSE; - butdisabled[ BUTSTART_ID ] = FALSE; - butdisabled[ BUTREC_ID ] = FALSE; + b = ReadFile( file, ( LPVOID ) &d, sizeof ( d ), &is_read, 0 ); + if ( !b ) + { + MessageBox( + main_win, + TEXT("Cannot read WAVE subchunk."), + TEXT("ERROR"), + MB_OK|MB_ICONERROR + ); + CloseHandle( file ); + return FALSE; + } - samples_max = AUD_BUF->samples_received(); + bytes_recorded_in_wav = r.chunksize - 36; - isnew = FALSE; - return TRUE; + if ( bytes_recorded_in_wav == 0 ) + { + MessageBox( + main_win, + TEXT("Cannot read file. No audio data."), + TEXT("ERROR"), + MB_OK|MB_ICONERROR + ); -} + CloseHandle( file ); + return FALSE; + } -BOOL - write_wav( TCHAR * f ) -{ + snd::audio_format openfmt + ( w.SampleRate, w.BitsPerSample, w.NumChannels ); - HANDLE file; - DWORD written; - BOOL is_writ; - int i; - riff_hdr r; - wave_hdr w; - data_chunk d; + AUD_BUF->clear(); + AUD_BUF->alloc_bytes( bytes_recorded_in_wav ); - file = CreateFile( - f, - GENERIC_WRITE, - 0, 0, - CREATE_NEW, - FILE_ATTRIBUTE_NORMAL, - 0 - ); + b = ReadFile( + file, + ( LPVOID ) AUD_BUF->audio_buffer(), + bytes_recorded_in_wav, + &is_read, + 0 + ); - if ( !file ) - { - i = MessageBox( - main_win, - TEXT("File already exist. Overwrite it?"), - TEXT("Warning"), - MB_YESNO|MB_ICONQUESTION - ); + AUD_BUF->set_b_received( bytes_recorded_in_wav ); - if ( i == IDYES ) - { - file = CreateFile( - f, - GENERIC_WRITE, - 0, 0, - CREATE_ALWAYS, - FILE_ATTRIBUTE_NORMAL, - 0 - ); + if (( !b ) || ( is_read != bytes_recorded_in_wav )) + { + MessageBox( + main_win, + TEXT("Cannot read file. Error reading audio data."), + TEXT("ERROR"), + MB_OK|MB_ICONERROR + ); - if ( !file ) - { - MessageBox( - main_win, - TEXT("File Error, CreateFile() failed."), - TEXT("ERROR"), - MB_OK|MB_ICONERROR - ); + CloseHandle( file ); + AUD_BUF->reset(); + return FALSE; + } - return FALSE; + CloseHandle( file ); - } + enable_but( BUTPLAY_ID ); + enable_but( BUTSTOP_ID ); + enable_but( BUTSTART_ID ); + enable_but( BUTEND_ID ); + enable_but( BUTREC_ID ); - } else - return FALSE; - } + samples_max = AUD_BUF->samples_received(); + isnew = FALSE; + return TRUE; +} - r.magic = 0x46464952; +BOOL +write_wav( TCHAR * f ) +{ - r.format = 0x45564157; - r.chunksize = 36 + AUD_BUF->bytes_recorded(); + HANDLE file; + + + DWORD written; + BOOL is_writ; + int i; + riff_hdr r; + wave_hdr w; + data_chunk d; - w.Subchunkid = 0x20746d66; - w.Subchunk1Size = 16; - w.AudioFormat = 1; - w.NumChannels = AUD_BUF->audinfo().channels(); - w.SampleRate = AUD_BUF->audinfo().sample_rate(); - w.ByteRate = AUD_BUF->audinfo().byte_rate(); - w.BlockAlign = AUD_BUF->audinfo().block_align(); - w.BitsPerSample = AUD_BUF->audinfo().bits(); + file = CreateFile( + f, + GENERIC_WRITE, + 0, 0, + CREATE_NEW, + FILE_ATTRIBUTE_NORMAL, + 0 + ); - d.subc = 0x61746164; - d.subc_size = AUD_BUF->bytes_recorded(); + if ( !file ) + { + i = MessageBox( + main_win, + TEXT("File already exist. Overwrite it?"), + TEXT("Warning"), + MB_YESNO|MB_ICONQUESTION + ); + if ( i == IDYES ) + { - // - // Writing headers - // + file = CreateFile( + f, + GENERIC_WRITE, + 0, 0, + CREATE_ALWAYS, + FILE_ATTRIBUTE_NORMAL, + 0 + ); + if ( !file ) + { + MessageBox( + main_win, + TEXT("File Error, CreateFile() failed."), + TEXT("ERROR"), + MB_OK|MB_ICONERROR + ); - is_writ = WriteFile( file, ( LPCVOID ) &r, sizeof ( r ), &written, 0 ); - if ( !is_writ ) - { - MessageBox( - main_win, - TEXT("File Error, WriteFile() failed."), - TEXT("ERROR"), - MB_OK|MB_ICONERROR - ); + return FALSE; - CloseHandle( file ); + } - return FALSE; - } + } else + return FALSE; + } - is_writ = WriteFile( file, ( LPCVOID ) &w, sizeof ( w ), &written, 0 ); + + + r.magic = 0x46464952; - if ( !is_writ ) - { - MessageBox( - main_win, - TEXT("File Error, WriteFile() failed."), - TEXT("ERROR"), - MB_OK|MB_ICONERROR - ); + + r.format = 0x45564157; + r.chunksize = 36 + AUD_BUF->bytes_recorded(); - CloseHandle( file ); + + w.Subchunkid = 0x20746d66; - return FALSE; + w.Subchunk1Size = 16; + w.AudioFormat = 1; + w.NumChannels = AUD_BUF->audinfo().channels(); + w.SampleRate = AUD_BUF->audinfo().sample_rate(); + w.ByteRate = AUD_BUF->audinfo().byte_rate(); + w.BlockAlign = AUD_BUF->audinfo().block_align(); + w.BitsPerSample = AUD_BUF->audinfo().bits(); - } + + d.subc = 0x61746164; + d.subc_size = AUD_BUF->bytes_recorded(); - is_writ = WriteFile( file, ( LPCVOID ) &d, sizeof ( d ), &written, 0 ); + // + // Writing headers + // - if ( !is_writ ) - { - MessageBox( - main_win, - TEXT("File Error, WriteFile() failed."), - TEXT("ERROR"), - MB_OK|MB_ICONERROR - ); + + is_writ = WriteFile( file, ( LPCVOID ) &r, sizeof ( r ), &written, 0 ); - CloseHandle( file ); + if ( !is_writ ) + { + MessageBox( + main_win, + TEXT("File Error, WriteFile() failed."), + TEXT("ERROR"), + MB_OK|MB_ICONERROR + ); + + CloseHandle( file ); - return FALSE; + return FALSE; - } + } + is_writ = WriteFile( file, ( LPCVOID ) &w, sizeof ( w ), &written, 0 ); - is_writ = WriteFile( - file, - ( LPCVOID ) AUD_BUF->audio_buffer(), - AUD_BUF->bytes_recorded(), - &written, - 0 - ); + if ( !is_writ ) + { + MessageBox( + main_win, + TEXT("File Error, WriteFile() failed."), + TEXT("ERROR"), + MB_OK|MB_ICONERROR + ); + + CloseHandle( file ); - if ( !is_writ ) - { - MessageBox( - main_win, - TEXT("File Error, WriteFile() failed."), - TEXT("ERROR"), - MB_OK|MB_ICONERROR - ); + return FALSE; - CloseHandle( file ); + } - return FALSE; - } + is_writ = WriteFile( file, ( LPCVOID ) &d, sizeof ( d ), &written, 0 ); - CloseHandle( file ); + if ( !is_writ ) + { + MessageBox( + main_win, + TEXT("File Error, WriteFile() failed."), + TEXT("ERROR"), + MB_OK|MB_ICONERROR + ); + + CloseHandle( file ); - return TRUE; -} + return FALSE; + } -void l_play_finished ( void ) -{ + + is_writ = WriteFile( + file, + ( LPCVOID ) AUD_BUF->audio_buffer(), + AUD_BUF->bytes_recorded(), + &written, + 0 + ); - stopped_flag = true; + if ( !is_writ ) + { + MessageBox( + main_win, + TEXT("File Error, WriteFile() failed."), + TEXT("ERROR"), + MB_OK|MB_ICONERROR + ); + CloseHandle( file ); + + return FALSE; + } -} -void l_audio_arrival ( unsigned int samples_arrival ) -{ + CloseHandle( file ); - - slider_pos += (DWORD) (( slider_max * samples_arrival ) / samples_max ); - - + return TRUE; } - -void l_buffer_resized ( unsigned int new_size ) -{ - - - - - -} - -VOID enable_but( DWORD id ) -{ - - - - - -} -VOID disable_but( DWORD id ) -{ - - - -} - - Index: audio_membuffer.cpp =================================================================== --- audio_membuffer.cpp (revision 44362) +++ audio_membuffer.cpp (working copy) @@ -1,61 +1,62 @@ -/* - * PROJECT: ReactOS Sound Record Application - * LICENSE: GPL - See COPYING in the top level directory - * FILE: base/applications/sndrec32/audio_membuffer.cpp - * PURPOSE: Audio MemBuffer - * PROGRAMMERS: Marco Pagliaricci - */ - -#include "stdafx.h" +#include "StdAfx.h" #include "audio_membuffer.hpp" + + _AUDIO_NAMESPACE_START_ + + +////////////////////////////////////// +/////// Protected Functions ///////// +////////////////////////////////////// + + 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; @@ -63,171 +64,171 @@ 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 ) +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. - // + } - } - } @@ -243,65 +244,65 @@ 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 ); } - + 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 )); } @@ -309,31 +310,31 @@ 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 ) + ); } @@ -353,149 +354,167 @@ 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 )); - - - } 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. + // + if (( out_buf ) && ( to_copy ) && ( audio_data )) + memcpy( out_buf, audio_data + bytes_played_, to_copy ); - // - // Copies the audio data out. - // - if (( out_buf ) && ( to_copy ) && ( audio_data )) - memcpy( out_buf, audio_data + bytes_played_, to_copy ); + // + // Increments the number of total bytes + // played (audio data gone out from the + // `audio_producer' object). + // + bytes_played_ += bytes; - // - // Increments the number of total bytes - // played (audio data gone out from the - // `audio_producer' object). - // - bytes_played_ += bytes; + if ( audio_arrival ) + audio_arrival( aud_info.samples_in_bytes( bytes )); + + // + // Returns the exact size of audio data + // produced. + // - if ( audio_arrival ) - audio_arrival( aud_info.samples_in_bytes( bytes )); - - - // - // 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_ Index: audio_resampler_acm.cpp =================================================================== --- audio_resampler_acm.cpp (revision 44362) +++ audio_resampler_acm.cpp (working copy) @@ -1,75 +1,69 @@ -/* - * PROJECT: ReactOS Sound Record Application - * LICENSE: GPL - See COPYING in the top level directory - * FILE: base/applications/sndrec32/audio_resampler_acm.cpp - * PURPOSE: Audio Resampler - * PROGRAMMERS: Marco Pagliaricci - */ - #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 + // + acm_header.cbStruct = sizeof( ACMSTREAMHEADER ); + wformat_src.cbSize = sizeof( WAVEFORMATEX ); + wformat_dst.cbSize = sizeof( WAVEFORMATEX ); - // - // Setting structures sizes - // - 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 + // + 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(); - // - // 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_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,71 +84,72 @@ 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 - printf("acmOpen error: %i\n", err); + 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 + // + err = acmStreamSize( acm_stream, + src_buflen, &dst_buflen, ACM_STREAMSIZEF_SOURCE ); + + if ( err != MMSYSERR_NOERROR ) + { + //TODO: throw error + MessageBox( 0, _T("acmStreamSize error"), _T("ERROR"), MB_ICONERROR ); - // - // Calcs destination source buffer lenght - // with help of ACM apis - // + } - err = acmStreamSize( acm_stream, - src_buflen, &dst_buflen, ACM_STREAMSIZEF_SOURCE ); - if ( err != MMSYSERR_NOERROR ) - { - //TODO: throw error - printf("acmSize error\n"); + // + // Initialize ACMSTREAMHEADER structure, + // and alloc memory for source and destination + // buffers. + // - } + acm_header.fdwStatus = 0; + acm_header.dwUser = 0; - - - // - // Initialize ACMSTREAMHEADER structure, - // and alloc memory for source and destination - // buffers. - // - - acm_header.fdwStatus = 0; - acm_header.dwUser = 0; - - - acm_header.pbSrc = ( LPBYTE ) new BYTE [ src_buflen ]; + + acm_header.pbSrc = ( LPBYTE ) new BYTE [ src_buflen ]; acm_header.cbSrcLength = src_buflen; acm_header.cbSrcLengthUsed = 0; acm_header.dwSrcUser = src_buflen; @@ -168,158 +163,165 @@ - // - // 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 - printf("prep. header error\n"); - } + if ( err != MMSYSERR_NOERROR ) + { + //TODO: throw error + MessageBox( 0, _T("acmStreamPrepareHeader error"), _T("ERROR"), MB_ICONERROR ); + } - // - // ACM stream successfully opened. - // - stream_opened = true; + // + // ACM stream successfully opened. + // + + stream_opened = true; + } void - audio_resampler_acm::close( void ) +audio_resampler_acm::close( void ) { - MMRESULT err; + MMRESULT err; - if ( acm_stream ) - { + if ( acm_stream ) + { - if ( acm_header.fdwStatus & ACMSTREAMHEADER_STATUSF_PREPARED ) - { + if ( acm_header.fdwStatus & ACMSTREAMHEADER_STATUSF_PREPARED ) + { - acm_header.cbSrcLength = src_buflen; + acm_header.cbSrcLength = src_buflen; acm_header.cbDstLength = dst_buflen; err = acmStreamUnprepareHeader( acm_stream, &acm_header, 0L ); + + if ( err != MMSYSERR_NOERROR ) + { + + // + // Free buffer memory + // - if ( err != MMSYSERR_NOERROR ) - { + if ( acm_header.pbSrc != 0 ) + delete[] acm_header.pbSrc; - // - // Free buffer memory - // + if ( acm_header.pbDst != 0 ) + delete[] acm_header.pbDst; - if ( acm_header.pbSrc != 0 ) - delete[] acm_header.pbSrc; - if ( acm_header.pbDst != 0 ) - delete[] acm_header.pbDst; + // + // Re-init structures + // + init_(); - // - // Re-init structures - // + // + // Updating status + // - init_(); + stream_opened = false; - // - // Updating status - // - stream_opened = false; + //TODO: throw error + MessageBox( 0, _T("acmStreamUnPrepareHeader error"), _T("ERROR"), MB_ICONERROR ); + + } + } - //TODO: throw error - } - } + err = acmStreamClose( acm_stream, 0 ); + acm_stream = 0; + if ( err != MMSYSERR_NOERROR ) + { - err = acmStreamClose( acm_stream, 0 ); - acm_stream = 0; + // + // Free buffer memory + // - if ( err != MMSYSERR_NOERROR ) - { + if ( acm_header.pbSrc != 0 ) + delete[] acm_header.pbSrc; - // - // Free buffer memory - // + if ( acm_header.pbDst != 0 ) + delete[] acm_header.pbDst; - if ( acm_header.pbSrc != 0 ) - delete[] acm_header.pbSrc; - if ( acm_header.pbDst != 0 ) - delete[] acm_header.pbDst; + // + // Re-init structures + // + init_(); - // - // Re-init structures - // - init_(); + // + // Updating status + // + stream_opened = false; - // - // Updating status - // - stream_opened = false; + //TODO: throw error! + MessageBox( 0, _T("acmStreamClose error"), _T("ERROR"), MB_ICONERROR ); - //TODO: throw error! - } + } - }//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. + // } @@ -328,60 +330,70 @@ void - audio_resampler_acm::audio_receive( unsigned char * data, unsigned int size ) +audio_resampler_acm::audio_receive( unsigned char * data, unsigned int size ) { - MMRESULT err; + MMRESULT err; - // - // Checking for acm stream opened - // + // + // Checking for acm stream opened + // - if ( stream_opened ) - { + if ( stream_opened ) + { + + // + // Copy audio data from extern to + // internal source buffer + // - // - // Copy audio data from extern to - // internal source buffer - // + memcpy( acm_header.pbSrc, data, size ); - memcpy( acm_header.pbSrc, data, size ); + acm_header.cbSrcLength = size; + acm_header.cbDstLengthUsed = 0; - acm_header.cbSrcLength = size; - acm_header.cbDstLengthUsed = 0; + err = acmStreamConvert( acm_stream, &acm_header, ACM_STREAMCONVERTF_BLOCKALIGN ); - err = acmStreamConvert( acm_stream, &acm_header, ACM_STREAMCONVERTF_BLOCKALIGN ); + if ( err != MMSYSERR_NOERROR ) + { + //TODO: throw error + MessageBox( 0, _T("acmStreamConvert error"), _T("ERROR"), MB_ICONERROR ); - if ( err != MMSYSERR_NOERROR ) - { - //TODO: throw error - printf("acm convert error\n"); - } + } - // - // 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 %lu bytes of audio.\n", acm_header.cbDstLengthUsed ); + // + // Copy resampled audio, to destination buffer. + // + //memcpy( pbOutputData, acm_header.pbDst, acm_header.cbDstLengthUsed ); - // - // Copy resampled audio, to destination buffer. - // - //memcpy( pbOutputData, acm_header.pbDst, acm_header.cbDstLengthUsed ); + } +} - } -} + + + + + + + _AUDIO_NAMESPACE_END_