2000-10-12 22:46:49 +02:00
|
|
|
/* -*- tab-width: 8; c-basic-offset: 4 -*- */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* MSACM32 library
|
|
|
|
*
|
|
|
|
* Copyright 2000 Eric Pouech
|
2004-12-13 14:31:36 +01:00
|
|
|
* Copyright 2004 Robert Reif
|
2000-10-23 01:49:40 +02:00
|
|
|
*
|
2002-03-10 00:29:33 +01:00
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
2006-05-18 14:49:52 +02:00
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
2002-03-10 00:29:33 +01:00
|
|
|
*
|
2000-10-23 01:49:40 +02:00
|
|
|
* FIXME / TODO list
|
|
|
|
* + get rid of hack for PCM_DriverProc (msacm32.dll shouldn't export
|
|
|
|
* a DriverProc, but this would require implementing a generic
|
|
|
|
* embedded driver handling scheme in msacm32.dll which isn't done yet
|
2000-10-12 22:46:49 +02:00
|
|
|
*/
|
|
|
|
|
2001-07-18 23:04:23 +02:00
|
|
|
|
2000-10-12 22:46:49 +02:00
|
|
|
#include <assert.h>
|
2003-09-06 01:08:26 +02:00
|
|
|
#include <stdarg.h>
|
2001-01-26 21:43:40 +01:00
|
|
|
#include <string.h>
|
2001-07-18 23:04:23 +02:00
|
|
|
|
2003-09-06 01:08:26 +02:00
|
|
|
#include "windef.h"
|
2000-10-12 22:46:49 +02:00
|
|
|
#include "winbase.h"
|
2003-09-06 01:08:26 +02:00
|
|
|
#include "mmsystem.h"
|
2004-08-11 21:35:34 +02:00
|
|
|
#define NOBITMAP
|
2003-09-06 01:08:26 +02:00
|
|
|
#include "mmreg.h"
|
|
|
|
#include "msacm.h"
|
2000-10-12 22:46:49 +02:00
|
|
|
#include "wingdi.h"
|
2001-07-18 23:04:23 +02:00
|
|
|
#include "winnls.h"
|
2000-10-12 22:46:49 +02:00
|
|
|
#include "winuser.h"
|
2001-07-18 23:04:23 +02:00
|
|
|
|
2000-10-12 22:46:49 +02:00
|
|
|
#include "msacmdrv.h"
|
2001-07-18 23:04:23 +02:00
|
|
|
#include "wineacm.h"
|
|
|
|
|
2002-03-10 00:29:33 +01:00
|
|
|
#include "wine/debug.h"
|
2000-10-12 22:46:49 +02:00
|
|
|
|
2002-03-10 00:29:33 +01:00
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(msacm);
|
2000-10-12 22:46:49 +02:00
|
|
|
|
2000-10-23 01:49:40 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* PCM_drvOpen
|
|
|
|
*/
|
2001-04-14 00:28:35 +02:00
|
|
|
static DWORD PCM_drvOpen(LPCSTR str, PACMDRVOPENDESCW adod)
|
2000-10-12 22:46:49 +02:00
|
|
|
{
|
2004-03-12 21:24:50 +01:00
|
|
|
TRACE("(%p, %p)\n", str, adod);
|
|
|
|
|
2001-05-22 21:21:16 +02:00
|
|
|
return (adod == NULL) ||
|
|
|
|
(adod->fccType == ACMDRIVERDETAILS_FCCTYPE_AUDIOCODEC &&
|
|
|
|
adod->fccComp == ACMDRIVERDETAILS_FCCCOMP_UNDEFINED);
|
2000-10-12 22:46:49 +02:00
|
|
|
}
|
|
|
|
|
2000-10-23 01:49:40 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* PCM_drvClose
|
|
|
|
*/
|
2000-10-12 22:46:49 +02:00
|
|
|
static DWORD PCM_drvClose(DWORD dwDevID)
|
|
|
|
{
|
2006-10-12 21:35:06 +02:00
|
|
|
TRACE("(%d)\n", dwDevID);
|
2004-03-12 21:24:50 +01:00
|
|
|
|
2000-10-12 22:46:49 +02:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2004-12-13 14:31:36 +01:00
|
|
|
#define NUM_OF(a,b) ((a)/(b))
|
2000-10-23 01:49:40 +02:00
|
|
|
|
|
|
|
/* flags for fdwDriver */
|
|
|
|
#define PCM_RESAMPLE 1
|
|
|
|
|
2017-06-15 20:25:48 +02:00
|
|
|
typedef void (*PCM_CONVERT_KEEP_RATE)(const unsigned char*, int, unsigned char*);
|
|
|
|
|
|
|
|
typedef void (*PCM_CONVERT_CHANGE_RATE)(const DWORD, const unsigned char*, DWORD*, const DWORD, unsigned char*, DWORD*);
|
|
|
|
|
2000-10-23 01:49:40 +02:00
|
|
|
/* data used while converting */
|
|
|
|
typedef struct tagAcmPcmData {
|
|
|
|
/* conversion routine, depending if rate conversion is required */
|
|
|
|
union {
|
2017-06-15 20:25:48 +02:00
|
|
|
PCM_CONVERT_KEEP_RATE cvtKeepRate;
|
|
|
|
PCM_CONVERT_CHANGE_RATE cvtChangeRate;
|
2000-10-23 01:49:40 +02:00
|
|
|
} cvt;
|
|
|
|
} AcmPcmData;
|
|
|
|
|
|
|
|
/* table to list all supported formats... those are the basic ones. this
|
|
|
|
* also helps given a unique index to each of the supported formats
|
|
|
|
*/
|
2006-12-01 13:19:31 +01:00
|
|
|
static const struct {
|
2000-10-12 22:46:49 +02:00
|
|
|
int nChannels;
|
|
|
|
int nBits;
|
|
|
|
int rate;
|
|
|
|
} PCM_Formats[] = {
|
2016-12-05 18:28:25 +01:00
|
|
|
{1, 8, 8000}, {2, 8, 8000}, {1, 16, 8000}, {2, 16, 8000}, {1, 24, 8000}, {2, 24, 8000},
|
|
|
|
{1, 8, 11025}, {2, 8, 11025}, {1, 16, 11025}, {2, 16, 11025}, {1, 24, 11025}, {2, 24, 11025},
|
|
|
|
{1, 8, 22050}, {2, 8, 22050}, {1, 16, 22050}, {2, 16, 22050}, {1, 24, 22050}, {2, 24, 22050},
|
|
|
|
{1, 8, 44100}, {2, 8, 44100}, {1, 16, 44100}, {2, 16, 44100}, {1, 24, 44100}, {2, 24, 44100},
|
|
|
|
{1, 8, 48000}, {2, 8, 48000}, {1, 16, 48000}, {2, 16, 48000}, {1, 24, 48000}, {2, 24, 48000},
|
|
|
|
{1, 8, 96000}, {2, 8, 96000}, {1, 16, 96000}, {2, 16, 96000}, {1, 24, 96000}, {2, 24, 96000},
|
2000-10-12 22:46:49 +02:00
|
|
|
};
|
|
|
|
|
2000-10-23 01:49:40 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* PCM_GetFormatIndex
|
|
|
|
*/
|
2002-12-13 03:18:20 +01:00
|
|
|
static DWORD PCM_GetFormatIndex(LPWAVEFORMATEX wfx)
|
2000-10-12 22:46:49 +02:00
|
|
|
{
|
2004-09-08 03:23:57 +02:00
|
|
|
unsigned int i;
|
2004-03-12 21:24:50 +01:00
|
|
|
TRACE("(%p)\n", wfx);
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2018-07-11 22:06:17 +02:00
|
|
|
for (i = 0; i < ARRAY_SIZE(PCM_Formats); i++) {
|
2000-10-12 22:46:49 +02:00
|
|
|
if (wfx->nChannels == PCM_Formats[i].nChannels &&
|
|
|
|
wfx->nSamplesPerSec == PCM_Formats[i].rate &&
|
|
|
|
wfx->wBitsPerSample == PCM_Formats[i].nBits)
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
return 0xFFFFFFFF;
|
|
|
|
}
|
|
|
|
|
2000-10-23 01:49:40 +02:00
|
|
|
/* PCM Conversions:
|
|
|
|
*
|
|
|
|
* parameters:
|
|
|
|
* + 8 bit unsigned vs 16 bit signed
|
|
|
|
* + mono vs stereo (1 or 2 channels)
|
2002-12-15 02:12:03 +01:00
|
|
|
* + sampling rate (8.0, 11.025, 22.05, 44.1 kHz are defined, but algo
|
|
|
|
* shall work in all cases)
|
2000-10-23 01:49:40 +02:00
|
|
|
*
|
|
|
|
* mono => stereo: copy the same sample on Left & Right channels
|
2004-12-13 14:31:36 +01:00
|
|
|
* stereo => mono: use the sum of Left & Right channels
|
2000-10-23 01:49:40 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* C816
|
|
|
|
*
|
|
|
|
* Converts a 8 bit sample to a 16 bit one
|
|
|
|
*/
|
2002-06-01 01:06:46 +02:00
|
|
|
static inline short C816(unsigned char b)
|
2000-10-23 01:49:40 +02:00
|
|
|
{
|
2004-12-13 14:31:36 +01:00
|
|
|
return (b - 128) << 8;
|
2000-10-23 01:49:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* C168
|
|
|
|
*
|
|
|
|
* Converts a 16 bit sample to a 8 bit one (data loss !!)
|
|
|
|
*/
|
2002-06-01 01:06:46 +02:00
|
|
|
static inline unsigned char C168(short s)
|
2000-10-23 01:49:40 +02:00
|
|
|
{
|
|
|
|
return HIBYTE(s) ^ (unsigned char)0x80;
|
|
|
|
}
|
|
|
|
|
2016-12-05 18:28:25 +01:00
|
|
|
/***********************************************************************
|
|
|
|
* C248
|
|
|
|
*
|
|
|
|
* Converts a 24 bit sample to a 8 bit one (data loss !!)
|
|
|
|
*/
|
|
|
|
static inline unsigned char C248(int s)
|
|
|
|
{
|
|
|
|
return HIBYTE(HIWORD(s)) ^ (unsigned char)0x80;
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* C2416
|
|
|
|
*
|
|
|
|
* Converts a 24 bit sample to a 16 bit one (data loss !!)
|
|
|
|
*/
|
|
|
|
static inline short C2416(int s)
|
|
|
|
{
|
|
|
|
return HIWORD(s);
|
|
|
|
}
|
|
|
|
|
2000-10-23 01:49:40 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* R16
|
|
|
|
*
|
2011-07-27 13:38:43 +02:00
|
|
|
* Read a 16 bit sample (correctly handles endianness)
|
2000-10-23 01:49:40 +02:00
|
|
|
*/
|
|
|
|
static inline short R16(const unsigned char* src)
|
|
|
|
{
|
|
|
|
return (short)((unsigned short)src[0] | ((unsigned short)src[1] << 8));
|
|
|
|
}
|
|
|
|
|
2016-12-05 18:28:25 +01:00
|
|
|
/***********************************************************************
|
|
|
|
* R24
|
|
|
|
*
|
|
|
|
* Read a 24 bit sample (correctly handles endianness)
|
|
|
|
* Note, to support signed arithmetic, the values are shifted high in the int
|
|
|
|
* and low 8 bytes are unused.
|
|
|
|
*/
|
|
|
|
static inline int R24(const unsigned char* src)
|
|
|
|
{
|
|
|
|
return ((int)src[0] | (int)src[1] << 8 | (int)src[2] << 16) << 8;
|
|
|
|
}
|
|
|
|
|
2000-10-23 01:49:40 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* W16
|
|
|
|
*
|
2011-07-27 13:38:43 +02:00
|
|
|
* Write a 16 bit sample (correctly handles endianness)
|
2000-10-23 01:49:40 +02:00
|
|
|
*/
|
|
|
|
static inline void W16(unsigned char* dst, short s)
|
|
|
|
{
|
|
|
|
dst[0] = LOBYTE(s);
|
|
|
|
dst[1] = HIBYTE(s);
|
|
|
|
}
|
|
|
|
|
2016-12-05 18:28:25 +01:00
|
|
|
/***********************************************************************
|
|
|
|
* W24
|
|
|
|
*
|
|
|
|
* Write a 24 bit sample (correctly handles endianness)
|
|
|
|
*/
|
|
|
|
static inline void W24(unsigned char* dst, int s)
|
|
|
|
{
|
|
|
|
dst[0] = HIBYTE(LOWORD(s));
|
|
|
|
dst[1] = LOBYTE(HIWORD(s));
|
|
|
|
dst[2] = HIBYTE(HIWORD(s));
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* M24
|
|
|
|
*
|
|
|
|
* Convert the (l,r) 24 bit stereo sample into a 24 bit mono
|
|
|
|
* (takes the sum of the two values)
|
|
|
|
*/
|
|
|
|
static inline int M24(int l, int r)
|
|
|
|
{
|
|
|
|
LONGLONG sum = l + r;
|
|
|
|
|
|
|
|
/* clip sum to saturation */
|
|
|
|
if (sum > 0x7fffff00)
|
|
|
|
sum = 0x7fffff00;
|
|
|
|
else if (sum < -0x7fffff00)
|
|
|
|
sum = -0x7fffff00;
|
|
|
|
|
|
|
|
return sum;
|
|
|
|
}
|
|
|
|
|
2000-10-23 01:49:40 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* M16
|
|
|
|
*
|
2002-06-01 01:06:46 +02:00
|
|
|
* Convert the (l,r) 16 bit stereo sample into a 16 bit mono
|
2004-12-13 14:31:36 +01:00
|
|
|
* (takes the sum of the two values)
|
2000-10-23 01:49:40 +02:00
|
|
|
*/
|
|
|
|
static inline short M16(short l, short r)
|
|
|
|
{
|
2004-12-13 14:31:36 +01:00
|
|
|
int sum = l + r;
|
|
|
|
|
|
|
|
/* clip sum to saturation */
|
|
|
|
if (sum > 32767)
|
|
|
|
sum = 32767;
|
|
|
|
else if (sum < -32768)
|
|
|
|
sum = -32768;
|
|
|
|
|
|
|
|
return sum;
|
2000-10-23 01:49:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* M8
|
|
|
|
*
|
2002-06-01 01:06:46 +02:00
|
|
|
* Convert the (l,r) 8 bit stereo sample into a 8 bit mono
|
2004-12-13 14:31:36 +01:00
|
|
|
* (takes the sum of the two values)
|
2000-10-23 01:49:40 +02:00
|
|
|
*/
|
|
|
|
static inline unsigned char M8(unsigned char a, unsigned char b)
|
|
|
|
{
|
2004-12-13 14:31:36 +01:00
|
|
|
int l = a - 128;
|
|
|
|
int r = b - 128;
|
|
|
|
int sum = (l + r) + 128;
|
|
|
|
|
|
|
|
/* clip sum to saturation */
|
|
|
|
if (sum > 0xff)
|
|
|
|
sum = 0xff;
|
|
|
|
else if (sum < 0)
|
|
|
|
sum = 0;
|
|
|
|
|
|
|
|
return sum;
|
2000-10-23 01:49:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* the conversion routines without rate conversion are labelled cvt<X><Y><N><M>K
|
|
|
|
* where :
|
|
|
|
* <X> is the (M)ono/(S)tereo configuration of input channel
|
|
|
|
* <Y> is the (M)ono/(S)tereo configuration of output channel
|
|
|
|
* <N> is the number of bits of input channel (8 or 16)
|
|
|
|
* <M> is the number of bits of output channel (8 or 16)
|
|
|
|
*
|
|
|
|
* in the parameters, ns is always the number of samples, so the size of input
|
|
|
|
* buffer (resp output buffer) is ns * (<X> == 'Mono' ? 1:2) * (<N> == 8 ? 1:2)
|
|
|
|
*/
|
|
|
|
|
|
|
|
static void cvtMM88K(const unsigned char* src, int ns, unsigned char* dst)
|
|
|
|
{
|
2004-03-12 21:24:50 +01:00
|
|
|
TRACE("(%p, %d, %p)\n", src, ns, dst);
|
2000-10-23 01:49:40 +02:00
|
|
|
memcpy(dst, src, ns);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void cvtSS88K(const unsigned char* src, int ns, unsigned char* dst)
|
|
|
|
{
|
2004-03-12 21:24:50 +01:00
|
|
|
TRACE("(%p, %d, %p)\n", src, ns, dst);
|
2000-10-23 01:49:40 +02:00
|
|
|
memcpy(dst, src, ns * 2);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void cvtMM1616K(const unsigned char* src, int ns, unsigned char* dst)
|
|
|
|
{
|
2004-03-12 21:24:50 +01:00
|
|
|
TRACE("(%p, %d, %p)\n", src, ns, dst);
|
2000-10-23 01:49:40 +02:00
|
|
|
memcpy(dst, src, ns * 2);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void cvtSS1616K(const unsigned char* src, int ns, unsigned char* dst)
|
|
|
|
{
|
2004-03-12 21:24:50 +01:00
|
|
|
TRACE("(%p, %d, %p)\n", src, ns, dst);
|
2000-10-23 01:49:40 +02:00
|
|
|
memcpy(dst, src, ns * 4);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void cvtMS88K(const unsigned char* src, int ns, unsigned char* dst)
|
|
|
|
{
|
2004-03-12 21:24:50 +01:00
|
|
|
TRACE("(%p, %d, %p)\n", src, ns, dst);
|
|
|
|
|
2000-10-23 01:49:40 +02:00
|
|
|
while (ns--) {
|
|
|
|
*dst++ = *src;
|
|
|
|
*dst++ = *src++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void cvtMS816K(const unsigned char* src, int ns, unsigned char* dst)
|
|
|
|
{
|
|
|
|
short v;
|
2004-03-12 21:24:50 +01:00
|
|
|
TRACE("(%p, %d, %p)\n", src, ns, dst);
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2000-10-23 01:49:40 +02:00
|
|
|
while (ns--) {
|
|
|
|
v = C816(*src++);
|
|
|
|
W16(dst, v); dst += 2;
|
|
|
|
W16(dst, v); dst += 2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void cvtMS168K(const unsigned char* src, int ns, unsigned char* dst)
|
|
|
|
{
|
|
|
|
unsigned char v;
|
2004-03-12 21:24:50 +01:00
|
|
|
TRACE("(%p, %d, %p)\n", src, ns, dst);
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2000-10-23 01:49:40 +02:00
|
|
|
while (ns--) {
|
2004-12-13 14:31:36 +01:00
|
|
|
v = C168(R16(src)); src += 2;
|
2000-10-23 01:49:40 +02:00
|
|
|
*dst++ = v;
|
|
|
|
*dst++ = v;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void cvtMS1616K(const unsigned char* src, int ns, unsigned char* dst)
|
|
|
|
{
|
|
|
|
short v;
|
2004-03-12 21:24:50 +01:00
|
|
|
TRACE("(%p, %d, %p)\n", src, ns, dst);
|
2000-10-23 01:49:40 +02:00
|
|
|
|
|
|
|
while (ns--) {
|
|
|
|
v = R16(src); src += 2;
|
|
|
|
W16(dst, v); dst += 2;
|
|
|
|
W16(dst, v); dst += 2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void cvtSM88K(const unsigned char* src, int ns, unsigned char* dst)
|
|
|
|
{
|
2004-03-12 21:24:50 +01:00
|
|
|
TRACE("(%p, %d, %p)\n", src, ns, dst);
|
|
|
|
|
2000-10-23 01:49:40 +02:00
|
|
|
while (ns--) {
|
|
|
|
*dst++ = M8(src[0], src[1]);
|
|
|
|
src += 2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void cvtSM816K(const unsigned char* src, int ns, unsigned char* dst)
|
|
|
|
{
|
|
|
|
short v;
|
2004-03-12 21:24:50 +01:00
|
|
|
TRACE("(%p, %d, %p)\n", src, ns, dst);
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2000-10-23 01:49:40 +02:00
|
|
|
while (ns--) {
|
|
|
|
v = M16(C816(src[0]), C816(src[1]));
|
|
|
|
src += 2;
|
|
|
|
W16(dst, v); dst += 2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void cvtSM168K(const unsigned char* src, int ns, unsigned char* dst)
|
|
|
|
{
|
2004-03-12 21:24:50 +01:00
|
|
|
TRACE("(%p, %d, %p)\n", src, ns, dst);
|
|
|
|
|
2000-10-23 01:49:40 +02:00
|
|
|
while (ns--) {
|
|
|
|
*dst++ = C168(M16(R16(src), R16(src + 2)));
|
|
|
|
src += 4;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void cvtSM1616K(const unsigned char* src, int ns, unsigned char* dst)
|
|
|
|
{
|
2004-03-12 21:24:50 +01:00
|
|
|
TRACE("(%p, %d, %p)\n", src, ns, dst);
|
|
|
|
|
2000-10-23 01:49:40 +02:00
|
|
|
while (ns--) {
|
|
|
|
W16(dst, M16(R16(src),R16(src+2))); dst += 2;
|
|
|
|
src += 4;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void cvtMM816K(const unsigned char* src, int ns, unsigned char* dst)
|
|
|
|
{
|
2004-03-12 21:24:50 +01:00
|
|
|
TRACE("(%p, %d, %p)\n", src, ns, dst);
|
|
|
|
|
2000-10-23 01:49:40 +02:00
|
|
|
while (ns--) {
|
|
|
|
W16(dst, C816(*src++)); dst += 2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void cvtSS816K(const unsigned char* src, int ns, unsigned char* dst)
|
|
|
|
{
|
2004-03-12 21:24:50 +01:00
|
|
|
TRACE("(%p, %d, %p)\n", src, ns, dst);
|
|
|
|
|
2000-10-23 01:49:40 +02:00
|
|
|
while (ns--) {
|
|
|
|
W16(dst, C816(*src++)); dst += 2;
|
|
|
|
W16(dst, C816(*src++)); dst += 2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void cvtMM168K(const unsigned char* src, int ns, unsigned char* dst)
|
|
|
|
{
|
2004-03-12 21:24:50 +01:00
|
|
|
TRACE("(%p, %d, %p)\n", src, ns, dst);
|
|
|
|
|
2000-10-23 01:49:40 +02:00
|
|
|
while (ns--) {
|
|
|
|
*dst++ = C168(R16(src)); src += 2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void cvtSS168K(const unsigned char* src, int ns, unsigned char* dst)
|
|
|
|
{
|
2004-03-12 21:24:50 +01:00
|
|
|
TRACE("(%p, %d, %p)\n", src, ns, dst);
|
|
|
|
|
2000-10-23 01:49:40 +02:00
|
|
|
while (ns--) {
|
|
|
|
*dst++ = C168(R16(src)); src += 2;
|
|
|
|
*dst++ = C168(R16(src)); src += 2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-05 18:28:25 +01:00
|
|
|
static void cvtMS248K(const unsigned char* src, int ns, unsigned char* dst)
|
|
|
|
{
|
|
|
|
unsigned char v;
|
|
|
|
TRACE("(%p, %d, %p)\n", src, ns, dst);
|
|
|
|
|
|
|
|
while (ns--) {
|
|
|
|
v = C248(R24(src)); src += 3;
|
|
|
|
*dst++ = v;
|
|
|
|
*dst++ = v;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void cvtSM248K(const unsigned char* src, int ns, unsigned char* dst)
|
|
|
|
{
|
|
|
|
TRACE("(%p, %d, %p)\n", src, ns, dst);
|
|
|
|
|
|
|
|
while (ns--) {
|
|
|
|
*dst++ = C248(M24(R24(src), R24(src + 3)));
|
|
|
|
src += 6;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void cvtMM248K(const unsigned char* src, int ns, unsigned char* dst)
|
|
|
|
{
|
|
|
|
TRACE("(%p, %d, %p)\n", src, ns, dst);
|
|
|
|
|
|
|
|
while (ns--) {
|
|
|
|
*dst++ = C248(R24(src)); src += 3;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void cvtSS248K(const unsigned char* src, int ns, unsigned char* dst)
|
|
|
|
{
|
|
|
|
TRACE("(%p, %d, %p)\n", src, ns, dst);
|
|
|
|
|
|
|
|
while (ns--) {
|
|
|
|
*dst++ = C248(R24(src)); src += 3;
|
|
|
|
*dst++ = C248(R24(src)); src += 3;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void cvtMS2416K(const unsigned char* src, int ns, unsigned char* dst)
|
|
|
|
{
|
|
|
|
short v;
|
|
|
|
TRACE("(%p, %d, %p)\n", src, ns, dst);
|
|
|
|
|
|
|
|
while (ns--) {
|
|
|
|
v = C2416(R24(src)); src += 3;
|
|
|
|
W16(dst, v); dst += 2;
|
|
|
|
W16(dst, v); dst += 2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void cvtSM2416K(const unsigned char* src, int ns, unsigned char* dst)
|
|
|
|
{
|
|
|
|
TRACE("(%p, %d, %p)\n", src, ns, dst);
|
|
|
|
|
|
|
|
while (ns--) {
|
|
|
|
W16(dst, C2416(M24(R24(src), R24(src + 3))));
|
|
|
|
dst += 2;
|
|
|
|
src += 6;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void cvtMM2416K(const unsigned char* src, int ns, unsigned char* dst)
|
|
|
|
{
|
|
|
|
TRACE("(%p, %d, %p)\n", src, ns, dst);
|
|
|
|
|
|
|
|
while (ns--) {
|
|
|
|
W16(dst, C2416(R24(src))); dst += 2; src += 3;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void cvtSS2416K(const unsigned char* src, int ns, unsigned char* dst)
|
|
|
|
{
|
|
|
|
TRACE("(%p, %d, %p)\n", src, ns, dst);
|
|
|
|
|
|
|
|
while (ns--) {
|
|
|
|
W16(dst, C2416(R24(src))); dst += 2; src += 3;
|
|
|
|
W16(dst, C2416(R24(src))); dst += 2; src += 3;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-12-01 13:19:31 +01:00
|
|
|
|
2016-12-05 18:28:25 +01:00
|
|
|
static const PCM_CONVERT_KEEP_RATE PCM_ConvertKeepRate[] = {
|
2000-10-23 01:49:40 +02:00
|
|
|
cvtSS88K, cvtSM88K, cvtMS88K, cvtMM88K,
|
|
|
|
cvtSS816K, cvtSM816K, cvtMS816K, cvtMM816K,
|
2016-12-05 18:28:25 +01:00
|
|
|
NULL, NULL, NULL, NULL, /* TODO: 8->24 */
|
2000-10-23 01:49:40 +02:00
|
|
|
cvtSS168K, cvtSM168K, cvtMS168K, cvtMM168K,
|
|
|
|
cvtSS1616K, cvtSM1616K, cvtMS1616K, cvtMM1616K,
|
2016-12-05 18:28:25 +01:00
|
|
|
NULL, NULL, NULL, NULL, /* TODO: 16->24 */
|
|
|
|
cvtSS248K, cvtSM248K, cvtMS248K, cvtMM248K,
|
|
|
|
cvtSS2416K, cvtSM2416K, cvtMS2416K, cvtMM2416K,
|
|
|
|
NULL, NULL, NULL, NULL, /* TODO: 24->24 */
|
2000-10-23 01:49:40 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
/* the conversion routines with rate conversion are labelled cvt<X><Y><N><M>C
|
|
|
|
* where :
|
|
|
|
* <X> is the (M)ono/(S)tereo configuration of input channel
|
|
|
|
* <Y> is the (M)ono/(S)tereo configuration of output channel
|
|
|
|
* <N> is the number of bits of input channel (8 or 16)
|
|
|
|
* <M> is the number of bits of output channel (8 or 16)
|
|
|
|
*
|
|
|
|
*/
|
2017-06-15 20:25:48 +02:00
|
|
|
|
|
|
|
static void cvtSS88C(const DWORD srcRate, const unsigned char *src, DWORD *nsrc,
|
|
|
|
const DWORD dstRate, unsigned char *dst, DWORD *ndst)
|
|
|
|
{
|
|
|
|
DWORD error = srcRate / 2;
|
|
|
|
DWORD maxSrc = *nsrc, maxDst = *ndst;
|
|
|
|
*ndst = 0;
|
|
|
|
for (*nsrc = 0; *nsrc < maxSrc; (*nsrc)++) {
|
|
|
|
error += dstRate;
|
|
|
|
while (error > srcRate) {
|
|
|
|
if (*ndst == maxDst)
|
2004-12-13 14:31:36 +01:00
|
|
|
return;
|
2017-06-15 20:25:48 +02:00
|
|
|
(*ndst)++;
|
|
|
|
error -= srcRate;
|
|
|
|
|
|
|
|
*dst++ = src[0];
|
|
|
|
*dst++ = src[1];
|
2004-12-13 14:31:36 +01:00
|
|
|
}
|
2017-06-15 20:25:48 +02:00
|
|
|
src += 2;
|
2000-10-23 01:49:40 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-06-15 20:25:48 +02:00
|
|
|
static void cvtSM88C(const DWORD srcRate, const unsigned char *src, DWORD *nsrc,
|
|
|
|
const DWORD dstRate, unsigned char *dst, DWORD *ndst)
|
2000-10-23 01:49:40 +02:00
|
|
|
{
|
2017-06-15 20:25:48 +02:00
|
|
|
DWORD error = srcRate / 2;
|
|
|
|
DWORD maxSrc = *nsrc, maxDst = *ndst;
|
|
|
|
*ndst = 0;
|
|
|
|
for (*nsrc = 0; *nsrc < maxSrc; (*nsrc)++) {
|
|
|
|
error += dstRate;
|
|
|
|
while (error > srcRate) {
|
|
|
|
if (*ndst == maxDst)
|
2004-12-13 14:31:36 +01:00
|
|
|
return;
|
2017-06-15 20:25:48 +02:00
|
|
|
(*ndst)++;
|
|
|
|
error -= srcRate;
|
|
|
|
|
|
|
|
*dst++ = M8(src[0], src[1]);
|
2004-12-13 14:31:36 +01:00
|
|
|
}
|
2017-06-15 20:25:48 +02:00
|
|
|
src += 2;
|
2000-10-23 01:49:40 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-06-15 20:25:48 +02:00
|
|
|
static void cvtMS88C(const DWORD srcRate, const unsigned char *src, DWORD *nsrc,
|
|
|
|
const DWORD dstRate, unsigned char *dst, DWORD *ndst)
|
2000-10-23 01:49:40 +02:00
|
|
|
{
|
2017-06-15 20:25:48 +02:00
|
|
|
DWORD error = srcRate / 2;
|
|
|
|
DWORD maxSrc = *nsrc, maxDst = *ndst;
|
|
|
|
*ndst = 0;
|
|
|
|
for (*nsrc = 0; *nsrc < maxSrc; (*nsrc)++) {
|
|
|
|
error += dstRate;
|
|
|
|
while (error > srcRate) {
|
|
|
|
if (*ndst == maxDst)
|
2004-12-13 14:31:36 +01:00
|
|
|
return;
|
2017-06-15 20:25:48 +02:00
|
|
|
(*ndst)++;
|
|
|
|
error -= srcRate;
|
|
|
|
|
|
|
|
*dst++ = src[0];
|
|
|
|
*dst++ = src[0];
|
2004-12-13 14:31:36 +01:00
|
|
|
}
|
2017-06-15 20:25:48 +02:00
|
|
|
src += 1;
|
2000-10-23 01:49:40 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-06-15 20:25:48 +02:00
|
|
|
static void cvtMM88C(const DWORD srcRate, const unsigned char *src, DWORD *nsrc,
|
|
|
|
const DWORD dstRate, unsigned char *dst, DWORD *ndst)
|
2000-10-23 01:49:40 +02:00
|
|
|
{
|
2017-06-15 20:25:48 +02:00
|
|
|
DWORD error = srcRate / 2;
|
|
|
|
DWORD maxSrc = *nsrc, maxDst = *ndst;
|
|
|
|
*ndst = 0;
|
|
|
|
for (*nsrc = 0; *nsrc < maxSrc; (*nsrc)++) {
|
|
|
|
error += dstRate;
|
|
|
|
while (error > srcRate) {
|
|
|
|
if (*ndst == maxDst)
|
2004-12-13 14:31:36 +01:00
|
|
|
return;
|
2017-06-15 20:25:48 +02:00
|
|
|
(*ndst)++;
|
|
|
|
error -= srcRate;
|
|
|
|
|
|
|
|
*dst++ = src[0];
|
2004-12-13 14:31:36 +01:00
|
|
|
}
|
2017-06-15 20:25:48 +02:00
|
|
|
src += 1;
|
2000-10-23 01:49:40 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-06-15 20:25:48 +02:00
|
|
|
static void cvtSS816C(const DWORD srcRate, const unsigned char *src, DWORD *nsrc,
|
|
|
|
const DWORD dstRate, unsigned char *dst, DWORD *ndst)
|
2000-10-23 01:49:40 +02:00
|
|
|
{
|
2017-06-15 20:25:48 +02:00
|
|
|
DWORD error = srcRate / 2;
|
|
|
|
DWORD maxSrc = *nsrc, maxDst = *ndst;
|
|
|
|
*ndst = 0;
|
|
|
|
for (*nsrc = 0; *nsrc < maxSrc; (*nsrc)++) {
|
|
|
|
error += dstRate;
|
|
|
|
while (error > srcRate) {
|
|
|
|
if (*ndst == maxDst)
|
2004-12-13 14:31:36 +01:00
|
|
|
return;
|
2017-06-15 20:25:48 +02:00
|
|
|
(*ndst)++;
|
|
|
|
error -= srcRate;
|
|
|
|
|
|
|
|
W16(dst, C816(src[0])); dst += 2;
|
|
|
|
W16(dst, C816(src[1])); dst += 2;
|
2004-12-13 14:31:36 +01:00
|
|
|
}
|
2017-06-15 20:25:48 +02:00
|
|
|
src += 2;
|
2000-10-23 01:49:40 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-06-15 20:25:48 +02:00
|
|
|
static void cvtSM816C(const DWORD srcRate, const unsigned char *src, DWORD *nsrc,
|
|
|
|
const DWORD dstRate, unsigned char *dst, DWORD *ndst)
|
2000-10-23 01:49:40 +02:00
|
|
|
{
|
2017-06-15 20:25:48 +02:00
|
|
|
DWORD error = srcRate / 2;
|
|
|
|
DWORD maxSrc = *nsrc, maxDst = *ndst;
|
|
|
|
*ndst = 0;
|
|
|
|
for (*nsrc = 0; *nsrc < maxSrc; (*nsrc)++) {
|
|
|
|
error += dstRate;
|
|
|
|
while (error > srcRate) {
|
|
|
|
if (*ndst == maxDst)
|
2004-12-13 14:31:36 +01:00
|
|
|
return;
|
2017-06-15 20:25:48 +02:00
|
|
|
(*ndst)++;
|
|
|
|
error -= srcRate;
|
|
|
|
|
|
|
|
W16(dst, M16(C816(src[0]), C816(src[1]))); dst += 2;
|
2004-12-13 14:31:36 +01:00
|
|
|
}
|
2017-06-15 20:25:48 +02:00
|
|
|
src += 2;
|
2000-10-23 01:49:40 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-06-15 20:25:48 +02:00
|
|
|
static void cvtMS816C(const DWORD srcRate, const unsigned char *src, DWORD *nsrc,
|
|
|
|
const DWORD dstRate, unsigned char *dst, DWORD *ndst)
|
2000-10-23 01:49:40 +02:00
|
|
|
{
|
2017-06-15 20:25:48 +02:00
|
|
|
DWORD error = srcRate / 2;
|
|
|
|
DWORD maxSrc = *nsrc, maxDst = *ndst;
|
|
|
|
*ndst = 0;
|
|
|
|
for (*nsrc = 0; *nsrc < maxSrc; (*nsrc)++) {
|
|
|
|
error += dstRate;
|
|
|
|
while (error > srcRate) {
|
|
|
|
if (*ndst == maxDst)
|
2004-12-13 14:31:36 +01:00
|
|
|
return;
|
2017-06-15 20:25:48 +02:00
|
|
|
(*ndst)++;
|
|
|
|
error -= srcRate;
|
|
|
|
|
|
|
|
W16(dst, C816(src[0])); dst += 2;
|
|
|
|
W16(dst, C816(src[0])); dst += 2;
|
2004-12-13 14:31:36 +01:00
|
|
|
}
|
2017-06-15 20:25:48 +02:00
|
|
|
src += 1;
|
2000-10-23 01:49:40 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-06-15 20:25:48 +02:00
|
|
|
static void cvtMM816C(const DWORD srcRate, const unsigned char *src, DWORD *nsrc,
|
|
|
|
const DWORD dstRate, unsigned char *dst, DWORD *ndst)
|
2000-10-23 01:49:40 +02:00
|
|
|
{
|
2017-06-15 20:25:48 +02:00
|
|
|
DWORD error = srcRate / 2;
|
|
|
|
DWORD maxSrc = *nsrc, maxDst = *ndst;
|
|
|
|
*ndst = 0;
|
|
|
|
for (*nsrc = 0; *nsrc < maxSrc; (*nsrc)++) {
|
|
|
|
error += dstRate;
|
|
|
|
while (error > srcRate) {
|
|
|
|
if (*ndst == maxDst)
|
2004-12-13 14:31:36 +01:00
|
|
|
return;
|
2017-06-15 20:25:48 +02:00
|
|
|
(*ndst)++;
|
|
|
|
error -= srcRate;
|
|
|
|
|
|
|
|
W16(dst, C816(src[0])); dst += 2;
|
2004-03-12 21:24:50 +01:00
|
|
|
}
|
2017-06-15 20:25:48 +02:00
|
|
|
src += 1;
|
2000-10-23 01:49:40 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-06-15 20:25:48 +02:00
|
|
|
static void cvtSS168C(const DWORD srcRate, const unsigned char *src, DWORD *nsrc,
|
|
|
|
const DWORD dstRate, unsigned char *dst, DWORD *ndst)
|
2000-10-23 01:49:40 +02:00
|
|
|
{
|
2017-06-15 20:25:48 +02:00
|
|
|
DWORD error = srcRate / 2;
|
|
|
|
DWORD maxSrc = *nsrc, maxDst = *ndst;
|
|
|
|
*ndst = 0;
|
|
|
|
for (*nsrc = 0; *nsrc < maxSrc; (*nsrc)++) {
|
|
|
|
error += dstRate;
|
|
|
|
while (error > srcRate) {
|
|
|
|
if (*ndst == maxDst)
|
2004-12-13 14:31:36 +01:00
|
|
|
return;
|
2017-06-15 20:25:48 +02:00
|
|
|
(*ndst)++;
|
|
|
|
error -= srcRate;
|
|
|
|
|
|
|
|
*dst++ = C168(R16(src));
|
|
|
|
*dst++ = C168(R16(src + 2));
|
2004-12-13 14:31:36 +01:00
|
|
|
}
|
2017-06-15 20:25:48 +02:00
|
|
|
src += 4;
|
2000-10-23 01:49:40 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-06-15 20:25:48 +02:00
|
|
|
static void cvtSM168C(const DWORD srcRate, const unsigned char *src, DWORD *nsrc,
|
|
|
|
const DWORD dstRate, unsigned char *dst, DWORD *ndst)
|
2000-10-23 01:49:40 +02:00
|
|
|
{
|
2017-06-15 20:25:48 +02:00
|
|
|
DWORD error = srcRate / 2;
|
|
|
|
DWORD maxSrc = *nsrc, maxDst = *ndst;
|
|
|
|
*ndst = 0;
|
|
|
|
for (*nsrc = 0; *nsrc < maxSrc; (*nsrc)++) {
|
|
|
|
error += dstRate;
|
|
|
|
while (error > srcRate) {
|
|
|
|
if (*ndst == maxDst)
|
2004-12-13 14:31:36 +01:00
|
|
|
return;
|
2017-06-15 20:25:48 +02:00
|
|
|
(*ndst)++;
|
|
|
|
error -= srcRate;
|
|
|
|
|
|
|
|
*dst++ = C168(M16(R16(src), R16(src + 2)));
|
2004-12-13 14:31:36 +01:00
|
|
|
}
|
2017-06-15 20:25:48 +02:00
|
|
|
src += 4;
|
2000-10-23 01:49:40 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-06-15 20:25:48 +02:00
|
|
|
static void cvtMS168C(const DWORD srcRate, const unsigned char *src, DWORD *nsrc,
|
|
|
|
const DWORD dstRate, unsigned char *dst, DWORD *ndst)
|
2004-12-13 14:31:36 +01:00
|
|
|
{
|
2017-06-15 20:25:48 +02:00
|
|
|
DWORD error = srcRate / 2;
|
|
|
|
DWORD maxSrc = *nsrc, maxDst = *ndst;
|
|
|
|
*ndst = 0;
|
|
|
|
for (*nsrc = 0; *nsrc < maxSrc; (*nsrc)++) {
|
|
|
|
error += dstRate;
|
|
|
|
while (error > srcRate) {
|
|
|
|
if (*ndst == maxDst)
|
2004-12-13 14:31:36 +01:00
|
|
|
return;
|
2017-06-15 20:25:48 +02:00
|
|
|
(*ndst)++;
|
|
|
|
error -= srcRate;
|
|
|
|
|
|
|
|
*dst++ = C168(R16(src));
|
|
|
|
*dst++ = C168(R16(src));
|
2004-12-13 14:31:36 +01:00
|
|
|
}
|
2017-06-15 20:25:48 +02:00
|
|
|
src += 2;
|
2004-12-13 14:31:36 +01:00
|
|
|
}
|
|
|
|
}
|
2000-10-23 01:49:40 +02:00
|
|
|
|
2017-06-15 20:25:48 +02:00
|
|
|
static void cvtMM168C(const DWORD srcRate, const unsigned char *src, DWORD *nsrc,
|
|
|
|
const DWORD dstRate, unsigned char *dst, DWORD *ndst)
|
2000-10-23 01:49:40 +02:00
|
|
|
{
|
2017-06-15 20:25:48 +02:00
|
|
|
DWORD error = srcRate / 2;
|
|
|
|
DWORD maxSrc = *nsrc, maxDst = *ndst;
|
|
|
|
*ndst = 0;
|
|
|
|
for (*nsrc = 0; *nsrc < maxSrc; (*nsrc)++) {
|
|
|
|
error += dstRate;
|
|
|
|
while (error > srcRate) {
|
|
|
|
if (*ndst == maxDst)
|
2004-12-13 14:31:36 +01:00
|
|
|
return;
|
2017-06-15 20:25:48 +02:00
|
|
|
(*ndst)++;
|
|
|
|
error -= srcRate;
|
|
|
|
|
|
|
|
*dst++ = C168(R16(src));
|
2004-12-13 14:31:36 +01:00
|
|
|
}
|
2017-06-15 20:25:48 +02:00
|
|
|
src += 2;
|
2000-10-23 01:49:40 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-06-15 20:25:48 +02:00
|
|
|
static void cvtSS1616C(const DWORD srcRate, const unsigned char *src, DWORD *nsrc,
|
|
|
|
const DWORD dstRate, unsigned char *dst, DWORD *ndst)
|
2000-10-23 01:49:40 +02:00
|
|
|
{
|
2017-06-15 20:25:48 +02:00
|
|
|
DWORD error = srcRate / 2;
|
|
|
|
DWORD maxSrc = *nsrc, maxDst = *ndst;
|
|
|
|
*ndst = 0;
|
|
|
|
for (*nsrc = 0; *nsrc < maxSrc; (*nsrc)++) {
|
|
|
|
error += dstRate;
|
|
|
|
while (error > srcRate) {
|
|
|
|
if (*ndst == maxDst)
|
2004-12-13 14:31:36 +01:00
|
|
|
return;
|
2017-06-15 20:25:48 +02:00
|
|
|
(*ndst)++;
|
|
|
|
error -= srcRate;
|
|
|
|
|
|
|
|
W16(dst, R16(src)); dst += 2;
|
|
|
|
W16(dst, R16(src + 2)); dst += 2;
|
2004-12-13 14:31:36 +01:00
|
|
|
}
|
2017-06-15 20:25:48 +02:00
|
|
|
src += 4;
|
2000-10-23 01:49:40 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-06-15 20:25:48 +02:00
|
|
|
static void cvtSM1616C(const DWORD srcRate, const unsigned char *src, DWORD *nsrc,
|
|
|
|
const DWORD dstRate, unsigned char *dst, DWORD *ndst)
|
2000-10-23 01:49:40 +02:00
|
|
|
{
|
2017-06-15 20:25:48 +02:00
|
|
|
DWORD error = srcRate / 2;
|
|
|
|
DWORD maxSrc = *nsrc, maxDst = *ndst;
|
|
|
|
*ndst = 0;
|
|
|
|
for (*nsrc = 0; *nsrc < maxSrc; (*nsrc)++) {
|
|
|
|
error += dstRate;
|
|
|
|
while (error > srcRate) {
|
|
|
|
if (*ndst == maxDst)
|
2004-12-13 14:31:36 +01:00
|
|
|
return;
|
2017-06-15 20:25:48 +02:00
|
|
|
(*ndst)++;
|
|
|
|
error -= srcRate;
|
|
|
|
|
|
|
|
W16(dst, M16(R16(src), R16(src + 2))); dst += 2;
|
2004-12-13 14:31:36 +01:00
|
|
|
}
|
2017-06-15 20:25:48 +02:00
|
|
|
src += 4;
|
2000-10-23 01:49:40 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-06-15 20:25:48 +02:00
|
|
|
static void cvtMS1616C(const DWORD srcRate, const unsigned char *src, DWORD *nsrc,
|
|
|
|
const DWORD dstRate, unsigned char *dst, DWORD *ndst)
|
2000-10-23 01:49:40 +02:00
|
|
|
{
|
2017-06-15 20:25:48 +02:00
|
|
|
DWORD error = srcRate / 2;
|
|
|
|
DWORD maxSrc = *nsrc, maxDst = *ndst;
|
|
|
|
*ndst = 0;
|
|
|
|
for (*nsrc = 0; *nsrc < maxSrc; (*nsrc)++) {
|
|
|
|
error += dstRate;
|
|
|
|
while (error > srcRate) {
|
|
|
|
if (*ndst == maxDst)
|
2004-12-13 14:31:36 +01:00
|
|
|
return;
|
2017-06-15 20:25:48 +02:00
|
|
|
(*ndst)++;
|
|
|
|
error -= srcRate;
|
|
|
|
|
|
|
|
W16(dst, R16(src)); dst += 2;
|
|
|
|
W16(dst, R16(src)); dst += 2;
|
2004-12-13 14:31:36 +01:00
|
|
|
}
|
2017-06-15 20:25:48 +02:00
|
|
|
src += 2;
|
2000-10-23 01:49:40 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-06-15 20:25:48 +02:00
|
|
|
static void cvtMM1616C(const DWORD srcRate, const unsigned char *src, DWORD *nsrc,
|
|
|
|
const DWORD dstRate, unsigned char *dst, DWORD *ndst)
|
2000-10-23 01:49:40 +02:00
|
|
|
{
|
2017-06-15 20:25:48 +02:00
|
|
|
DWORD error = srcRate / 2;
|
|
|
|
DWORD maxSrc = *nsrc, maxDst = *ndst;
|
|
|
|
*ndst = 0;
|
|
|
|
for (*nsrc = 0; *nsrc < maxSrc; (*nsrc)++) {
|
|
|
|
error += dstRate;
|
|
|
|
while (error > srcRate) {
|
|
|
|
if (*ndst == maxDst)
|
2004-12-13 14:31:36 +01:00
|
|
|
return;
|
2017-06-15 20:25:48 +02:00
|
|
|
(*ndst)++;
|
|
|
|
error -= srcRate;
|
|
|
|
|
|
|
|
W16(dst, R16(src)); dst += 2;
|
2004-12-13 14:31:36 +01:00
|
|
|
}
|
2017-06-15 20:25:48 +02:00
|
|
|
src += 2;
|
2000-10-23 01:49:40 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-06-15 20:25:48 +02:00
|
|
|
static void cvtSS2424C(const DWORD srcRate, const unsigned char *src, DWORD *nsrc,
|
|
|
|
const DWORD dstRate, unsigned char *dst, DWORD *ndst)
|
2016-12-05 18:28:25 +01:00
|
|
|
{
|
2017-06-15 20:25:48 +02:00
|
|
|
DWORD error = srcRate / 2;
|
|
|
|
DWORD maxSrc = *nsrc, maxDst = *ndst;
|
|
|
|
*ndst = 0;
|
|
|
|
for (*nsrc = 0; *nsrc < maxSrc; (*nsrc)++) {
|
|
|
|
error += dstRate;
|
|
|
|
while (error > srcRate) {
|
|
|
|
if (*ndst == maxDst)
|
2016-12-05 18:28:25 +01:00
|
|
|
return;
|
2017-06-15 20:25:48 +02:00
|
|
|
(*ndst)++;
|
|
|
|
error -= srcRate;
|
|
|
|
|
|
|
|
W24(dst, R24(src)); dst += 3;
|
|
|
|
W24(dst, R24(src + 3)); dst += 3;
|
2016-12-05 18:28:25 +01:00
|
|
|
}
|
2017-06-15 20:25:48 +02:00
|
|
|
src += 6;
|
2016-12-05 18:28:25 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-06-15 20:25:48 +02:00
|
|
|
static void cvtSM2424C(const DWORD srcRate, const unsigned char *src, DWORD *nsrc,
|
|
|
|
const DWORD dstRate, unsigned char *dst, DWORD *ndst)
|
2016-12-05 18:28:25 +01:00
|
|
|
{
|
2017-06-15 20:25:48 +02:00
|
|
|
DWORD error = srcRate / 2;
|
|
|
|
DWORD maxSrc = *nsrc, maxDst = *ndst;
|
|
|
|
*ndst = 0;
|
|
|
|
for (*nsrc = 0; *nsrc < maxSrc; (*nsrc)++) {
|
|
|
|
error += dstRate;
|
|
|
|
while (error > srcRate) {
|
|
|
|
if (*ndst == maxDst)
|
2016-12-05 18:28:25 +01:00
|
|
|
return;
|
2017-06-15 20:25:48 +02:00
|
|
|
(*ndst)++;
|
|
|
|
error -= srcRate;
|
|
|
|
|
|
|
|
W24(dst, M24(R24(src), R24(src + 3))); dst += 3;
|
2016-12-05 18:28:25 +01:00
|
|
|
}
|
2017-06-15 20:25:48 +02:00
|
|
|
src += 6;
|
2016-12-05 18:28:25 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-06-15 20:25:48 +02:00
|
|
|
static void cvtMS2424C(const DWORD srcRate, const unsigned char *src, DWORD *nsrc,
|
|
|
|
const DWORD dstRate, unsigned char *dst, DWORD *ndst)
|
2016-12-05 18:28:25 +01:00
|
|
|
{
|
2017-06-15 20:25:48 +02:00
|
|
|
DWORD error = srcRate / 2;
|
|
|
|
DWORD maxSrc = *nsrc, maxDst = *ndst;
|
|
|
|
*ndst = 0;
|
|
|
|
for (*nsrc = 0; *nsrc < maxSrc; (*nsrc)++) {
|
|
|
|
error += dstRate;
|
|
|
|
while (error > srcRate) {
|
|
|
|
if (*ndst == maxDst)
|
2016-12-05 18:28:25 +01:00
|
|
|
return;
|
2017-06-15 20:25:48 +02:00
|
|
|
(*ndst)++;
|
|
|
|
error -= srcRate;
|
|
|
|
|
|
|
|
W24(dst, R24(src)); dst += 3;
|
|
|
|
W24(dst, R24(src)); dst += 3;
|
2016-12-05 18:28:25 +01:00
|
|
|
}
|
2017-06-15 20:25:48 +02:00
|
|
|
src += 3;
|
2016-12-05 18:28:25 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-06-15 20:25:48 +02:00
|
|
|
static void cvtMM2424C(const DWORD srcRate, const unsigned char *src, DWORD *nsrc,
|
|
|
|
const DWORD dstRate, unsigned char *dst, DWORD *ndst)
|
2016-12-05 18:28:25 +01:00
|
|
|
{
|
2017-06-15 20:25:48 +02:00
|
|
|
DWORD error = srcRate / 2;
|
|
|
|
DWORD maxSrc = *nsrc, maxDst = *ndst;
|
|
|
|
*ndst = 0;
|
|
|
|
for (*nsrc = 0; *nsrc < maxSrc; (*nsrc)++) {
|
|
|
|
error += dstRate;
|
|
|
|
while (error > srcRate) {
|
|
|
|
if (*ndst == maxDst)
|
2016-12-05 18:28:25 +01:00
|
|
|
return;
|
2017-06-15 20:25:48 +02:00
|
|
|
(*ndst)++;
|
|
|
|
error -= srcRate;
|
|
|
|
|
|
|
|
W24(dst, R24(src)); dst += 3;
|
2016-12-05 18:28:25 +01:00
|
|
|
}
|
2017-06-15 20:25:48 +02:00
|
|
|
src += 3;
|
2016-12-05 18:28:25 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static const PCM_CONVERT_CHANGE_RATE PCM_ConvertChangeRate[] = {
|
2000-10-23 01:49:40 +02:00
|
|
|
cvtSS88C, cvtSM88C, cvtMS88C, cvtMM88C,
|
|
|
|
cvtSS816C, cvtSM816C, cvtMS816C, cvtMM816C,
|
2016-12-05 18:28:25 +01:00
|
|
|
NULL, NULL, NULL, NULL, /* TODO: 8->24 */
|
2000-10-23 01:49:40 +02:00
|
|
|
cvtSS168C, cvtSM168C, cvtMS168C, cvtMM168C,
|
|
|
|
cvtSS1616C, cvtSM1616C, cvtMS1616C, cvtMM1616C,
|
2016-12-05 18:28:25 +01:00
|
|
|
NULL, NULL, NULL, NULL, /* TODO: 16->24 */
|
|
|
|
NULL, NULL, NULL, NULL, /* TODO: 24->8 */
|
|
|
|
NULL, NULL, NULL, NULL, /* TODO: 24->16 */
|
|
|
|
cvtSS2424C, cvtSM2424C, cvtMS2424C, cvtMM2424C,
|
2000-10-23 01:49:40 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* PCM_DriverDetails
|
|
|
|
*
|
|
|
|
*/
|
2000-10-12 22:46:49 +02:00
|
|
|
static LRESULT PCM_DriverDetails(PACMDRIVERDETAILSW add)
|
|
|
|
{
|
2004-03-12 21:24:50 +01:00
|
|
|
TRACE("(%p)\n", add);
|
|
|
|
|
2000-10-12 22:46:49 +02:00
|
|
|
add->fccType = ACMDRIVERDETAILS_FCCTYPE_AUDIOCODEC;
|
|
|
|
add->fccComp = ACMDRIVERDETAILS_FCCCOMP_UNDEFINED;
|
2015-05-26 22:09:31 +02:00
|
|
|
add->wMid = MM_MICROSOFT;
|
|
|
|
add->wPid = MM_MSFT_ACM_PCM;
|
2000-10-12 22:46:49 +02:00
|
|
|
add->vdwACM = 0x01000000;
|
|
|
|
add->vdwDriver = 0x01000000;
|
|
|
|
add->fdwSupport = ACMDRIVERDETAILS_SUPPORTF_CONVERTER;
|
|
|
|
add->cFormatTags = 1;
|
|
|
|
add->cFilterTags = 0;
|
2002-12-02 19:10:57 +01:00
|
|
|
add->hicon = NULL;
|
2018-07-26 00:05:50 +02:00
|
|
|
MultiByteToWideChar(CP_ACP, 0, "MS-PCM", -1, add->szShortName, ARRAY_SIZE(add->szShortName));
|
|
|
|
MultiByteToWideChar(CP_ACP, 0, "Wine PCM converter", -1,
|
|
|
|
add->szLongName, ARRAY_SIZE(add->szLongName));
|
|
|
|
MultiByteToWideChar(CP_ACP, 0, "Brought to you by the Wine team...", -1,
|
|
|
|
add->szCopyright, ARRAY_SIZE(add->szCopyright));
|
|
|
|
MultiByteToWideChar(CP_ACP, 0, "Refer to LICENSE file", -1,
|
|
|
|
add->szLicensing, ARRAY_SIZE(add->szLicensing) );
|
2000-10-12 22:46:49 +02:00
|
|
|
add->szFeatures[0] = 0;
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2000-10-12 22:46:49 +02:00
|
|
|
return MMSYSERR_NOERROR;
|
|
|
|
}
|
|
|
|
|
2000-10-23 01:49:40 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* PCM_FormatTagDetails
|
|
|
|
*
|
|
|
|
*/
|
2000-10-12 22:46:49 +02:00
|
|
|
static LRESULT PCM_FormatTagDetails(PACMFORMATTAGDETAILSW aftd, DWORD dwQuery)
|
|
|
|
{
|
2006-10-12 21:35:06 +02:00
|
|
|
TRACE("(%p, %08x)\n", aftd, dwQuery);
|
2004-03-12 21:24:50 +01:00
|
|
|
|
2000-10-12 22:46:49 +02:00
|
|
|
switch (dwQuery) {
|
|
|
|
case ACM_FORMATTAGDETAILSF_INDEX:
|
2004-03-12 21:24:50 +01:00
|
|
|
if (aftd->dwFormatTagIndex != 0) {
|
|
|
|
WARN("not possible\n");
|
|
|
|
return ACMERR_NOTPOSSIBLE;
|
|
|
|
}
|
2000-10-12 22:46:49 +02:00
|
|
|
break;
|
2002-06-01 01:06:46 +02:00
|
|
|
case ACM_FORMATTAGDETAILSF_FORMATTAG:
|
2004-03-12 21:24:50 +01:00
|
|
|
if (aftd->dwFormatTag != WAVE_FORMAT_PCM) {
|
|
|
|
WARN("not possible\n");
|
|
|
|
return ACMERR_NOTPOSSIBLE;
|
|
|
|
}
|
2000-10-12 22:46:49 +02:00
|
|
|
break;
|
|
|
|
case ACM_FORMATTAGDETAILSF_LARGESTSIZE:
|
2002-06-01 01:06:46 +02:00
|
|
|
if (aftd->dwFormatTag != WAVE_FORMAT_UNKNOWN &&
|
2004-03-12 21:24:50 +01:00
|
|
|
aftd->dwFormatTag != WAVE_FORMAT_PCM) {
|
|
|
|
WARN("not possible\n");
|
2000-10-12 22:46:49 +02:00
|
|
|
return ACMERR_NOTPOSSIBLE;
|
2004-03-12 21:24:50 +01:00
|
|
|
}
|
2000-10-12 22:46:49 +02:00
|
|
|
break;
|
|
|
|
default:
|
2006-10-12 21:35:06 +02:00
|
|
|
WARN("Unsupported query %08x\n", dwQuery);
|
2000-10-12 22:46:49 +02:00
|
|
|
return MMSYSERR_NOTSUPPORTED;
|
|
|
|
}
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2000-10-12 22:46:49 +02:00
|
|
|
aftd->dwFormatTagIndex = 0;
|
|
|
|
aftd->dwFormatTag = WAVE_FORMAT_PCM;
|
|
|
|
aftd->cbFormatSize = sizeof(PCMWAVEFORMAT);
|
|
|
|
aftd->fdwSupport = ACMDRIVERDETAILS_SUPPORTF_CONVERTER;
|
2018-07-11 22:06:17 +02:00
|
|
|
aftd->cStandardFormats = ARRAY_SIZE(PCM_Formats);
|
2000-10-12 22:46:49 +02:00
|
|
|
aftd->szFormatTag[0] = 0;
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2000-10-12 22:46:49 +02:00
|
|
|
return MMSYSERR_NOERROR;
|
|
|
|
}
|
|
|
|
|
2000-10-23 01:49:40 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* PCM_FormatDetails
|
|
|
|
*
|
|
|
|
*/
|
2000-10-12 22:46:49 +02:00
|
|
|
static LRESULT PCM_FormatDetails(PACMFORMATDETAILSW afd, DWORD dwQuery)
|
|
|
|
{
|
2006-10-12 21:35:06 +02:00
|
|
|
TRACE("(%p, %08x)\n", afd, dwQuery);
|
2004-03-12 21:24:50 +01:00
|
|
|
|
2000-10-12 22:46:49 +02:00
|
|
|
switch (dwQuery) {
|
|
|
|
case ACM_FORMATDETAILSF_FORMAT:
|
2004-03-12 21:24:50 +01:00
|
|
|
if (PCM_GetFormatIndex(afd->pwfx) == 0xFFFFFFFF) {
|
|
|
|
WARN("not possible\n");
|
2005-01-09 17:42:53 +01:00
|
|
|
return ACMERR_NOTPOSSIBLE;
|
2004-03-12 21:24:50 +01:00
|
|
|
}
|
2000-10-12 22:46:49 +02:00
|
|
|
break;
|
|
|
|
case ACM_FORMATDETAILSF_INDEX:
|
2018-07-11 22:06:17 +02:00
|
|
|
assert(afd->dwFormatIndex < ARRAY_SIZE(PCM_Formats));
|
2000-10-12 22:46:49 +02:00
|
|
|
afd->pwfx->wFormatTag = WAVE_FORMAT_PCM;
|
|
|
|
afd->pwfx->nChannels = PCM_Formats[afd->dwFormatIndex].nChannels;
|
|
|
|
afd->pwfx->nSamplesPerSec = PCM_Formats[afd->dwFormatIndex].rate;
|
|
|
|
afd->pwfx->wBitsPerSample = PCM_Formats[afd->dwFormatIndex].nBits;
|
2002-12-15 02:12:03 +01:00
|
|
|
/* native MSACM uses a PCMWAVEFORMAT structure, so cbSize is not
|
|
|
|
* accessible afd->pwfx->cbSize = 0;
|
2000-10-23 01:49:40 +02:00
|
|
|
*/
|
2002-06-01 01:06:46 +02:00
|
|
|
afd->pwfx->nBlockAlign =
|
2000-10-23 01:49:40 +02:00
|
|
|
(afd->pwfx->nChannels * afd->pwfx->wBitsPerSample) / 8;
|
2002-06-01 01:06:46 +02:00
|
|
|
afd->pwfx->nAvgBytesPerSec =
|
2000-10-23 01:49:40 +02:00
|
|
|
afd->pwfx->nSamplesPerSec * afd->pwfx->nBlockAlign;
|
2000-10-12 22:46:49 +02:00
|
|
|
break;
|
|
|
|
default:
|
2006-10-12 21:35:06 +02:00
|
|
|
WARN("Unsupported query %08x\n", dwQuery);
|
2002-06-01 01:06:46 +02:00
|
|
|
return MMSYSERR_NOTSUPPORTED;
|
2000-10-12 22:46:49 +02:00
|
|
|
}
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2000-10-12 22:46:49 +02:00
|
|
|
afd->dwFormatTag = WAVE_FORMAT_PCM;
|
|
|
|
afd->fdwSupport = ACMDRIVERDETAILS_SUPPORTF_CONVERTER;
|
|
|
|
afd->szFormat[0] = 0; /* let MSACM format this for us... */
|
2001-04-23 20:14:41 +02:00
|
|
|
afd->cbwfx = sizeof(PCMWAVEFORMAT);
|
|
|
|
|
2000-10-12 22:46:49 +02:00
|
|
|
return MMSYSERR_NOERROR;
|
|
|
|
}
|
|
|
|
|
2000-10-23 01:49:40 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* PCM_FormatSuggest
|
|
|
|
*
|
|
|
|
*/
|
2000-10-12 22:46:49 +02:00
|
|
|
static LRESULT PCM_FormatSuggest(PACMDRVFORMATSUGGEST adfs)
|
|
|
|
{
|
2004-03-12 21:24:50 +01:00
|
|
|
TRACE("(%p)\n", adfs);
|
|
|
|
|
2001-05-22 21:21:16 +02:00
|
|
|
/* some tests ... */
|
|
|
|
if (adfs->cbwfxSrc < sizeof(PCMWAVEFORMAT) ||
|
2015-09-09 06:10:55 +02:00
|
|
|
adfs->cbwfxDst < sizeof(PCMWAVEFORMAT) ||
|
|
|
|
PCM_GetFormatIndex(adfs->pwfxSrc) == 0xFFFFFFFF) {
|
2004-03-12 21:24:50 +01:00
|
|
|
WARN("not possible\n");
|
|
|
|
return ACMERR_NOTPOSSIBLE;
|
2004-12-13 14:31:36 +01:00
|
|
|
}
|
2001-05-22 21:21:16 +02:00
|
|
|
|
|
|
|
/* is no suggestion for destination, then copy source value */
|
|
|
|
if (!(adfs->fdwSuggest & ACM_FORMATSUGGESTF_NCHANNELS)) {
|
2015-09-09 06:10:55 +02:00
|
|
|
adfs->pwfxDst->nChannels = adfs->pwfxSrc->nChannels;
|
2001-05-22 21:21:16 +02:00
|
|
|
}
|
|
|
|
if (!(adfs->fdwSuggest & ACM_FORMATSUGGESTF_NSAMPLESPERSEC)) {
|
2015-09-09 06:10:55 +02:00
|
|
|
adfs->pwfxDst->nSamplesPerSec = adfs->pwfxSrc->nSamplesPerSec;
|
2001-05-22 21:21:16 +02:00
|
|
|
}
|
|
|
|
if (!(adfs->fdwSuggest & ACM_FORMATSUGGESTF_WBITSPERSAMPLE)) {
|
2015-09-09 06:10:55 +02:00
|
|
|
adfs->pwfxDst->wBitsPerSample = adfs->pwfxSrc->wBitsPerSample;
|
2001-05-22 21:21:16 +02:00
|
|
|
}
|
|
|
|
if (!(adfs->fdwSuggest & ACM_FORMATSUGGESTF_WFORMATTAG)) {
|
2015-09-09 06:10:55 +02:00
|
|
|
if (adfs->pwfxSrc->wFormatTag != WAVE_FORMAT_PCM) {
|
|
|
|
WARN("source format 0x%x not supported\n", adfs->pwfxSrc->wFormatTag);
|
|
|
|
return ACMERR_NOTPOSSIBLE;
|
|
|
|
}
|
|
|
|
adfs->pwfxDst->wFormatTag = adfs->pwfxSrc->wFormatTag;
|
|
|
|
} else {
|
|
|
|
if (adfs->pwfxDst->wFormatTag != WAVE_FORMAT_PCM) {
|
|
|
|
WARN("destination format 0x%x not supported\n", adfs->pwfxDst->wFormatTag);
|
2004-03-12 21:24:50 +01:00
|
|
|
return ACMERR_NOTPOSSIBLE;
|
2004-05-10 21:56:53 +02:00
|
|
|
}
|
2001-05-22 21:21:16 +02:00
|
|
|
}
|
|
|
|
/* check if result is ok */
|
2004-03-12 21:24:50 +01:00
|
|
|
if (PCM_GetFormatIndex(adfs->pwfxDst) == 0xFFFFFFFF) {
|
|
|
|
WARN("not possible\n");
|
|
|
|
return ACMERR_NOTPOSSIBLE;
|
|
|
|
}
|
2001-05-22 21:21:16 +02:00
|
|
|
|
|
|
|
/* recompute other values */
|
|
|
|
adfs->pwfxDst->nBlockAlign = (adfs->pwfxDst->nChannels * adfs->pwfxDst->wBitsPerSample) / 8;
|
|
|
|
adfs->pwfxDst->nAvgBytesPerSec = adfs->pwfxDst->nSamplesPerSec * adfs->pwfxDst->nBlockAlign;
|
|
|
|
|
|
|
|
return MMSYSERR_NOERROR;
|
2000-10-12 22:46:49 +02:00
|
|
|
}
|
|
|
|
|
2000-10-23 01:49:40 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* PCM_StreamOpen
|
|
|
|
*
|
|
|
|
*/
|
2000-10-12 22:46:49 +02:00
|
|
|
static LRESULT PCM_StreamOpen(PACMDRVSTREAMINSTANCE adsi)
|
|
|
|
{
|
2016-12-05 18:28:25 +01:00
|
|
|
AcmPcmData* apd;
|
|
|
|
int idx;
|
|
|
|
DWORD flags;
|
2000-10-23 01:49:40 +02:00
|
|
|
|
2004-03-12 21:24:50 +01:00
|
|
|
TRACE("(%p)\n", adsi);
|
|
|
|
|
2000-10-12 22:46:49 +02:00
|
|
|
assert(!(adsi->fdwOpen & ACM_STREAMOPENF_ASYNC));
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2016-12-05 18:28:25 +01:00
|
|
|
switch(adsi->pwfxSrc->wBitsPerSample){
|
|
|
|
case 8:
|
|
|
|
idx = 0;
|
|
|
|
break;
|
|
|
|
case 16:
|
|
|
|
idx = 12;
|
|
|
|
break;
|
|
|
|
case 24:
|
|
|
|
if (adsi->pwfxSrc->nBlockAlign != 3 * adsi->pwfxSrc->nChannels) {
|
|
|
|
FIXME("Source: 24-bit samples must be packed\n");
|
|
|
|
return MMSYSERR_NOTSUPPORTED;
|
|
|
|
}
|
|
|
|
idx = 24;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
FIXME("Unsupported source bit depth: %u\n", adsi->pwfxSrc->wBitsPerSample);
|
|
|
|
return MMSYSERR_NOTSUPPORTED;
|
2004-03-12 21:24:50 +01:00
|
|
|
}
|
2000-10-23 01:49:40 +02:00
|
|
|
|
2016-12-05 18:28:25 +01:00
|
|
|
switch(adsi->pwfxDst->wBitsPerSample){
|
|
|
|
case 8:
|
|
|
|
break;
|
|
|
|
case 16:
|
|
|
|
idx += 4;
|
|
|
|
break;
|
|
|
|
case 24:
|
2016-12-12 14:42:56 +01:00
|
|
|
if (adsi->pwfxDst->nBlockAlign != 3 * adsi->pwfxDst->nChannels) {
|
2016-12-05 18:28:25 +01:00
|
|
|
FIXME("Destination: 24-bit samples must be packed\n");
|
|
|
|
return MMSYSERR_NOTSUPPORTED;
|
|
|
|
}
|
|
|
|
idx += 8;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
FIXME("Unsupported destination bit depth: %u\n", adsi->pwfxDst->wBitsPerSample);
|
|
|
|
return MMSYSERR_NOTSUPPORTED;
|
|
|
|
}
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2000-10-23 01:49:40 +02:00
|
|
|
if (adsi->pwfxSrc->nChannels == 1) idx += 2;
|
2016-12-05 18:28:25 +01:00
|
|
|
|
2000-10-23 01:49:40 +02:00
|
|
|
if (adsi->pwfxDst->nChannels == 1) idx += 1;
|
|
|
|
|
2016-12-05 18:28:25 +01:00
|
|
|
apd = HeapAlloc(GetProcessHeap(), 0, sizeof(AcmPcmData));
|
|
|
|
if (!apd)
|
|
|
|
return MMSYSERR_NOMEM;
|
|
|
|
|
2000-10-23 01:49:40 +02:00
|
|
|
if (adsi->pwfxSrc->nSamplesPerSec == adsi->pwfxDst->nSamplesPerSec) {
|
2016-12-05 18:28:25 +01:00
|
|
|
flags = 0;
|
|
|
|
apd->cvt.cvtKeepRate = PCM_ConvertKeepRate[idx];
|
2000-10-23 01:49:40 +02:00
|
|
|
} else {
|
2016-12-05 18:28:25 +01:00
|
|
|
flags = PCM_RESAMPLE;
|
|
|
|
apd->cvt.cvtChangeRate = PCM_ConvertChangeRate[idx];
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!apd->cvt.cvtChangeRate && !apd->cvt.cvtKeepRate){
|
|
|
|
FIXME("Unimplemented conversion from %u -> %u bps\n",
|
|
|
|
adsi->pwfxSrc->wBitsPerSample,
|
|
|
|
adsi->pwfxDst->wBitsPerSample);
|
|
|
|
HeapFree(GetProcessHeap(), 0, apd);
|
|
|
|
return MMSYSERR_NOTSUPPORTED;
|
2000-10-23 01:49:40 +02:00
|
|
|
}
|
|
|
|
|
2016-12-05 18:28:25 +01:00
|
|
|
adsi->dwDriver = (DWORD_PTR)apd;
|
|
|
|
adsi->fdwDriver = flags;
|
|
|
|
|
2000-10-12 22:46:49 +02:00
|
|
|
return MMSYSERR_NOERROR;
|
|
|
|
}
|
|
|
|
|
2000-10-23 01:49:40 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* PCM_StreamClose
|
|
|
|
*
|
|
|
|
*/
|
2000-10-12 22:46:49 +02:00
|
|
|
static LRESULT PCM_StreamClose(PACMDRVSTREAMINSTANCE adsi)
|
|
|
|
{
|
2004-03-12 21:24:50 +01:00
|
|
|
TRACE("(%p)\n", adsi);
|
|
|
|
|
2000-10-23 01:49:40 +02:00
|
|
|
HeapFree(GetProcessHeap(), 0, (void*)adsi->dwDriver);
|
2000-10-12 22:46:49 +02:00
|
|
|
return MMSYSERR_NOERROR;
|
|
|
|
}
|
|
|
|
|
2000-10-23 01:49:40 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* PCM_round
|
|
|
|
*
|
|
|
|
*/
|
2000-10-12 22:46:49 +02:00
|
|
|
static inline DWORD PCM_round(DWORD a, DWORD b, DWORD c)
|
|
|
|
{
|
2003-07-21 22:00:17 +02:00
|
|
|
assert(c);
|
2000-10-12 22:46:49 +02:00
|
|
|
/* to be sure, always return an entire number of c... */
|
2000-10-23 01:49:40 +02:00
|
|
|
return ((double)a * (double)b + (double)c - 1) / (double)c;
|
2000-10-12 22:46:49 +02:00
|
|
|
}
|
|
|
|
|
2000-10-23 01:49:40 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* PCM_StreamSize
|
|
|
|
*
|
|
|
|
*/
|
2000-10-12 22:46:49 +02:00
|
|
|
static LRESULT PCM_StreamSize(PACMDRVSTREAMINSTANCE adsi, PACMDRVSTREAMSIZE adss)
|
|
|
|
{
|
2001-04-14 00:28:35 +02:00
|
|
|
DWORD srcMask = ~(adsi->pwfxSrc->nBlockAlign - 1);
|
|
|
|
DWORD dstMask = ~(adsi->pwfxDst->nBlockAlign - 1);
|
|
|
|
|
2004-03-12 21:24:50 +01:00
|
|
|
TRACE("(%p, %p)\n", adsi, adss);
|
|
|
|
|
2000-10-12 22:46:49 +02:00
|
|
|
switch (adss->fdwSize) {
|
|
|
|
case ACM_STREAMSIZEF_DESTINATION:
|
|
|
|
/* cbDstLength => cbSrcLength */
|
2001-04-14 00:28:35 +02:00
|
|
|
adss->cbSrcLength = PCM_round(adss->cbDstLength & dstMask,
|
2002-06-01 01:06:46 +02:00
|
|
|
adsi->pwfxSrc->nAvgBytesPerSec,
|
2001-04-14 00:28:35 +02:00
|
|
|
adsi->pwfxDst->nAvgBytesPerSec) & srcMask;
|
2000-10-12 22:46:49 +02:00
|
|
|
break;
|
|
|
|
case ACM_STREAMSIZEF_SOURCE:
|
|
|
|
/* cbSrcLength => cbDstLength */
|
2001-04-14 00:28:35 +02:00
|
|
|
adss->cbDstLength = PCM_round(adss->cbSrcLength & srcMask,
|
2002-06-01 01:06:46 +02:00
|
|
|
adsi->pwfxDst->nAvgBytesPerSec,
|
2001-04-14 00:28:35 +02:00
|
|
|
adsi->pwfxSrc->nAvgBytesPerSec) & dstMask;
|
2000-10-12 22:46:49 +02:00
|
|
|
break;
|
|
|
|
default:
|
2006-10-12 21:35:06 +02:00
|
|
|
WARN("Unsupported query %08x\n", adss->fdwSize);
|
2002-06-01 01:06:46 +02:00
|
|
|
return MMSYSERR_NOTSUPPORTED;
|
2000-10-12 22:46:49 +02:00
|
|
|
}
|
|
|
|
return MMSYSERR_NOERROR;
|
|
|
|
}
|
|
|
|
|
2000-10-23 01:49:40 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* PCM_StreamConvert
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
static LRESULT PCM_StreamConvert(PACMDRVSTREAMINSTANCE adsi, PACMDRVSTREAMHEADER adsh)
|
2000-10-12 22:46:49 +02:00
|
|
|
{
|
2000-10-23 01:49:40 +02:00
|
|
|
AcmPcmData* apd = (AcmPcmData*)adsi->dwDriver;
|
|
|
|
DWORD nsrc = NUM_OF(adsh->cbSrcLength, adsi->pwfxSrc->nBlockAlign);
|
|
|
|
DWORD ndst = NUM_OF(adsh->cbDstLength, adsi->pwfxDst->nBlockAlign);
|
2000-10-12 22:46:49 +02:00
|
|
|
|
2004-03-12 21:24:50 +01:00
|
|
|
TRACE("(%p, %p)\n", adsi, adsh);
|
|
|
|
|
2006-10-12 21:35:06 +02:00
|
|
|
TRACE("nsrc=%d,adsh->cbSrcLength=%d\n", nsrc, adsh->cbSrcLength);
|
|
|
|
TRACE("ndst=%d,adsh->cbDstLength=%d\n", ndst, adsh->cbDstLength);
|
|
|
|
TRACE("src [wFormatTag=%u, nChannels=%u, nSamplesPerSec=%u, nAvgBytesPerSec=%u, nBlockAlign=%u, wBitsPerSample=%u, cbSize=%u]\n",
|
2004-03-12 21:24:50 +01:00
|
|
|
adsi->pwfxSrc->wFormatTag, adsi->pwfxSrc->nChannels, adsi->pwfxSrc->nSamplesPerSec, adsi->pwfxSrc->nAvgBytesPerSec,
|
|
|
|
adsi->pwfxSrc->nBlockAlign, adsi->pwfxSrc->wBitsPerSample, adsi->pwfxSrc->cbSize);
|
2006-10-12 21:35:06 +02:00
|
|
|
TRACE("dst [wFormatTag=%u, nChannels=%u, nSamplesPerSec=%u, nAvgBytesPerSec=%u, nBlockAlign=%u, wBitsPerSample=%u, cbSize=%u]\n",
|
2004-03-12 21:24:50 +01:00
|
|
|
adsi->pwfxDst->wFormatTag, adsi->pwfxDst->nChannels, adsi->pwfxDst->nSamplesPerSec, adsi->pwfxDst->nAvgBytesPerSec,
|
|
|
|
adsi->pwfxDst->nBlockAlign, adsi->pwfxDst->wBitsPerSample, adsi->pwfxDst->cbSize);
|
|
|
|
|
2002-06-01 01:06:46 +02:00
|
|
|
if (adsh->fdwConvert &
|
2000-10-23 01:49:40 +02:00
|
|
|
~(ACM_STREAMCONVERTF_BLOCKALIGN|
|
|
|
|
ACM_STREAMCONVERTF_END|
|
|
|
|
ACM_STREAMCONVERTF_START)) {
|
2006-10-12 21:35:06 +02:00
|
|
|
FIXME("Unsupported fdwConvert (%08x), ignoring it\n", adsh->fdwConvert);
|
2000-10-12 22:46:49 +02:00
|
|
|
}
|
2000-10-23 01:49:40 +02:00
|
|
|
/* ACM_STREAMCONVERTF_BLOCKALIGN
|
|
|
|
* currently all conversions are block aligned, so do nothing for this flag
|
|
|
|
* ACM_STREAMCONVERTF_END
|
|
|
|
* no pending data, so do nothing for this flag
|
|
|
|
*/
|
2002-06-01 01:06:46 +02:00
|
|
|
if ((adsh->fdwConvert & ACM_STREAMCONVERTF_START) &&
|
2000-10-23 01:49:40 +02:00
|
|
|
(adsi->fdwDriver & PCM_RESAMPLE)) {
|
2000-10-12 22:46:49 +02:00
|
|
|
}
|
|
|
|
|
2000-10-23 01:49:40 +02:00
|
|
|
/* do the job */
|
|
|
|
if (adsi->fdwDriver & PCM_RESAMPLE) {
|
2017-06-15 20:25:48 +02:00
|
|
|
apd->cvt.cvtChangeRate(adsi->pwfxSrc->nSamplesPerSec, adsh->pbSrc, &nsrc,
|
|
|
|
adsi->pwfxDst->nSamplesPerSec, adsh->pbDst, &ndst);
|
2000-10-23 01:49:40 +02:00
|
|
|
} else {
|
|
|
|
if (nsrc < ndst) ndst = nsrc; else nsrc = ndst;
|
2000-10-12 22:46:49 +02:00
|
|
|
|
2000-10-23 01:49:40 +02:00
|
|
|
/* nsrc is now equal to ndst */
|
|
|
|
apd->cvt.cvtKeepRate(adsh->pbSrc, nsrc, adsh->pbDst);
|
2000-10-12 22:46:49 +02:00
|
|
|
}
|
|
|
|
|
2000-10-23 01:49:40 +02:00
|
|
|
adsh->cbSrcLengthUsed = nsrc * adsi->pwfxSrc->nBlockAlign;
|
|
|
|
adsh->cbDstLengthUsed = ndst * adsi->pwfxDst->nBlockAlign;
|
2000-10-12 22:46:49 +02:00
|
|
|
|
|
|
|
return MMSYSERR_NOERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**************************************************************************
|
2001-07-11 20:56:41 +02:00
|
|
|
* DriverProc (MSACM32.@)
|
2000-10-12 22:46:49 +02:00
|
|
|
*/
|
2005-11-28 20:53:22 +01:00
|
|
|
LRESULT CALLBACK PCM_DriverProc(DWORD_PTR dwDevID, HDRVR hDriv, UINT wMsg,
|
2000-10-12 22:46:49 +02:00
|
|
|
LPARAM dwParam1, LPARAM dwParam2)
|
|
|
|
{
|
2005-09-12 16:12:46 +02:00
|
|
|
TRACE("(%08lx %p %u %08lx %08lx);\n",
|
|
|
|
dwDevID, hDriv, wMsg, dwParam1, dwParam2);
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2000-10-12 22:46:49 +02:00
|
|
|
switch (wMsg) {
|
|
|
|
case DRV_LOAD: return 1;
|
|
|
|
case DRV_FREE: return 1;
|
2001-04-14 00:28:35 +02:00
|
|
|
case DRV_OPEN: return PCM_drvOpen((LPSTR)dwParam1, (PACMDRVOPENDESCW)dwParam2);
|
2000-10-12 22:46:49 +02:00
|
|
|
case DRV_CLOSE: return PCM_drvClose(dwDevID);
|
2002-06-01 01:06:46 +02:00
|
|
|
case DRV_ENABLE: return 1;
|
2000-10-12 22:46:49 +02:00
|
|
|
case DRV_DISABLE: return 1;
|
|
|
|
case DRV_QUERYCONFIGURE: return 1;
|
|
|
|
case DRV_CONFIGURE: MessageBoxA(0, "MSACM PCM filter !", "Wine Driver", MB_OK); return 1;
|
|
|
|
case DRV_INSTALL: return DRVCNF_RESTART;
|
|
|
|
case DRV_REMOVE: return DRVCNF_RESTART;
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2000-10-12 22:46:49 +02:00
|
|
|
case ACMDM_DRIVER_NOTIFY:
|
|
|
|
/* no caching from other ACM drivers is done so far */
|
|
|
|
return MMSYSERR_NOERROR;
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2000-10-12 22:46:49 +02:00
|
|
|
case ACMDM_DRIVER_DETAILS:
|
|
|
|
return PCM_DriverDetails((PACMDRIVERDETAILSW)dwParam1);
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2000-10-12 22:46:49 +02:00
|
|
|
case ACMDM_FORMATTAG_DETAILS:
|
|
|
|
return PCM_FormatTagDetails((PACMFORMATTAGDETAILSW)dwParam1, dwParam2);
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2000-10-12 22:46:49 +02:00
|
|
|
case ACMDM_FORMAT_DETAILS:
|
|
|
|
return PCM_FormatDetails((PACMFORMATDETAILSW)dwParam1, dwParam2);
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2000-10-12 22:46:49 +02:00
|
|
|
case ACMDM_FORMAT_SUGGEST:
|
|
|
|
return PCM_FormatSuggest((PACMDRVFORMATSUGGEST)dwParam1);
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2000-10-12 22:46:49 +02:00
|
|
|
case ACMDM_STREAM_OPEN:
|
|
|
|
return PCM_StreamOpen((PACMDRVSTREAMINSTANCE)dwParam1);
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2000-10-12 22:46:49 +02:00
|
|
|
case ACMDM_STREAM_CLOSE:
|
|
|
|
return PCM_StreamClose((PACMDRVSTREAMINSTANCE)dwParam1);
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2000-10-12 22:46:49 +02:00
|
|
|
case ACMDM_STREAM_SIZE:
|
|
|
|
return PCM_StreamSize((PACMDRVSTREAMINSTANCE)dwParam1, (PACMDRVSTREAMSIZE)dwParam2);
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2000-10-12 22:46:49 +02:00
|
|
|
case ACMDM_STREAM_CONVERT:
|
|
|
|
return PCM_StreamConvert((PACMDRVSTREAMINSTANCE)dwParam1, (PACMDRVSTREAMHEADER)dwParam2);
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2000-10-12 22:46:49 +02:00
|
|
|
case ACMDM_HARDWARE_WAVE_CAPS_INPUT:
|
|
|
|
case ACMDM_HARDWARE_WAVE_CAPS_OUTPUT:
|
|
|
|
/* this converter is not a hardware driver */
|
|
|
|
case ACMDM_FILTERTAG_DETAILS:
|
|
|
|
case ACMDM_FILTER_DETAILS:
|
|
|
|
/* this converter is not a filter */
|
|
|
|
case ACMDM_STREAM_RESET:
|
|
|
|
/* only needed for asynchronous driver... we aren't, so just say it */
|
|
|
|
case ACMDM_STREAM_PREPARE:
|
|
|
|
case ACMDM_STREAM_UNPREPARE:
|
|
|
|
/* nothing special to do here... so don't do anything */
|
|
|
|
return MMSYSERR_NOTSUPPORTED;
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2000-10-12 22:46:49 +02:00
|
|
|
default:
|
|
|
|
return DefDriverProc(dwDevID, hDriv, wMsg, dwParam1, dwParam2);
|
|
|
|
}
|
|
|
|
}
|