/*********************************************************************** * ADPCM_FormatSuggest * */ static LRESULT ADPCM_FormatSuggest(PACMDRVFORMATSUGGEST adfs) { /* some tests ... */ if (adfs->cbwfxSrc < sizeof(PCMWAVEFORMAT) || adfs->cbwfxDst < sizeof(PCMWAVEFORMAT) || adfs->pwfxSrc->wFormatTag == adfs->pwfxDst->wFormatTag || ADPCM_GetFormatIndex(adfs->pwfxSrc) == 0xFFFFFFFF) return ACMERR_NOTPOSSIBLE; /* FIXME: should do those tests against the real size (according to format tag */ /* If 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)) { if (adfs->pwfxSrc->wFormatTag == WAVE_FORMAT_PCM) adfs->pwfxDst->wBitsPerSample = 4; else adfs->pwfxDst->wBitsPerSample = 16; } if (!(adfs->fdwSuggest & ACM_FORMATSUGGESTF_WFORMATTAG)) { if (adfs->pwfxSrc->wFormatTag == WAVE_FORMAT_PCM) adfs->pwfxDst->wFormatTag = WAVE_FORMAT_ADPCM; else adfs->pwfxDst->wFormatTag = WAVE_FORMAT_PCM; } /* recompute other values */ switch (adfs->pwfxDst->wFormatTag) { case WAVE_FORMAT_PCM: adfs->pwfxDst->nBlockAlign = (adfs->pwfxDst->nChannels * adfs->pwfxDst->wBitsPerSample) / 8; adfs->pwfxDst->nAvgBytesPerSec = adfs->pwfxDst->nSamplesPerSec * adfs->pwfxDst->nBlockAlign; /* check if result is ok */ if (ADPCM_GetFormatIndex(adfs->pwfxDst) == 0xFFFFFFFF) return ACMERR_NOTPOSSIBLE; break; case WAVE_FORMAT_ADPCM: init_wfx_adpcm((ADPCMWAVEFORMAT*)adfs->pwfxDst); /* check if result is ok */ if (ADPCM_GetFormatIndex(adfs->pwfxDst) == 0xFFFFFFFF) return ACMERR_NOTPOSSIBLE; break; default: return ACMERR_NOTPOSSIBLE; } return MMSYSERR_NOERROR; }
static void init_wfx_adpcm(ADPCMWAVEFORMAT* awfx) { register WAVEFORMATEX* pwfx = &awfx->wfx; /* we assume wFormatTag, nChannels, nSamplesPerSec and wBitsPerSample * have been initialized... */ if (pwfx->wFormatTag != WAVE_FORMAT_ADPCM) {FIXME("wrong FT\n"); return;} if (ADPCM_GetFormatIndex(pwfx) == 0xFFFFFFFF) {FIXME("wrong fmt\n"); return;} switch (pwfx->nSamplesPerSec) { case 8000: pwfx->nBlockAlign = 256 * pwfx->nChannels; break; case 11025: pwfx->nBlockAlign = 256 * pwfx->nChannels; break; case 22050: pwfx->nBlockAlign = 512 * pwfx->nChannels; break; case 44100: pwfx->nBlockAlign = 1024 * pwfx->nChannels; break; default: break; } pwfx->cbSize = 2 * sizeof(WORD) + 7 * sizeof(ADPCMCOEFSET); /* 7 is the size of the block head (which contains two samples) */ awfx->wSamplesPerBlock = pwfx->nBlockAlign * 2 / pwfx->nChannels - 12; pwfx->nAvgBytesPerSec = (pwfx->nSamplesPerSec * pwfx->nBlockAlign) / awfx->wSamplesPerBlock; awfx->wNumCoef = 7; memcpy(awfx->aCoef, MSADPCM_CoeffSet, 7 * sizeof(ADPCMCOEFSET)); }
/*********************************************************************** * ADPCM_FormatDetails * */ static LRESULT ADPCM_FormatDetails(PACMFORMATDETAILSW afd, DWORD dwQuery) { switch (dwQuery) { case ACM_FORMATDETAILSF_FORMAT: if (ADPCM_GetFormatIndex(afd->pwfx) == 0xFFFFFFFF) return ACMERR_NOTPOSSIBLE; break; case ACM_FORMATDETAILSF_INDEX: afd->pwfx->wFormatTag = afd->dwFormatTag; switch (afd->dwFormatTag) { case WAVE_FORMAT_PCM: if (afd->dwFormatIndex >= NUM_PCM_FORMATS) return ACMERR_NOTPOSSIBLE; 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; case WAVE_FORMAT_ADPCM: if (afd->dwFormatIndex >= NUM_ADPCM_FORMATS) return ACMERR_NOTPOSSIBLE; if (afd->cbwfx < sizeof(ADPCMWAVEFORMAT) + (7 - 1) * sizeof(ADPCMCOEFSET)) return ACMERR_NOTPOSSIBLE; afd->pwfx->nChannels = ADPCM_Formats[afd->dwFormatIndex].nChannels; afd->pwfx->nSamplesPerSec = ADPCM_Formats[afd->dwFormatIndex].rate; afd->pwfx->wBitsPerSample = ADPCM_Formats[afd->dwFormatIndex].nBits; init_wfx_adpcm((ADPCMWAVEFORMAT*)afd->pwfx); break; default: WARN("Unsupported tag %08x\n", afd->dwFormatTag); return MMSYSERR_INVALPARAM; } break; default: WARN("Unsupported query %08x\n", dwQuery); return MMSYSERR_NOTSUPPORTED; } afd->fdwSupport = ACMDRIVERDETAILS_SUPPORTF_CODEC; afd->szFormat[0] = 0; /* let MSACM format this for us... */ return MMSYSERR_NOERROR; }
static void init_wfx_ima_adpcm(IMAADPCMWAVEFORMAT* awfx/*, DWORD nba*/) { WAVEFORMATEX* pwfx = &awfx->wfx; /* we assume wFormatTag, nChannels, nSamplesPerSec and wBitsPerSample * have been initialized... */ if (pwfx->wFormatTag != WAVE_FORMAT_IMA_ADPCM) { FIXME("wrong FT\n"); return; } if (ADPCM_GetFormatIndex(pwfx) == 0xFFFFFFFF) { FIXME("wrong fmt\n"); return; } switch (pwfx->nSamplesPerSec) { case 8000: pwfx->nBlockAlign = 256 * pwfx->nChannels; break; case 11025: pwfx->nBlockAlign = 256 * pwfx->nChannels; break; case 22050: pwfx->nBlockAlign = 512 * pwfx->nChannels; break; case 44100: pwfx->nBlockAlign = 1024 * pwfx->nChannels; break; default: /*pwfx->nBlockAlign = nba;*/ break; } pwfx->cbSize = sizeof(WORD); awfx->wSamplesPerBlock = (pwfx->nBlockAlign - (4 * pwfx->nChannels) * 2) / pwfx->nChannels + 1; pwfx->nAvgBytesPerSec = (pwfx->nSamplesPerSec * pwfx->nBlockAlign) / awfx->wSamplesPerBlock; }
/*********************************************************************** * ADPCM_StreamOpen * */ static LRESULT ADPCM_StreamOpen(PACMDRVSTREAMINSTANCE adsi) { AcmAdpcmData* aad; assert(!(adsi->fdwOpen & ACM_STREAMOPENF_ASYNC)); if (ADPCM_GetFormatIndex(adsi->pwfxSrc) == 0xFFFFFFFF || ADPCM_GetFormatIndex(adsi->pwfxDst) == 0xFFFFFFFF) return ACMERR_NOTPOSSIBLE; aad = HeapAlloc(GetProcessHeap(), 0, sizeof(AcmAdpcmData)); if (aad == 0) return MMSYSERR_NOMEM; adsi->dwDriver = (DWORD_PTR)aad; if (adsi->pwfxSrc->wFormatTag == WAVE_FORMAT_PCM && adsi->pwfxDst->wFormatTag == WAVE_FORMAT_PCM) { goto theEnd; } else if (adsi->pwfxSrc->wFormatTag == WAVE_FORMAT_ADPCM && adsi->pwfxDst->wFormatTag == WAVE_FORMAT_PCM) { /* resampling or mono <=> stereo not available * ADPCM algo only define 16 bit per sample output */ if (adsi->pwfxSrc->nSamplesPerSec != adsi->pwfxDst->nSamplesPerSec || adsi->pwfxSrc->nChannels != adsi->pwfxDst->nChannels || adsi->pwfxDst->wBitsPerSample != 16) goto theEnd; #if 0 { unsigned int nspb = ((IMAADPCMWAVEFORMAT*)adsi->pwfxSrc)->wSamplesPerBlock; FIXME("spb=%u\n", nspb); /* we check that in a block, after the header, samples are present on * 4-sample packet pattern * we also check that the block alignment is bigger than the expected size */ if (((nspb - 1) & 3) != 0) goto theEnd; if ((((nspb - 1) / 2) + 4) * adsi->pwfxSrc->nChannels < adsi->pwfxSrc->nBlockAlign) goto theEnd; } #endif /* adpcm decoding... */ if (adsi->pwfxDst->wBitsPerSample == 16 && adsi->pwfxDst->nChannels == 2) aad->convert = cvtSSms16K; if (adsi->pwfxDst->wBitsPerSample == 16 && adsi->pwfxDst->nChannels == 1) aad->convert = cvtMMms16K; } else if (adsi->pwfxSrc->wFormatTag == WAVE_FORMAT_PCM && adsi->pwfxDst->wFormatTag == WAVE_FORMAT_ADPCM) { if (adsi->pwfxSrc->nSamplesPerSec != adsi->pwfxDst->nSamplesPerSec || adsi->pwfxSrc->nChannels != adsi->pwfxDst->nChannels || adsi->pwfxSrc->wBitsPerSample != 16) goto theEnd; #if 0 nspb = ((IMAADPCMWAVEFORMAT*)adsi->pwfxDst)->wSamplesPerBlock; FIXME("spb=%u\n", nspb); /* we check that in a block, after the header, samples are present on * 4-sample packet pattern * we also check that the block alignment is bigger than the expected size */ if (((nspb - 1) & 3) != 0) goto theEnd; if ((((nspb - 1) / 2) + 4) * adsi->pwfxDst->nChannels < adsi->pwfxDst->nBlockAlign) goto theEnd; #endif #if 0 /* adpcm coding... */ if (adsi->pwfxSrc->wBitsPerSample == 16 && adsi->pwfxSrc->nChannels == 2) aad->convert = cvtSS16msK; if (adsi->pwfxSrc->wBitsPerSample == 16 && adsi->pwfxSrc->nChannels == 1) aad->convert = cvtMM16msK; #endif FIXME("We don't support encoding yet\n"); goto theEnd; } else goto theEnd; ADPCM_Reset(adsi, aad); return MMSYSERR_NOERROR; theEnd: HeapFree(GetProcessHeap(), 0, aad); adsi->dwDriver = 0L; return MMSYSERR_NOTSUPPORTED; }