1 /* -*- tab-width: 8; c-basic-offset: 4 -*- */
6 * Copyright 2000 Eric Pouech
7 * Copyright 2004 Robert Reif
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2.1 of the License, or (at your option) any later version.
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
24 * + get rid of hack for PCM_DriverProc (msacm32.dll shouldn't export
25 * a DriverProc, but this would require implementing a generic
26 * embedded driver handling scheme in msacm32.dll which isn't done yet
33 /***********************************************************************
36 static DWORD
PCM_drvOpen(LPCSTR str
, PACMDRVOPENDESCW adod
)
38 TRACE("(%p, %p)\n", str
, adod
);
40 return (adod
== NULL
) ||
41 (adod
->fccType
== ACMDRIVERDETAILS_FCCTYPE_AUDIOCODEC
&&
42 adod
->fccComp
== ACMDRIVERDETAILS_FCCCOMP_UNDEFINED
);
45 /***********************************************************************
48 static DWORD
PCM_drvClose(DWORD dwDevID
)
50 TRACE("(%d)\n", dwDevID
);
55 #define NUM_PCM_FORMATS (sizeof(PCM_Formats) / sizeof(PCM_Formats[0]))
56 #define NUM_OF(a,b) ((a)/(b))
58 /* flags for fdwDriver */
59 #define PCM_RESAMPLE 1
61 /* data used while converting */
62 typedef struct tagAcmPcmData
{
63 /* conversion routine, depending if rate conversion is required */
65 void (*cvtKeepRate
)(const unsigned char*, int, unsigned char*);
66 void (*cvtChangeRate
)(DWORD
, const unsigned char*, LPDWORD
,
67 DWORD
, unsigned char*, LPDWORD
);
71 /* table to list all supported formats... those are the basic ones. this
72 * also helps given a unique index to each of the supported formats
79 {1, 8, 8000}, {2, 8, 8000}, {1, 16, 8000}, {2, 16, 8000},
80 {1, 8, 11025}, {2, 8, 11025}, {1, 16, 11025}, {2, 16, 11025},
81 {1, 8, 22050}, {2, 8, 22050}, {1, 16, 22050}, {2, 16, 22050},
82 {1, 8, 44100}, {2, 8, 44100}, {1, 16, 44100}, {2, 16, 44100},
83 {1, 8, 48000}, {2, 8, 48000}, {1, 16, 48000}, {2, 16, 48000},
84 {1, 8, 96000}, {2, 8, 96000}, {1, 16, 96000}, {2, 16, 96000}
87 /***********************************************************************
90 static DWORD
PCM_GetFormatIndex(LPWAVEFORMATEX wfx
)
95 for (i
= 0; i
< NUM_PCM_FORMATS
; i
++) {
96 if (wfx
->nChannels
== PCM_Formats
[i
].nChannels
&&
97 wfx
->nSamplesPerSec
== PCM_Formats
[i
].rate
&&
98 wfx
->wBitsPerSample
== PCM_Formats
[i
].nBits
)
107 * + 8 bit unsigned vs 16 bit signed
108 * + mono vs stereo (1 or 2 channels)
109 * + sampling rate (8.0, 11.025, 22.05, 44.1 kHz are defined, but algo
110 * shall work in all cases)
112 * mono => stereo: copy the same sample on Left & Right channels
113 * stereo => mono: use the sum of Left & Right channels
116 /***********************************************************************
119 * Converts a 8 bit sample to a 16 bit one
121 static inline short C816(unsigned char b
)
123 return (b
- 128) << 8;
126 /***********************************************************************
129 * Converts a 16 bit sample to a 8 bit one (data loss !!)
131 static inline unsigned char C168(short s
)
133 return HIBYTE(s
) ^ (unsigned char)0x80;
136 /***********************************************************************
139 * Read a 16 bit sample (correctly handles endianness)
141 static inline short R16(const unsigned char* src
)
143 return (short)((unsigned short)src
[0] | ((unsigned short)src
[1] << 8));
146 /***********************************************************************
149 * Write a 16 bit sample (correctly handles endianness)
151 static inline void W16(unsigned char* dst
, short s
)
157 /***********************************************************************
160 * Convert the (l,r) 16 bit stereo sample into a 16 bit mono
161 * (takes the sum of the two values)
163 static inline short M16(short l
, short r
)
167 /* clip sum to saturation */
170 else if (sum
< -32768)
176 /***********************************************************************
179 * Convert the (l,r) 8 bit stereo sample into a 8 bit mono
180 * (takes the sum of the two values)
182 static inline unsigned char M8(unsigned char a
, unsigned char b
)
186 int sum
= (l
+ r
) + 128;
188 /* clip sum to saturation */
197 /* the conversion routines without rate conversion are labelled cvt<X><Y><N><M>K
199 * <X> is the (M)ono/(S)tereo configuration of input channel
200 * <Y> is the (M)ono/(S)tereo configuration of output channel
201 * <N> is the number of bits of input channel (8 or 16)
202 * <M> is the number of bits of output channel (8 or 16)
204 * in the parameters, ns is always the number of samples, so the size of input
205 * buffer (resp output buffer) is ns * (<X> == 'Mono' ? 1:2) * (<N> == 8 ? 1:2)
208 static void cvtMM88K(const unsigned char* src
, int ns
, unsigned char* dst
)
210 TRACE("(%p, %d, %p)\n", src
, ns
, dst
);
211 memcpy(dst
, src
, ns
);
214 static void cvtSS88K(const unsigned char* src
, int ns
, unsigned char* dst
)
216 TRACE("(%p, %d, %p)\n", src
, ns
, dst
);
217 memcpy(dst
, src
, ns
* 2);
220 static void cvtMM1616K(const unsigned char* src
, int ns
, unsigned char* dst
)
222 TRACE("(%p, %d, %p)\n", src
, ns
, dst
);
223 memcpy(dst
, src
, ns
* 2);
226 static void cvtSS1616K(const unsigned char* src
, int ns
, unsigned char* dst
)
228 TRACE("(%p, %d, %p)\n", src
, ns
, dst
);
229 memcpy(dst
, src
, ns
* 4);
232 static void cvtMS88K(const unsigned char* src
, int ns
, unsigned char* dst
)
234 TRACE("(%p, %d, %p)\n", src
, ns
, dst
);
242 static void cvtMS816K(const unsigned char* src
, int ns
, unsigned char* dst
)
245 TRACE("(%p, %d, %p)\n", src
, ns
, dst
);
249 W16(dst
, v
); dst
+= 2;
250 W16(dst
, v
); dst
+= 2;
254 static void cvtMS168K(const unsigned char* src
, int ns
, unsigned char* dst
)
257 TRACE("(%p, %d, %p)\n", src
, ns
, dst
);
260 v
= C168(R16(src
)); src
+= 2;
266 static void cvtMS1616K(const unsigned char* src
, int ns
, unsigned char* dst
)
269 TRACE("(%p, %d, %p)\n", src
, ns
, dst
);
272 v
= R16(src
); src
+= 2;
273 W16(dst
, v
); dst
+= 2;
274 W16(dst
, v
); dst
+= 2;
278 static void cvtSM88K(const unsigned char* src
, int ns
, unsigned char* dst
)
280 TRACE("(%p, %d, %p)\n", src
, ns
, dst
);
283 *dst
++ = M8(src
[0], src
[1]);
288 static void cvtSM816K(const unsigned char* src
, int ns
, unsigned char* dst
)
291 TRACE("(%p, %d, %p)\n", src
, ns
, dst
);
294 v
= M16(C816(src
[0]), C816(src
[1]));
296 W16(dst
, v
); dst
+= 2;
300 static void cvtSM168K(const unsigned char* src
, int ns
, unsigned char* dst
)
302 TRACE("(%p, %d, %p)\n", src
, ns
, dst
);
305 *dst
++ = C168(M16(R16(src
), R16(src
+ 2)));
310 static void cvtSM1616K(const unsigned char* src
, int ns
, unsigned char* dst
)
312 TRACE("(%p, %d, %p)\n", src
, ns
, dst
);
315 W16(dst
, M16(R16(src
),R16(src
+2))); dst
+= 2;
320 static void cvtMM816K(const unsigned char* src
, int ns
, unsigned char* dst
)
322 TRACE("(%p, %d, %p)\n", src
, ns
, dst
);
325 W16(dst
, C816(*src
++)); dst
+= 2;
329 static void cvtSS816K(const unsigned char* src
, int ns
, unsigned char* dst
)
331 TRACE("(%p, %d, %p)\n", src
, ns
, dst
);
334 W16(dst
, C816(*src
++)); dst
+= 2;
335 W16(dst
, C816(*src
++)); dst
+= 2;
339 static void cvtMM168K(const unsigned char* src
, int ns
, unsigned char* dst
)
341 TRACE("(%p, %d, %p)\n", src
, ns
, dst
);
344 *dst
++ = C168(R16(src
)); src
+= 2;
348 static void cvtSS168K(const unsigned char* src
, int ns
, unsigned char* dst
)
350 TRACE("(%p, %d, %p)\n", src
, ns
, dst
);
353 *dst
++ = C168(R16(src
)); src
+= 2;
354 *dst
++ = C168(R16(src
)); src
+= 2;
359 typedef void (*PCM_CONVERT_KEEP_RATE
)(const unsigned char*, int, unsigned char*);
361 static const PCM_CONVERT_KEEP_RATE PCM_ConvertKeepRate
[16] = {
362 cvtSS88K
, cvtSM88K
, cvtMS88K
, cvtMM88K
,
363 cvtSS816K
, cvtSM816K
, cvtMS816K
, cvtMM816K
,
364 cvtSS168K
, cvtSM168K
, cvtMS168K
, cvtMM168K
,
365 cvtSS1616K
, cvtSM1616K
, cvtMS1616K
, cvtMM1616K
,
368 /* the conversion routines with rate conversion are labelled cvt<X><Y><N><M>C
370 * <X> is the (M)ono/(S)tereo configuration of input channel
371 * <Y> is the (M)ono/(S)tereo configuration of output channel
372 * <N> is the number of bits of input channel (8 or 16)
373 * <M> is the number of bits of output channel (8 or 16)
376 static void cvtSS88C(DWORD srcRate
, const unsigned char* src
, LPDWORD nsrc
,
377 DWORD dstRate
, unsigned char* dst
, LPDWORD ndst
)
379 DWORD error
= dstRate
/ 2;
380 TRACE("(%d, %p, %p, %d, %p, %p)\n", srcRate
, src
, nsrc
, dstRate
, dst
, ndst
);
385 error
= error
+ srcRate
;
386 while (error
> dstRate
) {
391 error
= error
- dstRate
;
396 static void cvtSM88C(DWORD srcRate
, const unsigned char* src
, LPDWORD nsrc
,
397 DWORD dstRate
, unsigned char* dst
, LPDWORD ndst
)
399 DWORD error
= dstRate
/ 2;
400 TRACE("(%d, %p, %p, %d, %p, %p)\n", srcRate
, src
, nsrc
, dstRate
, dst
, ndst
);
403 *dst
++ = M8(src
[0], src
[1]);
404 error
= error
+ srcRate
;
405 while (error
> dstRate
) {
410 error
= error
- dstRate
;
415 static void cvtMS88C(DWORD srcRate
, const unsigned char* src
, LPDWORD nsrc
,
416 DWORD dstRate
, unsigned char* dst
, LPDWORD ndst
)
418 DWORD error
= dstRate
/ 2;
419 TRACE("(%d, %p, %p, %d, %p, %p)\n", srcRate
, src
, nsrc
, dstRate
, dst
, ndst
);
424 error
= error
+ srcRate
;
425 while (error
> dstRate
) {
430 error
= error
- dstRate
;
435 static void cvtMM88C(DWORD srcRate
, const unsigned char* src
, LPDWORD nsrc
,
436 DWORD dstRate
, unsigned char* dst
, LPDWORD ndst
)
438 DWORD error
= dstRate
/ 2;
439 TRACE("(%d, %p, %p, %d, %p, %p)\n", srcRate
, src
, nsrc
, dstRate
, dst
, ndst
);
443 error
= error
+ srcRate
;
444 while (error
> dstRate
) {
449 error
= error
- dstRate
;
454 static void cvtSS816C(DWORD srcRate
, const unsigned char* src
, LPDWORD nsrc
,
455 DWORD dstRate
, unsigned char* dst
, LPDWORD ndst
)
457 DWORD error
= dstRate
/ 2;
458 TRACE("(%d, %p, %p, %d, %p, %p)\n", srcRate
, src
, nsrc
, dstRate
, dst
, ndst
);
461 W16(dst
, C816(src
[0])); dst
+= 2;
462 W16(dst
, C816(src
[1])); dst
+= 2;
463 error
= error
+ srcRate
;
464 while (error
> dstRate
) {
469 error
= error
- dstRate
;
474 static void cvtSM816C(DWORD srcRate
, const unsigned char* src
, LPDWORD nsrc
,
475 DWORD dstRate
, unsigned char* dst
, LPDWORD ndst
)
477 DWORD error
= dstRate
/ 2;
478 TRACE("(%d, %p, %p, %d, %p, %p)\n", srcRate
, src
, nsrc
, dstRate
, dst
, ndst
);
481 W16(dst
, M16(C816(src
[0]), C816(src
[1]))); dst
+= 2;
482 error
= error
+ srcRate
;
483 while (error
> dstRate
) {
488 error
= error
- dstRate
;
493 static void cvtMS816C(DWORD srcRate
, const unsigned char* src
, LPDWORD nsrc
,
494 DWORD dstRate
, unsigned char* dst
, LPDWORD ndst
)
496 DWORD error
= dstRate
/ 2;
497 TRACE("(%d, %p, %p, %d, %p, %p)\n", srcRate
, src
, nsrc
, dstRate
, dst
, ndst
);
500 W16(dst
, C816(*src
)); dst
+= 2;
501 W16(dst
, C816(*src
)); dst
+= 2;
502 error
= error
+ srcRate
;
503 while (error
> dstRate
) {
508 error
= error
- dstRate
;
513 static void cvtMM816C(DWORD srcRate
, const unsigned char* src
, LPDWORD nsrc
,
514 DWORD dstRate
, unsigned char* dst
, LPDWORD ndst
)
516 DWORD error
= dstRate
/ 2;
517 TRACE("(%d, %p, %p, %d, %p, %p)\n", srcRate
, src
, nsrc
, dstRate
, dst
, ndst
);
520 W16(dst
, C816(*src
)); dst
+= 2;
521 error
= error
+ srcRate
;
522 while (error
> dstRate
) {
527 error
= error
- dstRate
;
532 static void cvtSS168C(DWORD srcRate
, const unsigned char* src
, LPDWORD nsrc
,
533 DWORD dstRate
, unsigned char* dst
, LPDWORD ndst
)
535 DWORD error
= dstRate
/ 2;
536 TRACE("(%d, %p, %p, %d, %p, %p)\n", srcRate
, src
, nsrc
, dstRate
, dst
, ndst
);
539 *dst
++ = C168(R16(src
));
540 *dst
++ = C168(R16(src
+ 2));
541 error
= error
+ srcRate
;
542 while (error
> dstRate
) {
547 error
= error
- dstRate
;
552 static void cvtSM168C(DWORD srcRate
, const unsigned char* src
, LPDWORD nsrc
,
553 DWORD dstRate
, unsigned char* dst
, LPDWORD ndst
)
555 DWORD error
= dstRate
/ 2;
556 TRACE("(%d, %p, %p, %d, %p, %p)\n", srcRate
, src
, nsrc
, dstRate
, dst
, ndst
);
559 *dst
++ = C168(M16(R16(src
), R16(src
+ 2)));
560 error
= error
+ srcRate
;
561 while (error
> dstRate
) {
566 error
= error
- dstRate
;
571 static void cvtMS168C(DWORD srcRate
, const unsigned char* src
, LPDWORD nsrc
,
572 DWORD dstRate
, unsigned char* dst
, LPDWORD ndst
)
574 DWORD error
= dstRate
/ 2;
575 TRACE("(%d, %p, %p, %d, %p, %p)\n", srcRate
, src
, nsrc
, dstRate
, dst
, ndst
);
578 *dst
++ = C168(R16(src
));
579 *dst
++ = C168(R16(src
));
580 error
= error
+ srcRate
;
581 while (error
> dstRate
) {
586 error
= error
- dstRate
;
591 static void cvtMM168C(DWORD srcRate
, const unsigned char* src
, LPDWORD nsrc
,
592 DWORD dstRate
, unsigned char* dst
, LPDWORD ndst
)
594 DWORD error
= dstRate
/ 2;
595 TRACE("(%d, %p, %p, %d, %p, %p)\n", srcRate
, src
, nsrc
, dstRate
, dst
, ndst
);
598 *dst
++ = C168(R16(src
));
599 error
= error
+ srcRate
;
600 while (error
> dstRate
) {
605 error
= error
- dstRate
;
610 static void cvtSS1616C(DWORD srcRate
, const unsigned char* src
, LPDWORD nsrc
,
611 DWORD dstRate
, unsigned char* dst
, LPDWORD ndst
)
613 DWORD error
= dstRate
/ 2;
614 TRACE("(%d, %p, %p, %d, %p, %p)\n", srcRate
, src
, nsrc
, dstRate
, dst
, ndst
);
617 W16(dst
, R16(src
)); dst
+= 2;
618 W16(dst
, R16(src
)); dst
+= 2;
619 error
= error
+ srcRate
;
620 while (error
> dstRate
) {
625 error
= error
- dstRate
;
630 static void cvtSM1616C(DWORD srcRate
, const unsigned char* src
, LPDWORD nsrc
,
631 DWORD dstRate
, unsigned char* dst
, LPDWORD ndst
)
633 DWORD error
= dstRate
/ 2;
634 TRACE("(%d, %p, %p, %d, %p, %p)\n", srcRate
, src
, nsrc
, dstRate
, dst
, ndst
);
637 W16(dst
, M16(R16(src
), R16(src
+ 2))); dst
+= 2;
638 error
= error
+ srcRate
;
639 while (error
> dstRate
) {
644 error
= error
- dstRate
;
649 static void cvtMS1616C(DWORD srcRate
, const unsigned char* src
, LPDWORD nsrc
,
650 DWORD dstRate
, unsigned char* dst
, LPDWORD ndst
)
652 DWORD error
= dstRate
/ 2;
653 TRACE("(%d, %p, %p, %d, %p, %p)\n", srcRate
, src
, nsrc
, dstRate
, dst
, ndst
);
656 W16(dst
, R16(src
)); dst
+= 2;
657 W16(dst
, R16(src
)); dst
+= 2;
658 error
= error
+ srcRate
;
659 while (error
> dstRate
) {
664 error
= error
- dstRate
;
669 static void cvtMM1616C(DWORD srcRate
, const unsigned char* src
, LPDWORD nsrc
,
670 DWORD dstRate
, unsigned char* dst
, LPDWORD ndst
)
672 DWORD error
= dstRate
/ 2;
673 TRACE("(%d, %p, %p, %d, %p, %p)\n", srcRate
, src
, nsrc
, dstRate
, dst
, ndst
);
676 W16(dst
, R16(src
)); dst
+= 2;
677 error
= error
+ srcRate
;
678 while (error
> dstRate
) {
683 error
= error
- dstRate
;
688 typedef void (*PCM_CONVERT_CHANGE_RATE
)(DWORD
, const unsigned char*, LPDWORD
, DWORD
, unsigned char*, LPDWORD
);
690 static const PCM_CONVERT_CHANGE_RATE PCM_ConvertChangeRate
[16] = {
691 cvtSS88C
, cvtSM88C
, cvtMS88C
, cvtMM88C
,
692 cvtSS816C
, cvtSM816C
, cvtMS816C
, cvtMM816C
,
693 cvtSS168C
, cvtSM168C
, cvtMS168C
, cvtMM168C
,
694 cvtSS1616C
, cvtSM1616C
, cvtMS1616C
, cvtMM1616C
,
697 /***********************************************************************
701 static LRESULT
PCM_DriverDetails(PACMDRIVERDETAILSW add
)
703 TRACE("(%p)\n", add
);
705 add
->fccType
= ACMDRIVERDETAILS_FCCTYPE_AUDIOCODEC
;
706 add
->fccComp
= ACMDRIVERDETAILS_FCCCOMP_UNDEFINED
;
709 add
->vdwACM
= 0x01000000;
710 add
->vdwDriver
= 0x01000000;
711 add
->fdwSupport
= ACMDRIVERDETAILS_SUPPORTF_CONVERTER
;
712 add
->cFormatTags
= 1;
713 add
->cFilterTags
= 0;
715 MultiByteToWideChar( CP_ACP
, 0, "WINE-PCM", -1,
716 add
->szShortName
, sizeof(add
->szShortName
)/sizeof(WCHAR
) );
717 MultiByteToWideChar( CP_ACP
, 0, "Wine PCM converter", -1,
718 add
->szLongName
, sizeof(add
->szLongName
)/sizeof(WCHAR
) );
719 MultiByteToWideChar( CP_ACP
, 0, "Brought to you by the Wine team...", -1,
720 add
->szCopyright
, sizeof(add
->szCopyright
)/sizeof(WCHAR
) );
721 MultiByteToWideChar( CP_ACP
, 0, "Refer to LICENSE file", -1,
722 add
->szLicensing
, sizeof(add
->szLicensing
)/sizeof(WCHAR
) );
723 add
->szFeatures
[0] = 0;
725 return MMSYSERR_NOERROR
;
728 /***********************************************************************
729 * PCM_FormatTagDetails
732 static LRESULT
PCM_FormatTagDetails(PACMFORMATTAGDETAILSW aftd
, DWORD dwQuery
)
734 TRACE("(%p, %08x)\n", aftd
, dwQuery
);
737 case ACM_FORMATTAGDETAILSF_INDEX
:
738 if (aftd
->dwFormatTagIndex
!= 0) {
739 WARN("not possible\n");
740 return ACMERR_NOTPOSSIBLE
;
743 case ACM_FORMATTAGDETAILSF_FORMATTAG
:
744 if (aftd
->dwFormatTag
!= WAVE_FORMAT_PCM
) {
745 WARN("not possible\n");
746 return ACMERR_NOTPOSSIBLE
;
749 case ACM_FORMATTAGDETAILSF_LARGESTSIZE
:
750 if (aftd
->dwFormatTag
!= WAVE_FORMAT_UNKNOWN
&&
751 aftd
->dwFormatTag
!= WAVE_FORMAT_PCM
) {
752 WARN("not possible\n");
753 return ACMERR_NOTPOSSIBLE
;
757 WARN("Unsupported query %08x\n", dwQuery
);
758 return MMSYSERR_NOTSUPPORTED
;
761 aftd
->dwFormatTagIndex
= 0;
762 aftd
->dwFormatTag
= WAVE_FORMAT_PCM
;
763 aftd
->cbFormatSize
= sizeof(PCMWAVEFORMAT
);
764 aftd
->fdwSupport
= ACMDRIVERDETAILS_SUPPORTF_CONVERTER
;
765 aftd
->cStandardFormats
= NUM_PCM_FORMATS
;
766 aftd
->szFormatTag
[0] = 0;
768 return MMSYSERR_NOERROR
;
771 /***********************************************************************
775 static LRESULT
PCM_FormatDetails(PACMFORMATDETAILSW afd
, DWORD dwQuery
)
777 TRACE("(%p, %08x)\n", afd
, dwQuery
);
780 case ACM_FORMATDETAILSF_FORMAT
:
781 if (PCM_GetFormatIndex(afd
->pwfx
) == 0xFFFFFFFF) {
782 WARN("not possible\n");
783 return ACMERR_NOTPOSSIBLE
;
786 case ACM_FORMATDETAILSF_INDEX
:
787 assert(afd
->dwFormatIndex
< NUM_PCM_FORMATS
);
788 afd
->pwfx
->wFormatTag
= WAVE_FORMAT_PCM
;
789 afd
->pwfx
->nChannels
= PCM_Formats
[afd
->dwFormatIndex
].nChannels
;
790 afd
->pwfx
->nSamplesPerSec
= PCM_Formats
[afd
->dwFormatIndex
].rate
;
791 afd
->pwfx
->wBitsPerSample
= PCM_Formats
[afd
->dwFormatIndex
].nBits
;
792 /* native MSACM uses a PCMWAVEFORMAT structure, so cbSize is not
793 * accessible afd->pwfx->cbSize = 0;
795 afd
->pwfx
->nBlockAlign
=
796 (afd
->pwfx
->nChannels
* afd
->pwfx
->wBitsPerSample
) / 8;
797 afd
->pwfx
->nAvgBytesPerSec
=
798 afd
->pwfx
->nSamplesPerSec
* afd
->pwfx
->nBlockAlign
;
801 WARN("Unsupported query %08x\n", dwQuery
);
802 return MMSYSERR_NOTSUPPORTED
;
805 afd
->dwFormatTag
= WAVE_FORMAT_PCM
;
806 afd
->fdwSupport
= ACMDRIVERDETAILS_SUPPORTF_CONVERTER
;
807 afd
->szFormat
[0] = 0; /* let MSACM format this for us... */
808 afd
->cbwfx
= sizeof(PCMWAVEFORMAT
);
810 return MMSYSERR_NOERROR
;
813 /***********************************************************************
817 static LRESULT
PCM_FormatSuggest(PACMDRVFORMATSUGGEST adfs
)
819 TRACE("(%p)\n", adfs
);
822 if (adfs
->cbwfxSrc
< sizeof(PCMWAVEFORMAT
) ||
823 adfs
->cbwfxDst
< sizeof(PCMWAVEFORMAT
) ||
824 PCM_GetFormatIndex(adfs
->pwfxSrc
) == 0xFFFFFFFF) {
825 WARN("not possible\n");
826 return ACMERR_NOTPOSSIBLE
;
829 /* is no suggestion for destination, then copy source value */
830 if (!(adfs
->fdwSuggest
& ACM_FORMATSUGGESTF_NCHANNELS
)) {
831 adfs
->pwfxDst
->nChannels
= adfs
->pwfxSrc
->nChannels
;
833 if (!(adfs
->fdwSuggest
& ACM_FORMATSUGGESTF_NSAMPLESPERSEC
)) {
834 adfs
->pwfxDst
->nSamplesPerSec
= adfs
->pwfxSrc
->nSamplesPerSec
;
836 if (!(adfs
->fdwSuggest
& ACM_FORMATSUGGESTF_WBITSPERSAMPLE
)) {
837 adfs
->pwfxDst
->wBitsPerSample
= adfs
->pwfxSrc
->wBitsPerSample
;
839 if (!(adfs
->fdwSuggest
& ACM_FORMATSUGGESTF_WFORMATTAG
)) {
840 if (adfs
->pwfxSrc
->wFormatTag
!= WAVE_FORMAT_PCM
) {
841 WARN("not possible\n");
842 return ACMERR_NOTPOSSIBLE
;
844 adfs
->pwfxDst
->wFormatTag
= adfs
->pwfxSrc
->wFormatTag
;
846 /* check if result is ok */
847 if (PCM_GetFormatIndex(adfs
->pwfxDst
) == 0xFFFFFFFF) {
848 WARN("not possible\n");
849 return ACMERR_NOTPOSSIBLE
;
852 /* recompute other values */
853 adfs
->pwfxDst
->nBlockAlign
= (adfs
->pwfxDst
->nChannels
* adfs
->pwfxDst
->wBitsPerSample
) / 8;
854 adfs
->pwfxDst
->nAvgBytesPerSec
= adfs
->pwfxDst
->nSamplesPerSec
* adfs
->pwfxDst
->nBlockAlign
;
856 return MMSYSERR_NOERROR
;
859 /***********************************************************************
863 static LRESULT
PCM_StreamOpen(PACMDRVSTREAMINSTANCE adsi
)
868 TRACE("(%p)\n", adsi
);
870 assert(!(adsi
->fdwOpen
& ACM_STREAMOPENF_ASYNC
));
872 apd
= HeapAlloc(GetProcessHeap(), 0, sizeof(AcmPcmData
));
875 return MMSYSERR_NOMEM
;
878 adsi
->dwDriver
= (DWORD_PTR
)apd
;
881 if (adsi
->pwfxSrc
->wBitsPerSample
== 16) idx
+= 8;
882 if (adsi
->pwfxDst
->wBitsPerSample
== 16) idx
+= 4;
883 if (adsi
->pwfxSrc
->nChannels
== 1) idx
+= 2;
884 if (adsi
->pwfxDst
->nChannels
== 1) idx
+= 1;
886 if (adsi
->pwfxSrc
->nSamplesPerSec
== adsi
->pwfxDst
->nSamplesPerSec
) {
887 apd
->cvt
.cvtKeepRate
= PCM_ConvertKeepRate
[idx
];
889 adsi
->fdwDriver
|= PCM_RESAMPLE
;
890 apd
->cvt
.cvtChangeRate
= PCM_ConvertChangeRate
[idx
];
893 return MMSYSERR_NOERROR
;
896 /***********************************************************************
900 static LRESULT
PCM_StreamClose(PACMDRVSTREAMINSTANCE adsi
)
902 TRACE("(%p)\n", adsi
);
904 HeapFree(GetProcessHeap(), 0, (void*)adsi
->dwDriver
);
905 return MMSYSERR_NOERROR
;
908 /***********************************************************************
912 static inline DWORD
PCM_round(DWORD a
, DWORD b
, DWORD c
)
915 /* to be sure, always return an entire number of c... */
916 return ((double)a
* (double)b
+ (double)c
- 1) / (double)c
;
919 /***********************************************************************
923 static LRESULT
PCM_StreamSize(PACMDRVSTREAMINSTANCE adsi
, PACMDRVSTREAMSIZE adss
)
925 DWORD srcMask
= ~(adsi
->pwfxSrc
->nBlockAlign
- 1);
926 DWORD dstMask
= ~(adsi
->pwfxDst
->nBlockAlign
- 1);
928 TRACE("(%p, %p)\n", adsi
, adss
);
930 switch (adss
->fdwSize
) {
931 case ACM_STREAMSIZEF_DESTINATION
:
932 /* cbDstLength => cbSrcLength */
933 adss
->cbSrcLength
= PCM_round(adss
->cbDstLength
& dstMask
,
934 adsi
->pwfxSrc
->nAvgBytesPerSec
,
935 adsi
->pwfxDst
->nAvgBytesPerSec
) & srcMask
;
937 case ACM_STREAMSIZEF_SOURCE
:
938 /* cbSrcLength => cbDstLength */
939 adss
->cbDstLength
= PCM_round(adss
->cbSrcLength
& srcMask
,
940 adsi
->pwfxDst
->nAvgBytesPerSec
,
941 adsi
->pwfxSrc
->nAvgBytesPerSec
) & dstMask
;
944 WARN("Unsupported query %08x\n", adss
->fdwSize
);
945 return MMSYSERR_NOTSUPPORTED
;
947 return MMSYSERR_NOERROR
;
950 /***********************************************************************
954 static LRESULT
PCM_StreamConvert(PACMDRVSTREAMINSTANCE adsi
, PACMDRVSTREAMHEADER adsh
)
956 AcmPcmData
* apd
= (AcmPcmData
*)adsi
->dwDriver
;
957 DWORD nsrc
= NUM_OF(adsh
->cbSrcLength
, adsi
->pwfxSrc
->nBlockAlign
);
958 DWORD ndst
= NUM_OF(adsh
->cbDstLength
, adsi
->pwfxDst
->nBlockAlign
);
960 TRACE("(%p, %p)\n", adsi
, adsh
);
962 TRACE("nsrc=%d,adsh->cbSrcLength=%d\n", nsrc
, adsh
->cbSrcLength
);
963 TRACE("ndst=%d,adsh->cbDstLength=%d\n", ndst
, adsh
->cbDstLength
);
964 TRACE("src [wFormatTag=%u, nChannels=%u, nSamplesPerSec=%u, nAvgBytesPerSec=%u, nBlockAlign=%u, wBitsPerSample=%u, cbSize=%u]\n",
965 adsi
->pwfxSrc
->wFormatTag
, adsi
->pwfxSrc
->nChannels
, adsi
->pwfxSrc
->nSamplesPerSec
, adsi
->pwfxSrc
->nAvgBytesPerSec
,
966 adsi
->pwfxSrc
->nBlockAlign
, adsi
->pwfxSrc
->wBitsPerSample
, adsi
->pwfxSrc
->cbSize
);
967 TRACE("dst [wFormatTag=%u, nChannels=%u, nSamplesPerSec=%u, nAvgBytesPerSec=%u, nBlockAlign=%u, wBitsPerSample=%u, cbSize=%u]\n",
968 adsi
->pwfxDst
->wFormatTag
, adsi
->pwfxDst
->nChannels
, adsi
->pwfxDst
->nSamplesPerSec
, adsi
->pwfxDst
->nAvgBytesPerSec
,
969 adsi
->pwfxDst
->nBlockAlign
, adsi
->pwfxDst
->wBitsPerSample
, adsi
->pwfxDst
->cbSize
);
971 if (adsh
->fdwConvert
&
972 ~(ACM_STREAMCONVERTF_BLOCKALIGN
|
973 ACM_STREAMCONVERTF_END
|
974 ACM_STREAMCONVERTF_START
)) {
975 FIXME("Unsupported fdwConvert (%08x), ignoring it\n", adsh
->fdwConvert
);
977 /* ACM_STREAMCONVERTF_BLOCKALIGN
978 * currently all conversions are block aligned, so do nothing for this flag
979 * ACM_STREAMCONVERTF_END
980 * no pending data, so do nothing for this flag
982 if ((adsh
->fdwConvert
& ACM_STREAMCONVERTF_START
) &&
983 (adsi
->fdwDriver
& PCM_RESAMPLE
)) {
987 if (adsi
->fdwDriver
& PCM_RESAMPLE
) {
990 apd
->cvt
.cvtChangeRate(adsi
->pwfxSrc
->nSamplesPerSec
, adsh
->pbSrc
, &nsrc2
,
991 adsi
->pwfxDst
->nSamplesPerSec
, adsh
->pbDst
, &ndst2
);
995 if (nsrc
< ndst
) ndst
= nsrc
; else nsrc
= ndst
;
997 /* nsrc is now equal to ndst */
998 apd
->cvt
.cvtKeepRate(adsh
->pbSrc
, nsrc
, adsh
->pbDst
);
1001 adsh
->cbSrcLengthUsed
= nsrc
* adsi
->pwfxSrc
->nBlockAlign
;
1002 adsh
->cbDstLengthUsed
= ndst
* adsi
->pwfxDst
->nBlockAlign
;
1004 return MMSYSERR_NOERROR
;
1007 /**************************************************************************
1008 * DriverProc (MSACM32.@)
1010 LRESULT CALLBACK
PCM_DriverProc(DWORD_PTR dwDevID
, HDRVR hDriv
, UINT wMsg
,
1011 LPARAM dwParam1
, LPARAM dwParam2
)
1013 TRACE("(%08lx %p %u %08lx %08lx);\n",
1014 dwDevID
, hDriv
, wMsg
, dwParam1
, dwParam2
);
1017 case DRV_LOAD
: return 1;
1018 case DRV_FREE
: return 1;
1019 case DRV_OPEN
: return PCM_drvOpen((LPSTR
)dwParam1
, (PACMDRVOPENDESCW
)dwParam2
);
1020 case DRV_CLOSE
: return PCM_drvClose(dwDevID
);
1021 case DRV_ENABLE
: return 1;
1022 case DRV_DISABLE
: return 1;
1023 case DRV_QUERYCONFIGURE
: return 1;
1024 case DRV_CONFIGURE
: MessageBoxA(0, "MSACM PCM filter !", "Wine Driver", MB_OK
); return 1;
1025 case DRV_INSTALL
: return DRVCNF_RESTART
;
1026 case DRV_REMOVE
: return DRVCNF_RESTART
;
1028 case ACMDM_DRIVER_NOTIFY
:
1029 /* no caching from other ACM drivers is done so far */
1030 return MMSYSERR_NOERROR
;
1032 case ACMDM_DRIVER_DETAILS
:
1033 return PCM_DriverDetails((PACMDRIVERDETAILSW
)dwParam1
);
1035 case ACMDM_FORMATTAG_DETAILS
:
1036 return PCM_FormatTagDetails((PACMFORMATTAGDETAILSW
)dwParam1
, dwParam2
);
1038 case ACMDM_FORMAT_DETAILS
:
1039 return PCM_FormatDetails((PACMFORMATDETAILSW
)dwParam1
, dwParam2
);
1041 case ACMDM_FORMAT_SUGGEST
:
1042 return PCM_FormatSuggest((PACMDRVFORMATSUGGEST
)dwParam1
);
1044 case ACMDM_STREAM_OPEN
:
1045 return PCM_StreamOpen((PACMDRVSTREAMINSTANCE
)dwParam1
);
1047 case ACMDM_STREAM_CLOSE
:
1048 return PCM_StreamClose((PACMDRVSTREAMINSTANCE
)dwParam1
);
1050 case ACMDM_STREAM_SIZE
:
1051 return PCM_StreamSize((PACMDRVSTREAMINSTANCE
)dwParam1
, (PACMDRVSTREAMSIZE
)dwParam2
);
1053 case ACMDM_STREAM_CONVERT
:
1054 return PCM_StreamConvert((PACMDRVSTREAMINSTANCE
)dwParam1
, (PACMDRVSTREAMHEADER
)dwParam2
);
1056 case ACMDM_HARDWARE_WAVE_CAPS_INPUT
:
1057 case ACMDM_HARDWARE_WAVE_CAPS_OUTPUT
:
1058 /* this converter is not a hardware driver */
1059 case ACMDM_FILTERTAG_DETAILS
:
1060 case ACMDM_FILTER_DETAILS
:
1061 /* this converter is not a filter */
1062 case ACMDM_STREAM_RESET
:
1063 /* only needed for asynchronous driver... we aren't, so just say it */
1064 case ACMDM_STREAM_PREPARE
:
1065 case ACMDM_STREAM_UNPREPARE
:
1066 /* nothing special to do here... so don't do anything */
1067 return MMSYSERR_NOTSUPPORTED
;
1070 return DefDriverProc(dwDevID
, hDriv
, wMsg
, dwParam1
, dwParam2
);