Changeset 950110ee in mainline


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

hound: convert format while mixing.

Still no resampling.

Location:
uspace/srv/audio/hound
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • uspace/srv/audio/hound/audio_format.c

    r389ef25 r950110ee  
    9090int audio_format_mix(void *dst, const void *src, size_t size, const audio_format_t *f)
    9191{
    92         if (!dst || !src || !f)
     92        return audio_format_convert_and_mix(dst, size, src, size, f, f);
     93}
     94int 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)
    9398                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)
    96105                return EINVAL;
    97106
     
    101110#define LOOP_ADD(type, endian, low, high) \
    102111do { \
    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; \
    105113        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) { \
    107115                        const float a = \
    108                             get_normalized_sample(dst, size, i, j, f);\
     116                            get_normalized_sample(dst, src_size, i, j, df);\
    109117                        const float b = \
    110                             get_normalized_sample(src, size, i, j, f);\
     118                            get_normalized_sample(src, dst_size, i, j, sf);\
    111119                        float c = (a + b); \
    112120                        if (c < -1.0) c = -1.0; \
     
    115123                        c *= ((float)(type)high - (float)(type)low) / 2; \
    116124                        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                         } \
    123125                        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))) \
    126128                                dst_buf[pos] = to((type)c, type, endian); \
    127129                } \
     
    129131} while (0)
    130132
    131         switch (f->sample_format) {
     133        switch (df->sample_format) {
    132134        case PCM_SAMPLE_UINT8:
    133135                LOOP_ADD(uint8_t, le, UINT8_MIN, UINT8_MAX); break;
  • uspace/srv/audio/hound/audio_format.h

    r389ef25 r950110ee  
    7171        return audio_format_same(f, &AUDIO_FORMAT_ANY);
    7272}
     73int audio_format_convert_and_mix(void *dst, size_t dst_size, const void *src,
     74    size_t src_size, const audio_format_t *sf, const audio_format_t *df);
    7375int audio_format_mix(void *dst, const void *src, size_t size, const audio_format_t *f);
    7476int audio_format_convert(audio_format_t a, void* srca, size_t sizea,
  • uspace/srv/audio/hound/audio_source.c

    r389ef25 r950110ee  
    120120                return ENOTSUP;
    121121        }
     122        const size_t src_frame_size = audio_format_frame_size(&source->format);
     123        const size_t dst_frames = size / audio_format_frame_size(f);
     124
    122125        if (source->available_data.position == NULL ||
    123126            source->available_data.size == 0) {
    124127                int ret = EOVERFLOW; /* In fact this is underflow... */
    125128                if (source->update_available_data)
    126                         ret = source->update_available_data(source, size);
     129                        ret = source->update_available_data(source,
     130                            dst_frames * src_frame_size);
    127131                if (ret != EOK) {
    128132                        log_debug("No data to add to %p(%zu)", buffer, size);
     
    131135        }
    132136
    133         const size_t real_size = min(size, source->available_data.size);
    134         const int ret =
    135             audio_format_mix(buffer, source->available_data.position, real_size, f);
     137        const int ret = audio_format_convert_and_mix(buffer, size,
     138               source->available_data.position, source->available_data.size,
     139               &source->format, f);
    136140        if (ret != EOK) {
    137                 log_debug("Mixing failed %p <= %p, %zu",
    138                     buffer, source->available_data.position, real_size);
     141                log_debug("Mixing failed %p <= %p, frames: %zu",
     142                    buffer, source->available_data.position, dst_frames);
    139143                return ret;
    140144        }
    141145
    142         source->available_data.position += real_size;
    143         source->available_data.size -= real_size;
    144 
    145 //      log_verbose("Mixing successful %p <= %p, %zu",
    146 //          buffer, source->available_data.position, real_size);
    147 
    148         buffer += real_size;
    149         size -= real_size;
    150 
    151         //TODO update data again
    152         if (size)
    153                 log_warning("not enough data");
    154 
     146        source->available_data.position += (dst_frames * src_frame_size);
     147        source->available_data.size -= (dst_frames * src_frame_size);
    155148        return EOK;
    156149}
Note: See TracChangeset for help on using the changeset viewer.