1 /* -*- tab-width: 8; c-basic-offset: 4 -*- */
6 * Copyright 2000 Eric Pouech
9 * + most of the computation should be done in fixed point arithmetic
10 * instead of floating point (16 bits for integral part, and 16 bits
11 * for fractional part for example)
12 * + implement PCM_FormatSuggest function
13 * + get rid of hack for PCM_DriverProc (msacm32.dll shouldn't export
14 * a DriverProc, but this would require implementing a generic
15 * embedded driver handling scheme in msacm32.dll which isn't done yet
26 #include "debugtools.h"
28 DEFAULT_DEBUG_CHANNEL(msacm
);
30 /***********************************************************************
33 static DWORD
PCM_drvOpen(LPCSTR str
)
38 /***********************************************************************
41 static DWORD
PCM_drvClose(DWORD dwDevID
)
46 #define NUM_PCM_FORMATS (sizeof(PCM_Formats) / sizeof(PCM_Formats[0]))
47 #define NUM_OF(a,b) (((a)+(b)-1)/(b))
49 /* flags for fdwDriver */
50 #define PCM_RESAMPLE 1
52 /* data used while converting */
53 typedef struct tagAcmPcmData
{
54 /* conversion routine, depending if rate conversion is required */
56 void (*cvtKeepRate
)(const unsigned char*, int, unsigned char*);
57 void (*cvtChangeRate
)(struct tagAcmPcmData
*, const unsigned char*,
58 LPDWORD
, unsigned char*, LPDWORD
);
60 /* the following fields are used only with rate conversion) */
61 DWORD srcPos
; /* position in source stream */
62 double dstPos
; /* position in destination stream */
63 double dstIncr
; /* value to increment dst stream when src stream
64 is incremented by 1 */
65 /* last source stream value read */
67 unsigned char b
; /* 8 bit value */
68 short s
; /* 16 bit value */
69 } last
[2]; /* two channels max (stereo) */
72 /* table to list all supported formats... those are the basic ones. this
73 * also helps given a unique index to each of the supported formats
80 {1, 8, 8000}, {2, 8, 8000}, {1, 16, 8000}, {2, 16, 8000},
81 {1, 8, 11025}, {2, 8, 11025}, {1, 16, 11025}, {2, 16, 11025},
82 {1, 8, 22050}, {2, 8, 22050}, {1, 16, 22050}, {2, 16, 22050},
83 {1, 8, 44100}, {2, 8, 44100}, {1, 16, 44100}, {2, 16, 44100},
86 /***********************************************************************
89 static DWORD
PCM_GetFormatIndex(LPWAVEFORMATEX wfx
)
93 for (i
= 0; i
< NUM_PCM_FORMATS
; i
++) {
94 if (wfx
->nChannels
== PCM_Formats
[i
].nChannels
&&
95 wfx
->nSamplesPerSec
== PCM_Formats
[i
].rate
&&
96 wfx
->wBitsPerSample
== PCM_Formats
[i
].nBits
)
105 * + 8 bit unsigned vs 16 bit signed
106 * + mono vs stereo (1 or 2 channels)
107 * + sampling rate (8.0, 11.025, 22.05, 44.1 kHz are defined, but algo shall work
110 * mono => stereo: copy the same sample on Left & Right channels
111 * stereo =) mono: use the average value of samples from Left & Right channels
112 * resampling; we lookup for each destination sample the two source adjacent samples
113 * were src <= dst < src+1 (dst is increased by a fractional value which is
114 * equivalent to the increment by one on src); then we use a linear
115 * interpolation between src and src+1
118 /***********************************************************************
121 * Converts a 8 bit sample to a 16 bit one
123 static inline short C816(unsigned char b
)
125 return (short)(b
^ 0x80) * 256;
128 /***********************************************************************
131 * Converts a 16 bit sample to a 8 bit one (data loss !!)
133 static inline unsigned char C168(short s
)
135 return HIBYTE(s
) ^ (unsigned char)0x80;
138 /***********************************************************************
141 * Read a 16 bit sample (correctly handles endianess)
143 static inline short R16(const unsigned char* src
)
145 return (short)((unsigned short)src
[0] | ((unsigned short)src
[1] << 8));
148 /***********************************************************************
151 * Write a 16 bit sample (correctly handles endianess)
153 static inline void W16(unsigned char* dst
, short s
)
159 /***********************************************************************
162 * Convert the (l,r) 16 bit stereo sample into a 16 bit mono
163 * (takes the mid-point of the two values)
165 static inline short M16(short l
, short r
)
170 /***********************************************************************
173 * Convert the (l,r) 8 bit stereo sample into a 8 bit mono
174 * (takes the mid-point of the two values)
176 static inline unsigned char M8(unsigned char a
, unsigned char b
)
178 return (unsigned char)((a
+ b
) / 2);
181 /* the conversion routines without rate conversion are labelled cvt<X><Y><N><M>K
183 * <X> is the (M)ono/(S)tereo configuration of input channel
184 * <Y> is the (M)ono/(S)tereo configuration of output channel
185 * <N> is the number of bits of input channel (8 or 16)
186 * <M> is the number of bits of output channel (8 or 16)
188 * in the parameters, ns is always the number of samples, so the size of input
189 * buffer (resp output buffer) is ns * (<X> == 'Mono' ? 1:2) * (<N> == 8 ? 1:2)
192 static void cvtMM88K(const unsigned char* src
, int ns
, unsigned char* dst
)
194 memcpy(dst
, src
, ns
);
197 static void cvtSS88K(const unsigned char* src
, int ns
, unsigned char* dst
)
199 memcpy(dst
, src
, ns
* 2);
202 static void cvtMM1616K(const unsigned char* src
, int ns
, unsigned char* dst
)
204 memcpy(dst
, src
, ns
* 2);
207 static void cvtSS1616K(const unsigned char* src
, int ns
, unsigned char* dst
)
209 memcpy(dst
, src
, ns
* 4);
212 static void cvtMS88K(const unsigned char* src
, int ns
, unsigned char* dst
)
220 static void cvtMS816K(const unsigned char* src
, int ns
, unsigned char* dst
)
226 W16(dst
, v
); dst
+= 2;
227 W16(dst
, v
); dst
+= 2;
231 static void cvtMS168K(const unsigned char* src
, int ns
, unsigned char* dst
)
236 v
= C168(R16(src
)); src
+= 2;
242 static void cvtMS1616K(const unsigned char* src
, int ns
, unsigned char* dst
)
247 v
= R16(src
); src
+= 2;
248 W16(dst
, v
); dst
+= 2;
249 W16(dst
, v
); dst
+= 2;
253 static void cvtSM88K(const unsigned char* src
, int ns
, unsigned char* dst
)
256 *dst
++ = M8(src
[0], src
[1]);
261 static void cvtSM816K(const unsigned char* src
, int ns
, unsigned char* dst
)
266 v
= M16(C816(src
[0]), C816(src
[1]));
268 W16(dst
, v
); dst
+= 2;
272 static void cvtSM168K(const unsigned char* src
, int ns
, unsigned char* dst
)
275 *dst
++ = C168(M16(R16(src
), R16(src
+ 2)));
280 static void cvtSM1616K(const unsigned char* src
, int ns
, unsigned char* dst
)
283 W16(dst
, M16(R16(src
),R16(src
+2))); dst
+= 2;
288 static void cvtMM816K(const unsigned char* src
, int ns
, unsigned char* dst
)
291 W16(dst
, C816(*src
++)); dst
+= 2;
295 static void cvtSS816K(const unsigned char* src
, int ns
, unsigned char* dst
)
298 W16(dst
, C816(*src
++)); dst
+= 2;
299 W16(dst
, C816(*src
++)); dst
+= 2;
303 static void cvtMM168K(const unsigned char* src
, int ns
, unsigned char* dst
)
306 *dst
++ = C168(R16(src
)); src
+= 2;
310 static void cvtSS168K(const unsigned char* src
, int ns
, unsigned char* dst
)
313 *dst
++ = C168(R16(src
)); src
+= 2;
314 *dst
++ = C168(R16(src
)); src
+= 2;
318 static void (*PCM_ConvertKeepRate
[16])(const unsigned char*, int, unsigned char*) = {
319 cvtSS88K
, cvtSM88K
, cvtMS88K
, cvtMM88K
,
320 cvtSS816K
, cvtSM816K
, cvtMS816K
, cvtMM816K
,
321 cvtSS168K
, cvtSM168K
, cvtMS168K
, cvtMM168K
,
322 cvtSS1616K
, cvtSM1616K
, cvtMS1616K
, cvtMM1616K
,
325 /***********************************************************************
328 * Interpolate the value at r (r in ]0, 1]) between the two points v1 and v2
329 * Linear interpolation is used
331 static inline double I(double v1
, double v2
, double r
)
333 if (0.0 >= r
|| r
> 1.0) FIXME("r!! %f\n", r
);
334 return (1.0 - r
) * v1
+ r
* v2
;
337 static void cvtSS88C(AcmPcmData
* apd
, const unsigned char* src
, LPDWORD nsrc
,
338 unsigned char* dst
, LPDWORD ndst
)
342 while (*nsrc
!= 0 && *ndst
!= 0) {
343 while ((r
= (double)apd
->srcPos
- apd
->dstPos
) <= 0) {
344 if (*nsrc
== 0) return;
345 apd
->last
[0].b
= *src
++;
346 apd
->last
[1].b
= *src
++;
350 /* now do the interpolation */
351 *dst
++ = I(apd
->last
[0].b
, src
[0], r
);
352 *dst
++ = I(apd
->last
[1].b
, src
[1], r
);
353 apd
->dstPos
+= apd
->dstIncr
;
358 /* the conversion routines with rate conversion are labelled cvt<X><Y><N><M>C
360 * <X> is the (M)ono/(S)tereo configuration of input channel
361 * <Y> is the (M)ono/(S)tereo configuration of output channel
362 * <N> is the number of bits of input channel (8 or 16)
363 * <M> is the number of bits of output channel (8 or 16)
366 static void cvtSM88C(AcmPcmData
* apd
, const unsigned char* src
, LPDWORD nsrc
,
367 unsigned char* dst
, LPDWORD ndst
)
371 while (*nsrc
!= 0 && *ndst
!= 0) {
372 while ((r
= (double)apd
->srcPos
- apd
->dstPos
) <= 0) {
373 if (*nsrc
== 0) return;
374 apd
->last
[0].b
= *src
++;
375 apd
->last
[1].b
= *src
++;
379 /* now do the interpolation */
380 *dst
++ = I(M8(apd
->last
[0].b
, apd
->last
[1].b
), M8(src
[0], src
[1]), r
);
381 apd
->dstPos
+= apd
->dstIncr
;
386 static void cvtMS88C(AcmPcmData
* apd
, const unsigned char* src
, LPDWORD nsrc
,
387 unsigned char* dst
, LPDWORD ndst
)
391 while (*nsrc
!= 0 && *ndst
!= 0) {
392 while ((r
= (double)apd
->srcPos
- apd
->dstPos
) <= 0) {
393 if (*nsrc
== 0) return;
394 apd
->last
[0].b
= *src
++;
398 /* now do the interpolation */
399 dst
[0] = dst
[1] = I(apd
->last
[0].b
, src
[0], r
);
401 apd
->dstPos
+= apd
->dstIncr
;
406 static void cvtMM88C(AcmPcmData
* apd
, const unsigned char* src
, LPDWORD nsrc
,
407 unsigned char* dst
, LPDWORD ndst
)
411 while (*nsrc
!= 0 && *ndst
!= 0) {
412 while ((r
= (double)apd
->srcPos
- apd
->dstPos
) <= 0) {
413 if (*nsrc
== 0) return;
414 apd
->last
[0].b
= *src
++;
418 /* now do the interpolation */
419 *dst
++ = I(apd
->last
[0].b
, src
[0], r
);
420 apd
->dstPos
+= apd
->dstIncr
;
425 static void cvtSS816C(AcmPcmData
* apd
, const unsigned char* src
, LPDWORD nsrc
,
426 unsigned char* dst
, LPDWORD ndst
)
430 while (*nsrc
!= 0 && *ndst
!= 0) {
431 while ((r
= (double)apd
->srcPos
- apd
->dstPos
) <= 0) {
432 if (*nsrc
== 0) return;
433 apd
->last
[0].b
= *src
++;
434 apd
->last
[1].b
= *src
++;
438 /* now do the interpolation */
439 W16(dst
, I(C816(apd
->last
[0].b
), C816(src
[0]), r
)); dst
+= 2;
440 W16(dst
, I(C816(apd
->last
[1].b
), C816(src
[1]), r
)); dst
+= 2;
441 apd
->dstPos
+= apd
->dstIncr
;
446 static void cvtSM816C(AcmPcmData
* apd
, const unsigned char* src
, LPDWORD nsrc
,
447 unsigned char* dst
, LPDWORD ndst
)
451 while (*nsrc
!= 0 && *ndst
!= 0) {
452 while ((r
= (double)apd
->srcPos
- apd
->dstPos
) <= 0) {
453 if (*nsrc
== 0) return;
454 apd
->last
[0].b
= *src
++;
455 apd
->last
[1].b
= *src
++;
459 /* now do the interpolation */
460 W16(dst
, I(M16(C816(apd
->last
[0].b
), C816(apd
->last
[1].b
)),
461 M16(C816(src
[0]), C816(src
[1])), r
));
463 apd
->dstPos
+= apd
->dstIncr
;
468 static void cvtMS816C(AcmPcmData
* apd
, const unsigned char* src
, LPDWORD nsrc
,
469 unsigned char* dst
, LPDWORD ndst
)
474 while (*nsrc
!= 0 && *ndst
!= 0) {
475 while ((r
= (double)apd
->srcPos
- apd
->dstPos
) <= 0) {
476 if (*nsrc
== 0) return;
477 apd
->last
[0].b
= *src
++;
481 /* now do the interpolation */
482 v
= I(C816(apd
->last
[0].b
), C816(src
[0]), r
);
483 W16(dst
, v
); dst
+= 2;
484 W16(dst
, v
); dst
+= 2;
485 apd
->dstPos
+= apd
->dstIncr
;
490 static void cvtMM816C(AcmPcmData
* apd
, const unsigned char* src
, LPDWORD nsrc
,
491 unsigned char* dst
, LPDWORD ndst
)
495 while (*nsrc
!= 0 && *ndst
!= 0) {
496 while ((r
= (double)apd
->srcPos
- apd
->dstPos
) <= 0) {
497 if (*nsrc
== 0) return;
498 apd
->last
[0].b
= *src
++;
502 /* now do the interpolation */
503 W16(dst
, I(C816(apd
->last
[0].b
), C816(src
[0]), r
));
505 apd
->dstPos
+= apd
->dstIncr
;
510 static void cvtSS168C(AcmPcmData
* apd
, const unsigned char* src
, LPDWORD nsrc
,
511 unsigned char* dst
, LPDWORD ndst
)
515 while (*nsrc
!= 0 && *ndst
!= 0) {
516 while ((r
= (double)apd
->srcPos
- apd
->dstPos
) <= 0) {
517 if (*nsrc
== 0) return;
518 apd
->last
[0].s
= R16(src
); src
+= 2;
519 apd
->last
[1].s
= R16(src
); src
+= 2;
523 /* now do the interpolation */
524 *dst
++ = C168(I(apd
->last
[0].s
, R16(src
) , r
));
525 *dst
++ = C168(I(apd
->last
[1].s
, R16(src
+2), r
));
526 apd
->dstPos
+= apd
->dstIncr
;
531 static void cvtSM168C(AcmPcmData
* apd
, const unsigned char* src
, LPDWORD nsrc
,
532 unsigned char* dst
, LPDWORD ndst
)
536 while (*nsrc
!= 0 && *ndst
!= 0) {
537 while ((r
= (double)apd
->srcPos
- apd
->dstPos
) <= 0) {
538 if (*nsrc
== 0) return;
539 apd
->last
[0].s
= R16(src
); src
+= 2;
540 apd
->last
[1].s
= R16(src
); src
+= 2;
544 /* now do the interpolation */
545 *dst
++ = C168(I(M16(apd
->last
[0].s
, apd
->last
[1].s
),
546 M16(R16(src
), R16(src
+ 2)), r
));
547 apd
->dstPos
+= apd
->dstIncr
;
553 static void cvtMS168C(AcmPcmData
* apd
, const unsigned char* src
, LPDWORD nsrc
,
554 unsigned char* dst
, LPDWORD ndst
)
558 while (*nsrc
!= 0 && *ndst
!= 0) {
559 while ((r
= (double)apd
->srcPos
- apd
->dstPos
) <= 0) {
560 if (*nsrc
== 0) return;
561 apd
->last
[0].s
= R16(src
); src
+= 2;
565 /* now do the interpolation */
566 dst
[0] = dst
[1] = C168(I(apd
->last
[0].s
, R16(src
), r
)); dst
+= 2;
567 apd
->dstPos
+= apd
->dstIncr
;
573 static void cvtMM168C(AcmPcmData
* apd
, const unsigned char* src
, LPDWORD nsrc
,
574 unsigned char* dst
, LPDWORD ndst
)
578 while (*nsrc
!= 0 && *ndst
!= 0) {
579 while ((r
= (double)apd
->srcPos
- apd
->dstPos
) <= 0) {
580 if (*nsrc
== 0) return;
581 apd
->last
[0].s
= R16(src
); src
+= 2;
585 /* now do the interpolation */
586 *dst
++ = C168(I(apd
->last
[0].s
, R16(src
), r
));
587 apd
->dstPos
+= apd
->dstIncr
;
592 static void cvtSS1616C(AcmPcmData
* apd
, const unsigned char* src
, LPDWORD nsrc
,
593 unsigned char* dst
, LPDWORD ndst
)
597 while (*nsrc
!= 0 && *ndst
!= 0) {
598 while ((r
= (double)apd
->srcPos
- apd
->dstPos
) <= 0) {
599 if (*nsrc
== 0) return;
600 apd
->last
[0].s
= R16(src
); src
+= 2;
601 apd
->last
[1].s
= R16(src
); src
+= 2;
605 /* now do the interpolation */
606 W16(dst
, I(apd
->last
[0].s
, R16(src
) , r
)); dst
+= 2;
607 W16(dst
, I(apd
->last
[1].s
, R16(src
+2), r
)); dst
+= 2;
608 apd
->dstPos
+= apd
->dstIncr
;
613 static void cvtSM1616C(AcmPcmData
* apd
, const unsigned char* src
, LPDWORD nsrc
,
614 unsigned char* dst
, LPDWORD ndst
)
618 while (*nsrc
!= 0 && *ndst
!= 0) {
619 while ((r
= (double)apd
->srcPos
- apd
->dstPos
) <= 0) {
620 if (*nsrc
== 0) return;
621 apd
->last
[0].s
= R16(src
); src
+= 2;
622 apd
->last
[1].s
= R16(src
); src
+= 2;
626 /* now do the interpolation */
627 W16(dst
, I(M16(apd
->last
[0].s
, apd
->last
[1].s
),
628 M16(R16(src
), R16(src
+2)), r
));
630 apd
->dstPos
+= apd
->dstIncr
;
635 static void cvtMS1616C(AcmPcmData
* apd
, const unsigned char* src
, LPDWORD nsrc
,
636 unsigned char* dst
, LPDWORD ndst
)
641 while (*nsrc
!= 0 && *ndst
!= 0) {
642 while ((r
= (double)apd
->srcPos
- apd
->dstPos
) <= 0) {
643 if (*nsrc
== 0) return;
644 apd
->last
[0].s
= R16(src
); src
+= 2;
648 /* now do the interpolation */
649 v
= I(apd
->last
[0].s
, R16(src
), r
);
650 W16(dst
, v
); dst
+= 2;
651 W16(dst
, v
); dst
+= 2;
652 apd
->dstPos
+= apd
->dstIncr
;
657 static void cvtMM1616C(AcmPcmData
* apd
, const unsigned char* src
, LPDWORD nsrc
,
658 unsigned char* dst
, LPDWORD ndst
)
662 while (*nsrc
!= 0 && *ndst
!= 0) {
663 while ((r
= (double)apd
->srcPos
- apd
->dstPos
) <= 0) {
664 if (*nsrc
== 0) return;
665 apd
->last
[0].s
= R16(src
); src
+= 2;
669 /* now do the interpolation */
670 W16(dst
, I(apd
->last
[0].s
, R16(src
), r
)); dst
+= 2;
671 apd
->dstPos
+= apd
->dstIncr
;
676 static void (*PCM_ConvertChangeRate
[16])(AcmPcmData
* apd
,
677 const unsigned char* src
, LPDWORD nsrc
,
678 unsigned char* dst
, LPDWORD ndst
) = {
679 cvtSS88C
, cvtSM88C
, cvtMS88C
, cvtMM88C
,
680 cvtSS816C
, cvtSM816C
, cvtMS816C
, cvtMM816C
,
681 cvtSS168C
, cvtSM168C
, cvtMS168C
, cvtMM168C
,
682 cvtSS1616C
, cvtSM1616C
, cvtMS1616C
, cvtMM1616C
,
685 /***********************************************************************
689 static LRESULT
PCM_DriverDetails(PACMDRIVERDETAILSW add
)
691 add
->fccType
= ACMDRIVERDETAILS_FCCTYPE_AUDIOCODEC
;
692 add
->fccComp
= ACMDRIVERDETAILS_FCCCOMP_UNDEFINED
;
695 add
->vdwACM
= 0x01000000;
696 add
->vdwDriver
= 0x01000000;
697 add
->fdwSupport
= ACMDRIVERDETAILS_SUPPORTF_CONVERTER
;
698 add
->cFormatTags
= 1;
699 add
->cFilterTags
= 0;
700 add
->hicon
= (HICON
)0;
701 MultiByteToWideChar( CP_ACP
, 0, "WINE-PCM", -1,
702 add
->szShortName
, sizeof(add
->szShortName
)/sizeof(WCHAR
) );
703 MultiByteToWideChar( CP_ACP
, 0, "Wine PCM converter", -1,
704 add
->szLongName
, sizeof(add
->szLongName
)/sizeof(WCHAR
) );
705 MultiByteToWideChar( CP_ACP
, 0, "Brought to you by the Wine team...", -1,
706 add
->szCopyright
, sizeof(add
->szCopyright
)/sizeof(WCHAR
) );
707 MultiByteToWideChar( CP_ACP
, 0, "Refer to LICENSE file", -1,
708 add
->szLicensing
, sizeof(add
->szLicensing
)/sizeof(WCHAR
) );
709 add
->szFeatures
[0] = 0;
711 return MMSYSERR_NOERROR
;
714 /***********************************************************************
715 * PCM_FormatTagDetails
718 static LRESULT
PCM_FormatTagDetails(PACMFORMATTAGDETAILSW aftd
, DWORD dwQuery
)
721 case ACM_FORMATTAGDETAILSF_INDEX
:
722 if (aftd
->dwFormatTagIndex
!= 0) return ACMERR_NOTPOSSIBLE
;
724 case ACM_FORMATTAGDETAILSF_FORMATTAG
:
725 if (aftd
->dwFormatTag
!= WAVE_FORMAT_PCM
) return ACMERR_NOTPOSSIBLE
;
727 case ACM_FORMATTAGDETAILSF_LARGESTSIZE
:
728 if (aftd
->dwFormatTag
!= WAVE_FORMAT_UNKNOWN
&&
729 aftd
->dwFormatTag
!= WAVE_FORMAT_UNKNOWN
)
730 return ACMERR_NOTPOSSIBLE
;
733 WARN("Unsupported query %08lx\n", dwQuery
);
734 return MMSYSERR_NOTSUPPORTED
;
737 aftd
->dwFormatTagIndex
= 0;
738 aftd
->dwFormatTag
= WAVE_FORMAT_PCM
;
739 aftd
->cbFormatSize
= sizeof(PCMWAVEFORMAT
);
740 aftd
->fdwSupport
= ACMDRIVERDETAILS_SUPPORTF_CONVERTER
;
741 aftd
->cStandardFormats
= NUM_PCM_FORMATS
;
742 aftd
->szFormatTag
[0] = 0;
744 return MMSYSERR_NOERROR
;
747 /***********************************************************************
751 static LRESULT
PCM_FormatDetails(PACMFORMATDETAILSW afd
, DWORD dwQuery
)
754 case ACM_FORMATDETAILSF_FORMAT
:
755 afd
->dwFormatIndex
= PCM_GetFormatIndex(afd
->pwfx
);
756 if (afd
->dwFormatIndex
== 0xFFFFFFFF) return ACMERR_NOTPOSSIBLE
;
758 case ACM_FORMATDETAILSF_INDEX
:
759 assert(afd
->dwFormatIndex
< NUM_PCM_FORMATS
);
760 afd
->pwfx
->wFormatTag
= WAVE_FORMAT_PCM
;
761 afd
->pwfx
->nChannels
= PCM_Formats
[afd
->dwFormatIndex
].nChannels
;
762 afd
->pwfx
->nSamplesPerSec
= PCM_Formats
[afd
->dwFormatIndex
].rate
;
763 afd
->pwfx
->wBitsPerSample
= PCM_Formats
[afd
->dwFormatIndex
].nBits
;
764 /* native MSACM uses a PCMWAVEFORMAT structure, so cbSize is not accessible
765 * afd->pwfx->cbSize = 0;
767 afd
->pwfx
->nBlockAlign
=
768 (afd
->pwfx
->nChannels
* afd
->pwfx
->wBitsPerSample
) / 8;
769 afd
->pwfx
->nAvgBytesPerSec
=
770 afd
->pwfx
->nSamplesPerSec
* afd
->pwfx
->nBlockAlign
;
773 WARN("Unsupported query %08lx\n", dwQuery
);
774 return MMSYSERR_NOTSUPPORTED
;
777 afd
->dwFormatTag
= WAVE_FORMAT_PCM
;
778 afd
->fdwSupport
= ACMDRIVERDETAILS_SUPPORTF_CONVERTER
;
779 afd
->szFormat
[0] = 0; /* let MSACM format this for us... */
781 return MMSYSERR_NOERROR
;
784 /***********************************************************************
788 static LRESULT
PCM_FormatSuggest(PACMDRVFORMATSUGGEST adfs
)
790 FIXME("(%p);\n", adfs
);
791 return MMSYSERR_NOTSUPPORTED
;
794 /***********************************************************************
798 static void PCM_Reset(AcmPcmData
* apd
, int srcNumBits
)
802 /* initialize with neutral value */
803 if (srcNumBits
== 16) {
807 apd
->last
[0].b
= (BYTE
)0x80;
808 apd
->last
[1].b
= (BYTE
)0x80;
812 /***********************************************************************
816 static LRESULT
PCM_StreamOpen(PACMDRVSTREAMINSTANCE adsi
)
821 assert(!(adsi
->fdwOpen
& ACM_STREAMOPENF_ASYNC
));
823 if (PCM_GetFormatIndex(adsi
->pwfxSrc
) == 0xFFFFFFFF ||
824 PCM_GetFormatIndex(adsi
->pwfxDst
) == 0xFFFFFFFF)
825 return ACMERR_NOTPOSSIBLE
;
827 apd
= HeapAlloc(GetProcessHeap(), 0, sizeof(AcmPcmData
));
828 if (apd
== 0) return MMSYSERR_NOMEM
;
830 adsi
->dwDriver
= (DWORD
)apd
;
833 if (adsi
->pwfxSrc
->wBitsPerSample
== 16) idx
+= 8;
834 if (adsi
->pwfxDst
->wBitsPerSample
== 16) idx
+= 4;
835 if (adsi
->pwfxSrc
->nChannels
== 1) idx
+= 2;
836 if (adsi
->pwfxDst
->nChannels
== 1) idx
+= 1;
838 if (adsi
->pwfxSrc
->nSamplesPerSec
== adsi
->pwfxDst
->nSamplesPerSec
) {
839 apd
->cvt
.cvtKeepRate
= PCM_ConvertKeepRate
[idx
];
841 adsi
->fdwDriver
|= PCM_RESAMPLE
;
842 apd
->dstIncr
= (double)(adsi
->pwfxSrc
->nSamplesPerSec
) /
843 (double)(adsi
->pwfxDst
->nSamplesPerSec
);
844 PCM_Reset(apd
, adsi
->pwfxSrc
->wBitsPerSample
);
845 apd
->cvt
.cvtChangeRate
= PCM_ConvertChangeRate
[idx
];
848 return MMSYSERR_NOERROR
;
851 /***********************************************************************
855 static LRESULT
PCM_StreamClose(PACMDRVSTREAMINSTANCE adsi
)
857 HeapFree(GetProcessHeap(), 0, (void*)adsi
->dwDriver
);
858 return MMSYSERR_NOERROR
;
861 /***********************************************************************
865 static inline DWORD
PCM_round(DWORD a
, DWORD b
, DWORD c
)
868 /* to be sure, always return an entire number of c... */
869 return ((double)a
* (double)b
+ (double)c
- 1) / (double)c
;
872 /***********************************************************************
876 static LRESULT
PCM_StreamSize(PACMDRVSTREAMINSTANCE adsi
, PACMDRVSTREAMSIZE adss
)
878 switch (adss
->fdwSize
) {
879 case ACM_STREAMSIZEF_DESTINATION
:
880 /* cbDstLength => cbSrcLength */
881 adss
->cbSrcLength
= PCM_round(adss
->cbDstLength
,
882 adsi
->pwfxSrc
->nAvgBytesPerSec
,
883 adsi
->pwfxDst
->nAvgBytesPerSec
);
885 case ACM_STREAMSIZEF_SOURCE
:
886 /* cbSrcLength => cbDstLength */
887 adss
->cbDstLength
= PCM_round(adss
->cbSrcLength
,
888 adsi
->pwfxDst
->nAvgBytesPerSec
,
889 adsi
->pwfxSrc
->nAvgBytesPerSec
);
892 WARN("Unsupported query %08lx\n", adss
->fdwSize
);
893 return MMSYSERR_NOTSUPPORTED
;
895 return MMSYSERR_NOERROR
;
898 /***********************************************************************
902 static LRESULT
PCM_StreamConvert(PACMDRVSTREAMINSTANCE adsi
, PACMDRVSTREAMHEADER adsh
)
904 AcmPcmData
* apd
= (AcmPcmData
*)adsi
->dwDriver
;
905 DWORD nsrc
= NUM_OF(adsh
->cbSrcLength
, adsi
->pwfxSrc
->nBlockAlign
);
906 DWORD ndst
= NUM_OF(adsh
->cbDstLength
, adsi
->pwfxDst
->nBlockAlign
);
908 if (adsh
->fdwConvert
&
909 ~(ACM_STREAMCONVERTF_BLOCKALIGN
|
910 ACM_STREAMCONVERTF_END
|
911 ACM_STREAMCONVERTF_START
)) {
912 FIXME("Unsupported fdwConvert (%08lx), ignoring it\n", adsh
->fdwConvert
);
914 /* ACM_STREAMCONVERTF_BLOCKALIGN
915 * currently all conversions are block aligned, so do nothing for this flag
916 * ACM_STREAMCONVERTF_END
917 * no pending data, so do nothing for this flag
919 if ((adsh
->fdwConvert
& ACM_STREAMCONVERTF_START
) &&
920 (adsi
->fdwDriver
& PCM_RESAMPLE
)) {
921 PCM_Reset(apd
, adsi
->pwfxSrc
->wBitsPerSample
);
925 if (adsi
->fdwDriver
& PCM_RESAMPLE
) {
929 apd
->cvt
.cvtChangeRate(apd
, adsh
->pbSrc
, &nsrc2
, adsh
->pbDst
, &ndst2
);
933 if (nsrc
< ndst
) ndst
= nsrc
; else nsrc
= ndst
;
935 /* nsrc is now equal to ndst */
936 apd
->cvt
.cvtKeepRate(adsh
->pbSrc
, nsrc
, adsh
->pbDst
);
939 adsh
->cbSrcLengthUsed
= nsrc
* adsi
->pwfxSrc
->nBlockAlign
;
940 adsh
->cbDstLengthUsed
= ndst
* adsi
->pwfxDst
->nBlockAlign
;
942 return MMSYSERR_NOERROR
;
945 /**************************************************************************
946 * PCM_DriverProc [exported]
948 LRESULT CALLBACK
PCM_DriverProc(DWORD dwDevID
, HDRVR hDriv
, UINT wMsg
,
949 LPARAM dwParam1
, LPARAM dwParam2
)
951 TRACE("(%08lx %08lx %u %08lx %08lx);\n",
952 dwDevID
, (DWORD
)hDriv
, wMsg
, dwParam1
, dwParam2
);
955 case DRV_LOAD
: return 1;
956 case DRV_FREE
: return 1;
957 case DRV_OPEN
: return PCM_drvOpen((LPSTR
)dwParam1
);
958 case DRV_CLOSE
: return PCM_drvClose(dwDevID
);
959 case DRV_ENABLE
: return 1;
960 case DRV_DISABLE
: return 1;
961 case DRV_QUERYCONFIGURE
: return 1;
962 case DRV_CONFIGURE
: MessageBoxA(0, "MSACM PCM filter !", "Wine Driver", MB_OK
); return 1;
963 case DRV_INSTALL
: return DRVCNF_RESTART
;
964 case DRV_REMOVE
: return DRVCNF_RESTART
;
966 case ACMDM_DRIVER_NOTIFY
:
967 /* no caching from other ACM drivers is done so far */
968 return MMSYSERR_NOERROR
;
970 case ACMDM_DRIVER_DETAILS
:
971 return PCM_DriverDetails((PACMDRIVERDETAILSW
)dwParam1
);
973 case ACMDM_FORMATTAG_DETAILS
:
974 return PCM_FormatTagDetails((PACMFORMATTAGDETAILSW
)dwParam1
, dwParam2
);
976 case ACMDM_FORMAT_DETAILS
:
977 return PCM_FormatDetails((PACMFORMATDETAILSW
)dwParam1
, dwParam2
);
979 case ACMDM_FORMAT_SUGGEST
:
980 return PCM_FormatSuggest((PACMDRVFORMATSUGGEST
)dwParam1
);
982 case ACMDM_STREAM_OPEN
:
983 return PCM_StreamOpen((PACMDRVSTREAMINSTANCE
)dwParam1
);
985 case ACMDM_STREAM_CLOSE
:
986 return PCM_StreamClose((PACMDRVSTREAMINSTANCE
)dwParam1
);
988 case ACMDM_STREAM_SIZE
:
989 return PCM_StreamSize((PACMDRVSTREAMINSTANCE
)dwParam1
, (PACMDRVSTREAMSIZE
)dwParam2
);
991 case ACMDM_STREAM_CONVERT
:
992 return PCM_StreamConvert((PACMDRVSTREAMINSTANCE
)dwParam1
, (PACMDRVSTREAMHEADER
)dwParam2
);
994 case ACMDM_HARDWARE_WAVE_CAPS_INPUT
:
995 case ACMDM_HARDWARE_WAVE_CAPS_OUTPUT
:
996 /* this converter is not a hardware driver */
997 case ACMDM_FILTERTAG_DETAILS
:
998 case ACMDM_FILTER_DETAILS
:
999 /* this converter is not a filter */
1000 case ACMDM_STREAM_RESET
:
1001 /* only needed for asynchronous driver... we aren't, so just say it */
1002 case ACMDM_STREAM_PREPARE
:
1003 case ACMDM_STREAM_UNPREPARE
:
1004 /* nothing special to do here... so don't do anything */
1005 return MMSYSERR_NOTSUPPORTED
;
1008 return DefDriverProc(dwDevID
, hDriv
, wMsg
, dwParam1
, dwParam2
);