Changeset 43c40a3 in mainline
- Timestamp:
- 2012-07-13T21:13:15Z (12 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 6906f61
- Parents:
- 13df13c8
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/audio/hound/audio_format.c
r13df13c8 r43c40a3 37 37 #include <byteorder.h> 38 38 #include <errno.h> 39 #include <macros.h> 39 40 40 41 #include "audio_format.h" 42 43 #define uint8_t_le2host(x) (x) 44 #define host2uint8_t_le(x) (x) 45 #define uint8_t_be2host(x) (x) 46 #define host2uint8_t_be(x) (x) 47 48 #define int8_t_le2host(x) (x) 49 #define host2int8_t_le(x) (x) 50 51 #define int16_t_le2host(x) uint16_t_le2host(x) 52 #define host2int16_t_le(x) host2uint16_t_le(x) 53 54 #define int32_t_le2host(x) uint32_t_le2host(x) 55 #define host2int32_t_le(x) host2uint32_t_le(x) 56 57 #define int8_t_be2host(x) (x) 58 #define host2int8_t_be(x) (x) 59 60 #define int16_t_be2host(x) uint16_t_be2host(x) 61 #define host2int16_t_be(x) host2uint16_t_be(x) 62 63 #define int32_t_be2host(x) uint32_t_be2host(x) 64 #define host2int32_t_be(x) host2uint32_t_be(x) 41 65 42 66 bool audio_format_same(const audio_format_t *a, const audio_format_t* b) … … 61 85 * and all little fluffy things... 62 86 * AND it does not check for overflows (FIXME)*/ 63 #define LOOP_ADD(type, endian ) \87 #define LOOP_ADD(type, endian, max) \ 64 88 do { \ 65 89 const type *src_buff = src; \ 66 90 type *dst_buff = dst; \ 67 91 for (size_t i = 0; i < size / sizeof(type); ++i) { \ 68 const type a = type ## _ ## endian ##2host(dst_buff[i]); \ 69 const type b = type ## _ ## endian ##2host(src_buff[i]); \ 70 const type c = a + b; \ 92 const float a = type ## _ ## endian ##2host(dst_buff[i]); \ 93 const float b = type ## _ ## endian ##2host(src_buff[i]); \ 94 float c = min((a + b), max); \ 95 if (c <= (float)-max) c = -max + 1.0; \ 71 96 dst_buff[i] = host2 ## type ## _ ## endian(c); \ 72 97 } \ … … 89 114 } 90 115 case PCM_SAMPLE_UINT16_LE: 116 LOOP_ADD(uint16_t, le, UINT16_MAX); break; 91 117 case PCM_SAMPLE_SINT16_LE: 92 LOOP_ADD( uint16_t, le); break;118 LOOP_ADD(int16_t, le, INT16_MAX); break; 93 119 case PCM_SAMPLE_UINT16_BE: 120 LOOP_ADD(uint16_t, be, UINT16_MAX); break; 94 121 case PCM_SAMPLE_SINT16_BE: 95 LOOP_ADD( uint16_t, be); break;122 LOOP_ADD(int16_t, be, INT16_MAX); break; 96 123 case PCM_SAMPLE_UINT24_32_LE: 124 case PCM_SAMPLE_UINT32_LE: 125 LOOP_ADD(uint32_t, le, UINT32_MAX); break; 97 126 case PCM_SAMPLE_SINT24_32_LE: 98 case PCM_SAMPLE_UINT32_LE:99 127 case PCM_SAMPLE_SINT32_LE: 100 LOOP_ADD( uint32_t, le); break;128 LOOP_ADD(int32_t, le, INT32_MAX); break; 101 129 case PCM_SAMPLE_UINT24_32_BE: 130 case PCM_SAMPLE_UINT32_BE: 131 LOOP_ADD(uint32_t, be, UINT32_MAX); break; 102 132 case PCM_SAMPLE_SINT24_32_BE: 103 case PCM_SAMPLE_UINT32_BE:104 133 case PCM_SAMPLE_SINT32_BE: 105 LOOP_ADD( uint32_t, be); break;134 LOOP_ADD(int32_t, be, INT32_MAX); break; 106 135 case PCM_SAMPLE_UINT24_LE: 107 136 case PCM_SAMPLE_SINT24_LE:
Note:
See TracChangeset
for help on using the changeset viewer.