Convert between stereo split and interleaved

Would this be the best way to convert between stereo split and stereo interleaved audio data?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
void* split_to_interleaved(char *dest, size_t byteWidth, size_t size, int numSources, ...) {

	// Setup variable arguments
	va_list source;
	va_start(source, numSources);
	
	// Copy data to dest making it interleaved
	for (size_t i = 0; i < size * byteWidth; i += byteWidth)
		for (size_t j = 0; j < numSources; j++)
			memcpy(dest+i*numSources+j*byteWidth, va_arg(source, char*)+i, byteWidth);

	// End variable arguments
	va_end(source);

	return dest;
}

void* interleaved_to_split(const char *source, size_t byteWidth, size_t size, int numDests, ...) {

	// Setup variable arguments
	va_list dest;
	va_start(dest, numDests);

	// Copy data to dest making it split
	for (size_t i = 0; i < size * byteWidth; i += byteWidth)
		for (size_t j = 0; j < numDests; j++)
			memcpy(va_arg(dest, char*)+i, source+i*numDests+j*byteWidth, byteWidth);

	return dest;
}
Topic archived. No new replies allowed.