mirror of
https://github.com/alsa-project/alsa-utils
synced 2024-11-10 04:35:43 +01:00
speaker-test.c - fix pink noise generator on big-endian archs
This patch makes speaker-test fill the buffers with properly coded data on both big- and little-endian processors. Signed-off-by: Giuliano Pochini <pochini@shiny.it>
This commit is contained in:
parent
6372f4acc2
commit
1b7f9278af
1 changed files with 41 additions and 11 deletions
|
@ -259,7 +259,8 @@ static void generate_pink_noise( uint8_t *frames, int channel, int count) {
|
||||||
|
|
||||||
while (count-- > 0) {
|
while (count-- > 0) {
|
||||||
for(chn=0;chn<channels;chn++) {
|
for(chn=0;chn<channels;chn++) {
|
||||||
if (sample_size_bits == 8) {
|
switch (format) {
|
||||||
|
case SND_PCM_FORMAT_S8:
|
||||||
if (chn==channel) {
|
if (chn==channel) {
|
||||||
res = generate_pink_noise_sample(&pink) * 0x03fffffff; /* Don't use MAX volume */
|
res = generate_pink_noise_sample(&pink) * 0x03fffffff; /* Don't use MAX volume */
|
||||||
ires = res;
|
ires = res;
|
||||||
|
@ -267,35 +268,64 @@ static void generate_pink_noise( uint8_t *frames, int channel, int count) {
|
||||||
} else {
|
} else {
|
||||||
*samp8++ = 0;
|
*samp8++ = 0;
|
||||||
}
|
}
|
||||||
} else if (sample_size_bits == 16) {
|
break;
|
||||||
|
case SND_PCM_FORMAT_S16_LE:
|
||||||
if (chn==channel) {
|
if (chn==channel) {
|
||||||
res = generate_pink_noise_sample(&pink) * 0x03fffffff; /* Don't use MAX volume */
|
res = generate_pink_noise_sample(&pink) * 0x03fffffff; /* Don't use MAX volume */
|
||||||
ires = res;
|
ires = res;
|
||||||
*samp16++ = ires >>16;
|
#if __BYTE_ORDER == __LITTLE_ENDIAN
|
||||||
|
*samp16++ = ires >> 16;
|
||||||
|
#elif __BYTE_ORDER == __BIG_ENDIAN
|
||||||
|
*samp16++ = bswap_16(ires >> 16);
|
||||||
|
#endif
|
||||||
} else {
|
} else {
|
||||||
*samp16++ = 0;
|
*samp16++ = 0;
|
||||||
}
|
}
|
||||||
} else if ((sample_size_bits == 32) && (format == SND_PCM_FORMAT_FLOAT_LE)) {
|
break;
|
||||||
|
case SND_PCM_FORMAT_S16_BE:
|
||||||
if (chn==channel) {
|
if (chn==channel) {
|
||||||
res = generate_pink_noise_sample(&pink) * 0.75; /* Don't use MAX volume */
|
res = generate_pink_noise_sample(&pink) * 0x03fffffff; /* Don't use MAX volume */
|
||||||
fres = res;
|
ires = res;
|
||||||
*samp_f++ = fres;
|
#if __BYTE_ORDER == __BIG_ENDIAN
|
||||||
|
*samp16++ = ires >> 16;
|
||||||
|
#elif __BYTE_ORDER == __LITTLE_ENDIAN
|
||||||
|
*samp16++ = bswap_16(ires >> 16);
|
||||||
|
#endif
|
||||||
} else {
|
} else {
|
||||||
*samp_f++ = 0.0;
|
*samp16++ = 0;
|
||||||
}
|
}
|
||||||
} else if ((sample_size_bits == 32) && (format != SND_PCM_FORMAT_FLOAT_LE)) {
|
break;
|
||||||
|
case SND_PCM_FORMAT_S32_LE:
|
||||||
|
if (chn==channel) {
|
||||||
|
res = generate_pink_noise_sample(&pink) * 0x03fffffff; /* Don't use MAX volume */
|
||||||
|
ires = res;
|
||||||
|
#if __BYTE_ORDER == __LITTLE_ENDIAN
|
||||||
|
*samp32++ = ires;
|
||||||
|
#elif __BYTE_ORDER == __BIG_ENDIAN
|
||||||
|
*samp32++ = bswap_32(ires);
|
||||||
|
#endif
|
||||||
|
} else {
|
||||||
|
*samp32++ = 0;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case SND_PCM_FORMAT_S32_BE:
|
||||||
if (chn==channel) {
|
if (chn==channel) {
|
||||||
res = generate_pink_noise_sample(&pink) * 0x03fffffff; /* Don't use MAX volume */
|
res = generate_pink_noise_sample(&pink) * 0x03fffffff; /* Don't use MAX volume */
|
||||||
ires = res;
|
ires = res;
|
||||||
|
#if __BYTE_ORDER == __BIG_ENDIAN
|
||||||
*samp32++ = ires;
|
*samp32++ = ires;
|
||||||
|
#elif __BYTE_ORDER == __LITTLE_ENDIAN
|
||||||
|
*samp32++ = bswap_32(ires);
|
||||||
|
#endif
|
||||||
} else {
|
} else {
|
||||||
*samp32++ = 0;
|
*samp32++ = 0;
|
||||||
}
|
}
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int set_hwparams(snd_pcm_t *handle, snd_pcm_hw_params_t *params, snd_pcm_access_t access) {
|
static int set_hwparams(snd_pcm_t *handle, snd_pcm_hw_params_t *params, snd_pcm_access_t access) {
|
||||||
|
|
Loading…
Reference in a new issue