📄 configur.c
字号:
goto errReturn;
}
pwfPCM->wf.wFormatTag = WAVE_FORMAT_PCM; // Mono 16-bit!!!
pwfPCM->wf.nChannels = 1;
pwfPCM->wf.nSamplesPerSec = 8000;
pwfPCM->wf.nBlockAlign = 2;
pwfPCM->wBitsPerSample = 16;
pwfPCM->wf.nAvgBytesPerSec = pwfPCM->wf.nSamplesPerSec *
pwfPCM->wf.nBlockAlign;
//
// Get this driver to suggest a format to convert to. Note: we may
// want to constrain the suggestion partly, depending on the
// capabilities of the ACM. We should always choose the most
// complex conversion if there are several possibilities.
//
padfs = (LPACMDRVFORMATSUGGEST)GlobalAllocPtr( GPTR, sizeof(*padfs) );
pwfADPCM = (LPIMAALGORITHWAVEFORMAT)GlobalAllocPtr( GPTR, sizeof(*pwfADPCM) );
if( NULL == padfs || NULL == pwfADPCM )
{
uIDS = IDS_ERROR_NOMEM;
goto errReturn;
}
padfs->cbStruct = sizeof(*padfs);
padfs->fdwSuggest = 0; // Default everything.
padfs->pwfxSrc = (LPWAVEFORMATEX)pwfPCM;
padfs->cbwfxSrc = sizeof(*pwfPCM);
padfs->pwfxDst = (LPWAVEFORMATEX)pwfADPCM;
padfs->cbwfxDst = sizeof(*pwfADPCM);
(void)acmdFormatSuggest( pdi, padfs ); // This will always work, right?
//
// Set stream instance data. Note: we assume that the members that
// we don't set here never actually get used. Make sure that this
// is really true!
//
padsi = (LPACMDRVSTREAMINSTANCE)GlobalAllocPtr( GPTR, sizeof(*padsi) );
psi = (PSTREAMINSTANCE)LocalAlloc( LPTR, sizeof(*psi) );
if( NULL == padsi || NULL == psi )
{
uIDS = IDS_ERROR_NOMEM;
goto errReturn;
}
// Make sure that psi->fnConvert matches the PCM format in pwfPCM!!!
psi->fnConvert = IMAAlgorithEncode4Bit_M16;
psi->fdwConfigur = pdi->fdwConfigur;
psi->nStepIndexL = 0;
psi->nStepIndexR = 0;
// Make sure that no other members of padsi are used!!!
padsi->cbStruct = sizeof(*padsi);
padsi->pwfxSrc = (LPWAVEFORMATEX)pwfPCM;
padsi->pwfxDst = (LPWAVEFORMATEX)pwfADPCM;
padsi->dwDriver = (DWORD_PTR)psi;
//
// Now, get the driver to tell us how much space is required for the
// destination buffer.
//
cbPCM = IMAALGORITH_CONFIGURTESTTIME * pwfPCM->wf.nAvgBytesPerSec;
padss = (LPACMDRVSTREAMSIZE)GlobalAllocPtr( GPTR, sizeof(*padss) );
if( NULL == padss )
{
uIDS = IDS_ERROR_NOMEM;
goto errReturn;
}
padss->cbStruct = sizeof(padss);
padss->fdwSize = ACM_STREAMSIZEF_SOURCE;
padss->cbSrcLength = cbPCM;
(void)acmdStreamSize( padsi, padss ); // This will always work, right?
//
// Allocate source and destination buffers. Note that we specifically
// don't zero-initialize them, so that we will get random PCM data in
// the PCM buffer.
//
cbADPCM = padss->cbDstLength;
pBufPCM = (LPBYTE)GlobalAllocPtr( GMEM_FIXED, (UINT)cbPCM );
pBufADPCM = (LPBYTE)GlobalAllocPtr( GMEM_FIXED, (UINT)cbADPCM );
if( NULL == pBufPCM || NULL == pBufADPCM )
{
uIDS = IDS_ERROR_NOMEM;
goto errReturn;
}
//
// Now, tell the driver to convert our buffer and measure the time.
// Note that we don't care what is in the source buffer, we only
// care how long it takes.
//
padsh = (LPACMDRVSTREAMHEADER)GlobalAllocPtr( GPTR, sizeof(*padsh) );
if( NULL == padsh )
{
uIDS = IDS_ERROR_NOMEM;
goto errReturn;
}
// Make sure that no other members of padsh are used!!!
padsh->cbStruct = sizeof(*padsh);
padsh->pbSrc = pBufPCM;
padsh->cbSrcLength = cbPCM;
padsh->pbDst = pBufADPCM;
padsh->cbDstLength = cbADPCM;
padsh->fdwConvert = 0; // Should be 0 already, but...
dwStartTime = timeGetTime();
(void)acmdStreamConvert( pdi, padsi, padsh ); // Won't fail?!
dwEncodeTime = timeGetTime() - dwStartTime;
//
// Now, we have an encoded IMA ADPCM buffer. Tell the driver to
// convert it back to PCM, measuring the time. First we reset the
// size of the ADPCM buffer to correspond with the buffer returned
// by the convert. Then we zero out our structure buffers and reset
// them for the new conversion. Note: we assume that the PCM buffer
// is already large enough to handle the conversion.
//
cbADPCM = padsh->cbDstLengthUsed;
#ifdef WIN32
ZeroMemory( psi, sizeof(*psi) );
ZeroMemory( padsi, sizeof(*padsi) );
ZeroMemory( padsh, sizeof(*padsh) );
#else
_fmemset( psi, 0, sizeof(*psi) );
_fmemset( padsi, 0, sizeof(*padsi) );
_fmemset( padsh, 0, sizeof(*padsh) );
#endif
// Make sure that psi->fnConvert matches the format in pfwADPCM!!!
psi->fnConvert = IMAAlgorithDecode4Bit_M16;
psi->fdwConfigur = pdi->fdwConfigur;
psi->nStepIndexL = 0;
psi->nStepIndexR = 0;
// Make sure that no other members of padsi are used!!!
padsi->cbStruct = sizeof(*padsi);
padsi->pwfxSrc = (LPWAVEFORMATEX)pwfADPCM;
padsi->pwfxDst = (LPWAVEFORMATEX)pwfPCM;
padsi->dwDriver = (DWORD_PTR)psi;
// Make sure that no other members of padsh are used!!!
padsh->cbStruct = sizeof(*padsh);
padsh->pbSrc = pBufADPCM;
padsh->cbSrcLength = cbADPCM;
padsh->pbDst = pBufPCM;
padsh->cbDstLength = cbPCM;
padsh->fdwConvert = 0; // Should be 0 already, but...
dwStartTime = timeGetTime();
(void)acmdStreamConvert( pdi, padsi, padsh ); // Won't fail?!
dwDecodeTime = timeGetTime() - dwStartTime;
//
// Now, figure out the max encode and decode rates implied by the
// times required by the conversions.
//
if( dwEncodeTime == 0 )
dwMaxEncodeRate = 0xFFFFFFFFL;
else
dwMaxEncodeRate = MathHelp32( pwfPCM->wf.nSamplesPerSec,
1000L * IMAALGORITH_CONFIGURTESTTIME,
dwEncodeTime ) *
pdi->nConfigurPercentCPU / 100;
if( dwDecodeTime == 0 )
dwMaxDecodeRate = 0xFFFFFFFFL;
else
dwMaxDecodeRate = MathHelp32( pwfPCM->wf.nSamplesPerSec,
1000L * IMAALGORITH_CONFIGURTESTTIME,
dwDecodeTime ) *
pdi->nConfigurPercentCPU / 100;
DPF(1,"dwEncodeTime=%d, dwMaxEncodeRate=%d", dwEncodeTime,dwMaxEncodeRate);
DPF(1,"dwDecodeTime=%d, dwMaxDecodeRate=%d", dwDecodeTime,dwMaxDecodeRate);
//
// Now set the Configururation based on these values. We scan the
// gaRateListFormat[] array looking at the dwMonoRate to determine
// the appropriate setting.
//
// Encode.
//
nConfigur = 0;
while( gaRateListFormat[nConfigur].dwMonoRate < dwMaxEncodeRate &&
IMAALGORITH_CONFIGUR_NUMSETTINGS > nConfigur )
{
nConfigur++;
}
*pnEncodeSetting = nConfigur - 1; // We went too far.
//
// Decode.
//
nConfigur = 0;
while( gaRateListFormat[nConfigur].dwMonoRate < dwMaxDecodeRate &&
IMAALGORITH_CONFIGUR_NUMSETTINGS > nConfigur )
{
nConfigur++;
}
*pnDecodeSetting = nConfigur - 1; // We went too far.
//
// Free structure allocations and exit.
//
//
errReturn:
if( NULL != pwfPCM )
GlobalFreePtr( pwfPCM );
if( NULL != pwfADPCM )
GlobalFreePtr( pwfADPCM );
if( NULL != padfs )
GlobalFreePtr( padfs );
if( NULL != padsi )
GlobalFreePtr( padsi );
if( NULL != padsh )
GlobalFreePtr( padsh );
if( NULL != padss )
GlobalFreePtr( padss );
if( NULL != psi )
LocalFree( (HLOCAL)psi );
SetCursor( hCursorSave );
return uIDS;
}
//==========================================================================;
//
//
//
//
//==========================================================================;
//--------------------------------------------------------------------------;
//
// INT_PTR acmdDlgProcConfigurure
//
// Description:
// This routine handles the Configururation dialog box.
//
// Arguments:
// HWND hwnd:
//
// UINT uMsg:
//
// WPARAM wParam:
//
// LPARAM lParam:
//
// Return (BOOL):
//
//
// Note: In order to avoid using a static fHelpRunning flag which will
// still be here after we exit, we allocate an fHelpRunning
// variable in the DRIVERINSTANCE structure. This is purely to
// avoid static variables (which force us to have a data segment
// of 4K); the fHelpRunning is not used in any other procedures.
//
//--------------------------------------------------------------------------;
INT_PTR FNWCALLBACK acmdDlgProcConfigurure
(
HWND hwnd,
UINT uMsg,
WPARAM wParam,
LPARAM lParam
)
{
PDRIVERINSTANCE pdi;
HWND hctrlEnc;
HWND hctrlDec;
UINT uCmdId;
UINT u;
int n;
TCHAR szFormat[IMAALGORITH_CONFIGUR_TEXTLEN];
TCHAR szOutput[IMAALGORITH_CONFIGUR_TEXTLEN];
UINT nConfigurMaxRTEncodeSetting;
UINT nConfigurMaxRTDecodeSetting;
switch (uMsg)
{
case WM_INITDIALOG:
pdi = (PDRIVERINSTANCE)(UINT)lParam;
pdi->fHelpRunning = FALSE; // Used only in this procedure.
#ifdef WIN4
//
// This driver is marked Windows Subsystem version 3.5 in order
// that it be compatible with Daytona - however, that means that
// Chicago will think it is a Win 3.1 application and give it
// Win 3.1 default colors. This makes the Configur dialog look
// white, whereas the Chicago default uses 3DFACE. This code
// (and the CTLCOLOR messages) sets the colors explicitly.
//
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -