?? input.cpp
字號:
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
//
// Use of this sample source code is subject to the terms of the Microsoft
// license agreement under which you licensed this sample source code. If
// you did not accept the terms of the license agreement, you are not
// authorized to use this sample source code. For the terms of the license,
// please see the license agreement between you and Microsoft or, if applicable,
// see the LICENSE.RTF on your install media or the root of your tools installation.
// THE SAMPLE SOURCE CODE IS PROVIDED "AS IS", WITH NO WARRANTIES.
//
/*
** Copyright 2000-2003 Intel Corporation All Rights Reserved.
**
** Portions of the source code contained or described herein and all documents
** related to such source code (Material) are owned by Intel Corporation
** or its suppliers or licensors and is licensed by Microsoft Corporation for distribution.
** Title to the Material remains with Intel Corporation or its suppliers and licensors.
** Use of the Materials is subject to the terms of the Microsoft license agreement which accompanied the Materials.
** No other license under any patent, copyright, trade secret or other intellectual
** property right is granted to or conferred upon you by disclosure or
** delivery of the Materials, either expressly, by implication, inducement,
** estoppel or otherwise
** Some portion of the Materials may be copyrighted by Microsoft Corporation.
*/
#include "wavemain.h"
// Init input m_DeltaT with (HWSampleRate/SampleRate) calculated in 24.8 fixed point form
// Note that we need to hold the result in a 64-bit value until we're done shifting,
// since the result of the multiply will overflow 32 bits for sample rates greater than
// or equal to the hardware's sample rate.
DWORD InputStreamContext::SetRate(DWORD dwMultiplier)
{
UINT64 Delta;
m_dwMultiplier = dwMultiplier;
Delta = m_WaveFormat.nSamplesPerSec;
Delta *= m_dwMultiplier;
Delta >>= 16;
Delta = ((UINT32)(((1i64<<32)/Delta)+1));
Delta = (Delta * SAMPLERATE);
Delta >>= DELTAINT;
m_DeltaT = (DWORD)Delta;
return MMSYSERR_NOERROR;
}
DWORD InputStreamContext::Stop()
{
// Stop the stream
WaveStreamContext::Stop();
// Return any partially filled buffers to the client
if ((m_lpWaveHdrCurrent) && (m_lpWaveHdrCurrent->dwBytesRecorded>0))
{
GetNextBuffer();
}
return MMSYSERR_NOERROR;
}
#if (OUTCHANNELS==2)
PBYTE InputStreamContext::Render2(PBYTE pBuffer, PBYTE pBufferEnd, PBYTE pBufferLast)
{
PBYTE pCurrData = m_lpCurrData;
PBYTE pCurrDataEnd = m_lpCurrDataEnd;
LONG CurrT = m_CurrT;
LONG DeltaT = m_DeltaT;
PCM_TYPE SampleType = m_SampleType;
LONG CurrSamp0 = m_CurrSamp[0];
LONG PrevSamp0 = m_PrevSamp[0];
LONG CurrSamp1 = m_CurrSamp[1];
LONG PrevSamp1 = m_PrevSamp[1];
LONG InSamp0;
LONG InSamp1;
for (;;)
{
// Make sure we have a place to put the data
if (pCurrData>=pCurrDataEnd)
{
goto Exit;
}
// Get the next sample
while (CurrT >= DELTA_OVERFLOW)
{
if (pBuffer>=pBufferEnd)
{
goto Exit;
}
PrevSamp0 = CurrSamp0;
PrevSamp1 = CurrSamp1;
CurrSamp0 = ((HWSAMPLE *)pBuffer)[0];
CurrSamp1 = ((HWSAMPLE *)pBuffer)[1];
pBuffer += 2*sizeof(HWSAMPLE);
// Apply input gain?
// CurrSamp0 = (CurrSamp0 * fxpGain) >> 16;
// CurrSamp1 = (CurrSamp1 * fxpGain) >> 16;
CurrT -= DELTA_OVERFLOW;
}
InSamp0 = (PrevSamp0 + ((CurrT * (CurrSamp0 - PrevSamp0)) >> DELTAFRAC));
InSamp1 = (PrevSamp1 + ((CurrT * (CurrSamp1 - PrevSamp1)) >> DELTAFRAC));
CurrT += DeltaT;
PPCM_SAMPLE pSampleDest = (PPCM_SAMPLE)pCurrData;
switch (m_SampleType)
{
case PCM_TYPE_M8:
default:
pSampleDest->m8.sample = (UINT8)( ((InSamp0+InSamp1) >> 9) + 128);
pCurrData += 1;
break;
case PCM_TYPE_S8:
pSampleDest->s8.sample_left = (UINT8)((InSamp0 >> 8) + 128);
pSampleDest->s8.sample_right = (UINT8)((InSamp1 >> 8) + 128);
pCurrData += 2;
break;
case PCM_TYPE_M16:
pSampleDest->m16.sample = (INT16)((InSamp0+InSamp1)>>1);
pCurrData += 2;
break;
case PCM_TYPE_S16:
pSampleDest->s16.sample_left = (INT16)InSamp0;
pSampleDest->s16.sample_right = (INT16)InSamp1;
pCurrData += 4;
break;
}
}
Exit:
m_lpWaveHdrCurrent->dwBytesRecorded += (pCurrData-m_lpCurrData);
m_dwByteCount += (pCurrData-m_lpCurrData);
m_lpCurrData = pCurrData;
m_CurrT = CurrT;
m_PrevSamp[0] = PrevSamp0;
m_CurrSamp[0] = CurrSamp0;
m_PrevSamp[1] = PrevSamp1;
m_CurrSamp[1] = CurrSamp1;
return pBuffer;
}
#else
PBYTE InputStreamContext::Render2(PBYTE pBuffer, PBYTE pBufferEnd, PBYTE pBufferLast)
{
PBYTE pCurrData = m_lpCurrData;
PBYTE pCurrDataEnd = m_lpCurrDataEnd;
LONG CurrT = m_CurrT;
LONG DeltaT = m_DeltaT;
LONG CurrSamp0 = m_CurrSamp[0];
LONG PrevSamp0 = m_PrevSamp[0];
LONG InSamp0;
PCM_TYPE SampleType = m_SampleType;
for (;;)
{
// Make sure we have a place to put the data
if (pCurrData>=pCurrDataEnd)
{
goto Exit;
}
// Get the next sample
while (CurrT >= DELTA_OVERFLOW)
{
if (pBuffer>=pBufferEnd)
{
goto Exit;
}
PrevSamp0 = CurrSamp0;
CurrSamp0 = *(HWSAMPLE *)pBuffer;
pBuffer += sizeof(HWSAMPLE);
// Apply input gain?
// CurrSamp0 = (CurrSamp0 * fxpGain) >> 16;
CurrT -= DELTA_OVERFLOW;
}
InSamp0 = (PrevSamp0 + ((CurrT * (CurrSamp0 - PrevSamp0)) >> DELTAFRAC));
CurrT += DeltaT;
PPCM_SAMPLE pSampleDest = (PPCM_SAMPLE)pCurrData;
switch (m_SampleType)
{
case PCM_TYPE_M8:
default:
pSampleDest->m8.sample = (UINT8)((InSamp0 >> 8) + 128);
pCurrData += 1;
break;
case PCM_TYPE_S8:
pSampleDest->s8.sample_left = (UINT8)((InSamp0 >> 8) + 128);
pSampleDest->s8.sample_right = (UINT8)((InSamp0 >> 8) + 128);
pCurrData += 2;
break;
case PCM_TYPE_M16:
pSampleDest->m16.sample = (INT16)InSamp0;
pCurrData += 2;
break;
case PCM_TYPE_S16:
pSampleDest->s16.sample_left = (INT16)InSamp0;
pSampleDest->s16.sample_right = (INT16)InSamp0;
pCurrData += 4;
break;
}
}
Exit:
m_lpWaveHdrCurrent->dwBytesRecorded += (pCurrData-m_lpCurrData);
m_dwByteCount += (pCurrData-m_lpCurrData);
m_lpCurrData = pCurrData;
m_CurrT = CurrT;
m_PrevSamp[0] = PrevSamp0;
m_CurrSamp[0] = CurrSamp0;
return pBuffer;
}
#endif
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -