⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 recoder.cpp

📁 Screen Chatting source
💻 CPP
字号:
//---------------------------------------------------------------------------


#pragma hdrstop

#include "DebugStr.h"

#include "Recoder.h"

//---------------------------------------------------------------------------


#pragma package(smart_init)

//---------------------------------------------------------------------------
bool Wave_InitRecorder (void)
{
    UINT iDevCnt;

    // Find a device compatible with the available wave characteristics...
    iDevCnt = waveInGetNumDevs();
    Log_String (LOG_VERBOSE, "waveInGetNumDevs() = %d", iDevCnt);
    if( iDevCnt < 1 ) {
        Log_String (LOG_NORMAL, "No wave audio recording devices found.");
        return false;
    }

    return true;
}


//---------------------------------------------------------------------------
bool Wave_StartRecording (t_wavedevice *pDevice, HWND hWnd, DWORD dwWaveBufSize)
{
    // if the device is still open, just return...
    if( pDevice->bDeviceOpen ) return false;
    pDevice->nBufferIndex   = 0;
    pDevice->dwByteDataSize = 0;

    // open the device for recording...
    if( waveInOpen( &pDevice->hWaveIn,
                    (UINT)WAVE_MAPPER,
                    pDevice->pWaveFmtEx,
                    (DWORD) hWnd, 0, CALLBACK_WINDOW|WAVE_ALLOWSYNC ) ) {
        Log_String (LOG_NORMAL, "Could not open the input device for recording.");
        return false;
    }
    pDevice->bDeviceOpen = true;

    // prepare the headers...
    Wave_InitHeader (pDevice, dwWaveBufSize);

    SHORT nI;
    for (nI=0; nI<WAVE_BLOCKCNT; nI++) {
        if( waveInPrepareHeader( pDevice->hWaveIn, pDevice->pWaveHdr[ nI ], sizeof(WAVEHDR) ) ) {
            Wave_CloseRecorder (pDevice);
            Log_String (LOG_NORMAL,"Error preparing header for recording.");
            return false;
        }
    }

    // add the first buffer...
    if( !Wave_AddBuffer2Recorder (pDevice) ) return false;

    // start recording to first buffer...
    if( waveInStart( pDevice->hWaveIn ) ) {
        Wave_CloseRecorder ( pDevice );
        Log_String (LOG_NORMAL, "Error starting wave record.");
        return false;
    }

    pDevice->nDeviceMode = WAVEDEVICE_RECORDER;

    // queue the next buffer...
    if( !Wave_AddBuffer2Recorder (pDevice) ) return false;

    return true;
}


//---------------------------------------------------------------------------
/*
    Add the buffer to the wave input queue and toggle buffer index. This
    routine is called from the main window proc.
*/
bool Wave_AddBuffer2Recorder (t_wavedevice *pDevice)
{
    // queue the buffer for input...
    if ( waveInAddBuffer( pDevice->hWaveIn, pDevice->pWaveHdr[ pDevice->nBufferIndex ], sizeof(WAVEHDR) ) ) {
        Wave_StopRecorder (pDevice);
        Log_String (LOG_NORMAL, "Error adding buffer.");
        return false;
    }

    // toggle for next buffer...
    pDevice->nBufferIndex = ( pDevice->nBufferIndex + 1 ) % WAVE_BLOCKCNT;

    return true;
}


//---------------------------------------------------------------------------
void Wave_StopRecorder (t_wavedevice *pDevice)
{
    /*
        Stop the recording.
    */
    // set flag before stopping since it's used in the MM_WIM_DATA message
    // in our main window proc to control whether we add another buffer
    // or to close the device.
    pDevice->nDeviceMode = WAVEDEVICE_NULL;

    // stop recording and return queued buffers...
    if( waveInReset( pDevice->hWaveIn ) )
        Log_String (LOG_NORMAL, "Error in waveInReset");
}


//---------------------------------------------------------------------------
void Wave_CloseRecorder (t_wavedevice *pDevice)
{
    /*
        Close wave recording device.
    */
    // if the device is already closed, just return...
    if ( pDevice->bDeviceOpen == false ) return;

    // unprepare the headers...
    SHORT nI;
    for (nI=0; nI<WAVE_BLOCKCNT; nI++) {
        if ( waveInUnprepareHeader( pDevice->hWaveIn, pDevice->pWaveHdr[ nI ], sizeof(WAVEHDR)) )
            Log_String (LOG_NORMAL, "Error in waveInUnprepareHeader" );
    }

    // close the wave input device...
    if ( waveInClose( pDevice->hWaveIn ) )
        Log_String (LOG_NORMAL, "Error closing input device.");

    // tell this function we are now closed...
    pDevice->bDeviceOpen = false;
}
//---------------------------------------------------------------------------
//---------------------------------------------------------------------------
//---------------------------------------------------------------------------
//---------------------------------------------------------------------------
//---------------------------------------------------------------------------
//---------------------------------------------------------------------------

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -