28
28
#include "reorder_ch.h"
30
static inline void reorder_to_planar_(void *restrict out, const void *restrict in,
31
size_t size, size_t nchan, size_t nmemb)
34
char *outptr = (char *) out;
35
size_t instep = nchan * size;
37
for (c = 0; c < nchan; ++c) {
38
const char *inptr = ((const char *) in) + c * size;
39
for (i = 0; i < nmemb; ++i, inptr += instep, outptr += size) {
40
memcpy(outptr, inptr, size);
45
void reorder_to_planar(void *restrict out, const void *restrict in,
46
size_t size, size_t nchan, size_t nmemb)
48
// special case for mono (nothing to do...)
50
memcpy(out, in, size * nchan * nmemb);
51
// these calls exist to insert an inline copy of to_planar_ here with known
52
// value of size to help the compiler replace the memcpy calls by mov
55
reorder_to_planar_(out, in, 1, nchan, nmemb);
57
reorder_to_planar_(out, in, 2, nchan, nmemb);
59
reorder_to_planar_(out, in, 4, nchan, nmemb);
60
// general case (calls memcpy a lot, should actually never happen, but
61
// stays here for correctness purposes)
63
reorder_to_planar_(out, in, size, nchan, nmemb);
66
static inline void reorder_to_packed_(uint8_t *out, uint8_t **in,
67
size_t size, size_t nchan, size_t nmemb)
69
size_t outstep = nchan * size;
71
for (size_t c = 0; c < nchan; ++c) {
72
char *outptr = out + c * size;
74
for (size_t i = 0; i < nmemb; ++i, outptr += outstep, inptr += size) {
75
memcpy(outptr, inptr, size);
80
// out = destination array of packed samples of given size, nmemb frames
81
// in[channel] = source array of samples for the given channel
82
void reorder_to_packed(uint8_t *out, uint8_t **in,
83
size_t size, size_t nchan, size_t nmemb)
86
memcpy(out, in, size * nchan * nmemb);
87
// See reorder_to_planar() why this is done this way
89
reorder_to_packed_(out, in, 1, nchan, nmemb);
91
reorder_to_packed_(out, in, 2, nchan, nmemb);
93
reorder_to_packed_(out, in, 4, nchan, nmemb);
95
reorder_to_packed_(out, in, size, nchan, nmemb);
98
30
#define MAX_SAMPLESIZE 8
100
32
static void reorder_channels_(uint8_t *restrict data, int *restrict ch_order,