Changeset 950110ee in mainline for uspace/srv/audio/hound/audio_format.c
- Timestamp:
- 2012-07-17T07:33:43Z (11 years ago)
- Branches:
- lfn, master, serial
- Children:
- ea6c838
- Parents:
- 389ef25
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/audio/hound/audio_format.c
r389ef25 r950110ee 90 90 int audio_format_mix(void *dst, const void *src, size_t size, const audio_format_t *f) 91 91 { 92 if (!dst || !src || !f) 92 return audio_format_convert_and_mix(dst, size, src, size, f, f); 93 } 94 int audio_format_convert_and_mix(void *dst, size_t dst_size, const void *src, 95 size_t src_size, const audio_format_t *sf, const audio_format_t *df) 96 { 97 if (!dst || !src || !sf || !df) 93 98 return EINVAL; 94 const size_t sample_size = pcm_sample_format_size(f->sample_format); 95 if ((size % sample_size) != 0) 99 const size_t src_frame_size = audio_format_frame_size(sf); 100 if ((src_size % src_frame_size) != 0) 101 return EINVAL; 102 103 const size_t dst_frame_size = audio_format_frame_size(df); 104 if ((src_size % dst_frame_size) != 0) 96 105 return EINVAL; 97 106 … … 101 110 #define LOOP_ADD(type, endian, low, high) \ 102 111 do { \ 103 const unsigned frame_size = audio_format_frame_size(f); \ 104 const unsigned frame_count = size / frame_size; \ 112 const unsigned frame_count = dst_size / dst_frame_size; \ 105 113 for (size_t i = 0; i < frame_count; ++i) { \ 106 for (unsigned j = 0; j < f->channels; ++j) { \114 for (unsigned j = 0; j < df->channels; ++j) { \ 107 115 const float a = \ 108 get_normalized_sample(dst, s ize, i, j,f);\116 get_normalized_sample(dst, src_size, i, j, df);\ 109 117 const float b = \ 110 get_normalized_sample(src, size, i, j,f);\118 get_normalized_sample(src, dst_size, i, j, sf);\ 111 119 float c = (a + b); \ 112 120 if (c < -1.0) c = -1.0; \ … … 115 123 c *= ((float)(type)high - (float)(type)low) / 2; \ 116 124 c += (float)(type)low; \ 117 if (c > (float)(type)high) { \118 printf("SCALE HIGH failed\n"); \119 } \120 if (c < (float)(type)low) { \121 printf("SCALE LOW failed\n"); \122 } \123 125 type *dst_buf = dst; \ 124 const unsigned pos = i * f->channels + j; \125 if (pos < ( size / sizeof(type))) \126 const unsigned pos = i * df->channels + j; \ 127 if (pos < (dst_size / sizeof(type))) \ 126 128 dst_buf[pos] = to((type)c, type, endian); \ 127 129 } \ … … 129 131 } while (0) 130 132 131 switch ( f->sample_format) {133 switch (df->sample_format) { 132 134 case PCM_SAMPLE_UINT8: 133 135 LOOP_ADD(uint8_t, le, UINT8_MIN, UINT8_MAX); break;
Note: See TracChangeset
for help on using the changeset viewer.