| 1 | /* |
| 2 | * Copyright (C) 2013 nu774 |
| 3 | * For conditions of distribution and use, see copyright notice in COPYING |
| 4 | */ |
| 5 | #ifndef LPCM_H |
| 6 | #define LPCM_H |
| 7 | |
| 8 | enum pcm_type { |
| 9 | PCM_TYPE_UNKNOWN = 0, |
| 10 | PCM_TYPE_SINT = 1, |
| 11 | PCM_TYPE_UINT = 2, |
| 12 | PCM_TYPE_FLOAT = 4, |
| 13 | PCM_TYPE_SINT_BE = (8|1), |
| 14 | PCM_TYPE_UINT_BE = (8|2), |
| 15 | PCM_TYPE_FLOAT_BE = (8|4), |
| 16 | }; |
| 17 | |
| 18 | typedef struct pcm_sample_description_t { |
| 19 | enum pcm_type sample_type; |
| 20 | uint32_t sample_rate; |
| 21 | uint8_t bits_per_channel; |
| 22 | uint8_t bytes_per_frame; |
| 23 | uint8_t channels_per_frame; |
| 24 | uint32_t channel_mask; |
| 25 | } pcm_sample_description_t; |
| 26 | |
| 27 | #define PCM_IS_SINT(desc) ((desc)->sample_type & 1) |
| 28 | #define PCM_IS_UINT(desc) ((desc)->sample_type & 2) |
| 29 | #define PCM_IS_FLOAT(desc) ((desc)->sample_type & 4) |
| 30 | #define PCM_IS_BIG_ENDIAN(desc) ((desc)->sample_type & 8) |
| 31 | #define PCM_BYTES_PER_CHANNEL(desc) \ |
| 32 | ((desc)->bytes_per_frame / (desc)->channels_per_frame) |
| 33 | |
| 34 | int pcm_convert_to_native_sint16(const pcm_sample_description_t *format, |
| 35 | const void *input, uint32_t nframes, |
| 36 | int16_t *result); |
| 37 | #endif |