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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
30 #include "../msacmdrv.h"
31 #include "wine/debug.h"
33 /* see http://www.pcisys.net/~melanson/codecs/adpcm.txt for the details */
35 WINE_DEFAULT_DEBUG_CHANNEL(adpcm
);
37 /***********************************************************************
40 static DWORD
ADPCM_drvOpen(LPCSTR str
)
45 /***********************************************************************
48 static DWORD
ADPCM_drvClose(DWORD dwDevID
)
53 typedef struct tagAcmAdpcmData
55 void (*convert
)(PACMDRVSTREAMINSTANCE adsi
,
56 const unsigned char*, LPDWORD
, unsigned char*, LPDWORD
);
59 /* table to list all supported formats... those are the basic ones. this
60 * also helps given a unique index to each of the supported formats
69 static Format PCM_Formats
[] =
71 {1, 8, 8000}, {2, 8, 8000}, {1, 16, 8000}, {2, 16, 8000},
72 {1, 8, 11025}, {2, 8, 11025}, {1, 16, 11025}, {2, 16, 11025},
73 {1, 8, 22050}, {2, 8, 22050}, {1, 16, 22050}, {2, 16, 22050},
74 {1, 8, 44100}, {2, 8, 44100}, {1, 16, 44100}, {2, 16, 44100},
77 static Format ADPCM_Formats
[] =
79 {1, 4, 8000}, {2, 4, 8000}, {1, 4, 11025}, {2, 4, 11025},
80 {1, 4, 22050}, {2, 4, 22050}, {1, 4, 44100}, {2, 4, 44100},
83 #define NUM_PCM_FORMATS (sizeof(PCM_Formats) / sizeof(PCM_Formats[0]))
84 #define NUM_ADPCM_FORMATS (sizeof(ADPCM_Formats) / sizeof(ADPCM_Formats[0]))
86 static int MS_Delta
[] =
88 230, 230, 230, 230, 307, 409, 512, 614,
89 768, 614, 512, 409, 307, 230, 230, 230
93 static ADPCMCOEFSET MSADPCM_CoeffSet
[] =
95 {256, 0}, {512, -256}, {0, 0}, {192, 64}, {240, 0}, {460, -208}, {392, -232}
98 /***********************************************************************
99 * ADPCM_GetFormatIndex
101 static DWORD
ADPCM_GetFormatIndex(WAVEFORMATEX
* wfx
)
106 switch (wfx
->wFormatTag
)
108 case WAVE_FORMAT_PCM
:
109 hi
= NUM_PCM_FORMATS
;
112 case WAVE_FORMAT_ADPCM
:
113 hi
= NUM_ADPCM_FORMATS
;
114 fmts
= ADPCM_Formats
;
120 for (i
= 0; i
< hi
; i
++)
122 if (wfx
->nChannels
== fmts
[i
].nChannels
&&
123 wfx
->nSamplesPerSec
== fmts
[i
].rate
&&
124 wfx
->wBitsPerSample
== fmts
[i
].nBits
)
131 static void init_wfx_adpcm(ADPCMWAVEFORMAT
* awfx
)
133 register WAVEFORMATEX
* pwfx
= &awfx
->wfx
;
135 /* we assume wFormatTag, nChannels, nSamplesPerSec and wBitsPerSample
136 * have been initialized... */
138 if (pwfx
->wFormatTag
!= WAVE_FORMAT_ADPCM
) {FIXME("wrong FT\n"); return;}
139 if (ADPCM_GetFormatIndex(pwfx
) == 0xFFFFFFFF) {FIXME("wrong fmt\n"); return;}
141 switch (pwfx
->nSamplesPerSec
)
143 case 8000: pwfx
->nBlockAlign
= 256; break;
144 case 11025: pwfx
->nBlockAlign
= 256; break;
145 case 22050: pwfx
->nBlockAlign
= 512; break;
147 case 44100: pwfx
->nBlockAlign
= 1024; break;
149 pwfx
->cbSize
= 2 * sizeof(WORD
) + 7 * sizeof(ADPCMCOEFSET
);
150 /* 7 is the size of the block head (which contains two samples) */
152 awfx
->wSamplesPerBlock
= (pwfx
->nBlockAlign
- (7 * pwfx
->nChannels
)) * (2 / pwfx
->nChannels
) + 2;
153 pwfx
->nAvgBytesPerSec
= (pwfx
->nSamplesPerSec
* pwfx
->nBlockAlign
) / awfx
->wSamplesPerBlock
;
155 memcpy(awfx
->aCoef
, MSADPCM_CoeffSet
, 7 * sizeof(ADPCMCOEFSET
));
158 /***********************************************************************
161 * Read a 16 bit sample (correctly handles endianess)
163 static inline short R16(const unsigned char* src
)
165 return (short)((unsigned short)src
[0] | ((unsigned short)src
[1] << 8));
168 /***********************************************************************
171 * Write a 16 bit sample (correctly handles endianess)
173 static inline void W16(unsigned char* dst
, short s
)
179 static inline void clamp_sample(int* sample
)
181 if (*sample
< -32768) *sample
= -32768;
182 if (*sample
> 32767) *sample
= 32767;
185 static inline void process_nibble(unsigned nibble
, int* idelta
,
186 int* sample1
, int* sample2
,
187 const ADPCMCOEFSET
* coeff
)
192 /* nibble is in fact a signed 4 bit integer => propagate sign if needed */
193 snibble
= (nibble
& 0x08) ? (nibble
- 16) : nibble
;
194 sample
= ((*sample1
* coeff
->iCoef1
) + (*sample2
* coeff
->iCoef2
)) / 256 +
196 clamp_sample(&sample
);
200 *idelta
= ((MS_Delta
[nibble
] * *idelta
) / 256);
201 if (*idelta
< 16) *idelta
= 16;
204 static void cvtSSms16K(PACMDRVSTREAMINSTANCE adsi
,
205 const unsigned char* src
, LPDWORD nsrc
,
206 unsigned char* dst
, LPDWORD ndst
)
208 int ideltaL
, ideltaR
;
209 int sample1L
, sample2L
;
210 int sample1R
, sample2R
;
211 ADPCMCOEFSET coeffL
, coeffR
;
213 int nsamp_blk
= ((ADPCMWAVEFORMAT
*)adsi
->pwfxSrc
)->wSamplesPerBlock
;
214 DWORD nblock
= min(*nsrc
/ adsi
->pwfxSrc
->nBlockAlign
,
215 *ndst
/ (nsamp_blk
* 2 * 2));
217 *nsrc
= nblock
* adsi
->pwfxSrc
->nBlockAlign
;
218 *ndst
= nblock
* nsamp_blk
* 2 * 2;
220 nsamp_blk
-= 2; /* see below for samples from block head */
221 for (; nblock
> 0; nblock
--)
223 const unsigned char* in_src
= src
;
226 coeffL
= MSADPCM_CoeffSet
[*src
++];
228 coeffR
= MSADPCM_CoeffSet
[*src
++];
230 ideltaL
= R16(src
); src
+= 2;
231 ideltaR
= R16(src
); src
+= 2;
232 sample1L
= R16(src
); src
+= 2;
233 sample1R
= R16(src
); src
+= 2;
234 sample2L
= R16(src
); src
+= 2;
235 sample2R
= R16(src
); src
+= 2;
237 /* store samples from block head */
238 W16(dst
, sample2L
); dst
+= 2;
239 W16(dst
, sample2R
); dst
+= 2;
240 W16(dst
, sample1L
); dst
+= 2;
241 W16(dst
, sample1R
); dst
+= 2;
243 for (nsamp
= nsamp_blk
; nsamp
> 0; nsamp
--)
245 process_nibble(*src
>> 4, &ideltaL
, &sample1L
, &sample2L
, &coeffL
);
246 W16(dst
, sample1L
); dst
+= 2;
247 process_nibble(*src
++ & 0x0F, &ideltaR
, &sample1R
, &sample2R
, &coeffR
);
248 W16(dst
, sample1R
); dst
+= 2;
250 src
= in_src
+ adsi
->pwfxSrc
->nBlockAlign
;
254 static void cvtMMms16K(PACMDRVSTREAMINSTANCE adsi
,
255 const unsigned char* src
, LPDWORD nsrc
,
256 unsigned char* dst
, LPDWORD ndst
)
259 int sample1
, sample2
;
262 int nsamp_blk
= ((ADPCMWAVEFORMAT
*)adsi
->pwfxSrc
)->wSamplesPerBlock
;
263 DWORD nblock
= min(*nsrc
/ adsi
->pwfxSrc
->nBlockAlign
,
264 *ndst
/ (nsamp_blk
* 2));
266 *nsrc
= nblock
* adsi
->pwfxSrc
->nBlockAlign
;
267 *ndst
= nblock
* nsamp_blk
* 2;
269 nsamp_blk
-= 2; /* see below for samples from block head */
270 for (; nblock
> 0; nblock
--)
272 const unsigned char* in_src
= src
;
275 coeff
= MSADPCM_CoeffSet
[*src
++];
277 idelta
= R16(src
); src
+= 2;
278 sample1
= R16(src
); src
+= 2;
279 sample2
= R16(src
); src
+= 2;
281 /* store samples from block head */
282 W16(dst
, sample2
); dst
+= 2;
283 W16(dst
, sample1
); dst
+= 2;
285 for (nsamp
= nsamp_blk
; nsamp
> 0; nsamp
-= 2)
287 process_nibble(*src
>> 4, &idelta
, &sample1
, &sample2
, &coeff
);
288 W16(dst
, sample1
); dst
+= 2;
289 process_nibble(*src
++ & 0x0F, &idelta
, &sample1
, &sample2
, &coeff
);
290 W16(dst
, sample1
); dst
+= 2;
292 src
= in_src
+ adsi
->pwfxSrc
->nBlockAlign
;
297 static void cvtSS16msK(PACMDRVSTREAMINSTANCE adsi
,
298 const unsigned char* src
, LPDWORD nsrc
,
299 unsigned char* dst
, LPDWORD ndst
)
303 static void cvtMM16msK(PACMDRVSTREAMINSTANCE adsi
,
304 const unsigned char* src
, LPDWORD nsrc
,
305 unsigned char* dst
, LPDWORD ndst
)
310 /***********************************************************************
311 * ADPCM_DriverDetails
314 static LRESULT
ADPCM_DriverDetails(PACMDRIVERDETAILSW add
)
316 add
->fccType
= ACMDRIVERDETAILS_FCCTYPE_AUDIOCODEC
;
317 add
->fccComp
= ACMDRIVERDETAILS_FCCCOMP_UNDEFINED
;
320 add
->vdwACM
= 0x01000000;
321 add
->vdwDriver
= 0x01000000;
322 add
->fdwSupport
= ACMDRIVERDETAILS_SUPPORTF_CODEC
;
323 add
->cFormatTags
= 2; /* PCM, MS ADPCM */
324 add
->cFilterTags
= 0;
326 MultiByteToWideChar( CP_ACP
, 0, "WINE-MS ADPCM", -1,
327 add
->szShortName
, sizeof(add
->szShortName
)/sizeof(WCHAR
) );
328 MultiByteToWideChar( CP_ACP
, 0, "Wine MS ADPCM converter", -1,
329 add
->szLongName
, sizeof(add
->szLongName
)/sizeof(WCHAR
) );
330 MultiByteToWideChar( CP_ACP
, 0, "Brought to you by the Wine team...", -1,
331 add
->szCopyright
, sizeof(add
->szCopyright
)/sizeof(WCHAR
) );
332 MultiByteToWideChar( CP_ACP
, 0, "Refer to LICENSE file", -1,
333 add
->szLicensing
, sizeof(add
->szLicensing
)/sizeof(WCHAR
) );
334 add
->szFeatures
[0] = 0;
336 return MMSYSERR_NOERROR
;
339 /***********************************************************************
340 * ADPCM_FormatTagDetails
343 static LRESULT
ADPCM_FormatTagDetails(PACMFORMATTAGDETAILSW aftd
, DWORD dwQuery
)
345 static WCHAR szPcm
[]={'P','C','M',0};
346 static WCHAR szMsAdPcm
[]={'M','S',' ','A','d','P','C','M',0};
350 case ACM_FORMATTAGDETAILSF_INDEX
:
351 if (aftd
->dwFormatTagIndex
>= 2) return ACMERR_NOTPOSSIBLE
;
353 case ACM_FORMATTAGDETAILSF_LARGESTSIZE
:
354 if (aftd
->dwFormatTag
== WAVE_FORMAT_UNKNOWN
)
356 aftd
->dwFormatTagIndex
= 1; /* WAVE_FORMAT_ADPCM is bigger than PCM */
360 case ACM_FORMATTAGDETAILSF_FORMATTAG
:
361 switch (aftd
->dwFormatTag
)
363 case WAVE_FORMAT_PCM
: aftd
->dwFormatTagIndex
= 0; break;
364 case WAVE_FORMAT_ADPCM
: aftd
->dwFormatTagIndex
= 1; break;
365 default: return ACMERR_NOTPOSSIBLE
;
369 WARN("Unsupported query %08lx\n", dwQuery
);
370 return MMSYSERR_NOTSUPPORTED
;
373 aftd
->fdwSupport
= ACMDRIVERDETAILS_SUPPORTF_CODEC
;
374 switch (aftd
->dwFormatTagIndex
)
377 aftd
->dwFormatTag
= WAVE_FORMAT_PCM
;
378 aftd
->cbFormatSize
= sizeof(PCMWAVEFORMAT
);
379 aftd
->cStandardFormats
= NUM_PCM_FORMATS
;
380 lstrcpyW(aftd
->szFormatTag
, szPcm
);
383 aftd
->dwFormatTag
= WAVE_FORMAT_ADPCM
;
384 aftd
->cbFormatSize
= sizeof(ADPCMWAVEFORMAT
) + (7 - 1) * sizeof(ADPCMCOEFSET
);
385 aftd
->cStandardFormats
= NUM_ADPCM_FORMATS
;
386 lstrcpyW(aftd
->szFormatTag
, szMsAdPcm
);
389 return MMSYSERR_NOERROR
;
392 /***********************************************************************
393 * ADPCM_FormatDetails
396 static LRESULT
ADPCM_FormatDetails(PACMFORMATDETAILSW afd
, DWORD dwQuery
)
400 case ACM_FORMATDETAILSF_FORMAT
:
401 if (ADPCM_GetFormatIndex(afd
->pwfx
) == 0xFFFFFFFF) return ACMERR_NOTPOSSIBLE
;
403 case ACM_FORMATDETAILSF_INDEX
:
404 afd
->pwfx
->wFormatTag
= afd
->dwFormatTag
;
405 switch (afd
->dwFormatTag
)
407 case WAVE_FORMAT_PCM
:
408 if (afd
->dwFormatIndex
>= NUM_PCM_FORMATS
) return ACMERR_NOTPOSSIBLE
;
409 afd
->pwfx
->nChannels
= PCM_Formats
[afd
->dwFormatIndex
].nChannels
;
410 afd
->pwfx
->nSamplesPerSec
= PCM_Formats
[afd
->dwFormatIndex
].rate
;
411 afd
->pwfx
->wBitsPerSample
= PCM_Formats
[afd
->dwFormatIndex
].nBits
;
412 /* native MSACM uses a PCMWAVEFORMAT structure, so cbSize is not accessible
413 * afd->pwfx->cbSize = 0;
415 afd
->pwfx
->nBlockAlign
=
416 (afd
->pwfx
->nChannels
* afd
->pwfx
->wBitsPerSample
) / 8;
417 afd
->pwfx
->nAvgBytesPerSec
=
418 afd
->pwfx
->nSamplesPerSec
* afd
->pwfx
->nBlockAlign
;
420 case WAVE_FORMAT_ADPCM
:
421 if (afd
->dwFormatIndex
>= NUM_ADPCM_FORMATS
) return ACMERR_NOTPOSSIBLE
;
422 if (afd
->cbwfx
< sizeof(ADPCMWAVEFORMAT
) + (7 - 1) * sizeof(ADPCMCOEFSET
))
423 return ACMERR_NOTPOSSIBLE
;
424 afd
->pwfx
->nChannels
= ADPCM_Formats
[afd
->dwFormatIndex
].nChannels
;
425 afd
->pwfx
->nSamplesPerSec
= ADPCM_Formats
[afd
->dwFormatIndex
].rate
;
426 afd
->pwfx
->wBitsPerSample
= ADPCM_Formats
[afd
->dwFormatIndex
].nBits
;
427 init_wfx_adpcm((ADPCMWAVEFORMAT
*)afd
->pwfx
);
430 WARN("Unsupported tag %08lx\n", afd
->dwFormatTag
);
431 return MMSYSERR_INVALPARAM
;
435 WARN("Unsupported query %08lx\n", dwQuery
);
436 return MMSYSERR_NOTSUPPORTED
;
438 afd
->fdwSupport
= ACMDRIVERDETAILS_SUPPORTF_CODEC
;
439 afd
->szFormat
[0] = 0; /* let MSACM format this for us... */
441 return MMSYSERR_NOERROR
;
444 /***********************************************************************
445 * ADPCM_FormatSuggest
448 static LRESULT
ADPCM_FormatSuggest(PACMDRVFORMATSUGGEST adfs
)
451 if (adfs
->cbwfxSrc
< sizeof(PCMWAVEFORMAT
) ||
452 adfs
->cbwfxDst
< sizeof(PCMWAVEFORMAT
) ||
453 ADPCM_GetFormatIndex(adfs
->pwfxSrc
) == 0xFFFFFFFF) return ACMERR_NOTPOSSIBLE
;
454 /* FIXME: should do those tests against the real size (according to format tag */
456 /* If no suggestion for destination, then copy source value */
457 if (!(adfs
->fdwSuggest
& ACM_FORMATSUGGESTF_NCHANNELS
))
458 adfs
->pwfxDst
->nChannels
= adfs
->pwfxSrc
->nChannels
;
459 if (!(adfs
->fdwSuggest
& ACM_FORMATSUGGESTF_NSAMPLESPERSEC
))
460 adfs
->pwfxDst
->nSamplesPerSec
= adfs
->pwfxSrc
->nSamplesPerSec
;
462 if (!(adfs
->fdwSuggest
& ACM_FORMATSUGGESTF_WBITSPERSAMPLE
))
464 if (adfs
->pwfxSrc
->wFormatTag
== WAVE_FORMAT_PCM
)
465 adfs
->pwfxDst
->wBitsPerSample
= 4;
467 adfs
->pwfxDst
->wBitsPerSample
= 16;
469 if (!(adfs
->fdwSuggest
& ACM_FORMATSUGGESTF_WFORMATTAG
))
471 if (adfs
->pwfxSrc
->wFormatTag
== WAVE_FORMAT_PCM
)
472 adfs
->pwfxDst
->wFormatTag
= WAVE_FORMAT_ADPCM
;
474 adfs
->pwfxDst
->wFormatTag
= WAVE_FORMAT_PCM
;
477 /* check if result is ok */
478 if (ADPCM_GetFormatIndex(adfs
->pwfxDst
) == 0xFFFFFFFF) return ACMERR_NOTPOSSIBLE
;
480 /* recompute other values */
481 switch (adfs
->pwfxDst
->wFormatTag
)
483 case WAVE_FORMAT_PCM
:
484 adfs
->pwfxDst
->nBlockAlign
= (adfs
->pwfxDst
->nChannels
* adfs
->pwfxDst
->wBitsPerSample
) / 8;
485 adfs
->pwfxDst
->nAvgBytesPerSec
= adfs
->pwfxDst
->nSamplesPerSec
* adfs
->pwfxDst
->nBlockAlign
;
487 case WAVE_FORMAT_ADPCM
:
488 init_wfx_adpcm((ADPCMWAVEFORMAT
*)adfs
->pwfxDst
);
495 return MMSYSERR_NOERROR
;
498 /***********************************************************************
502 static void ADPCM_Reset(PACMDRVSTREAMINSTANCE adsi
, AcmAdpcmData
* aad
)
506 /***********************************************************************
510 static LRESULT
ADPCM_StreamOpen(PACMDRVSTREAMINSTANCE adsi
)
514 assert(!(adsi
->fdwOpen
& ACM_STREAMOPENF_ASYNC
));
516 if (ADPCM_GetFormatIndex(adsi
->pwfxSrc
) == 0xFFFFFFFF ||
517 ADPCM_GetFormatIndex(adsi
->pwfxDst
) == 0xFFFFFFFF)
518 return ACMERR_NOTPOSSIBLE
;
520 aad
= HeapAlloc(GetProcessHeap(), 0, sizeof(AcmAdpcmData
));
521 if (aad
== 0) return MMSYSERR_NOMEM
;
523 adsi
->dwDriver
= (DWORD
)aad
;
525 if (adsi
->pwfxSrc
->wFormatTag
== WAVE_FORMAT_PCM
&&
526 adsi
->pwfxDst
->wFormatTag
== WAVE_FORMAT_PCM
)
530 else if (adsi
->pwfxSrc
->wFormatTag
== WAVE_FORMAT_ADPCM
&&
531 adsi
->pwfxDst
->wFormatTag
== WAVE_FORMAT_PCM
)
533 /* resampling or mono <=> stereo not available
534 * ADPCM algo only define 16 bit per sample output
536 if (adsi
->pwfxSrc
->nSamplesPerSec
!= adsi
->pwfxDst
->nSamplesPerSec
||
537 adsi
->pwfxSrc
->nChannels
!= adsi
->pwfxDst
->nChannels
||
538 adsi
->pwfxDst
->wBitsPerSample
!= 16)
543 unsigned int nspb
= ((IMAADPCMWAVEFORMAT
*)adsi
->pwfxSrc
)->wSamplesPerBlock
;
544 FIXME("spb=%u\n", nspb
);
546 /* we check that in a block, after the header, samples are present on
547 * 4-sample packet pattern
548 * we also check that the block alignement is bigger than the expected size
550 if (((nspb
- 1) & 3) != 0) goto theEnd
;
551 if ((((nspb
- 1) / 2) + 4) * adsi
->pwfxSrc
->nChannels
< adsi
->pwfxSrc
->nBlockAlign
)
556 /* adpcm decoding... */
557 if (adsi
->pwfxDst
->wBitsPerSample
== 16 && adsi
->pwfxDst
->nChannels
== 2)
558 aad
->convert
= cvtSSms16K
;
559 if (adsi
->pwfxDst
->wBitsPerSample
== 16 && adsi
->pwfxDst
->nChannels
== 1)
560 aad
->convert
= cvtMMms16K
;
562 else if (adsi
->pwfxSrc
->wFormatTag
== WAVE_FORMAT_PCM
&&
563 adsi
->pwfxDst
->wFormatTag
== WAVE_FORMAT_ADPCM
)
565 if (adsi
->pwfxSrc
->nSamplesPerSec
!= adsi
->pwfxDst
->nSamplesPerSec
||
566 adsi
->pwfxSrc
->nChannels
!= adsi
->pwfxDst
->nChannels
||
567 adsi
->pwfxSrc
->wBitsPerSample
!= 16)
570 nspb
= ((IMAADPCMWAVEFORMAT
*)adsi
->pwfxDst
)->wSamplesPerBlock
;
571 FIXME("spb=%u\n", nspb
);
573 /* we check that in a block, after the header, samples are present on
574 * 4-sample packet pattern
575 * we also check that the block alignement is bigger than the expected size
577 if (((nspb
- 1) & 3) != 0) goto theEnd
;
578 if ((((nspb
- 1) / 2) + 4) * adsi
->pwfxDst
->nChannels
< adsi
->pwfxDst
->nBlockAlign
)
582 /* adpcm coding... */
583 if (adsi
->pwfxSrc
->wBitsPerSample
== 16 && adsi
->pwfxSrc
->nChannels
== 2)
584 aad
->convert
= cvtSS16msK
;
585 if (adsi
->pwfxSrc
->wBitsPerSample
== 16 && adsi
->pwfxSrc
->nChannels
== 1)
586 aad
->convert
= cvtMM16msK
;
588 FIXME("We don't support encoding yet\n");
592 ADPCM_Reset(adsi
, aad
);
594 return MMSYSERR_NOERROR
;
597 HeapFree(GetProcessHeap(), 0, aad
);
599 return MMSYSERR_NOTSUPPORTED
;
602 /***********************************************************************
606 static LRESULT
ADPCM_StreamClose(PACMDRVSTREAMINSTANCE adsi
)
608 HeapFree(GetProcessHeap(), 0, (void*)adsi
->dwDriver
);
609 return MMSYSERR_NOERROR
;
612 /***********************************************************************
616 static inline DWORD
ADPCM_round(DWORD a
, DWORD b
, DWORD c
)
619 /* to be sure, always return an entire number of c... */
620 return ((double)a
* (double)b
+ (double)c
- 1) / (double)c
;
623 /***********************************************************************
627 static LRESULT
ADPCM_StreamSize(PACMDRVSTREAMINSTANCE adsi
, PACMDRVSTREAMSIZE adss
)
629 switch (adss
->fdwSize
)
631 case ACM_STREAMSIZEF_DESTINATION
:
632 /* cbDstLength => cbSrcLength */
633 if (adsi
->pwfxSrc
->wFormatTag
== WAVE_FORMAT_PCM
&&
634 adsi
->pwfxDst
->wFormatTag
== WAVE_FORMAT_ADPCM
)
636 /* don't take block overhead into account, doesn't matter too much */
637 adss
->cbSrcLength
= adss
->cbDstLength
* 4;
639 else if (adsi
->pwfxSrc
->wFormatTag
== WAVE_FORMAT_ADPCM
&&
640 adsi
->pwfxDst
->wFormatTag
== WAVE_FORMAT_PCM
)
642 FIXME("misses the block header overhead\n");
643 adss
->cbSrcLength
= 256 + adss
->cbDstLength
/ 4;
647 return MMSYSERR_NOTSUPPORTED
;
650 case ACM_STREAMSIZEF_SOURCE
:
651 /* cbSrcLength => cbDstLength */
652 if (adsi
->pwfxSrc
->wFormatTag
== WAVE_FORMAT_PCM
&&
653 adsi
->pwfxDst
->wFormatTag
== WAVE_FORMAT_ADPCM
)
655 FIXME("misses the block header overhead\n");
656 adss
->cbDstLength
= 256 + adss
->cbSrcLength
/ 4;
658 else if (adsi
->pwfxSrc
->wFormatTag
== WAVE_FORMAT_ADPCM
&&
659 adsi
->pwfxDst
->wFormatTag
== WAVE_FORMAT_PCM
)
661 /* don't take block overhead into account, doesn't matter too much */
662 adss
->cbDstLength
= adss
->cbSrcLength
* 4;
666 return MMSYSERR_NOTSUPPORTED
;
670 WARN("Unsupported query %08lx\n", adss
->fdwSize
);
671 return MMSYSERR_NOTSUPPORTED
;
673 return MMSYSERR_NOERROR
;
676 /***********************************************************************
677 * ADPCM_StreamConvert
680 static LRESULT
ADPCM_StreamConvert(PACMDRVSTREAMINSTANCE adsi
, PACMDRVSTREAMHEADER adsh
)
682 AcmAdpcmData
* aad
= (AcmAdpcmData
*)adsi
->dwDriver
;
683 DWORD nsrc
= adsh
->cbSrcLength
;
684 DWORD ndst
= adsh
->cbDstLength
;
686 if (adsh
->fdwConvert
&
687 ~(ACM_STREAMCONVERTF_BLOCKALIGN
|
688 ACM_STREAMCONVERTF_END
|
689 ACM_STREAMCONVERTF_START
))
691 FIXME("Unsupported fdwConvert (%08lx), ignoring it\n", adsh
->fdwConvert
);
693 /* ACM_STREAMCONVERTF_BLOCKALIGN
694 * currently all conversions are block aligned, so do nothing for this flag
695 * ACM_STREAMCONVERTF_END
696 * no pending data, so do nothing for this flag
698 if ((adsh
->fdwConvert
& ACM_STREAMCONVERTF_START
))
700 ADPCM_Reset(adsi
, aad
);
703 aad
->convert(adsi
, adsh
->pbSrc
, &nsrc
, adsh
->pbDst
, &ndst
);
704 adsh
->cbSrcLengthUsed
= nsrc
;
705 adsh
->cbDstLengthUsed
= ndst
;
707 return MMSYSERR_NOERROR
;
710 /**************************************************************************
711 * ADPCM_DriverProc [exported]
713 LRESULT CALLBACK
ADPCM_DriverProc(DWORD dwDevID
, HDRVR hDriv
, UINT wMsg
,
714 LPARAM dwParam1
, LPARAM dwParam2
)
716 TRACE("(%08lx %08lx %04x %08lx %08lx);\n",
717 dwDevID
, (DWORD
)hDriv
, wMsg
, dwParam1
, dwParam2
);
721 case DRV_LOAD
: return 1;
722 case DRV_FREE
: return 1;
723 case DRV_OPEN
: return ADPCM_drvOpen((LPSTR
)dwParam1
);
724 case DRV_CLOSE
: return ADPCM_drvClose(dwDevID
);
725 case DRV_ENABLE
: return 1;
726 case DRV_DISABLE
: return 1;
727 case DRV_QUERYCONFIGURE
: return 1;
728 case DRV_CONFIGURE
: MessageBoxA(0, "MSACM MS ADPCM filter !", "Wine Driver", MB_OK
); return 1;
729 case DRV_INSTALL
: return DRVCNF_RESTART
;
730 case DRV_REMOVE
: return DRVCNF_RESTART
;
732 case ACMDM_DRIVER_NOTIFY
:
733 /* no caching from other ACM drivers is done so far */
734 return MMSYSERR_NOERROR
;
736 case ACMDM_DRIVER_DETAILS
:
737 return ADPCM_DriverDetails((PACMDRIVERDETAILSW
)dwParam1
);
739 case ACMDM_FORMATTAG_DETAILS
:
740 return ADPCM_FormatTagDetails((PACMFORMATTAGDETAILSW
)dwParam1
, dwParam2
);
742 case ACMDM_FORMAT_DETAILS
:
743 return ADPCM_FormatDetails((PACMFORMATDETAILSW
)dwParam1
, dwParam2
);
745 case ACMDM_FORMAT_SUGGEST
:
746 return ADPCM_FormatSuggest((PACMDRVFORMATSUGGEST
)dwParam1
);
748 case ACMDM_STREAM_OPEN
:
749 return ADPCM_StreamOpen((PACMDRVSTREAMINSTANCE
)dwParam1
);
751 case ACMDM_STREAM_CLOSE
:
752 return ADPCM_StreamClose((PACMDRVSTREAMINSTANCE
)dwParam1
);
754 case ACMDM_STREAM_SIZE
:
755 return ADPCM_StreamSize((PACMDRVSTREAMINSTANCE
)dwParam1
, (PACMDRVSTREAMSIZE
)dwParam2
);
757 case ACMDM_STREAM_CONVERT
:
758 return ADPCM_StreamConvert((PACMDRVSTREAMINSTANCE
)dwParam1
, (PACMDRVSTREAMHEADER
)dwParam2
);
760 case ACMDM_HARDWARE_WAVE_CAPS_INPUT
:
761 case ACMDM_HARDWARE_WAVE_CAPS_OUTPUT
:
762 /* this converter is not a hardware driver */
763 case ACMDM_FILTERTAG_DETAILS
:
764 case ACMDM_FILTER_DETAILS
:
765 /* this converter is not a filter */
766 case ACMDM_STREAM_RESET
:
767 /* only needed for asynchronous driver... we aren't, so just say it */
768 return MMSYSERR_NOTSUPPORTED
;
769 case ACMDM_STREAM_PREPARE
:
770 case ACMDM_STREAM_UNPREPARE
:
771 /* nothing special to do here... so don't do anything */
772 return MMSYSERR_NOERROR
;
775 return DefDriverProc(dwDevID
, hDriv
, wMsg
, dwParam1
, dwParam2
);