test/pcm.c: Sample generation on big endian platforms was broken.

Has not worked since commit 3d1fa92490

Signed-off-by: Kenneth Johansson <kenneth@southpole.se>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
This commit is contained in:
Kenneth Johansson 2009-07-03 22:31:38 +02:00 committed by Takashi Iwai
parent 5a70411d6c
commit d23845e563

View file

@ -34,14 +34,10 @@ static void generate_sine(const snd_pcm_channel_area_t *areas,
static double max_phase = 2. * M_PI; static double max_phase = 2. * M_PI;
double phase = *_phase; double phase = *_phase;
double step = max_phase*freq/(double)rate; double step = max_phase*freq/(double)rate;
double res; unsigned char *samples[channels];
unsigned char *samples[channels], *tmp;
int steps[channels]; int steps[channels];
unsigned int chn, byte; unsigned int chn;
union {
int i;
unsigned char c[4];
} ires;
unsigned int maxval = (1 << (snd_pcm_format_width(format) - 1)) - 1; unsigned int maxval = (1 << (snd_pcm_format_width(format) - 1)) - 1;
int bps = snd_pcm_format_width(format) / 8; /* bytes per sample */ int bps = snd_pcm_format_width(format) / 8; /* bytes per sample */
@ -61,12 +57,18 @@ static void generate_sine(const snd_pcm_channel_area_t *areas,
} }
/* fill the channel areas */ /* fill the channel areas */
while (count-- > 0) { while (count-- > 0) {
int res, i;
res = sin(phase) * maxval; res = sin(phase) * maxval;
ires.i = res;
tmp = ires.c;
for (chn = 0; chn < channels; chn++) { for (chn = 0; chn < channels; chn++) {
for (byte = 0; byte < (unsigned int)bps; byte++) /* Generate data in native endian format */
*(samples[chn] + byte) = tmp[byte]; for (i = 0; i < bps; i++) {
#if (__BYTE_ORDER == __BIG_ENDIAN)
*(samples[chn] + bps - 1 - i) = (res >> i * 8) & 0xff;
#else
*(samples[chn] + i) = (res >> i * 8) & 0xff;
#endif
}
samples[chn] += steps[chn]; samples[chn] += steps[chn];
} }
phase += step; phase += step;