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
29 #define WIN32_NO_STATUS
39 //#include "mmsystem.h"
48 //#include "wineacm.h"
50 #include <wine/debug.h>
52 WINE_DEFAULT_DEBUG_CHANNEL(msacm
);
54 /***********************************************************************
57 static DWORD
PCM_drvOpen(LPCSTR str
, PACMDRVOPENDESCW adod
)
59 TRACE("(%p, %p)\n", str
, adod
);
61 return (adod
== NULL
) ||
62 (adod
->fccType
== ACMDRIVERDETAILS_FCCTYPE_AUDIOCODEC
&&
63 adod
->fccComp
== ACMDRIVERDETAILS_FCCCOMP_UNDEFINED
);
66 /***********************************************************************
69 static DWORD
PCM_drvClose(DWORD dwDevID
)
71 TRACE("(%d)\n", dwDevID
);
76 #define NUM_PCM_FORMATS (sizeof(PCM_Formats) / sizeof(PCM_Formats[0]))
77 #define NUM_OF(a,b) ((a)/(b))
79 /* flags for fdwDriver */
80 #define PCM_RESAMPLE 1
82 /* data used while converting */
83 typedef struct tagAcmPcmData
{
84 /* conversion routine, depending if rate conversion is required */
86 void (*cvtKeepRate
)(const unsigned char*, int, unsigned char*);
87 void (*cvtChangeRate
)(DWORD
, const unsigned char*, LPDWORD
,
88 DWORD
, unsigned char*, LPDWORD
);
92 /* table to list all supported formats... those are the basic ones. this
93 * also helps given a unique index to each of the supported formats
100 {1, 8, 8000}, {2, 8, 8000}, {1, 16, 8000}, {2, 16, 8000},
101 {1, 8, 11025}, {2, 8, 11025}, {1, 16, 11025}, {2, 16, 11025},
102 {1, 8, 22050}, {2, 8, 22050}, {1, 16, 22050}, {2, 16, 22050},
103 {1, 8, 44100}, {2, 8, 44100}, {1, 16, 44100}, {2, 16, 44100},
104 {1, 8, 48000}, {2, 8, 48000}, {1, 16, 48000}, {2, 16, 48000},
105 {1, 8, 96000}, {2, 8, 96000}, {1, 16, 96000}, {2, 16, 96000}
108 /***********************************************************************
111 static DWORD
PCM_GetFormatIndex(LPWAVEFORMATEX wfx
)
114 TRACE("(%p)\n", wfx
);
116 for (i
= 0; i
< NUM_PCM_FORMATS
; i
++) {
117 if (wfx
->nChannels
== PCM_Formats
[i
].nChannels
&&
118 wfx
->nSamplesPerSec
== PCM_Formats
[i
].rate
&&
119 wfx
->wBitsPerSample
== PCM_Formats
[i
].nBits
)
128 * + 8 bit unsigned vs 16 bit signed
129 * + mono vs stereo (1 or 2 channels)
130 * + sampling rate (8.0, 11.025, 22.05, 44.1 kHz are defined, but algo
131 * shall work in all cases)
133 * mono => stereo: copy the same sample on Left & Right channels
134 * stereo => mono: use the sum of Left & Right channels
137 /***********************************************************************
140 * Converts a 8 bit sample to a 16 bit one
142 static inline short C816(unsigned char b
)
144 return (b
- 128) << 8;
147 /***********************************************************************
150 * Converts a 16 bit sample to a 8 bit one (data loss !!)
152 static inline unsigned char C168(short s
)
154 return HIBYTE(s
) ^ (unsigned char)0x80;
157 /***********************************************************************
160 * Read a 16 bit sample (correctly handles endianness)
162 static inline short R16(const unsigned char* src
)
164 return (short)((unsigned short)src
[0] | ((unsigned short)src
[1] << 8));
167 /***********************************************************************
170 * Write a 16 bit sample (correctly handles endianness)
172 static inline void W16(unsigned char* dst
, short s
)
178 /***********************************************************************
181 * Convert the (l,r) 16 bit stereo sample into a 16 bit mono
182 * (takes the sum of the two values)
184 static inline short M16(short l
, short r
)
188 /* clip sum to saturation */
191 else if (sum
< -32768)
197 /***********************************************************************
200 * Convert the (l,r) 8 bit stereo sample into a 8 bit mono
201 * (takes the sum of the two values)
203 static inline unsigned char M8(unsigned char a
, unsigned char b
)
207 int sum
= (l
+ r
) + 128;
209 /* clip sum to saturation */
218 /* the conversion routines without rate conversion are labelled cvt<X><Y><N><M>K
220 * <X> is the (M)ono/(S)tereo configuration of input channel
221 * <Y> is the (M)ono/(S)tereo configuration of output channel
222 * <N> is the number of bits of input channel (8 or 16)
223 * <M> is the number of bits of output channel (8 or 16)
225 * in the parameters, ns is always the number of samples, so the size of input
226 * buffer (resp output buffer) is ns * (<X> == 'Mono' ? 1:2) * (<N> == 8 ? 1:2)
229 static void cvtMM88K(const unsigned char* src
, int ns
, unsigned char* dst
)
231 TRACE("(%p, %d, %p)\n", src
, ns
, dst
);
232 memcpy(dst
, src
, ns
);
235 static void cvtSS88K(const unsigned char* src
, int ns
, unsigned char* dst
)
237 TRACE("(%p, %d, %p)\n", src
, ns
, dst
);
238 memcpy(dst
, src
, ns
* 2);
241 static void cvtMM1616K(const unsigned char* src
, int ns
, unsigned char* dst
)
243 TRACE("(%p, %d, %p)\n", src
, ns
, dst
);
244 memcpy(dst
, src
, ns
* 2);
247 static void cvtSS1616K(const unsigned char* src
, int ns
, unsigned char* dst
)
249 TRACE("(%p, %d, %p)\n", src
, ns
, dst
);
250 memcpy(dst
, src
, ns
* 4);
253 static void cvtMS88K(const unsigned char* src
, int ns
, unsigned char* dst
)
255 TRACE("(%p, %d, %p)\n", src
, ns
, dst
);
263 static void cvtMS816K(const unsigned char* src
, int ns
, unsigned char* dst
)
266 TRACE("(%p, %d, %p)\n", src
, ns
, dst
);
270 W16(dst
, v
); dst
+= 2;
271 W16(dst
, v
); dst
+= 2;
275 static void cvtMS168K(const unsigned char* src
, int ns
, unsigned char* dst
)
278 TRACE("(%p, %d, %p)\n", src
, ns
, dst
);
281 v
= C168(R16(src
)); src
+= 2;
287 static void cvtMS1616K(const unsigned char* src
, int ns
, unsigned char* dst
)
290 TRACE("(%p, %d, %p)\n", src
, ns
, dst
);
293 v
= R16(src
); src
+= 2;
294 W16(dst
, v
); dst
+= 2;
295 W16(dst
, v
); dst
+= 2;
299 static void cvtSM88K(const unsigned char* src
, int ns
, unsigned char* dst
)
301 TRACE("(%p, %d, %p)\n", src
, ns
, dst
);
304 *dst
++ = M8(src
[0], src
[1]);
309 static void cvtSM816K(const unsigned char* src
, int ns
, unsigned char* dst
)
312 TRACE("(%p, %d, %p)\n", src
, ns
, dst
);
315 v
= M16(C816(src
[0]), C816(src
[1]));
317 W16(dst
, v
); dst
+= 2;
321 static void cvtSM168K(const unsigned char* src
, int ns
, unsigned char* dst
)
323 TRACE("(%p, %d, %p)\n", src
, ns
, dst
);
326 *dst
++ = C168(M16(R16(src
), R16(src
+ 2)));
331 static void cvtSM1616K(const unsigned char* src
, int ns
, unsigned char* dst
)
333 TRACE("(%p, %d, %p)\n", src
, ns
, dst
);
336 W16(dst
, M16(R16(src
),R16(src
+2))); dst
+= 2;
341 static void cvtMM816K(const unsigned char* src
, int ns
, unsigned char* dst
)
343 TRACE("(%p, %d, %p)\n", src
, ns
, dst
);
346 W16(dst
, C816(*src
++)); dst
+= 2;
350 static void cvtSS816K(const unsigned char* src
, int ns
, unsigned char* dst
)
352 TRACE("(%p, %d, %p)\n", src
, ns
, dst
);
355 W16(dst
, C816(*src
++)); dst
+= 2;
356 W16(dst
, C816(*src
++)); dst
+= 2;
360 static void cvtMM168K(const unsigned char* src
, int ns
, unsigned char* dst
)
362 TRACE("(%p, %d, %p)\n", src
, ns
, dst
);
365 *dst
++ = C168(R16(src
)); src
+= 2;
369 static void cvtSS168K(const unsigned char* src
, int ns
, unsigned char* dst
)
371 TRACE("(%p, %d, %p)\n", src
, ns
, dst
);
374 *dst
++ = C168(R16(src
)); src
+= 2;
375 *dst
++ = C168(R16(src
)); src
+= 2;
380 typedef void (*PCM_CONVERT_KEEP_RATE
)(const unsigned char*, int, unsigned char*);
382 static const PCM_CONVERT_KEEP_RATE PCM_ConvertKeepRate
[16] = {
383 cvtSS88K
, cvtSM88K
, cvtMS88K
, cvtMM88K
,
384 cvtSS816K
, cvtSM816K
, cvtMS816K
, cvtMM816K
,
385 cvtSS168K
, cvtSM168K
, cvtMS168K
, cvtMM168K
,
386 cvtSS1616K
, cvtSM1616K
, cvtMS1616K
, cvtMM1616K
,
389 /* the conversion routines with rate conversion are labelled cvt<X><Y><N><M>C
391 * <X> is the (M)ono/(S)tereo configuration of input channel
392 * <Y> is the (M)ono/(S)tereo configuration of output channel
393 * <N> is the number of bits of input channel (8 or 16)
394 * <M> is the number of bits of output channel (8 or 16)
397 static void cvtSS88C(DWORD srcRate
, const unsigned char* src
, LPDWORD nsrc
,
398 DWORD dstRate
, unsigned char* dst
, LPDWORD ndst
)
400 DWORD error
= dstRate
/ 2;
401 TRACE("(%d, %p, %p, %d, %p, %p)\n", srcRate
, src
, nsrc
, dstRate
, dst
, ndst
);
406 error
= error
+ srcRate
;
407 while (error
> dstRate
) {
412 error
= error
- dstRate
;
417 static void cvtSM88C(DWORD srcRate
, const unsigned char* src
, LPDWORD nsrc
,
418 DWORD dstRate
, unsigned char* dst
, LPDWORD ndst
)
420 DWORD error
= dstRate
/ 2;
421 TRACE("(%d, %p, %p, %d, %p, %p)\n", srcRate
, src
, nsrc
, dstRate
, dst
, ndst
);
424 *dst
++ = M8(src
[0], src
[1]);
425 error
= error
+ srcRate
;
426 while (error
> dstRate
) {
431 error
= error
- dstRate
;
436 static void cvtMS88C(DWORD srcRate
, const unsigned char* src
, LPDWORD nsrc
,
437 DWORD dstRate
, unsigned char* dst
, LPDWORD ndst
)
439 DWORD error
= dstRate
/ 2;
440 TRACE("(%d, %p, %p, %d, %p, %p)\n", srcRate
, src
, nsrc
, dstRate
, dst
, ndst
);
445 error
= error
+ srcRate
;
446 while (error
> dstRate
) {
451 error
= error
- dstRate
;
456 static void cvtMM88C(DWORD srcRate
, const unsigned char* src
, LPDWORD nsrc
,
457 DWORD dstRate
, unsigned char* dst
, LPDWORD ndst
)
459 DWORD error
= dstRate
/ 2;
460 TRACE("(%d, %p, %p, %d, %p, %p)\n", srcRate
, src
, nsrc
, dstRate
, dst
, ndst
);
464 error
= error
+ srcRate
;
465 while (error
> dstRate
) {
470 error
= error
- dstRate
;
475 static void cvtSS816C(DWORD srcRate
, const unsigned char* src
, LPDWORD nsrc
,
476 DWORD dstRate
, unsigned char* dst
, LPDWORD ndst
)
478 DWORD error
= dstRate
/ 2;
479 TRACE("(%d, %p, %p, %d, %p, %p)\n", srcRate
, src
, nsrc
, dstRate
, dst
, ndst
);
482 W16(dst
, C816(src
[0])); dst
+= 2;
483 W16(dst
, C816(src
[1])); dst
+= 2;
484 error
= error
+ srcRate
;
485 while (error
> dstRate
) {
490 error
= error
- dstRate
;
495 static void cvtSM816C(DWORD srcRate
, const unsigned char* src
, LPDWORD nsrc
,
496 DWORD dstRate
, unsigned char* dst
, LPDWORD ndst
)
498 DWORD error
= dstRate
/ 2;
499 TRACE("(%d, %p, %p, %d, %p, %p)\n", srcRate
, src
, nsrc
, dstRate
, dst
, ndst
);
502 W16(dst
, M16(C816(src
[0]), C816(src
[1]))); dst
+= 2;
503 error
= error
+ srcRate
;
504 while (error
> dstRate
) {
509 error
= error
- dstRate
;
514 static void cvtMS816C(DWORD srcRate
, const unsigned char* src
, LPDWORD nsrc
,
515 DWORD dstRate
, unsigned char* dst
, LPDWORD ndst
)
517 DWORD error
= dstRate
/ 2;
518 TRACE("(%d, %p, %p, %d, %p, %p)\n", srcRate
, src
, nsrc
, dstRate
, dst
, ndst
);
521 W16(dst
, C816(*src
)); dst
+= 2;
522 W16(dst
, C816(*src
)); dst
+= 2;
523 error
= error
+ srcRate
;
524 while (error
> dstRate
) {
529 error
= error
- dstRate
;
534 static void cvtMM816C(DWORD srcRate
, const unsigned char* src
, LPDWORD nsrc
,
535 DWORD dstRate
, unsigned char* dst
, LPDWORD ndst
)
537 DWORD error
= dstRate
/ 2;
538 TRACE("(%d, %p, %p, %d, %p, %p)\n", srcRate
, src
, nsrc
, dstRate
, dst
, ndst
);
541 W16(dst
, C816(*src
)); dst
+= 2;
542 error
= error
+ srcRate
;
543 while (error
> dstRate
) {
548 error
= error
- dstRate
;
553 static void cvtSS168C(DWORD srcRate
, const unsigned char* src
, LPDWORD nsrc
,
554 DWORD dstRate
, unsigned char* dst
, LPDWORD ndst
)
556 DWORD error
= dstRate
/ 2;
557 TRACE("(%d, %p, %p, %d, %p, %p)\n", srcRate
, src
, nsrc
, dstRate
, dst
, ndst
);
560 *dst
++ = C168(R16(src
));
561 *dst
++ = C168(R16(src
+ 2));
562 error
= error
+ srcRate
;
563 while (error
> dstRate
) {
568 error
= error
- dstRate
;
573 static void cvtSM168C(DWORD srcRate
, const unsigned char* src
, LPDWORD nsrc
,
574 DWORD dstRate
, unsigned char* dst
, LPDWORD ndst
)
576 DWORD error
= dstRate
/ 2;
577 TRACE("(%d, %p, %p, %d, %p, %p)\n", srcRate
, src
, nsrc
, dstRate
, dst
, ndst
);
580 *dst
++ = C168(M16(R16(src
), R16(src
+ 2)));
581 error
= error
+ srcRate
;
582 while (error
> dstRate
) {
587 error
= error
- dstRate
;
592 static void cvtMS168C(DWORD srcRate
, const unsigned char* src
, LPDWORD nsrc
,
593 DWORD dstRate
, unsigned char* dst
, LPDWORD ndst
)
595 DWORD error
= dstRate
/ 2;
596 TRACE("(%d, %p, %p, %d, %p, %p)\n", srcRate
, src
, nsrc
, dstRate
, dst
, ndst
);
599 *dst
++ = C168(R16(src
));
600 *dst
++ = C168(R16(src
));
601 error
= error
+ srcRate
;
602 while (error
> dstRate
) {
607 error
= error
- dstRate
;
612 static void cvtMM168C(DWORD srcRate
, const unsigned char* src
, LPDWORD nsrc
,
613 DWORD dstRate
, unsigned char* dst
, LPDWORD ndst
)
615 DWORD error
= dstRate
/ 2;
616 TRACE("(%d, %p, %p, %d, %p, %p)\n", srcRate
, src
, nsrc
, dstRate
, dst
, ndst
);
619 *dst
++ = C168(R16(src
));
620 error
= error
+ srcRate
;
621 while (error
> dstRate
) {
626 error
= error
- dstRate
;
631 static void cvtSS1616C(DWORD srcRate
, const unsigned char* src
, LPDWORD nsrc
,
632 DWORD dstRate
, unsigned char* dst
, LPDWORD ndst
)
634 DWORD error
= dstRate
/ 2;
635 TRACE("(%d, %p, %p, %d, %p, %p)\n", srcRate
, src
, nsrc
, dstRate
, dst
, ndst
);
638 W16(dst
, R16(src
)); dst
+= 2;
639 W16(dst
, R16(src
)); dst
+= 2;
640 error
= error
+ srcRate
;
641 while (error
> dstRate
) {
646 error
= error
- dstRate
;
651 static void cvtSM1616C(DWORD srcRate
, const unsigned char* src
, LPDWORD nsrc
,
652 DWORD dstRate
, unsigned char* dst
, LPDWORD ndst
)
654 DWORD error
= dstRate
/ 2;
655 TRACE("(%d, %p, %p, %d, %p, %p)\n", srcRate
, src
, nsrc
, dstRate
, dst
, ndst
);
658 W16(dst
, M16(R16(src
), R16(src
+ 2))); dst
+= 2;
659 error
= error
+ srcRate
;
660 while (error
> dstRate
) {
665 error
= error
- dstRate
;
670 static void cvtMS1616C(DWORD srcRate
, const unsigned char* src
, LPDWORD nsrc
,
671 DWORD dstRate
, unsigned char* dst
, LPDWORD ndst
)
673 DWORD error
= dstRate
/ 2;
674 TRACE("(%d, %p, %p, %d, %p, %p)\n", srcRate
, src
, nsrc
, dstRate
, dst
, ndst
);
677 W16(dst
, R16(src
)); dst
+= 2;
678 W16(dst
, R16(src
)); dst
+= 2;
679 error
= error
+ srcRate
;
680 while (error
> dstRate
) {
685 error
= error
- dstRate
;
690 static void cvtMM1616C(DWORD srcRate
, const unsigned char* src
, LPDWORD nsrc
,
691 DWORD dstRate
, unsigned char* dst
, LPDWORD ndst
)
693 DWORD error
= dstRate
/ 2;
694 TRACE("(%d, %p, %p, %d, %p, %p)\n", srcRate
, src
, nsrc
, dstRate
, dst
, ndst
);
697 W16(dst
, R16(src
)); dst
+= 2;
698 error
= error
+ srcRate
;
699 while (error
> dstRate
) {
704 error
= error
- dstRate
;
709 typedef void (*PCM_CONVERT_CHANGE_RATE
)(DWORD
, const unsigned char*, LPDWORD
, DWORD
, unsigned char*, LPDWORD
);
711 static const PCM_CONVERT_CHANGE_RATE PCM_ConvertChangeRate
[16] = {
712 cvtSS88C
, cvtSM88C
, cvtMS88C
, cvtMM88C
,
713 cvtSS816C
, cvtSM816C
, cvtMS816C
, cvtMM816C
,
714 cvtSS168C
, cvtSM168C
, cvtMS168C
, cvtMM168C
,
715 cvtSS1616C
, cvtSM1616C
, cvtMS1616C
, cvtMM1616C
,
718 /***********************************************************************
722 static LRESULT
PCM_DriverDetails(PACMDRIVERDETAILSW add
)
724 TRACE("(%p)\n", add
);
726 add
->fccType
= ACMDRIVERDETAILS_FCCTYPE_AUDIOCODEC
;
727 add
->fccComp
= ACMDRIVERDETAILS_FCCCOMP_UNDEFINED
;
730 add
->vdwACM
= 0x01000000;
731 add
->vdwDriver
= 0x01000000;
732 add
->fdwSupport
= ACMDRIVERDETAILS_SUPPORTF_CONVERTER
;
733 add
->cFormatTags
= 1;
734 add
->cFilterTags
= 0;
736 MultiByteToWideChar( CP_ACP
, 0, "WINE-PCM", -1,
737 add
->szShortName
, sizeof(add
->szShortName
)/sizeof(WCHAR
) );
738 MultiByteToWideChar( CP_ACP
, 0, "Wine PCM converter", -1,
739 add
->szLongName
, sizeof(add
->szLongName
)/sizeof(WCHAR
) );
740 MultiByteToWideChar( CP_ACP
, 0, "Brought to you by the Wine team...", -1,
741 add
->szCopyright
, sizeof(add
->szCopyright
)/sizeof(WCHAR
) );
742 MultiByteToWideChar( CP_ACP
, 0, "Refer to LICENSE file", -1,
743 add
->szLicensing
, sizeof(add
->szLicensing
)/sizeof(WCHAR
) );
744 add
->szFeatures
[0] = 0;
746 return MMSYSERR_NOERROR
;
749 /***********************************************************************
750 * PCM_FormatTagDetails
753 static LRESULT
PCM_FormatTagDetails(PACMFORMATTAGDETAILSW aftd
, DWORD dwQuery
)
755 TRACE("(%p, %08x)\n", aftd
, dwQuery
);
758 case ACM_FORMATTAGDETAILSF_INDEX
:
759 if (aftd
->dwFormatTagIndex
!= 0) {
760 WARN("not possible\n");
761 return ACMERR_NOTPOSSIBLE
;
764 case ACM_FORMATTAGDETAILSF_FORMATTAG
:
765 if (aftd
->dwFormatTag
!= WAVE_FORMAT_PCM
) {
766 WARN("not possible\n");
767 return ACMERR_NOTPOSSIBLE
;
770 case ACM_FORMATTAGDETAILSF_LARGESTSIZE
:
771 if (aftd
->dwFormatTag
!= WAVE_FORMAT_UNKNOWN
&&
772 aftd
->dwFormatTag
!= WAVE_FORMAT_PCM
) {
773 WARN("not possible\n");
774 return ACMERR_NOTPOSSIBLE
;
778 WARN("Unsupported query %08x\n", dwQuery
);
779 return MMSYSERR_NOTSUPPORTED
;
782 aftd
->dwFormatTagIndex
= 0;
783 aftd
->dwFormatTag
= WAVE_FORMAT_PCM
;
784 aftd
->cbFormatSize
= sizeof(PCMWAVEFORMAT
);
785 aftd
->fdwSupport
= ACMDRIVERDETAILS_SUPPORTF_CONVERTER
;
786 aftd
->cStandardFormats
= NUM_PCM_FORMATS
;
787 aftd
->szFormatTag
[0] = 0;
789 return MMSYSERR_NOERROR
;
792 /***********************************************************************
796 static LRESULT
PCM_FormatDetails(PACMFORMATDETAILSW afd
, DWORD dwQuery
)
798 TRACE("(%p, %08x)\n", afd
, dwQuery
);
801 case ACM_FORMATDETAILSF_FORMAT
:
802 if (PCM_GetFormatIndex(afd
->pwfx
) == 0xFFFFFFFF) {
803 WARN("not possible\n");
804 return ACMERR_NOTPOSSIBLE
;
807 case ACM_FORMATDETAILSF_INDEX
:
808 assert(afd
->dwFormatIndex
< NUM_PCM_FORMATS
);
809 afd
->pwfx
->wFormatTag
= WAVE_FORMAT_PCM
;
810 afd
->pwfx
->nChannels
= PCM_Formats
[afd
->dwFormatIndex
].nChannels
;
811 afd
->pwfx
->nSamplesPerSec
= PCM_Formats
[afd
->dwFormatIndex
].rate
;
812 afd
->pwfx
->wBitsPerSample
= PCM_Formats
[afd
->dwFormatIndex
].nBits
;
813 /* native MSACM uses a PCMWAVEFORMAT structure, so cbSize is not
814 * accessible afd->pwfx->cbSize = 0;
816 afd
->pwfx
->nBlockAlign
=
817 (afd
->pwfx
->nChannels
* afd
->pwfx
->wBitsPerSample
) / 8;
818 afd
->pwfx
->nAvgBytesPerSec
=
819 afd
->pwfx
->nSamplesPerSec
* afd
->pwfx
->nBlockAlign
;
822 WARN("Unsupported query %08x\n", dwQuery
);
823 return MMSYSERR_NOTSUPPORTED
;
826 afd
->dwFormatTag
= WAVE_FORMAT_PCM
;
827 afd
->fdwSupport
= ACMDRIVERDETAILS_SUPPORTF_CONVERTER
;
828 afd
->szFormat
[0] = 0; /* let MSACM format this for us... */
829 afd
->cbwfx
= sizeof(PCMWAVEFORMAT
);
831 return MMSYSERR_NOERROR
;
834 /***********************************************************************
838 static LRESULT
PCM_FormatSuggest(PACMDRVFORMATSUGGEST adfs
)
840 TRACE("(%p)\n", adfs
);
843 if (adfs
->cbwfxSrc
< sizeof(PCMWAVEFORMAT
) ||
844 adfs
->cbwfxDst
< sizeof(PCMWAVEFORMAT
) ||
845 PCM_GetFormatIndex(adfs
->pwfxSrc
) == 0xFFFFFFFF) {
846 WARN("not possible\n");
847 return ACMERR_NOTPOSSIBLE
;
850 /* is no suggestion for destination, then copy source value */
851 if (!(adfs
->fdwSuggest
& ACM_FORMATSUGGESTF_NCHANNELS
)) {
852 adfs
->pwfxDst
->nChannels
= adfs
->pwfxSrc
->nChannels
;
854 if (!(adfs
->fdwSuggest
& ACM_FORMATSUGGESTF_NSAMPLESPERSEC
)) {
855 adfs
->pwfxDst
->nSamplesPerSec
= adfs
->pwfxSrc
->nSamplesPerSec
;
857 if (!(adfs
->fdwSuggest
& ACM_FORMATSUGGESTF_WBITSPERSAMPLE
)) {
858 adfs
->pwfxDst
->wBitsPerSample
= adfs
->pwfxSrc
->wBitsPerSample
;
860 if (!(adfs
->fdwSuggest
& ACM_FORMATSUGGESTF_WFORMATTAG
)) {
861 if (adfs
->pwfxSrc
->wFormatTag
!= WAVE_FORMAT_PCM
) {
862 WARN("not possible\n");
863 return ACMERR_NOTPOSSIBLE
;
865 adfs
->pwfxDst
->wFormatTag
= adfs
->pwfxSrc
->wFormatTag
;
867 /* check if result is ok */
868 if (PCM_GetFormatIndex(adfs
->pwfxDst
) == 0xFFFFFFFF) {
869 WARN("not possible\n");
870 return ACMERR_NOTPOSSIBLE
;
873 /* recompute other values */
874 adfs
->pwfxDst
->nBlockAlign
= (adfs
->pwfxDst
->nChannels
* adfs
->pwfxDst
->wBitsPerSample
) / 8;
875 adfs
->pwfxDst
->nAvgBytesPerSec
= adfs
->pwfxDst
->nSamplesPerSec
* adfs
->pwfxDst
->nBlockAlign
;
877 return MMSYSERR_NOERROR
;
880 /***********************************************************************
884 static LRESULT
PCM_StreamOpen(PACMDRVSTREAMINSTANCE adsi
)
889 TRACE("(%p)\n", adsi
);
891 assert(!(adsi
->fdwOpen
& ACM_STREAMOPENF_ASYNC
));
893 apd
= HeapAlloc(GetProcessHeap(), 0, sizeof(AcmPcmData
));
896 return MMSYSERR_NOMEM
;
899 adsi
->dwDriver
= (DWORD_PTR
)apd
;
902 if (adsi
->pwfxSrc
->wBitsPerSample
== 16) idx
+= 8;
903 if (adsi
->pwfxDst
->wBitsPerSample
== 16) idx
+= 4;
904 if (adsi
->pwfxSrc
->nChannels
== 1) idx
+= 2;
905 if (adsi
->pwfxDst
->nChannels
== 1) idx
+= 1;
907 if (adsi
->pwfxSrc
->nSamplesPerSec
== adsi
->pwfxDst
->nSamplesPerSec
) {
908 apd
->cvt
.cvtKeepRate
= PCM_ConvertKeepRate
[idx
];
910 adsi
->fdwDriver
|= PCM_RESAMPLE
;
911 apd
->cvt
.cvtChangeRate
= PCM_ConvertChangeRate
[idx
];
914 return MMSYSERR_NOERROR
;
917 /***********************************************************************
921 static LRESULT
PCM_StreamClose(PACMDRVSTREAMINSTANCE adsi
)
923 TRACE("(%p)\n", adsi
);
925 HeapFree(GetProcessHeap(), 0, (void*)adsi
->dwDriver
);
926 return MMSYSERR_NOERROR
;
929 /***********************************************************************
933 static inline DWORD
PCM_round(DWORD a
, DWORD b
, DWORD c
)
936 /* to be sure, always return an entire number of c... */
937 return ((double)a
* (double)b
+ (double)c
- 1) / (double)c
;
940 /***********************************************************************
944 static LRESULT
PCM_StreamSize(PACMDRVSTREAMINSTANCE adsi
, PACMDRVSTREAMSIZE adss
)
946 DWORD srcMask
= ~(adsi
->pwfxSrc
->nBlockAlign
- 1);
947 DWORD dstMask
= ~(adsi
->pwfxDst
->nBlockAlign
- 1);
949 TRACE("(%p, %p)\n", adsi
, adss
);
951 switch (adss
->fdwSize
) {
952 case ACM_STREAMSIZEF_DESTINATION
:
953 /* cbDstLength => cbSrcLength */
954 adss
->cbSrcLength
= PCM_round(adss
->cbDstLength
& dstMask
,
955 adsi
->pwfxSrc
->nAvgBytesPerSec
,
956 adsi
->pwfxDst
->nAvgBytesPerSec
) & srcMask
;
958 case ACM_STREAMSIZEF_SOURCE
:
959 /* cbSrcLength => cbDstLength */
960 adss
->cbDstLength
= PCM_round(adss
->cbSrcLength
& srcMask
,
961 adsi
->pwfxDst
->nAvgBytesPerSec
,
962 adsi
->pwfxSrc
->nAvgBytesPerSec
) & dstMask
;
965 WARN("Unsupported query %08x\n", adss
->fdwSize
);
966 return MMSYSERR_NOTSUPPORTED
;
968 return MMSYSERR_NOERROR
;
971 /***********************************************************************
975 static LRESULT
PCM_StreamConvert(PACMDRVSTREAMINSTANCE adsi
, PACMDRVSTREAMHEADER adsh
)
977 AcmPcmData
* apd
= (AcmPcmData
*)adsi
->dwDriver
;
978 DWORD nsrc
= NUM_OF(adsh
->cbSrcLength
, adsi
->pwfxSrc
->nBlockAlign
);
979 DWORD ndst
= NUM_OF(adsh
->cbDstLength
, adsi
->pwfxDst
->nBlockAlign
);
981 TRACE("(%p, %p)\n", adsi
, adsh
);
983 TRACE("nsrc=%d,adsh->cbSrcLength=%d\n", nsrc
, adsh
->cbSrcLength
);
984 TRACE("ndst=%d,adsh->cbDstLength=%d\n", ndst
, adsh
->cbDstLength
);
985 TRACE("src [wFormatTag=%u, nChannels=%u, nSamplesPerSec=%u, nAvgBytesPerSec=%u, nBlockAlign=%u, wBitsPerSample=%u, cbSize=%u]\n",
986 adsi
->pwfxSrc
->wFormatTag
, adsi
->pwfxSrc
->nChannels
, adsi
->pwfxSrc
->nSamplesPerSec
, adsi
->pwfxSrc
->nAvgBytesPerSec
,
987 adsi
->pwfxSrc
->nBlockAlign
, adsi
->pwfxSrc
->wBitsPerSample
, adsi
->pwfxSrc
->cbSize
);
988 TRACE("dst [wFormatTag=%u, nChannels=%u, nSamplesPerSec=%u, nAvgBytesPerSec=%u, nBlockAlign=%u, wBitsPerSample=%u, cbSize=%u]\n",
989 adsi
->pwfxDst
->wFormatTag
, adsi
->pwfxDst
->nChannels
, adsi
->pwfxDst
->nSamplesPerSec
, adsi
->pwfxDst
->nAvgBytesPerSec
,
990 adsi
->pwfxDst
->nBlockAlign
, adsi
->pwfxDst
->wBitsPerSample
, adsi
->pwfxDst
->cbSize
);
992 if (adsh
->fdwConvert
&
993 ~(ACM_STREAMCONVERTF_BLOCKALIGN
|
994 ACM_STREAMCONVERTF_END
|
995 ACM_STREAMCONVERTF_START
)) {
996 FIXME("Unsupported fdwConvert (%08x), ignoring it\n", adsh
->fdwConvert
);
998 /* ACM_STREAMCONVERTF_BLOCKALIGN
999 * currently all conversions are block aligned, so do nothing for this flag
1000 * ACM_STREAMCONVERTF_END
1001 * no pending data, so do nothing for this flag
1003 if ((adsh
->fdwConvert
& ACM_STREAMCONVERTF_START
) &&
1004 (adsi
->fdwDriver
& PCM_RESAMPLE
)) {
1008 if (adsi
->fdwDriver
& PCM_RESAMPLE
) {
1011 apd
->cvt
.cvtChangeRate(adsi
->pwfxSrc
->nSamplesPerSec
, adsh
->pbSrc
, &nsrc2
,
1012 adsi
->pwfxDst
->nSamplesPerSec
, adsh
->pbDst
, &ndst2
);
1016 if (nsrc
< ndst
) ndst
= nsrc
; else nsrc
= ndst
;
1018 /* nsrc is now equal to ndst */
1019 apd
->cvt
.cvtKeepRate(adsh
->pbSrc
, nsrc
, adsh
->pbDst
);
1022 adsh
->cbSrcLengthUsed
= nsrc
* adsi
->pwfxSrc
->nBlockAlign
;
1023 adsh
->cbDstLengthUsed
= ndst
* adsi
->pwfxDst
->nBlockAlign
;
1025 return MMSYSERR_NOERROR
;
1028 /**************************************************************************
1029 * DriverProc (MSACM32.@)
1031 LRESULT CALLBACK
PCM_DriverProc(DWORD_PTR dwDevID
, HDRVR hDriv
, UINT wMsg
,
1032 LPARAM dwParam1
, LPARAM dwParam2
)
1034 TRACE("(%08lx %p %u %08lx %08lx);\n",
1035 dwDevID
, hDriv
, wMsg
, dwParam1
, dwParam2
);
1038 case DRV_LOAD
: return 1;
1039 case DRV_FREE
: return 1;
1040 case DRV_OPEN
: return PCM_drvOpen((LPSTR
)dwParam1
, (PACMDRVOPENDESCW
)dwParam2
);
1041 case DRV_CLOSE
: return PCM_drvClose(dwDevID
);
1042 case DRV_ENABLE
: return 1;
1043 case DRV_DISABLE
: return 1;
1044 case DRV_QUERYCONFIGURE
: return 1;
1045 case DRV_CONFIGURE
: MessageBoxA(0, "MSACM PCM filter !", "Wine Driver", MB_OK
); return 1;
1046 case DRV_INSTALL
: return DRVCNF_RESTART
;
1047 case DRV_REMOVE
: return DRVCNF_RESTART
;
1049 case ACMDM_DRIVER_NOTIFY
:
1050 /* no caching from other ACM drivers is done so far */
1051 return MMSYSERR_NOERROR
;
1053 case ACMDM_DRIVER_DETAILS
:
1054 return PCM_DriverDetails((PACMDRIVERDETAILSW
)dwParam1
);
1056 case ACMDM_FORMATTAG_DETAILS
:
1057 return PCM_FormatTagDetails((PACMFORMATTAGDETAILSW
)dwParam1
, dwParam2
);
1059 case ACMDM_FORMAT_DETAILS
:
1060 return PCM_FormatDetails((PACMFORMATDETAILSW
)dwParam1
, dwParam2
);
1062 case ACMDM_FORMAT_SUGGEST
:
1063 return PCM_FormatSuggest((PACMDRVFORMATSUGGEST
)dwParam1
);
1065 case ACMDM_STREAM_OPEN
:
1066 return PCM_StreamOpen((PACMDRVSTREAMINSTANCE
)dwParam1
);
1068 case ACMDM_STREAM_CLOSE
:
1069 return PCM_StreamClose((PACMDRVSTREAMINSTANCE
)dwParam1
);
1071 case ACMDM_STREAM_SIZE
:
1072 return PCM_StreamSize((PACMDRVSTREAMINSTANCE
)dwParam1
, (PACMDRVSTREAMSIZE
)dwParam2
);
1074 case ACMDM_STREAM_CONVERT
:
1075 return PCM_StreamConvert((PACMDRVSTREAMINSTANCE
)dwParam1
, (PACMDRVSTREAMHEADER
)dwParam2
);
1077 case ACMDM_HARDWARE_WAVE_CAPS_INPUT
:
1078 case ACMDM_HARDWARE_WAVE_CAPS_OUTPUT
:
1079 /* this converter is not a hardware driver */
1080 case ACMDM_FILTERTAG_DETAILS
:
1081 case ACMDM_FILTER_DETAILS
:
1082 /* this converter is not a filter */
1083 case ACMDM_STREAM_RESET
:
1084 /* only needed for asynchronous driver... we aren't, so just say it */
1085 case ACMDM_STREAM_PREPARE
:
1086 case ACMDM_STREAM_UNPREPARE
:
1087 /* nothing special to do here... so don't do anything */
1088 return MMSYSERR_NOTSUPPORTED
;
1091 return DefDriverProc(dwDevID
, hDriv
, wMsg
, dwParam1
, dwParam2
);