]> git.alsa-project.org Git - alsa-utils.git/commitdiff
aplay/arecord - Add support for IEEE float 32-bit WAV files
authorAndrew Paprocki <andrew@ishiboo.com>
Wed, 6 Feb 2008 13:05:07 +0000 (14:05 +0100)
committerTakashi Iwai <tiwai@suse.de>
Wed, 6 Feb 2008 13:05:07 +0000 (14:05 +0100)
This patch modifies aplay/arecord to support playing/capturing IEEE float
32-bit WAV files. Tested on HDA hardware in both stereo and multi-channel
modes. Added the WAV file constant for Dolby AC-3 S/PDIF passthrough to
formats.h for future use when AC-3 passthrough is better supported.

Signed-off-by: Andrew Paprocki <andrew@ishiboo.com>
aplay/aplay.c
aplay/formats.h

index 88d1ef2e1eca89653b84a40d29ca69c227cb193a..9b22eb52c80d63f6d2e7cdcf2d883b62bc6b527b 100644 (file)
@@ -745,8 +745,9 @@ static ssize_t test_wavefile(int fd, u_char *_buffer, size_t size)
        check_wavefile_space(buffer, len, blimit);
        test_wavefile_read(fd, buffer, &size, len, __LINE__);
        f = (WaveFmtBody*) buffer;
-       if (LE_SHORT(f->format) != WAV_PCM_CODE) {
-               error(_("can't play not PCM-coded WAVE-files"));
+        if (LE_SHORT(f->format) != WAV_FMT_PCM &&
+            LE_SHORT(f->format) != WAV_FMT_IEEE_FLOAT) {
+                error(_("can't play WAVE-file format 0x%04x which is not PCM or FLOAT encoded"), LE_SHORT(f->format));
                exit(EXIT_FAILURE);
        }
        if (LE_SHORT(f->modus) < 1) {
@@ -788,7 +789,10 @@ static ssize_t test_wavefile(int fd, u_char *_buffer, size_t size)
                }
                break;
        case 32:
-               hwparams.format = SND_PCM_FORMAT_S32_LE;
+                if (LE_SHORT(f->format) == WAV_FMT_PCM)
+                        hwparams.format = SND_PCM_FORMAT_S32_LE;
+                else if (LE_SHORT(f->format) == WAV_FMT_IEEE_FLOAT)
+                        hwparams.format = SND_PCM_FORMAT_FLOAT_LE;
                break;
        default:
                error(_(" can't play WAVE-files with sample %d bits wide"),
@@ -1778,6 +1782,7 @@ static void begin_wave(int fd, size_t cnt)
                bits = 16;
                break;
        case SND_PCM_FORMAT_S32_LE:
+        case SND_PCM_FORMAT_FLOAT_LE:
                bits = 32;
                break;
        case SND_PCM_FORMAT_S24_LE:
@@ -1796,7 +1801,10 @@ static void begin_wave(int fd, size_t cnt)
        cf.type = WAV_FMT;
        cf.length = LE_INT(16);
 
-       f.format = LE_SHORT(WAV_PCM_CODE);
+        if (hwparams.format == SND_PCM_FORMAT_FLOAT_LE)
+                f.format = LE_SHORT(WAV_FMT_IEEE_FLOAT);
+        else
+                f.format = LE_SHORT(WAV_FMT_PCM);
        f.modus = LE_SHORT(hwparams.channels);
        f.sample_fq = LE_INT(hwparams.rate);
 #if 0
index 2c4f724f0f9ae20ced01445190e3df093d953a7b..3ba0bfabc146d306e4fb3ea8a49328ac3537a14e 100644 (file)
@@ -64,7 +64,11 @@ typedef struct voc_ext_block {
 #define WAV_WAVE               COMPOSE_ID('W','A','V','E')
 #define WAV_FMT                        COMPOSE_ID('f','m','t',' ')
 #define WAV_DATA               COMPOSE_ID('d','a','t','a')
-#define WAV_PCM_CODE           1
+
+/* WAVE fmt block constants from Microsoft mmreg.h header */
+#define WAV_FMT_PCM             0x0001
+#define WAV_FMT_IEEE_FLOAT      0x0003
+#define WAV_FMT_DOLBY_AC3_SPDIF 0x0092
 
 /* it's in chunks like .voc and AMIGA iff, but my source say there
    are in only in this combination, so I combined them in one header;