4 * Copyright (C) 2002 Eric Pouech
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
34 #include "wine/debug.h"
36 /* see http://www.pcisys.net/~melanson/codecs/adpcm.txt for the details */
38 WINE_DEFAULT_DEBUG_CHANNEL(adpcm
);
40 /***********************************************************************
43 static LRESULT
ADPCM_drvOpen(LPCSTR str
)
48 /***********************************************************************
51 static LRESULT
ADPCM_drvClose(DWORD_PTR dwDevID
)
56 typedef struct tagAcmAdpcmData
58 void (*convert
)(const ACMDRVSTREAMINSTANCE
*adsi
,
59 const unsigned char*, LPDWORD
, unsigned char*, LPDWORD
);
62 /* table to list all supported formats... those are the basic ones. this
63 * also helps given a unique index to each of the supported formats
72 static const Format PCM_Formats
[] =
74 {1, 8, 8000}, {2, 8, 8000}, {1, 16, 8000}, {2, 16, 8000},
75 {1, 8, 11025}, {2, 8, 11025}, {1, 16, 11025}, {2, 16, 11025},
76 {1, 8, 22050}, {2, 8, 22050}, {1, 16, 22050}, {2, 16, 22050},
77 {1, 8, 44100}, {2, 8, 44100}, {1, 16, 44100}, {2, 16, 44100},
80 static const Format ADPCM_Formats
[] =
82 {1, 4, 8000}, {2, 4, 8000}, {1, 4, 11025}, {2, 4, 11025},
83 {1, 4, 22050}, {2, 4, 22050}, {1, 4, 44100}, {2, 4, 44100},
86 #define NUM_PCM_FORMATS (sizeof(PCM_Formats) / sizeof(PCM_Formats[0]))
87 #define NUM_ADPCM_FORMATS (sizeof(ADPCM_Formats) / sizeof(ADPCM_Formats[0]))
89 static int MS_Delta
[] =
91 230, 230, 230, 230, 307, 409, 512, 614,
92 768, 614, 512, 409, 307, 230, 230, 230
96 static ADPCMCOEFSET MSADPCM_CoeffSet
[] =
98 {256, 0}, {512, -256}, {0, 0}, {192, 64}, {240, 0}, {460, -208}, {392, -232}
101 /***********************************************************************
102 * ADPCM_GetFormatIndex
104 static DWORD
ADPCM_GetFormatIndex(const WAVEFORMATEX
* wfx
)
109 switch (wfx
->wFormatTag
)
111 case WAVE_FORMAT_PCM
:
112 hi
= NUM_PCM_FORMATS
;
115 case WAVE_FORMAT_ADPCM
:
116 hi
= NUM_ADPCM_FORMATS
;
117 fmts
= ADPCM_Formats
;
123 for (i
= 0; i
< hi
; i
++)
125 if (wfx
->nChannels
== fmts
[i
].nChannels
&&
126 wfx
->nSamplesPerSec
== fmts
[i
].rate
&&
127 wfx
->wBitsPerSample
== fmts
[i
].nBits
)
134 static void init_wfx_adpcm(ADPCMWAVEFORMAT
* awfx
)
136 register WAVEFORMATEX
* pwfx
= &awfx
->wfx
;
138 /* we assume wFormatTag, nChannels, nSamplesPerSec and wBitsPerSample
139 * have been initialized... */
141 if (pwfx
->wFormatTag
!= WAVE_FORMAT_ADPCM
) {FIXME("wrong FT\n"); return;}
142 if (ADPCM_GetFormatIndex(pwfx
) == 0xFFFFFFFF) {FIXME("wrong fmt\n"); return;}
144 switch (pwfx
->nSamplesPerSec
)
146 case 8000: pwfx
->nBlockAlign
= 256; break;
147 case 11025: pwfx
->nBlockAlign
= 256; break;
148 case 22050: pwfx
->nBlockAlign
= 512; break;
150 case 44100: pwfx
->nBlockAlign
= 1024; break;
152 pwfx
->cbSize
= 2 * sizeof(WORD
) + 7 * sizeof(ADPCMCOEFSET
);
153 /* 7 is the size of the block head (which contains two samples) */
155 awfx
->wSamplesPerBlock
= (pwfx
->nBlockAlign
- (7 * pwfx
->nChannels
)) * (2 / pwfx
->nChannels
) + 2;
156 pwfx
->nAvgBytesPerSec
= (pwfx
->nSamplesPerSec
* pwfx
->nBlockAlign
) / awfx
->wSamplesPerBlock
;
158 memcpy(awfx
->aCoef
, MSADPCM_CoeffSet
, 7 * sizeof(ADPCMCOEFSET
));
161 /***********************************************************************
164 * Read a 16 bit sample (correctly handles endianess)
166 static inline short R16(const unsigned char* src
)
168 return (short)((unsigned short)src
[0] | ((unsigned short)src
[1] << 8));
171 /***********************************************************************
174 * Write a 16 bit sample (correctly handles endianess)
176 static inline void W16(unsigned char* dst
, short s
)
182 static inline void clamp_sample(int* sample
)
184 if (*sample
< -32768) *sample
= -32768;
185 if (*sample
> 32767) *sample
= 32767;
188 static inline void process_nibble(unsigned nibble
, int* idelta
,
189 int* sample1
, int* sample2
,
190 const ADPCMCOEFSET
* coeff
)
195 /* nibble is in fact a signed 4 bit integer => propagate sign if needed */
196 snibble
= (nibble
& 0x08) ? (nibble
- 16) : nibble
;
197 sample
= ((*sample1
* coeff
->iCoef1
) + (*sample2
* coeff
->iCoef2
)) / 256 +
199 clamp_sample(&sample
);
203 *idelta
= ((MS_Delta
[nibble
] * *idelta
) / 256);
204 if (*idelta
< 16) *idelta
= 16;
207 static void cvtSSms16K(const ACMDRVSTREAMINSTANCE
*adsi
,
208 const unsigned char* src
, LPDWORD nsrc
,
209 unsigned char* dst
, LPDWORD ndst
)
211 int ideltaL
, ideltaR
;
212 int sample1L
, sample2L
;
213 int sample1R
, sample2R
;
214 ADPCMCOEFSET coeffL
, coeffR
;
216 int nsamp_blk
= ((ADPCMWAVEFORMAT
*)adsi
->pwfxSrc
)->wSamplesPerBlock
;
217 DWORD nblock
= min(*nsrc
/ adsi
->pwfxSrc
->nBlockAlign
,
218 *ndst
/ (nsamp_blk
* 2 * 2));
220 *nsrc
= nblock
* adsi
->pwfxSrc
->nBlockAlign
;
221 *ndst
= nblock
* nsamp_blk
* 2 * 2;
223 nsamp_blk
-= 2; /* see below for samples from block head */
224 for (; nblock
> 0; nblock
--)
226 const unsigned char* in_src
= src
;
229 coeffL
= MSADPCM_CoeffSet
[*src
++];
231 coeffR
= MSADPCM_CoeffSet
[*src
++];
233 ideltaL
= R16(src
); src
+= 2;
234 ideltaR
= R16(src
); src
+= 2;
235 sample1L
= R16(src
); src
+= 2;
236 sample1R
= R16(src
); src
+= 2;
237 sample2L
= R16(src
); src
+= 2;
238 sample2R
= R16(src
); src
+= 2;
240 /* store samples from block head */
241 W16(dst
, sample2L
); dst
+= 2;
242 W16(dst
, sample2R
); dst
+= 2;
243 W16(dst
, sample1L
); dst
+= 2;
244 W16(dst
, sample1R
); dst
+= 2;
246 for (nsamp
= nsamp_blk
; nsamp
> 0; nsamp
--)
248 process_nibble(*src
>> 4, &ideltaL
, &sample1L
, &sample2L
, &coeffL
);
249 W16(dst
, sample1L
); dst
+= 2;
250 process_nibble(*src
++ & 0x0F, &ideltaR
, &sample1R
, &sample2R
, &coeffR
);
251 W16(dst
, sample1R
); dst
+= 2;
253 src
= in_src
+ adsi
->pwfxSrc
->nBlockAlign
;
257 static void cvtMMms16K(const ACMDRVSTREAMINSTANCE
*adsi
,
258 const unsigned char* src
, LPDWORD nsrc
,
259 unsigned char* dst
, LPDWORD ndst
)
262 int sample1
, sample2
;
265 int nsamp_blk
= ((ADPCMWAVEFORMAT
*)adsi
->pwfxSrc
)->wSamplesPerBlock
;
266 DWORD nblock
= min(*nsrc
/ adsi
->pwfxSrc
->nBlockAlign
,
267 *ndst
/ (nsamp_blk
* 2));
269 *nsrc
= nblock
* adsi
->pwfxSrc
->nBlockAlign
;
270 *ndst
= nblock
* nsamp_blk
* 2;
272 nsamp_blk
-= 2; /* see below for samples from block head */
273 for (; nblock
> 0; nblock
--)
275 const unsigned char* in_src
= src
;
278 coeff
= MSADPCM_CoeffSet
[*src
++];
280 idelta
= R16(src
); src
+= 2;
281 sample1
= R16(src
); src
+= 2;
282 sample2
= R16(src
); src
+= 2;
284 /* store samples from block head */
285 W16(dst
, sample2
); dst
+= 2;
286 W16(dst
, sample1
); dst
+= 2;
288 for (nsamp
= nsamp_blk
; nsamp
> 0; nsamp
-= 2)
290 process_nibble(*src
>> 4, &idelta
, &sample1
, &sample2
, &coeff
);
291 W16(dst
, sample1
); dst
+= 2;
292 process_nibble(*src
++ & 0x0F, &idelta
, &sample1
, &sample2
, &coeff
);
293 W16(dst
, sample1
); dst
+= 2;
295 src
= in_src
+ adsi
->pwfxSrc
->nBlockAlign
;
300 static void cvtSS16msK(PACMDRVSTREAMINSTANCE adsi
,
301 const unsigned char* src
, LPDWORD nsrc
,
302 unsigned char* dst
, LPDWORD ndst
)
306 static void cvtMM16msK(PACMDRVSTREAMINSTANCE adsi
,
307 const unsigned char* src
, LPDWORD nsrc
,
308 unsigned char* dst
, LPDWORD ndst
)
313 /***********************************************************************
314 * ADPCM_DriverDetails
317 static LRESULT
ADPCM_DriverDetails(PACMDRIVERDETAILSW add
)
319 add
->fccType
= ACMDRIVERDETAILS_FCCTYPE_AUDIOCODEC
;
320 add
->fccComp
= ACMDRIVERDETAILS_FCCCOMP_UNDEFINED
;
323 add
->vdwACM
= 0x01000000;
324 add
->vdwDriver
= 0x01000000;
325 add
->fdwSupport
= ACMDRIVERDETAILS_SUPPORTF_CODEC
;
326 add
->cFormatTags
= 2; /* PCM, MS ADPCM */
327 add
->cFilterTags
= 0;
329 MultiByteToWideChar( CP_ACP
, 0, "MS-ADPCM", -1,
330 add
->szShortName
, sizeof(add
->szShortName
)/sizeof(WCHAR
) );
331 MultiByteToWideChar( CP_ACP
, 0, "Wine MS ADPCM converter", -1,
332 add
->szLongName
, sizeof(add
->szLongName
)/sizeof(WCHAR
) );
333 MultiByteToWideChar( CP_ACP
, 0, "Brought to you by the Wine team...", -1,
334 add
->szCopyright
, sizeof(add
->szCopyright
)/sizeof(WCHAR
) );
335 MultiByteToWideChar( CP_ACP
, 0, "Refer to LICENSE file", -1,
336 add
->szLicensing
, sizeof(add
->szLicensing
)/sizeof(WCHAR
) );
337 add
->szFeatures
[0] = 0;
339 return MMSYSERR_NOERROR
;
342 /***********************************************************************
343 * ADPCM_FormatTagDetails
346 static LRESULT
ADPCM_FormatTagDetails(PACMFORMATTAGDETAILSW aftd
, DWORD dwQuery
)
348 static const WCHAR szPcm
[]={'P','C','M',0};
349 static const WCHAR szMsAdPcm
[]={'M','S',' ','A','d','P','C','M',0};
353 case ACM_FORMATTAGDETAILSF_INDEX
:
354 if (aftd
->dwFormatTagIndex
>= 2) return ACMERR_NOTPOSSIBLE
;
356 case ACM_FORMATTAGDETAILSF_LARGESTSIZE
:
357 if (aftd
->dwFormatTag
== WAVE_FORMAT_UNKNOWN
)
359 aftd
->dwFormatTagIndex
= 1; /* WAVE_FORMAT_ADPCM is bigger than PCM */
363 case ACM_FORMATTAGDETAILSF_FORMATTAG
:
364 switch (aftd
->dwFormatTag
)
366 case WAVE_FORMAT_PCM
: aftd
->dwFormatTagIndex
= 0; break;
367 case WAVE_FORMAT_ADPCM
: aftd
->dwFormatTagIndex
= 1; break;
368 default: return ACMERR_NOTPOSSIBLE
;
372 WARN("Unsupported query %08x\n", dwQuery
);
373 return MMSYSERR_NOTSUPPORTED
;
376 aftd
->fdwSupport
= ACMDRIVERDETAILS_SUPPORTF_CODEC
;
377 switch (aftd
->dwFormatTagIndex
)
380 aftd
->dwFormatTag
= WAVE_FORMAT_PCM
;
381 aftd
->cbFormatSize
= sizeof(PCMWAVEFORMAT
);
382 aftd
->cStandardFormats
= NUM_PCM_FORMATS
;
383 lstrcpyW(aftd
->szFormatTag
, szPcm
);
386 aftd
->dwFormatTag
= WAVE_FORMAT_ADPCM
;
387 aftd
->cbFormatSize
= sizeof(ADPCMWAVEFORMAT
) + (7 - 1) * sizeof(ADPCMCOEFSET
);
388 aftd
->cStandardFormats
= NUM_ADPCM_FORMATS
;
389 lstrcpyW(aftd
->szFormatTag
, szMsAdPcm
);
392 return MMSYSERR_NOERROR
;
395 /***********************************************************************
396 * ADPCM_FormatDetails
399 static LRESULT
ADPCM_FormatDetails(PACMFORMATDETAILSW afd
, DWORD dwQuery
)
403 case ACM_FORMATDETAILSF_FORMAT
:
404 if (ADPCM_GetFormatIndex(afd
->pwfx
) == 0xFFFFFFFF) return ACMERR_NOTPOSSIBLE
;
406 case ACM_FORMATDETAILSF_INDEX
:
407 afd
->pwfx
->wFormatTag
= afd
->dwFormatTag
;
408 switch (afd
->dwFormatTag
)
410 case WAVE_FORMAT_PCM
:
411 if (afd
->dwFormatIndex
>= NUM_PCM_FORMATS
) return ACMERR_NOTPOSSIBLE
;
412 afd
->pwfx
->nChannels
= PCM_Formats
[afd
->dwFormatIndex
].nChannels
;
413 afd
->pwfx
->nSamplesPerSec
= PCM_Formats
[afd
->dwFormatIndex
].rate
;
414 afd
->pwfx
->wBitsPerSample
= PCM_Formats
[afd
->dwFormatIndex
].nBits
;
415 /* native MSACM uses a PCMWAVEFORMAT structure, so cbSize is not accessible
416 * afd->pwfx->cbSize = 0;
418 afd
->pwfx
->nBlockAlign
=
419 (afd
->pwfx
->nChannels
* afd
->pwfx
->wBitsPerSample
) / 8;
420 afd
->pwfx
->nAvgBytesPerSec
=
421 afd
->pwfx
->nSamplesPerSec
* afd
->pwfx
->nBlockAlign
;
423 case WAVE_FORMAT_ADPCM
:
424 if (afd
->dwFormatIndex
>= NUM_ADPCM_FORMATS
) return ACMERR_NOTPOSSIBLE
;
425 if (afd
->cbwfx
< sizeof(ADPCMWAVEFORMAT
) + (7 - 1) * sizeof(ADPCMCOEFSET
))
426 return ACMERR_NOTPOSSIBLE
;
427 afd
->pwfx
->nChannels
= ADPCM_Formats
[afd
->dwFormatIndex
].nChannels
;
428 afd
->pwfx
->nSamplesPerSec
= ADPCM_Formats
[afd
->dwFormatIndex
].rate
;
429 afd
->pwfx
->wBitsPerSample
= ADPCM_Formats
[afd
->dwFormatIndex
].nBits
;
430 init_wfx_adpcm((ADPCMWAVEFORMAT
*)afd
->pwfx
);
433 WARN("Unsupported tag %08x\n", afd
->dwFormatTag
);
434 return MMSYSERR_INVALPARAM
;
438 WARN("Unsupported query %08x\n", dwQuery
);
439 return MMSYSERR_NOTSUPPORTED
;
441 afd
->fdwSupport
= ACMDRIVERDETAILS_SUPPORTF_CODEC
;
442 afd
->szFormat
[0] = 0; /* let MSACM format this for us... */
444 return MMSYSERR_NOERROR
;
447 /***********************************************************************
448 * ADPCM_FormatSuggest
451 static LRESULT
ADPCM_FormatSuggest(PACMDRVFORMATSUGGEST adfs
)
454 if (adfs
->cbwfxSrc
< sizeof(PCMWAVEFORMAT
) ||
455 adfs
->cbwfxDst
< sizeof(PCMWAVEFORMAT
) ||
456 ADPCM_GetFormatIndex(adfs
->pwfxSrc
) == 0xFFFFFFFF) return ACMERR_NOTPOSSIBLE
;
457 /* FIXME: should do those tests against the real size (according to format tag */
459 /* If no suggestion for destination, then copy source value */
460 if (!(adfs
->fdwSuggest
& ACM_FORMATSUGGESTF_NCHANNELS
))
461 adfs
->pwfxDst
->nChannels
= adfs
->pwfxSrc
->nChannels
;
462 if (!(adfs
->fdwSuggest
& ACM_FORMATSUGGESTF_NSAMPLESPERSEC
))
463 adfs
->pwfxDst
->nSamplesPerSec
= adfs
->pwfxSrc
->nSamplesPerSec
;
465 if (!(adfs
->fdwSuggest
& ACM_FORMATSUGGESTF_WBITSPERSAMPLE
))
467 if (adfs
->pwfxSrc
->wFormatTag
== WAVE_FORMAT_PCM
)
468 adfs
->pwfxDst
->wBitsPerSample
= 4;
470 adfs
->pwfxDst
->wBitsPerSample
= 16;
472 if (!(adfs
->fdwSuggest
& ACM_FORMATSUGGESTF_WFORMATTAG
))
474 if (adfs
->pwfxSrc
->wFormatTag
== WAVE_FORMAT_PCM
)
475 adfs
->pwfxDst
->wFormatTag
= WAVE_FORMAT_ADPCM
;
477 adfs
->pwfxDst
->wFormatTag
= WAVE_FORMAT_PCM
;
480 /* check if result is ok */
481 if (ADPCM_GetFormatIndex(adfs
->pwfxDst
) == 0xFFFFFFFF) return ACMERR_NOTPOSSIBLE
;
483 /* recompute other values */
484 switch (adfs
->pwfxDst
->wFormatTag
)
486 case WAVE_FORMAT_PCM
:
487 adfs
->pwfxDst
->nBlockAlign
= (adfs
->pwfxDst
->nChannels
* adfs
->pwfxDst
->wBitsPerSample
) / 8;
488 adfs
->pwfxDst
->nAvgBytesPerSec
= adfs
->pwfxDst
->nSamplesPerSec
* adfs
->pwfxDst
->nBlockAlign
;
490 case WAVE_FORMAT_ADPCM
:
491 init_wfx_adpcm((ADPCMWAVEFORMAT
*)adfs
->pwfxDst
);
498 return MMSYSERR_NOERROR
;
501 /***********************************************************************
505 static void ADPCM_Reset(PACMDRVSTREAMINSTANCE adsi
, AcmAdpcmData
* aad
)
509 /***********************************************************************
513 static LRESULT
ADPCM_StreamOpen(PACMDRVSTREAMINSTANCE adsi
)
517 assert(!(adsi
->fdwOpen
& ACM_STREAMOPENF_ASYNC
));
519 if (ADPCM_GetFormatIndex(adsi
->pwfxSrc
) == 0xFFFFFFFF ||
520 ADPCM_GetFormatIndex(adsi
->pwfxDst
) == 0xFFFFFFFF)
521 return ACMERR_NOTPOSSIBLE
;
523 aad
= HeapAlloc(GetProcessHeap(), 0, sizeof(AcmAdpcmData
));
524 if (aad
== 0) return MMSYSERR_NOMEM
;
526 adsi
->dwDriver
= (DWORD
)aad
;
528 if (adsi
->pwfxSrc
->wFormatTag
== WAVE_FORMAT_PCM
&&
529 adsi
->pwfxDst
->wFormatTag
== WAVE_FORMAT_PCM
)
533 else if (adsi
->pwfxSrc
->wFormatTag
== WAVE_FORMAT_ADPCM
&&
534 adsi
->pwfxDst
->wFormatTag
== WAVE_FORMAT_PCM
)
536 /* resampling or mono <=> stereo not available
537 * ADPCM algo only define 16 bit per sample output
539 if (adsi
->pwfxSrc
->nSamplesPerSec
!= adsi
->pwfxDst
->nSamplesPerSec
||
540 adsi
->pwfxSrc
->nChannels
!= adsi
->pwfxDst
->nChannels
||
541 adsi
->pwfxDst
->wBitsPerSample
!= 16)
546 unsigned int nspb
= ((IMAADPCMWAVEFORMAT
*)adsi
->pwfxSrc
)->wSamplesPerBlock
;
547 FIXME("spb=%u\n", nspb
);
549 /* we check that in a block, after the header, samples are present on
550 * 4-sample packet pattern
551 * we also check that the block alignment is bigger than the expected size
553 if (((nspb
- 1) & 3) != 0) goto theEnd
;
554 if ((((nspb
- 1) / 2) + 4) * adsi
->pwfxSrc
->nChannels
< adsi
->pwfxSrc
->nBlockAlign
)
559 /* adpcm decoding... */
560 if (adsi
->pwfxDst
->wBitsPerSample
== 16 && adsi
->pwfxDst
->nChannels
== 2)
561 aad
->convert
= cvtSSms16K
;
562 if (adsi
->pwfxDst
->wBitsPerSample
== 16 && adsi
->pwfxDst
->nChannels
== 1)
563 aad
->convert
= cvtMMms16K
;
565 else if (adsi
->pwfxSrc
->wFormatTag
== WAVE_FORMAT_PCM
&&
566 adsi
->pwfxDst
->wFormatTag
== WAVE_FORMAT_ADPCM
)
568 if (adsi
->pwfxSrc
->nSamplesPerSec
!= adsi
->pwfxDst
->nSamplesPerSec
||
569 adsi
->pwfxSrc
->nChannels
!= adsi
->pwfxDst
->nChannels
||
570 adsi
->pwfxSrc
->wBitsPerSample
!= 16)
573 nspb
= ((IMAADPCMWAVEFORMAT
*)adsi
->pwfxDst
)->wSamplesPerBlock
;
574 FIXME("spb=%u\n", nspb
);
576 /* we check that in a block, after the header, samples are present on
577 * 4-sample packet pattern
578 * we also check that the block alignment is bigger than the expected size
580 if (((nspb
- 1) & 3) != 0) goto theEnd
;
581 if ((((nspb
- 1) / 2) + 4) * adsi
->pwfxDst
->nChannels
< adsi
->pwfxDst
->nBlockAlign
)
585 /* adpcm coding... */
586 if (adsi
->pwfxSrc
->wBitsPerSample
== 16 && adsi
->pwfxSrc
->nChannels
== 2)
587 aad
->convert
= cvtSS16msK
;
588 if (adsi
->pwfxSrc
->wBitsPerSample
== 16 && adsi
->pwfxSrc
->nChannels
== 1)
589 aad
->convert
= cvtMM16msK
;
591 FIXME("We don't support encoding yet\n");
595 ADPCM_Reset(adsi
, aad
);
597 return MMSYSERR_NOERROR
;
600 HeapFree(GetProcessHeap(), 0, aad
);
602 return MMSYSERR_NOTSUPPORTED
;
605 /***********************************************************************
609 static LRESULT
ADPCM_StreamClose(PACMDRVSTREAMINSTANCE adsi
)
611 HeapFree(GetProcessHeap(), 0, (void*)adsi
->dwDriver
);
612 return MMSYSERR_NOERROR
;
615 /***********************************************************************
619 static LRESULT
ADPCM_StreamSize(const ACMDRVSTREAMINSTANCE
*adsi
, PACMDRVSTREAMSIZE adss
)
621 switch (adss
->fdwSize
)
623 case ACM_STREAMSIZEF_DESTINATION
:
624 /* cbDstLength => cbSrcLength */
625 if (adsi
->pwfxSrc
->wFormatTag
== WAVE_FORMAT_PCM
&&
626 adsi
->pwfxDst
->wFormatTag
== WAVE_FORMAT_ADPCM
)
628 /* don't take block overhead into account, doesn't matter too much */
629 adss
->cbSrcLength
= adss
->cbDstLength
* 4;
631 else if (adsi
->pwfxSrc
->wFormatTag
== WAVE_FORMAT_ADPCM
&&
632 adsi
->pwfxDst
->wFormatTag
== WAVE_FORMAT_PCM
)
634 FIXME("misses the block header overhead\n");
635 adss
->cbSrcLength
= 256 + adss
->cbDstLength
/ 4;
639 return MMSYSERR_NOTSUPPORTED
;
642 case ACM_STREAMSIZEF_SOURCE
:
643 /* cbSrcLength => cbDstLength */
644 if (adsi
->pwfxSrc
->wFormatTag
== WAVE_FORMAT_PCM
&&
645 adsi
->pwfxDst
->wFormatTag
== WAVE_FORMAT_ADPCM
)
647 FIXME("misses the block header overhead\n");
648 adss
->cbDstLength
= 256 + adss
->cbSrcLength
/ 4;
650 else if (adsi
->pwfxSrc
->wFormatTag
== WAVE_FORMAT_ADPCM
&&
651 adsi
->pwfxDst
->wFormatTag
== WAVE_FORMAT_PCM
)
653 /* don't take block overhead into account, doesn't matter too much */
654 adss
->cbDstLength
= adss
->cbSrcLength
* 4;
658 return MMSYSERR_NOTSUPPORTED
;
662 WARN("Unsupported query %08x\n", adss
->fdwSize
);
663 return MMSYSERR_NOTSUPPORTED
;
665 return MMSYSERR_NOERROR
;
668 /***********************************************************************
669 * ADPCM_StreamConvert
672 static LRESULT
ADPCM_StreamConvert(PACMDRVSTREAMINSTANCE adsi
, PACMDRVSTREAMHEADER adsh
)
674 AcmAdpcmData
* aad
= (AcmAdpcmData
*)adsi
->dwDriver
;
675 DWORD nsrc
= adsh
->cbSrcLength
;
676 DWORD ndst
= adsh
->cbDstLength
;
678 if (adsh
->fdwConvert
&
679 ~(ACM_STREAMCONVERTF_BLOCKALIGN
|
680 ACM_STREAMCONVERTF_END
|
681 ACM_STREAMCONVERTF_START
))
683 FIXME("Unsupported fdwConvert (%08x), ignoring it\n", adsh
->fdwConvert
);
685 /* ACM_STREAMCONVERTF_BLOCKALIGN
686 * currently all conversions are block aligned, so do nothing for this flag
687 * ACM_STREAMCONVERTF_END
688 * no pending data, so do nothing for this flag
690 if ((adsh
->fdwConvert
& ACM_STREAMCONVERTF_START
))
692 ADPCM_Reset(adsi
, aad
);
695 aad
->convert(adsi
, adsh
->pbSrc
, &nsrc
, adsh
->pbDst
, &ndst
);
696 adsh
->cbSrcLengthUsed
= nsrc
;
697 adsh
->cbDstLengthUsed
= ndst
;
699 return MMSYSERR_NOERROR
;
702 /**************************************************************************
703 * ADPCM_DriverProc [exported]
705 LRESULT CALLBACK
ADPCM_DriverProc(DWORD_PTR dwDevID
, HDRVR hDriv
, UINT wMsg
,
706 LPARAM dwParam1
, LPARAM dwParam2
)
708 TRACE("(%08lx %p %04x %08lx %08lx);\n",
709 dwDevID
, hDriv
, wMsg
, dwParam1
, dwParam2
);
713 case DRV_LOAD
: return 1;
714 case DRV_FREE
: return 1;
715 case DRV_OPEN
: return ADPCM_drvOpen((LPSTR
)dwParam1
);
716 case DRV_CLOSE
: return ADPCM_drvClose(dwDevID
);
717 case DRV_ENABLE
: return 1;
718 case DRV_DISABLE
: return 1;
719 case DRV_QUERYCONFIGURE
: return 1;
720 case DRV_CONFIGURE
: MessageBoxA(0, "MSACM MS ADPCM filter !", "Wine Driver", MB_OK
); return 1;
721 case DRV_INSTALL
: return DRVCNF_RESTART
;
722 case DRV_REMOVE
: return DRVCNF_RESTART
;
724 case ACMDM_DRIVER_NOTIFY
:
725 /* no caching from other ACM drivers is done so far */
726 return MMSYSERR_NOERROR
;
728 case ACMDM_DRIVER_DETAILS
:
729 return ADPCM_DriverDetails((PACMDRIVERDETAILSW
)dwParam1
);
731 case ACMDM_FORMATTAG_DETAILS
:
732 return ADPCM_FormatTagDetails((PACMFORMATTAGDETAILSW
)dwParam1
, dwParam2
);
734 case ACMDM_FORMAT_DETAILS
:
735 return ADPCM_FormatDetails((PACMFORMATDETAILSW
)dwParam1
, dwParam2
);
737 case ACMDM_FORMAT_SUGGEST
:
738 return ADPCM_FormatSuggest((PACMDRVFORMATSUGGEST
)dwParam1
);
740 case ACMDM_STREAM_OPEN
:
741 return ADPCM_StreamOpen((PACMDRVSTREAMINSTANCE
)dwParam1
);
743 case ACMDM_STREAM_CLOSE
:
744 return ADPCM_StreamClose((PACMDRVSTREAMINSTANCE
)dwParam1
);
746 case ACMDM_STREAM_SIZE
:
747 return ADPCM_StreamSize((PACMDRVSTREAMINSTANCE
)dwParam1
, (PACMDRVSTREAMSIZE
)dwParam2
);
749 case ACMDM_STREAM_CONVERT
:
750 return ADPCM_StreamConvert((PACMDRVSTREAMINSTANCE
)dwParam1
, (PACMDRVSTREAMHEADER
)dwParam2
);
752 case ACMDM_HARDWARE_WAVE_CAPS_INPUT
:
753 case ACMDM_HARDWARE_WAVE_CAPS_OUTPUT
:
754 /* this converter is not a hardware driver */
755 case ACMDM_FILTERTAG_DETAILS
:
756 case ACMDM_FILTER_DETAILS
:
757 /* this converter is not a filter */
758 case ACMDM_STREAM_RESET
:
759 /* only needed for asynchronous driver... we aren't, so just say it */
760 return MMSYSERR_NOTSUPPORTED
;
761 case ACMDM_STREAM_PREPARE
:
762 case ACMDM_STREAM_UNPREPARE
:
763 /* nothing special to do here... so don't do anything */
764 return MMSYSERR_NOERROR
;
767 return DefDriverProc(dwDevID
, hDriv
, wMsg
, dwParam1
, dwParam2
);