]> git.alsa-project.org Git - alsa-lib.git/commitdiff
Fixed silence_64 and added support for 24-bit samples to area_silence
authorJaroslav Kysela <perex@perex.cz>
Sun, 21 Jul 2002 08:19:40 +0000 (08:19 +0000)
committerJaroslav Kysela <perex@perex.cz>
Sun, 21 Jul 2002 08:19:40 +0000 (08:19 +0000)
src/pcm/pcm.c
src/pcm/pcm_misc.c
src/pcm/plugin_ops.h

index 76b0f276ae96a09464acd8962df446967b2b9775..9dc49a1aeb17e17a3c318ea4a07cd9b3743309cd 100644 (file)
@@ -1906,6 +1906,17 @@ int snd_pcm_area_silence(const snd_pcm_channel_area_t *dst_area, snd_pcm_uframes
                }
                break;
        }
+       case 24:
+#ifdef SNDRV_LITTLE_ENDIAN
+               *(dst + 0) = silence >> 0;
+               *(dst + 1) = silence >> 8;
+               *(dst + 2) = silence >> 16;
+#else
+               *(dst + 2) = silence >> 0;
+               *(dst + 1) = silence >> 8;
+               *(dst + 0) = silence >> 16;
+#endif
+               break;
        case 32: {
                u_int32_t sil = silence;
                while (samples-- > 0) {
index c62e700ca73ba4f8397b3e0851ef76cc669e77fd..619d36acc5f5b10c0193e0a053879b38b70ea218 100644 (file)
@@ -395,6 +395,18 @@ u_int64_t snd_pcm_format_silence_64(snd_pcm_format_t format)
                return 0x0000800000008000ULL;
        case SNDRV_PCM_FORMAT_U32_BE:
                return 0x0000008000000080ULL;
+       case SNDRV_PCM_FORMAT_U24_3LE:
+               return 0x0000800000800000ULL;
+       case SNDRV_PCM_FORMAT_U24_3BE:
+               return 0x0080000080000080ULL;
+       case SNDRV_PCM_FORMAT_U20_3LE:
+               return 0x0000080000080000ULL;
+       case SNDRV_PCM_FORMAT_U20_3BE:
+               return 0x0008000008000008ULL;
+       case SNDRV_PCM_FORMAT_U18_3LE:
+               return 0x0000020000020000ULL;
+       case SNDRV_PCM_FORMAT_U18_3BE:
+               return 0x0002000002000002ULL;
 #else
        case SNDRV_PCM_FORMAT_U16_LE:
                return 0x0080008000800080ULL;
@@ -408,27 +420,30 @@ u_int64_t snd_pcm_format_silence_64(snd_pcm_format_t format)
                return 0x0080000000800000ULL;
        case SNDRV_PCM_FORMAT_U32_BE:
                return 0x8000000080000000ULL;
-#endif
        case SNDRV_PCM_FORMAT_U24_3LE:
+               return 0x0080000080000080ULL;
        case SNDRV_PCM_FORMAT_U24_3BE:
                return 0x0000800000800000ULL;
        case SNDRV_PCM_FORMAT_U20_3LE:
+               return 0x0008000008000008ULL;
        case SNDRV_PCM_FORMAT_U20_3BE:
                return 0x0000080000080000ULL;
        case SNDRV_PCM_FORMAT_U18_3LE:
+               return 0x0002000002000002ULL;
        case SNDRV_PCM_FORMAT_U18_3BE:
                return 0x0000020000020000ULL;
+#endif
        case SNDRV_PCM_FORMAT_FLOAT_LE:
        {
                union {
-                       float f;
-                       u_int32_t i;
+                       float f[2];
+                       u_int64_t i;
                } u;
-               u.f = 0.0;
+               u.f[0] = u.f[1] = 0.0;
 #ifdef SNDRV_LITTLE_ENDIAN
                return u.i;
 #else
-               return bswap_32(u.i);
+               return bswap_64(u.i);
 #endif
        }
        case SNDRV_PCM_FORMAT_FLOAT64_LE:
@@ -447,12 +462,12 @@ u_int64_t snd_pcm_format_silence_64(snd_pcm_format_t format)
        case SNDRV_PCM_FORMAT_FLOAT_BE:         
        {
                union {
-                       float f;
-                       u_int32_t i;
+                       float f[2];
+                       u_int64_t i;
                } u;
-               u.f = 0.0;
+               u.f[0] = u.f[1] = 0.0;
 #ifdef SNDRV_LITTLE_ENDIAN
-               return bswap_32(u.i);
+               return bswap_64(u.i);
 #else
                return u.i;
 #endif
@@ -562,11 +577,16 @@ int snd_pcm_format_set_silence(snd_pcm_format_t format, void *data, unsigned int
                if (! silence)
                        memset(data, 0, samples * 3);
                else {
-                       /* FIXME: rewrite in the more better way.. */
-                       int i;
                        while (samples-- > 0) {
-                               for (i = 0; i < 3; i++)
-                                       *((u_int8_t *)data)++ = silence >> (i * 8);
+#ifdef SNDRV_LITTLE_ENDIAN
+                               *((u_int8_t *)data)++ = silence >> 0;
+                               *((u_int8_t *)data)++ = silence >> 8;
+                               *((u_int8_t *)data)++ = silence >> 16;
+#else
+                               *((u_int8_t *)data)++ = silence >> 16;
+                               *((u_int8_t *)data)++ = silence >> 8;
+                               *((u_int8_t *)data)++ = silence >> 0;
+#endif
                        }
                }
        }
index 9986d063c3ab702abd7a144fb22002af75d1e729..b752768254eaa204192a3370837637aa973c8131 100644 (file)
 
 #define as_u8c(ptr) (*(const u_int8_t*)(ptr))
 #define as_u16c(ptr) (*(const u_int16_t*)(ptr))
-#ifdef SND_LITTLE_ENDIAN
-#define as_u24c(ptr) (u_int32_t)(as_u8(ptr) | as_u8(((char *)ptr) + 1) << 8 | as_u8(((char *)ptr + 2) << 16)
-#elif defined(SND_BIG_ENDIAN)
-#define as_u24c(ptr) (u_int32_t)(as_u8(ptr) << 16 | as_u8(((char *)ptr) + 1) << 8 | as_u8(((char *)ptr + 2))
-#else
-#error "Wrong endian..."
-#endif
 #define as_u32c(ptr) (*(const u_int32_t*)(ptr))
 #define as_u64c(ptr) (*(const u_int64_t*)(ptr))
 #define as_s8c(ptr) (*(const int8_t*)(ptr))