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
48 #include "wine/debug.h"
50 WINE_DEFAULT_DEBUG_CHANNEL(msacm
);
52 /***********************************************************************
55 static DWORD
PCM_drvOpen(LPCSTR str
, PACMDRVOPENDESCW adod
)
57 TRACE("(%p, %p)\n", str
, adod
);
59 return (adod
== NULL
) ||
60 (adod
->fccType
== ACMDRIVERDETAILS_FCCTYPE_AUDIOCODEC
&&
61 adod
->fccComp
== ACMDRIVERDETAILS_FCCCOMP_UNDEFINED
);
64 /***********************************************************************
67 static DWORD
PCM_drvClose(DWORD dwDevID
)
69 TRACE("(%d)\n", dwDevID
);
74 #define NUM_PCM_FORMATS (sizeof(PCM_Formats) / sizeof(PCM_Formats[0]))
75 #define NUM_OF(a,b) ((a)/(b))
77 /* flags for fdwDriver */
78 #define PCM_RESAMPLE 1
80 /* data used while converting */
81 typedef struct tagAcmPcmData
{
82 /* conversion routine, depending if rate conversion is required */
84 void (*cvtKeepRate
)(const unsigned char*, int, unsigned char*);
85 void (*cvtChangeRate
)(DWORD
, const unsigned char*, LPDWORD
,
86 DWORD
, unsigned char*, LPDWORD
);
90 /* table to list all supported formats... those are the basic ones. this
91 * also helps given a unique index to each of the supported formats
98 {1, 8, 8000}, {2, 8, 8000}, {1, 16, 8000}, {2, 16, 8000},
99 {1, 8, 11025}, {2, 8, 11025}, {1, 16, 11025}, {2, 16, 11025},
100 {1, 8, 22050}, {2, 8, 22050}, {1, 16, 22050}, {2, 16, 22050},
101 {1, 8, 44100}, {2, 8, 44100}, {1, 16, 44100}, {2, 16, 44100},
102 {1, 8, 48000}, {2, 8, 48000}, {1, 16, 48000}, {2, 16, 48000},
103 {1, 8, 96000}, {2, 8, 96000}, {1, 16, 96000}, {2, 16, 96000}
106 /***********************************************************************
109 static DWORD
PCM_GetFormatIndex(LPWAVEFORMATEX wfx
)
112 TRACE("(%p)\n", wfx
);
114 for (i
= 0; i
< NUM_PCM_FORMATS
; i
++) {
115 if (wfx
->nChannels
== PCM_Formats
[i
].nChannels
&&
116 wfx
->nSamplesPerSec
== PCM_Formats
[i
].rate
&&
117 wfx
->wBitsPerSample
== PCM_Formats
[i
].nBits
)
126 * + 8 bit unsigned vs 16 bit signed
127 * + mono vs stereo (1 or 2 channels)
128 * + sampling rate (8.0, 11.025, 22.05, 44.1 kHz are defined, but algo
129 * shall work in all cases)
131 * mono => stereo: copy the same sample on Left & Right channels
132 * stereo => mono: use the sum of Left & Right channels
135 /***********************************************************************
138 * Converts a 8 bit sample to a 16 bit one
140 static inline short C816(unsigned char b
)
142 return (b
- 128) << 8;
145 /***********************************************************************
148 * Converts a 16 bit sample to a 8 bit one (data loss !!)
150 static inline unsigned char C168(short s
)
152 return HIBYTE(s
) ^ (unsigned char)0x80;
155 /***********************************************************************
158 * Read a 16 bit sample (correctly handles endianess)
160 static inline short R16(const unsigned char* src
)
162 return (short)((unsigned short)src
[0] | ((unsigned short)src
[1] << 8));
165 /***********************************************************************
168 * Write a 16 bit sample (correctly handles endianess)
170 static inline void W16(unsigned char* dst
, short s
)
176 /***********************************************************************
179 * Convert the (l,r) 16 bit stereo sample into a 16 bit mono
180 * (takes the sum of the two values)
182 static inline short M16(short l
, short r
)
186 /* clip sum to saturation */
189 else if (sum
< -32768)
195 /***********************************************************************
198 * Convert the (l,r) 8 bit stereo sample into a 8 bit mono
199 * (takes the sum of the two values)
201 static inline unsigned char M8(unsigned char a
, unsigned char b
)
205 int sum
= (l
+ r
) + 128;
207 /* clip sum to saturation */
216 /* the conversion routines without rate conversion are labelled cvt<X><Y><N><M>K
218 * <X> is the (M)ono/(S)tereo configuration of input channel
219 * <Y> is the (M)ono/(S)tereo configuration of output channel
220 * <N> is the number of bits of input channel (8 or 16)
221 * <M> is the number of bits of output channel (8 or 16)
223 * in the parameters, ns is always the number of samples, so the size of input
224 * buffer (resp output buffer) is ns * (<X> == 'Mono' ? 1:2) * (<N> == 8 ? 1:2)
227 static void cvtMM88K(const unsigned char* src
, int ns
, unsigned char* dst
)
229 TRACE("(%p, %d, %p)\n", src
, ns
, dst
);
230 memcpy(dst
, src
, ns
);
233 static void cvtSS88K(const unsigned char* src
, int ns
, unsigned char* dst
)
235 TRACE("(%p, %d, %p)\n", src
, ns
, dst
);
236 memcpy(dst
, src
, ns
* 2);
239 static void cvtMM1616K(const unsigned char* src
, int ns
, unsigned char* dst
)
241 TRACE("(%p, %d, %p)\n", src
, ns
, dst
);
242 memcpy(dst
, src
, ns
* 2);
245 static void cvtSS1616K(const unsigned char* src
, int ns
, unsigned char* dst
)
247 TRACE("(%p, %d, %p)\n", src
, ns
, dst
);
248 memcpy(dst
, src
, ns
* 4);
251 static void cvtMS88K(const unsigned char* src
, int ns
, unsigned char* dst
)
253 TRACE("(%p, %d, %p)\n", src
, ns
, dst
);
261 static void cvtMS816K(const unsigned char* src
, int ns
, unsigned char* dst
)
264 TRACE("(%p, %d, %p)\n", src
, ns
, dst
);
268 W16(dst
, v
); dst
+= 2;
269 W16(dst
, v
); dst
+= 2;
273 static void cvtMS168K(const unsigned char* src
, int ns
, unsigned char* dst
)
276 TRACE("(%p, %d, %p)\n", src
, ns
, dst
);
279 v
= C168(R16(src
)); src
+= 2;
285 static void cvtMS1616K(const unsigned char* src
, int ns
, unsigned char* dst
)
288 TRACE("(%p, %d, %p)\n", src
, ns
, dst
);
291 v
= R16(src
); src
+= 2;
292 W16(dst
, v
); dst
+= 2;
293 W16(dst
, v
); dst
+= 2;
297 static void cvtSM88K(const unsigned char* src
, int ns
, unsigned char* dst
)
299 TRACE("(%p, %d, %p)\n", src
, ns
, dst
);
302 *dst
++ = M8(src
[0], src
[1]);
307 static void cvtSM816K(const unsigned char* src
, int ns
, unsigned char* dst
)
310 TRACE("(%p, %d, %p)\n", src
, ns
, dst
);
313 v
= M16(C816(src
[0]), C816(src
[1]));
315 W16(dst
, v
); dst
+= 2;
319 static void cvtSM168K(const unsigned char* src
, int ns
, unsigned char* dst
)
321 TRACE("(%p, %d, %p)\n", src
, ns
, dst
);
324 *dst
++ = C168(M16(R16(src
), R16(src
+ 2)));
329 static void cvtSM1616K(const unsigned char* src
, int ns
, unsigned char* dst
)
331 TRACE("(%p, %d, %p)\n", src
, ns
, dst
);
334 W16(dst
, M16(R16(src
),R16(src
+2))); dst
+= 2;
339 static void cvtMM816K(const unsigned char* src
, int ns
, unsigned char* dst
)
341 TRACE("(%p, %d, %p)\n", src
, ns
, dst
);
344 W16(dst
, C816(*src
++)); dst
+= 2;
348 static void cvtSS816K(const unsigned char* src
, int ns
, unsigned char* dst
)
350 TRACE("(%p, %d, %p)\n", src
, ns
, dst
);
353 W16(dst
, C816(*src
++)); dst
+= 2;
354 W16(dst
, C816(*src
++)); dst
+= 2;
358 static void cvtMM168K(const unsigned char* src
, int ns
, unsigned char* dst
)
360 TRACE("(%p, %d, %p)\n", src
, ns
, dst
);
363 *dst
++ = C168(R16(src
)); src
+= 2;
367 static void cvtSS168K(const unsigned char* src
, int ns
, unsigned char* dst
)
369 TRACE("(%p, %d, %p)\n", src
, ns
, dst
);
372 *dst
++ = C168(R16(src
)); src
+= 2;
373 *dst
++ = C168(R16(src
)); src
+= 2;
378 typedef void (*PCM_CONVERT_KEEP_RATE
)(const unsigned char*, int, unsigned char*);
380 static const PCM_CONVERT_KEEP_RATE PCM_ConvertKeepRate
[16] = {
381 cvtSS88K
, cvtSM88K
, cvtMS88K
, cvtMM88K
,
382 cvtSS816K
, cvtSM816K
, cvtMS816K
, cvtMM816K
,
383 cvtSS168K
, cvtSM168K
, cvtMS168K
, cvtMM168K
,
384 cvtSS1616K
, cvtSM1616K
, cvtMS1616K
, cvtMM1616K
,
387 /* the conversion routines with rate conversion are labelled cvt<X><Y><N><M>C
389 * <X> is the (M)ono/(S)tereo configuration of input channel
390 * <Y> is the (M)ono/(S)tereo configuration of output channel
391 * <N> is the number of bits of input channel (8 or 16)
392 * <M> is the number of bits of output channel (8 or 16)
395 static void cvtSS88C(DWORD srcRate
, const unsigned char* src
, LPDWORD nsrc
,
396 DWORD dstRate
, unsigned char* dst
, LPDWORD ndst
)
398 DWORD error
= dstRate
/ 2;
399 TRACE("(%d, %p, %p, %d, %p, %p)\n", srcRate
, src
, nsrc
, dstRate
, dst
, ndst
);
404 error
= error
+ srcRate
;
405 while (error
> dstRate
) {
410 error
= error
- dstRate
;
415 static void cvtSM88C(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
);
422 *dst
++ = M8(src
[0], src
[1]);
423 error
= error
+ srcRate
;
424 while (error
> dstRate
) {
429 error
= error
- dstRate
;
434 static void cvtMS88C(DWORD srcRate
, const unsigned char* src
, LPDWORD nsrc
,
435 DWORD dstRate
, unsigned char* dst
, LPDWORD ndst
)
437 DWORD error
= dstRate
/ 2;
438 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 cvtMM88C(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
);
462 error
= error
+ srcRate
;
463 while (error
> dstRate
) {
468 error
= error
- dstRate
;
473 static void cvtSS816C(DWORD srcRate
, const unsigned char* src
, LPDWORD nsrc
,
474 DWORD dstRate
, unsigned char* dst
, LPDWORD ndst
)
476 DWORD error
= dstRate
/ 2;
477 TRACE("(%d, %p, %p, %d, %p, %p)\n", srcRate
, src
, nsrc
, dstRate
, dst
, ndst
);
480 W16(dst
, C816(src
[0])); dst
+= 2;
481 W16(dst
, C816(src
[1])); dst
+= 2;
482 error
= error
+ srcRate
;
483 while (error
> dstRate
) {
488 error
= error
- dstRate
;
493 static void cvtSM816C(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
, M16(C816(src
[0]), C816(src
[1]))); dst
+= 2;
501 error
= error
+ srcRate
;
502 while (error
> dstRate
) {
507 error
= error
- dstRate
;
512 static void cvtMS816C(DWORD srcRate
, const unsigned char* src
, LPDWORD nsrc
,
513 DWORD dstRate
, unsigned char* dst
, LPDWORD ndst
)
515 DWORD error
= dstRate
/ 2;
516 TRACE("(%d, %p, %p, %d, %p, %p)\n", srcRate
, src
, nsrc
, dstRate
, dst
, ndst
);
519 W16(dst
, C816(*src
)); dst
+= 2;
520 W16(dst
, C816(*src
)); dst
+= 2;
521 error
= error
+ srcRate
;
522 while (error
> dstRate
) {
527 error
= error
- dstRate
;
532 static void cvtMM816C(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 W16(dst
, C816(*src
)); dst
+= 2;
540 error
= error
+ srcRate
;
541 while (error
> dstRate
) {
546 error
= error
- dstRate
;
551 static void cvtSS168C(DWORD srcRate
, const unsigned char* src
, LPDWORD nsrc
,
552 DWORD dstRate
, unsigned char* dst
, LPDWORD ndst
)
554 DWORD error
= dstRate
/ 2;
555 TRACE("(%d, %p, %p, %d, %p, %p)\n", srcRate
, src
, nsrc
, dstRate
, dst
, ndst
);
558 *dst
++ = C168(R16(src
));
559 *dst
++ = C168(R16(src
+ 2));
560 error
= error
+ srcRate
;
561 while (error
> dstRate
) {
566 error
= error
- dstRate
;
571 static void cvtSM168C(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(M16(R16(src
), R16(src
+ 2)));
579 error
= error
+ srcRate
;
580 while (error
> dstRate
) {
585 error
= error
- dstRate
;
590 static void cvtMS168C(DWORD srcRate
, const unsigned char* src
, LPDWORD nsrc
,
591 DWORD dstRate
, unsigned char* dst
, LPDWORD ndst
)
593 DWORD error
= dstRate
/ 2;
594 TRACE("(%d, %p, %p, %d, %p, %p)\n", srcRate
, src
, nsrc
, dstRate
, dst
, ndst
);
597 *dst
++ = C168(R16(src
));
598 *dst
++ = C168(R16(src
));
599 error
= error
+ srcRate
;
600 while (error
> dstRate
) {
605 error
= error
- dstRate
;
610 static void cvtMM168C(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 *dst
++ = C168(R16(src
));
618 error
= error
+ srcRate
;
619 while (error
> dstRate
) {
624 error
= error
- dstRate
;
629 static void cvtSS1616C(DWORD srcRate
, const unsigned char* src
, LPDWORD nsrc
,
630 DWORD dstRate
, unsigned char* dst
, LPDWORD ndst
)
632 DWORD error
= dstRate
/ 2;
633 TRACE("(%d, %p, %p, %d, %p, %p)\n", srcRate
, src
, nsrc
, dstRate
, dst
, ndst
);
636 W16(dst
, R16(src
)); dst
+= 2;
637 W16(dst
, R16(src
)); dst
+= 2;
638 error
= error
+ srcRate
;
639 while (error
> dstRate
) {
644 error
= error
- dstRate
;
649 static void cvtSM1616C(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
, M16(R16(src
), R16(src
+ 2))); dst
+= 2;
657 error
= error
+ srcRate
;
658 while (error
> dstRate
) {
663 error
= error
- dstRate
;
668 static void cvtMS1616C(DWORD srcRate
, const unsigned char* src
, LPDWORD nsrc
,
669 DWORD dstRate
, unsigned char* dst
, LPDWORD ndst
)
671 DWORD error
= dstRate
/ 2;
672 TRACE("(%d, %p, %p, %d, %p, %p)\n", srcRate
, src
, nsrc
, dstRate
, dst
, ndst
);
675 W16(dst
, R16(src
)); dst
+= 2;
676 W16(dst
, R16(src
)); dst
+= 2;
677 error
= error
+ srcRate
;
678 while (error
> dstRate
) {
683 error
= error
- dstRate
;
688 static void cvtMM1616C(DWORD srcRate
, const unsigned char* src
, LPDWORD nsrc
,
689 DWORD dstRate
, unsigned char* dst
, LPDWORD ndst
)
691 DWORD error
= dstRate
/ 2;
692 TRACE("(%d, %p, %p, %d, %p, %p)\n", srcRate
, src
, nsrc
, dstRate
, dst
, ndst
);
695 W16(dst
, R16(src
)); dst
+= 2;
696 error
= error
+ srcRate
;
697 while (error
> dstRate
) {
702 error
= error
- dstRate
;
707 typedef void (*PCM_CONVERT_CHANGE_RATE
)(DWORD
, const unsigned char*, LPDWORD
, DWORD
, unsigned char*, LPDWORD
);
709 static const PCM_CONVERT_CHANGE_RATE PCM_ConvertChangeRate
[16] = {
710 cvtSS88C
, cvtSM88C
, cvtMS88C
, cvtMM88C
,
711 cvtSS816C
, cvtSM816C
, cvtMS816C
, cvtMM816C
,
712 cvtSS168C
, cvtSM168C
, cvtMS168C
, cvtMM168C
,
713 cvtSS1616C
, cvtSM1616C
, cvtMS1616C
, cvtMM1616C
,
716 /***********************************************************************
720 static LRESULT
PCM_DriverDetails(PACMDRIVERDETAILSW add
)
722 TRACE("(%p)\n", add
);
724 add
->fccType
= ACMDRIVERDETAILS_FCCTYPE_AUDIOCODEC
;
725 add
->fccComp
= ACMDRIVERDETAILS_FCCCOMP_UNDEFINED
;
728 add
->vdwACM
= 0x01000000;
729 add
->vdwDriver
= 0x01000000;
730 add
->fdwSupport
= ACMDRIVERDETAILS_SUPPORTF_CONVERTER
;
731 add
->cFormatTags
= 1;
732 add
->cFilterTags
= 0;
734 MultiByteToWideChar( CP_ACP
, 0, "WINE-PCM", -1,
735 add
->szShortName
, sizeof(add
->szShortName
)/sizeof(WCHAR
) );
736 MultiByteToWideChar( CP_ACP
, 0, "Wine PCM converter", -1,
737 add
->szLongName
, sizeof(add
->szLongName
)/sizeof(WCHAR
) );
738 MultiByteToWideChar( CP_ACP
, 0, "Brought to you by the Wine team...", -1,
739 add
->szCopyright
, sizeof(add
->szCopyright
)/sizeof(WCHAR
) );
740 MultiByteToWideChar( CP_ACP
, 0, "Refer to LICENSE file", -1,
741 add
->szLicensing
, sizeof(add
->szLicensing
)/sizeof(WCHAR
) );
742 add
->szFeatures
[0] = 0;
744 return MMSYSERR_NOERROR
;
747 /***********************************************************************
748 * PCM_FormatTagDetails
751 static LRESULT
PCM_FormatTagDetails(PACMFORMATTAGDETAILSW aftd
, DWORD dwQuery
)
753 TRACE("(%p, %08x)\n", aftd
, dwQuery
);
756 case ACM_FORMATTAGDETAILSF_INDEX
:
757 if (aftd
->dwFormatTagIndex
!= 0) {
758 WARN("not possible\n");
759 return ACMERR_NOTPOSSIBLE
;
762 case ACM_FORMATTAGDETAILSF_FORMATTAG
:
763 if (aftd
->dwFormatTag
!= WAVE_FORMAT_PCM
) {
764 WARN("not possible\n");
765 return ACMERR_NOTPOSSIBLE
;
768 case ACM_FORMATTAGDETAILSF_LARGESTSIZE
:
769 if (aftd
->dwFormatTag
!= WAVE_FORMAT_UNKNOWN
&&
770 aftd
->dwFormatTag
!= WAVE_FORMAT_PCM
) {
771 WARN("not possible\n");
772 return ACMERR_NOTPOSSIBLE
;
776 WARN("Unsupported query %08x\n", dwQuery
);
777 return MMSYSERR_NOTSUPPORTED
;
780 aftd
->dwFormatTagIndex
= 0;
781 aftd
->dwFormatTag
= WAVE_FORMAT_PCM
;
782 aftd
->cbFormatSize
= sizeof(PCMWAVEFORMAT
);
783 aftd
->fdwSupport
= ACMDRIVERDETAILS_SUPPORTF_CONVERTER
;
784 aftd
->cStandardFormats
= NUM_PCM_FORMATS
;
785 aftd
->szFormatTag
[0] = 0;
787 return MMSYSERR_NOERROR
;
790 /***********************************************************************
794 static LRESULT
PCM_FormatDetails(PACMFORMATDETAILSW afd
, DWORD dwQuery
)
796 TRACE("(%p, %08x)\n", afd
, dwQuery
);
799 case ACM_FORMATDETAILSF_FORMAT
:
800 if (PCM_GetFormatIndex(afd
->pwfx
) == 0xFFFFFFFF) {
801 WARN("not possible\n");
802 return ACMERR_NOTPOSSIBLE
;
805 case ACM_FORMATDETAILSF_INDEX
:
806 assert(afd
->dwFormatIndex
< NUM_PCM_FORMATS
);
807 afd
->pwfx
->wFormatTag
= WAVE_FORMAT_PCM
;
808 afd
->pwfx
->nChannels
= PCM_Formats
[afd
->dwFormatIndex
].nChannels
;
809 afd
->pwfx
->nSamplesPerSec
= PCM_Formats
[afd
->dwFormatIndex
].rate
;
810 afd
->pwfx
->wBitsPerSample
= PCM_Formats
[afd
->dwFormatIndex
].nBits
;
811 /* native MSACM uses a PCMWAVEFORMAT structure, so cbSize is not
812 * accessible afd->pwfx->cbSize = 0;
814 afd
->pwfx
->nBlockAlign
=
815 (afd
->pwfx
->nChannels
* afd
->pwfx
->wBitsPerSample
) / 8;
816 afd
->pwfx
->nAvgBytesPerSec
=
817 afd
->pwfx
->nSamplesPerSec
* afd
->pwfx
->nBlockAlign
;
820 WARN("Unsupported query %08x\n", dwQuery
);
821 return MMSYSERR_NOTSUPPORTED
;
824 afd
->dwFormatTag
= WAVE_FORMAT_PCM
;
825 afd
->fdwSupport
= ACMDRIVERDETAILS_SUPPORTF_CONVERTER
;
826 afd
->szFormat
[0] = 0; /* let MSACM format this for us... */
827 afd
->cbwfx
= sizeof(PCMWAVEFORMAT
);
829 return MMSYSERR_NOERROR
;
832 /***********************************************************************
836 static LRESULT
PCM_FormatSuggest(PACMDRVFORMATSUGGEST adfs
)
838 TRACE("(%p)\n", adfs
);
841 if (adfs
->cbwfxSrc
< sizeof(PCMWAVEFORMAT
) ||
842 adfs
->cbwfxDst
< sizeof(PCMWAVEFORMAT
) ||
843 PCM_GetFormatIndex(adfs
->pwfxSrc
) == 0xFFFFFFFF) {
844 WARN("not possible\n");
845 return ACMERR_NOTPOSSIBLE
;
848 /* is no suggestion for destination, then copy source value */
849 if (!(adfs
->fdwSuggest
& ACM_FORMATSUGGESTF_NCHANNELS
)) {
850 adfs
->pwfxDst
->nChannels
= adfs
->pwfxSrc
->nChannels
;
852 if (!(adfs
->fdwSuggest
& ACM_FORMATSUGGESTF_NSAMPLESPERSEC
)) {
853 adfs
->pwfxDst
->nSamplesPerSec
= adfs
->pwfxSrc
->nSamplesPerSec
;
855 if (!(adfs
->fdwSuggest
& ACM_FORMATSUGGESTF_WBITSPERSAMPLE
)) {
856 adfs
->pwfxDst
->wBitsPerSample
= adfs
->pwfxSrc
->wBitsPerSample
;
858 if (!(adfs
->fdwSuggest
& ACM_FORMATSUGGESTF_WFORMATTAG
)) {
859 if (adfs
->pwfxSrc
->wFormatTag
!= WAVE_FORMAT_PCM
) {
860 WARN("not possible\n");
861 return ACMERR_NOTPOSSIBLE
;
863 adfs
->pwfxDst
->wFormatTag
= adfs
->pwfxSrc
->wFormatTag
;
865 /* check if result is ok */
866 if (PCM_GetFormatIndex(adfs
->pwfxDst
) == 0xFFFFFFFF) {
867 WARN("not possible\n");
868 return ACMERR_NOTPOSSIBLE
;
871 /* recompute other values */
872 adfs
->pwfxDst
->nBlockAlign
= (adfs
->pwfxDst
->nChannels
* adfs
->pwfxDst
->wBitsPerSample
) / 8;
873 adfs
->pwfxDst
->nAvgBytesPerSec
= adfs
->pwfxDst
->nSamplesPerSec
* adfs
->pwfxDst
->nBlockAlign
;
875 return MMSYSERR_NOERROR
;
878 /***********************************************************************
882 static LRESULT
PCM_StreamOpen(PACMDRVSTREAMINSTANCE adsi
)
887 TRACE("(%p)\n", adsi
);
889 assert(!(adsi
->fdwOpen
& ACM_STREAMOPENF_ASYNC
));
891 apd
= HeapAlloc(GetProcessHeap(), 0, sizeof(AcmPcmData
));
894 return MMSYSERR_NOMEM
;
897 adsi
->dwDriver
= (DWORD
)apd
;
900 if (adsi
->pwfxSrc
->wBitsPerSample
== 16) idx
+= 8;
901 if (adsi
->pwfxDst
->wBitsPerSample
== 16) idx
+= 4;
902 if (adsi
->pwfxSrc
->nChannels
== 1) idx
+= 2;
903 if (adsi
->pwfxDst
->nChannels
== 1) idx
+= 1;
905 if (adsi
->pwfxSrc
->nSamplesPerSec
== adsi
->pwfxDst
->nSamplesPerSec
) {
906 apd
->cvt
.cvtKeepRate
= PCM_ConvertKeepRate
[idx
];
908 adsi
->fdwDriver
|= PCM_RESAMPLE
;
909 apd
->cvt
.cvtChangeRate
= PCM_ConvertChangeRate
[idx
];
912 return MMSYSERR_NOERROR
;
915 /***********************************************************************
919 static LRESULT
PCM_StreamClose(PACMDRVSTREAMINSTANCE adsi
)
921 TRACE("(%p)\n", adsi
);
923 HeapFree(GetProcessHeap(), 0, (void*)adsi
->dwDriver
);
924 return MMSYSERR_NOERROR
;
927 /***********************************************************************
931 static inline DWORD
PCM_round(DWORD a
, DWORD b
, DWORD c
)
934 /* to be sure, always return an entire number of c... */
935 return ((double)a
* (double)b
+ (double)c
- 1) / (double)c
;
938 /***********************************************************************
942 static LRESULT
PCM_StreamSize(PACMDRVSTREAMINSTANCE adsi
, PACMDRVSTREAMSIZE adss
)
944 DWORD srcMask
= ~(adsi
->pwfxSrc
->nBlockAlign
- 1);
945 DWORD dstMask
= ~(adsi
->pwfxDst
->nBlockAlign
- 1);
947 TRACE("(%p, %p)\n", adsi
, adss
);
949 switch (adss
->fdwSize
) {
950 case ACM_STREAMSIZEF_DESTINATION
:
951 /* cbDstLength => cbSrcLength */
952 adss
->cbSrcLength
= PCM_round(adss
->cbDstLength
& dstMask
,
953 adsi
->pwfxSrc
->nAvgBytesPerSec
,
954 adsi
->pwfxDst
->nAvgBytesPerSec
) & srcMask
;
956 case ACM_STREAMSIZEF_SOURCE
:
957 /* cbSrcLength => cbDstLength */
958 adss
->cbDstLength
= PCM_round(adss
->cbSrcLength
& srcMask
,
959 adsi
->pwfxDst
->nAvgBytesPerSec
,
960 adsi
->pwfxSrc
->nAvgBytesPerSec
) & dstMask
;
963 WARN("Unsupported query %08x\n", adss
->fdwSize
);
964 return MMSYSERR_NOTSUPPORTED
;
966 return MMSYSERR_NOERROR
;
969 /***********************************************************************
973 static LRESULT
PCM_StreamConvert(PACMDRVSTREAMINSTANCE adsi
, PACMDRVSTREAMHEADER adsh
)
975 AcmPcmData
* apd
= (AcmPcmData
*)adsi
->dwDriver
;
976 DWORD nsrc
= NUM_OF(adsh
->cbSrcLength
, adsi
->pwfxSrc
->nBlockAlign
);
977 DWORD ndst
= NUM_OF(adsh
->cbDstLength
, adsi
->pwfxDst
->nBlockAlign
);
979 TRACE("(%p, %p)\n", adsi
, adsh
);
981 TRACE("nsrc=%d,adsh->cbSrcLength=%d\n", nsrc
, adsh
->cbSrcLength
);
982 TRACE("ndst=%d,adsh->cbDstLength=%d\n", ndst
, adsh
->cbDstLength
);
983 TRACE("src [wFormatTag=%u, nChannels=%u, nSamplesPerSec=%u, nAvgBytesPerSec=%u, nBlockAlign=%u, wBitsPerSample=%u, cbSize=%u]\n",
984 adsi
->pwfxSrc
->wFormatTag
, adsi
->pwfxSrc
->nChannels
, adsi
->pwfxSrc
->nSamplesPerSec
, adsi
->pwfxSrc
->nAvgBytesPerSec
,
985 adsi
->pwfxSrc
->nBlockAlign
, adsi
->pwfxSrc
->wBitsPerSample
, adsi
->pwfxSrc
->cbSize
);
986 TRACE("dst [wFormatTag=%u, nChannels=%u, nSamplesPerSec=%u, nAvgBytesPerSec=%u, nBlockAlign=%u, wBitsPerSample=%u, cbSize=%u]\n",
987 adsi
->pwfxDst
->wFormatTag
, adsi
->pwfxDst
->nChannels
, adsi
->pwfxDst
->nSamplesPerSec
, adsi
->pwfxDst
->nAvgBytesPerSec
,
988 adsi
->pwfxDst
->nBlockAlign
, adsi
->pwfxDst
->wBitsPerSample
, adsi
->pwfxDst
->cbSize
);
990 if (adsh
->fdwConvert
&
991 ~(ACM_STREAMCONVERTF_BLOCKALIGN
|
992 ACM_STREAMCONVERTF_END
|
993 ACM_STREAMCONVERTF_START
)) {
994 FIXME("Unsupported fdwConvert (%08x), ignoring it\n", adsh
->fdwConvert
);
996 /* ACM_STREAMCONVERTF_BLOCKALIGN
997 * currently all conversions are block aligned, so do nothing for this flag
998 * ACM_STREAMCONVERTF_END
999 * no pending data, so do nothing for this flag
1001 if ((adsh
->fdwConvert
& ACM_STREAMCONVERTF_START
) &&
1002 (adsi
->fdwDriver
& PCM_RESAMPLE
)) {
1006 if (adsi
->fdwDriver
& PCM_RESAMPLE
) {
1009 apd
->cvt
.cvtChangeRate((DWORD
)adsi
->pwfxSrc
->nSamplesPerSec
, adsh
->pbSrc
, &nsrc2
,
1010 (DWORD
)adsi
->pwfxDst
->nSamplesPerSec
, adsh
->pbDst
, &ndst2
);
1014 if (nsrc
< ndst
) ndst
= nsrc
; else nsrc
= ndst
;
1016 /* nsrc is now equal to ndst */
1017 apd
->cvt
.cvtKeepRate(adsh
->pbSrc
, nsrc
, adsh
->pbDst
);
1020 adsh
->cbSrcLengthUsed
= nsrc
* adsi
->pwfxSrc
->nBlockAlign
;
1021 adsh
->cbDstLengthUsed
= ndst
* adsi
->pwfxDst
->nBlockAlign
;
1023 return MMSYSERR_NOERROR
;
1026 /**************************************************************************
1027 * DriverProc (MSACM32.@)
1029 LRESULT CALLBACK
PCM_DriverProc(DWORD_PTR dwDevID
, HDRVR hDriv
, UINT wMsg
,
1030 LPARAM dwParam1
, LPARAM dwParam2
)
1032 TRACE("(%08lx %p %u %08lx %08lx);\n",
1033 dwDevID
, hDriv
, wMsg
, dwParam1
, dwParam2
);
1036 case DRV_LOAD
: return 1;
1037 case DRV_FREE
: return 1;
1038 case DRV_OPEN
: return PCM_drvOpen((LPSTR
)dwParam1
, (PACMDRVOPENDESCW
)dwParam2
);
1039 case DRV_CLOSE
: return PCM_drvClose(dwDevID
);
1040 case DRV_ENABLE
: return 1;
1041 case DRV_DISABLE
: return 1;
1042 case DRV_QUERYCONFIGURE
: return 1;
1043 case DRV_CONFIGURE
: MessageBoxA(0, "MSACM PCM filter !", "Wine Driver", MB_OK
); return 1;
1044 case DRV_INSTALL
: return DRVCNF_RESTART
;
1045 case DRV_REMOVE
: return DRVCNF_RESTART
;
1047 case ACMDM_DRIVER_NOTIFY
:
1048 /* no caching from other ACM drivers is done so far */
1049 return MMSYSERR_NOERROR
;
1051 case ACMDM_DRIVER_DETAILS
:
1052 return PCM_DriverDetails((PACMDRIVERDETAILSW
)dwParam1
);
1054 case ACMDM_FORMATTAG_DETAILS
:
1055 return PCM_FormatTagDetails((PACMFORMATTAGDETAILSW
)dwParam1
, dwParam2
);
1057 case ACMDM_FORMAT_DETAILS
:
1058 return PCM_FormatDetails((PACMFORMATDETAILSW
)dwParam1
, dwParam2
);
1060 case ACMDM_FORMAT_SUGGEST
:
1061 return PCM_FormatSuggest((PACMDRVFORMATSUGGEST
)dwParam1
);
1063 case ACMDM_STREAM_OPEN
:
1064 return PCM_StreamOpen((PACMDRVSTREAMINSTANCE
)dwParam1
);
1066 case ACMDM_STREAM_CLOSE
:
1067 return PCM_StreamClose((PACMDRVSTREAMINSTANCE
)dwParam1
);
1069 case ACMDM_STREAM_SIZE
:
1070 return PCM_StreamSize((PACMDRVSTREAMINSTANCE
)dwParam1
, (PACMDRVSTREAMSIZE
)dwParam2
);
1072 case ACMDM_STREAM_CONVERT
:
1073 return PCM_StreamConvert((PACMDRVSTREAMINSTANCE
)dwParam1
, (PACMDRVSTREAMHEADER
)dwParam2
);
1075 case ACMDM_HARDWARE_WAVE_CAPS_INPUT
:
1076 case ACMDM_HARDWARE_WAVE_CAPS_OUTPUT
:
1077 /* this converter is not a hardware driver */
1078 case ACMDM_FILTERTAG_DETAILS
:
1079 case ACMDM_FILTER_DETAILS
:
1080 /* this converter is not a filter */
1081 case ACMDM_STREAM_RESET
:
1082 /* only needed for asynchronous driver... we aren't, so just say it */
1083 case ACMDM_STREAM_PREPARE
:
1084 case ACMDM_STREAM_UNPREPARE
:
1085 /* nothing special to do here... so don't do anything */
1086 return MMSYSERR_NOTSUPPORTED
;
1089 return DefDriverProc(dwDevID
, hDriv
, wMsg
, dwParam1
, dwParam2
);