From b8c4fef8bf34f25c58de83adaf31462a851f81d1 Mon Sep 17 00:00:00 2001 From: Takashi Iwai Date: Mon, 6 Jul 2009 08:56:53 +0200 Subject: [PATCH] test/pcm.c: float format support Signed-off-by: Takashi Iwai --- test/pcm.c | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/test/pcm.c b/test/pcm.c index 7a88f854..abb83e4c 100644 --- a/test/pcm.c +++ b/test/pcm.c @@ -43,6 +43,8 @@ static void generate_sine(const snd_pcm_channel_area_t *areas, int phys_bps = snd_pcm_format_physical_width(format) / 8; int big_endian = snd_pcm_format_big_endian(format) == 1; int to_unsigned = snd_pcm_format_unsigned(format) == 1; + int is_float = (format == SND_PCM_FORMAT_FLOAT_LE || + format == SND_PCM_FORMAT_FLOAT_BE); /* verify and prepare the contents of areas */ for (chn = 0; chn < channels; chn++) { @@ -60,8 +62,16 @@ static void generate_sine(const snd_pcm_channel_area_t *areas, } /* fill the channel areas */ while (count-- > 0) { + union { + float f; + int i; + } fval; int res, i; - res = sin(phase) * maxval; + if (is_float) { + fval.f = sin(phase) * maxval; + res = fval.i; + } else + res = sin(phase) * maxval; if (to_unsigned) res ^= 1U << (format_bits - 1); for (chn = 0; chn < channels; chn++) { @@ -833,8 +843,10 @@ int main(int argc, char *argv[]) } if (format == SND_PCM_FORMAT_LAST) format = SND_PCM_FORMAT_S16; - if (!snd_pcm_format_linear(format)) { - printf("Invalid (non-linear) format %s\n", + if (!snd_pcm_format_linear(format) && + !(format == SND_PCM_FORMAT_FLOAT_LE || + format == SND_PCM_FORMAT_FLOAT_BE)) { + printf("Invalid (non-linear/float) format %s\n", optarg); return 1; } -- 2.47.1