[PATCH v2] msacm32: Rewrite PCM conversion functions.

Alex Henrie alexhenrie24 at gmail.com
Wed Jun 14 12:05:13 CDT 2017


2017-06-14 10:13 GMT-06:00 Zebediah Figura <z.figura12 at gmail.com>:
> On 06/14/2017 08:42 AM, Andrew Eikum wrote:
>>
>> On Tue, Jun 13, 2017 at 04:35:52PM -0500, Zebediah Figura wrote:
>>>
>>> +#define PCM_CVT_CHANGE_FUNC(name)      static void name(DWORD srcRate,
>>> const unsigned char *src, DWORD *nsrc, \
>>> +                                                        DWORD dstRate,
>>> unsigned char *dst, DWORD *ndst) \
>>> +    { \
>>> +    DWORD error = srcRate / 2; \
>>> +    DWORD srcUsed = 0, dstUsed = 0; \
>>> +    for (srcUsed = 0; srcUsed < *nsrc; srcUsed++) { \
>>> +        error += dstRate; \
>>> +        while (error > srcRate) { \
>>> +            if (dstUsed == *ndst) { \
>>> +                *nsrc = srcUsed; \
>>> +                *ndst = dstUsed; \
>>> +                return; \
>>> +            }
>>> +
>>> +            /* conversion is done here */
>>> +
>>> +#define PCM_CVT_CHANGE_FUNC_END(offset)        \
>>> +            dstUsed++; \
>>> +            error -= srcRate; \
>>> +        } \
>>> +        src += offset; \
>>> +    } \
>>> +    *nsrc = srcUsed; \
>>> +    *ndst = dstUsed; \
>>> +}
>>> +
>>> +PCM_CVT_CHANGE_FUNC(cvtSS88C)
>>> +    *dst++ = src[0];
>>> +    *dst++ = src[1];
>>> +PCM_CVT_CHANGE_FUNC_END(2)
>>> +
>>
>>
>> I really dislike complicated preprocessor tricks. Can't this be done
>> in a similar way with real functions? If not, I'd rather have the
>> copy-pasted code than these difficult macros.
>>
>> Andrew
>>
>
> As far as I know there's no way to keep this structure without either using
> macros or rewriting the same function 20 times, neither of which is very
> desirable. On the other hand, might it be worth sacrificing a slight bit of
> efficiency (which may not even be that much) as in the attached patch?

You could make each codec function pass a codec-specific callback
function to the common function.

-Alex



More information about the wine-devel mailing list