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?