Changeset e6bba8f in mainline for uspace/lib/pcm/src/format.c


Ignore:
Timestamp:
2012-07-17T08:56:21Z (12 years ago)
Author:
Jan Vesely <jano.vesely@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
cd8f19d
Parents:
ea6c838
Message:

libpcm: Add function to generate normalized silence.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/pcm/src/format.c

    rea6c838 re6bba8f  
    8686            a->channels == b->channels &&
    8787            a->sample_format == b->sample_format;
     88}
     89
     90void pcm_format_silence(void *dst, size_t size, const pcm_format_t *f)
     91{
     92#define SET_NULL(type, endian, nullv) \
     93do { \
     94        type *buffer = dst; \
     95        const size_t sample_count = size / sizeof(type); \
     96        for (unsigned i = 0; i < sample_count; ++i) { \
     97                buffer[i] = to((type)nullv, type, endian); \
     98        } \
     99} while (0)
     100
     101        switch (f->sample_format) {
     102        case PCM_SAMPLE_UINT8:
     103                SET_NULL(uint8_t, le, INT8_MIN); break;
     104        case PCM_SAMPLE_SINT8:
     105                SET_NULL(int8_t, le, 0); break;
     106        case PCM_SAMPLE_UINT16_LE:
     107                SET_NULL(uint16_t, le, INT16_MIN); break;
     108        case PCM_SAMPLE_SINT16_LE:
     109                SET_NULL(int16_t, le, 0); break;
     110        case PCM_SAMPLE_UINT16_BE:
     111                SET_NULL(uint16_t, be, INT16_MIN); break;
     112        case PCM_SAMPLE_SINT16_BE:
     113                SET_NULL(int16_t, be, 0); break;
     114        case PCM_SAMPLE_UINT32_LE:
     115                SET_NULL(uint32_t, le, INT32_MIN); break;
     116        case PCM_SAMPLE_SINT32_LE:
     117                SET_NULL(int32_t, le, 0); break;
     118        case PCM_SAMPLE_UINT32_BE:
     119                SET_NULL(uint32_t, be, INT32_MIN); break;
     120        case PCM_SAMPLE_SINT32_BE:
     121                SET_NULL(int32_t, le, 0); break;
     122        case PCM_SAMPLE_UINT24_32_LE:
     123        case PCM_SAMPLE_SINT24_32_LE:
     124        case PCM_SAMPLE_UINT24_32_BE:
     125        case PCM_SAMPLE_SINT24_32_BE:
     126        case PCM_SAMPLE_UINT24_LE:
     127        case PCM_SAMPLE_SINT24_LE:
     128        case PCM_SAMPLE_UINT24_BE:
     129        case PCM_SAMPLE_SINT24_BE:
     130        case PCM_SAMPLE_FLOAT32:
     131        default: ;
     132        }
     133#undef SET_NULL
    88134}
    89135
Note: See TracChangeset for help on using the changeset viewer.