📄 pcmconverter.c
字号:
/***********************************************************************
* PCM_DriverDetails
*
*/
static LRESULT PCM_DriverDetails(PACMDRIVERDETAILSW add)
{
TRACE("(%p)\n", add);
add->fccType = ACMDRIVERDETAILS_FCCTYPE_AUDIOCODEC;
add->fccComp = ACMDRIVERDETAILS_FCCCOMP_UNDEFINED;
add->wMid = 0xFF;
add->wPid = 0x00;
add->vdwACM = 0x01000000;
add->vdwDriver = 0x01000000;
add->fdwSupport = ACMDRIVERDETAILS_SUPPORTF_CONVERTER;
add->cFormatTags = 1;
add->cFilterTags = 0;
add->hicon = NULL;
MultiByteToWideChar( CP_ACP, 0, "WINE-PCM", -1,
add->szShortName, sizeof(add->szShortName)/sizeof(WCHAR) );
MultiByteToWideChar( CP_ACP, 0, "Wine PCM converter", -1,
add->szLongName, sizeof(add->szLongName)/sizeof(WCHAR) );
MultiByteToWideChar( CP_ACP, 0, "Brought to you by the Wine team...", -1,
add->szCopyright, sizeof(add->szCopyright)/sizeof(WCHAR) );
MultiByteToWideChar( CP_ACP, 0, "Refer to LICENSE file", -1,
add->szLicensing, sizeof(add->szLicensing)/sizeof(WCHAR) );
add->szFeatures[0] = 0;
return MMSYSERR_NOERROR;
}
/***********************************************************************
* PCM_FormatTagDetails
*
*/
static LRESULT PCM_FormatTagDetails(PACMFORMATTAGDETAILSW aftd, DWORD dwQuery)
{
TRACE("(%p, %08lx)\n", aftd, dwQuery);
switch (dwQuery) {
case ACM_FORMATTAGDETAILSF_INDEX:
if (aftd->dwFormatTagIndex != 0) {
WARN("not possible\n");
return ACMERR_NOTPOSSIBLE;
}
break;
case ACM_FORMATTAGDETAILSF_FORMATTAG:
if (aftd->dwFormatTag != WAVE_FORMAT_PCM) {
WARN("not possible\n");
return ACMERR_NOTPOSSIBLE;
}
break;
case ACM_FORMATTAGDETAILSF_LARGESTSIZE:
if (aftd->dwFormatTag != WAVE_FORMAT_UNKNOWN &&
aftd->dwFormatTag != WAVE_FORMAT_PCM) {
WARN("not possible\n");
return ACMERR_NOTPOSSIBLE;
}
break;
default:
WARN("Unsupported query %08lx\n", dwQuery);
return MMSYSERR_NOTSUPPORTED;
}
aftd->dwFormatTagIndex = 0;
aftd->dwFormatTag = WAVE_FORMAT_PCM;
aftd->cbFormatSize = sizeof(PCMWAVEFORMAT);
aftd->fdwSupport = ACMDRIVERDETAILS_SUPPORTF_CONVERTER;
aftd->cStandardFormats = NUM_PCM_FORMATS;
aftd->szFormatTag[0] = 0;
return MMSYSERR_NOERROR;
}
/***********************************************************************
* PCM_FormatDetails
*
*/
static LRESULT PCM_FormatDetails(PACMFORMATDETAILSW afd, DWORD dwQuery)
{
TRACE("(%p, %08lx)\n", afd, dwQuery);
switch (dwQuery) {
case ACM_FORMATDETAILSF_FORMAT:
if (PCM_GetFormatIndex(afd->pwfx) == 0xFFFFFFFF) {
return ACMERR_NOTPOSSIBLE;
WARN("not possible\n");
}
break;
case ACM_FORMATDETAILSF_INDEX:
assert(afd->dwFormatIndex < NUM_PCM_FORMATS);
afd->pwfx->wFormatTag = WAVE_FORMAT_PCM;
afd->pwfx->nChannels = PCM_Formats[afd->dwFormatIndex].nChannels;
afd->pwfx->nSamplesPerSec = PCM_Formats[afd->dwFormatIndex].rate;
afd->pwfx->wBitsPerSample = PCM_Formats[afd->dwFormatIndex].nBits;
/* native MSACM uses a PCMWAVEFORMAT structure, so cbSize is not
* accessible afd->pwfx->cbSize = 0;
*/
afd->pwfx->nBlockAlign =
(afd->pwfx->nChannels * afd->pwfx->wBitsPerSample) / 8;
afd->pwfx->nAvgBytesPerSec =
afd->pwfx->nSamplesPerSec * afd->pwfx->nBlockAlign;
break;
default:
WARN("Unsupported query %08lx\n", dwQuery);
return MMSYSERR_NOTSUPPORTED;
}
afd->dwFormatTag = WAVE_FORMAT_PCM;
afd->fdwSupport = ACMDRIVERDETAILS_SUPPORTF_CONVERTER;
afd->szFormat[0] = 0; /* let MSACM format this for us... */
afd->cbwfx = sizeof(PCMWAVEFORMAT);
return MMSYSERR_NOERROR;
}
/***********************************************************************
* PCM_FormatSuggest
*
*/
static LRESULT PCM_FormatSuggest(PACMDRVFORMATSUGGEST adfs)
{
TRACE("(%p)\n", adfs);
/* some tests ... */
if (adfs->cbwfxSrc < sizeof(PCMWAVEFORMAT) ||
adfs->cbwfxDst < sizeof(PCMWAVEFORMAT) ||
PCM_GetFormatIndex(adfs->pwfxSrc) == 0xFFFFFFFF) {
WARN("not possible\n");
return ACMERR_NOTPOSSIBLE;
}
/* is no suggestion for destination, then copy source value */
if (!(adfs->fdwSuggest & ACM_FORMATSUGGESTF_NCHANNELS)) {
adfs->pwfxDst->nChannels = adfs->pwfxSrc->nChannels;
}
if (!(adfs->fdwSuggest & ACM_FORMATSUGGESTF_NSAMPLESPERSEC)) {
adfs->pwfxDst->nSamplesPerSec = adfs->pwfxSrc->nSamplesPerSec;
}
if (!(adfs->fdwSuggest & ACM_FORMATSUGGESTF_WBITSPERSAMPLE)) {
adfs->pwfxDst->wBitsPerSample = adfs->pwfxSrc->wBitsPerSample;
}
if (!(adfs->fdwSuggest & ACM_FORMATSUGGESTF_WFORMATTAG)) {
if (adfs->pwfxSrc->wFormatTag != WAVE_FORMAT_PCM) {
WARN("not possible\n");
return ACMERR_NOTPOSSIBLE;
}
adfs->pwfxDst->wFormatTag = adfs->pwfxSrc->wFormatTag;
}
/* check if result is ok */
if (PCM_GetFormatIndex(adfs->pwfxDst) == 0xFFFFFFFF) {
WARN("not possible\n");
return ACMERR_NOTPOSSIBLE;
}
/* recompute other values */
adfs->pwfxDst->nBlockAlign = (adfs->pwfxDst->nChannels * adfs->pwfxDst->wBitsPerSample) / 8;
adfs->pwfxDst->nAvgBytesPerSec = adfs->pwfxDst->nSamplesPerSec * adfs->pwfxDst->nBlockAlign;
return MMSYSERR_NOERROR;
}
/***********************************************************************
* PCM_Reset
*
*/
static void PCM_Reset(AcmPcmData* apd, int srcNumBits)
{
TRACE("(%p, %d)\n", apd, srcNumBits);
apd->srcPos = 0;
apd->dstPos = 0;
/* initialize with neutral value */
if (srcNumBits == 16) {
apd->last[0].s = 0;
apd->last[1].s = 0;
} else {
apd->last[0].b = (BYTE)0x80;
apd->last[1].b = (BYTE)0x80;
}
}
/***********************************************************************
* PCM_StreamOpen
*
*/
static LRESULT PCM_StreamOpen(PACMDRVSTREAMINSTANCE adsi)
{
AcmPcmData* apd;
int idx = 0;
TRACE("(%p)\n", adsi);
assert(!(adsi->fdwOpen & ACM_STREAMOPENF_ASYNC));
if (PCM_GetFormatIndex(adsi->pwfxSrc) == 0xFFFFFFFF ||
PCM_GetFormatIndex(adsi->pwfxDst) == 0xFFFFFFFF) {
WARN("not possible\n");
return ACMERR_NOTPOSSIBLE;
}
apd = HeapAlloc(GetProcessHeap(), 0, sizeof(AcmPcmData));
if (apd == 0) {
WARN("no memory\n");
return MMSYSERR_NOMEM;
}
adsi->dwDriver = (DWORD)apd;
adsi->fdwDriver = 0;
if (adsi->pwfxSrc->wBitsPerSample == 16) idx += 8;
if (adsi->pwfxDst->wBitsPerSample == 16) idx += 4;
if (adsi->pwfxSrc->nChannels == 1) idx += 2;
if (adsi->pwfxDst->nChannels == 1) idx += 1;
if (adsi->pwfxSrc->nSamplesPerSec == adsi->pwfxDst->nSamplesPerSec) {
apd->cvt.cvtKeepRate = PCM_ConvertKeepRate[idx];
} else {
adsi->fdwDriver |= PCM_RESAMPLE;
apd->dstIncr = (double)(adsi->pwfxSrc->nSamplesPerSec) /
(double)(adsi->pwfxDst->nSamplesPerSec);
PCM_Reset(apd, adsi->pwfxSrc->wBitsPerSample);
apd->cvt.cvtChangeRate = PCM_ConvertChangeRate[idx];
}
return MMSYSERR_NOERROR;
}
/***********************************************************************
* PCM_StreamClose
*
*/
static LRESULT PCM_StreamClose(PACMDRVSTREAMINSTANCE adsi)
{
TRACE("(%p)\n", adsi);
HeapFree(GetProcessHeap(), 0, (void*)adsi->dwDriver);
return MMSYSERR_NOERROR;
}
/***********************************************************************
* PCM_round
*
*/
static inline DWORD PCM_round(DWORD a, DWORD b, DWORD c)
{
assert(c);
/* to be sure, always return an entire number of c... */
return ((double)a * (double)b + (double)c - 1) / (double)c;
}
/***********************************************************************
* PCM_StreamSize
*
*/
static LRESULT PCM_StreamSize(PACMDRVSTREAMINSTANCE adsi, PACMDRVSTREAMSIZE adss)
{
DWORD srcMask = ~(adsi->pwfxSrc->nBlockAlign - 1);
DWORD dstMask = ~(adsi->pwfxDst->nBlockAlign - 1);
TRACE("(%p, %p)\n", adsi, adss);
switch (adss->fdwSize) {
case ACM_STREAMSIZEF_DESTINATION:
/* cbDstLength => cbSrcLength */
adss->cbSrcLength = PCM_round(adss->cbDstLength & dstMask,
adsi->pwfxSrc->nAvgBytesPerSec,
adsi->pwfxDst->nAvgBytesPerSec) & srcMask;
break;
case ACM_STREAMSIZEF_SOURCE:
/* cbSrcLength => cbDstLength */
adss->cbDstLength = PCM_round(adss->cbSrcLength & srcMask,
adsi->pwfxDst->nAvgBytesPerSec,
adsi->pwfxSrc->nAvgBytesPerSec) & dstMask;
break;
default:
WARN("Unsupported query %08lx\n", adss->fdwSize);
return MMSYSERR_NOTSUPPORTED;
}
return MMSYSERR_NOERROR;
}
/***********************************************************************
* PCM_StreamConvert
*
*/
static LRESULT PCM_StreamConvert(PACMDRVSTREAMINSTANCE adsi, PACMDRVSTREAMHEADER adsh)
{
AcmPcmData* apd = (AcmPcmData*)adsi->dwDriver;
DWORD nsrc = NUM_OF(adsh->cbSrcLength, adsi->pwfxSrc->nBlockAlign);
DWORD ndst = NUM_OF(adsh->cbDstLength, adsi->pwfxDst->nBlockAlign);
TRACE("(%p, %p)\n", adsi, adsh);
TRACE("nsrc=%ld,adsh->cbSrcLength=%ld\n", nsrc, adsh->cbSrcLength);
TRACE("ndst=%ld,adsh->cbDstLength=%ld\n", ndst, adsh->cbDstLength);
TRACE("src [wFormatTag=%u, nChannels=%u, nSamplesPerSec=%lu, nAvgBytesPerSec=%lu, nBlockAlign=%u, wBitsPerSample=%u, cbSize=%u]\n",
adsi->pwfxSrc->wFormatTag, adsi->pwfxSrc->nChannels, adsi->pwfxSrc->nSamplesPerSec, adsi->pwfxSrc->nAvgBytesPerSec,
adsi->pwfxSrc->nBlockAlign, adsi->pwfxSrc->wBitsPerSample, adsi->pwfxSrc->cbSize);
TRACE("dst [wFormatTag=%u, nChannels=%u, nSamplesPerSec=%lu, nAvgBytesPerSec=%lu, nBlockAlign=%u, wBitsPerSample=%u, cbSize=%u]\n",
adsi->pwfxDst->wFormatTag, adsi->pwfxDst->nChannels, adsi->pwfxDst->nSamplesPerSec, adsi->pwfxDst->nAvgBytesPerSec,
adsi->pwfxDst->nBlockAlign, adsi->pwfxDst->wBitsPerSample, adsi->pwfxDst->cbSize);
if (adsh->fdwConvert &
~(ACM_STREAMCONVERTF_BLOCKALIGN|
ACM_STREAMCONVERTF_END|
ACM_STREAMCONVERTF_START)) {
FIXME("Unsupported fdwConvert (%08lx), ignoring it\n", adsh->fdwConvert);
}
/* ACM_STREAMCONVERTF_BLOCKALIGN
* currently all conversions are block aligned, so do nothing for this flag
* ACM_STREAMCONVERTF_END
* no pending data, so do nothing for this flag
*/
if ((adsh->fdwConvert & ACM_STREAMCONVERTF_START) &&
(adsi->fdwDriver & PCM_RESAMPLE)) {
PCM_Reset(apd, adsi->pwfxSrc->wBitsPerSample);
}
/* do the job */
if (adsi->fdwDriver & PCM_RESAMPLE) {
DWORD nsrc2 = nsrc;
DWORD ndst2 = ndst;
apd->cvt.cvtChangeRate(apd, adsh->pbSrc, &nsrc2, adsh->pbDst, &ndst2);
nsrc -= nsrc2;
ndst -= ndst2;
} else {
if (nsrc < ndst) ndst = nsrc; else nsrc = ndst;
/* nsrc is now equal to ndst */
apd->cvt.cvtKeepRate(adsh->pbSrc, nsrc, adsh->pbDst);
}
adsh->cbSrcLengthUsed = nsrc * adsi->pwfxSrc->nBlockAlign;
adsh->cbDstLengthUsed = ndst * adsi->pwfxDst->nBlockAlign;
return MMSYSERR_NOERROR;
}
/**************************************************************************
* DriverProc (MSACM32.@)
*/
LRESULT CALLBACK PCM_DriverProc(DWORD dwDevID, HDRVR hDriv, UINT wMsg,
LPARAM dwParam1, LPARAM dwParam2)
{
TRACE("(%08lx %08lx %u %08lx %08lx);\n",
dwDevID, (DWORD)hDriv, wMsg, dwParam1, dwParam2);
switch (wMsg) {
case DRV_LOAD: return 1;
case DRV_FREE: return 1;
case DRV_OPEN: return PCM_drvOpen((LPSTR)dwParam1, (PACMDRVOPENDESCW)dwParam2);
case DRV_CLOSE: return PCM_drvClose(dwDevID);
case DRV_ENABLE: return 1;
case DRV_DISABLE: return 1;
case DRV_QUERYCONFIGURE: return 1;
case DRV_CONFIGURE: MessageBoxA(0, "MSACM PCM filter !", "Wine Driver", MB_OK); return 1;
case DRV_INSTALL: return DRVCNF_RESTART;
case DRV_REMOVE: return DRVCNF_RESTART;
case ACMDM_DRIVER_NOTIFY:
/* no caching from other ACM drivers is done so far */
return MMSYSERR_NOERROR;
case ACMDM_DRIVER_DETAILS:
return PCM_DriverDetails((PACMDRIVERDETAILSW)dwParam1);
case ACMDM_FORMATTAG_DETAILS:
return PCM_FormatTagDetails((PACMFORMATTAGDETAILSW)dwParam1, dwParam2);
case ACMDM_FORMAT_DETAILS:
return PCM_FormatDetails((PACMFORMATDETAILSW)dwParam1, dwParam2);
case ACMDM_FORMAT_SUGGEST:
return PCM_FormatSuggest((PACMDRVFORMATSUGGEST)dwParam1);
case ACMDM_STREAM_OPEN:
return PCM_StreamOpen((PACMDRVSTREAMINSTANCE)dwParam1);
case ACMDM_STREAM_CLOSE:
return PCM_StreamClose((PACMDRVSTREAMINSTANCE)dwParam1);
case ACMDM_STREAM_SIZE:
return PCM_StreamSize((PACMDRVSTREAMINSTANCE)dwParam1, (PACMDRVSTREAMSIZE)dwParam2);
case ACMDM_STREAM_CONVERT:
return PCM_StreamConvert((PACMDRVSTREAMINSTANCE)dwParam1, (PACMDRVSTREAMHEADER)dwParam2);
case ACMDM_HARDWARE_WAVE_CAPS_INPUT:
case ACMDM_HARDWARE_WAVE_CAPS_OUTPUT:
/* this converter is not a hardware driver */
case ACMDM_FILTERTAG_DETAILS:
case ACMDM_FILTER_DETAILS:
/* this converter is not a filter */
case ACMDM_STREAM_RESET:
/* only needed for asynchronous driver... we aren't, so just say it */
case ACMDM_STREAM_PREPARE:
case ACMDM_STREAM_UNPREPARE:
/* nothing special to do here... so don't do anything */
return MMSYSERR_NOTSUPPORTED;
default:
return DefDriverProc(dwDevID, hDriv, wMsg, dwParam1, dwParam2);
}
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -