Ignore:
Timestamp:
2012-07-12T17:21:08Z (12 years ago)
Author:
Jan Vesely <jano.vesely@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
992ef56
Parents:
737b4c0
Message:

hound: Move mixing to audio_source.

File:
1 edited

Legend:

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

    r737b4c0 rec49085  
    3636#include <assert.h>
    3737#include <errno.h>
     38#include <macros.h>
    3839#include <stdlib.h>
    3940#include <str.h>
     
    7677}
    7778
    78 int audio_source_get_buffer(audio_source_t *source, const void **buffer, size_t *size)
     79int audio_source_add_self(audio_source_t *source, void *buffer, size_t size,
     80    const audio_format_t *f)
    7981{
    8082        assert(source);
    81         if (!buffer || !size) {
    82                 log_debug("Incorrect parameters.");
     83        if (!buffer) {
     84                log_debug("Non-existent buffer");
     85                return EBADMEM;
     86        }
     87        if (!f || size == 0) {
     88                log_debug("No format or zero size");
     89        }
     90        if (size % (pcm_sample_format_size(f->sample_format) * f->channels)) {
     91                log_debug("Buffer does not fit integer number of frames");
    8392                return EINVAL;
    8493        }
    85         if (source->get_data.hook)
    86                 source->get_data.hook(source->get_data.arg);
    87         if (!source->available.base || !source->available.size)
    88                 return EOVERFLOW; /* In fact it's underflow */
     94        if (!audio_format_same(&source->format, f)) {
     95                log_debug("Format conversion is not supported yet");
     96                return ENOTSUP;
     97        }
    8998
    90         const size_t requested_size =
    91             (*size == 0) || (*size > source->available.size)
    92             ? source->available.size : *size;
    93         *buffer = source->available.base;
    94         *size = requested_size;
    95         source->available.size -= requested_size;
    96         source->available.base += requested_size;
     99        if (source->available.size == 0) {
     100                log_debug("No data to add");
     101                return EOVERFLOW; /* In fact this is underflow... */
     102        }
     103
     104        const size_t real_size = min(size, source->available.size);
     105        const int ret =
     106            audio_format_mix(buffer, source->available.base, real_size, f);
     107        if (ret != EOK) {
     108                log_debug("Mixing failed");
     109                return ret;
     110        }
     111        source->available.base += real_size;
     112        source->available.size -= real_size;
    97113        return EOK;
    98114}
     115
    99116/**
    100117 * @}
Note: See TracChangeset for help on using the changeset viewer.