Changeset ec49085 in mainline


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.

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

Legend:

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

    r737b4c0 rec49085  
    150150        list_foreach(sink->sources, it) {
    151151                audio_source_t *source = audio_source_list_instance(it);
    152                 assert(audio_format_same(&sink->format, audio_source_format(source)));
    153                 const void *source_buffer;
    154                 size_t source_buffer_size = size;
    155                 int ret = audio_source_get_buffer(source, &source_buffer,
    156                     &source_buffer_size);
    157                 if (ret != EOK) {
    158                         log_warning("Could not get buffer from source %s",
    159                             source->name);
    160                         continue;
    161                 }
    162                 assert(source_buffer_size == size);
    163                 ret = audio_format_mix(dest, source_buffer, size, &sink->format);
     152                const int ret =
     153                    audio_source_add_self(source, dest, size, &sink->format);
    164154                if (ret != EOK) {
    165155                        log_warning("Failed to mix source %s: %s",
  • 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 * @}
  • uspace/srv/audio/hound/audio_source.h

    r737b4c0 rec49085  
    7676}
    7777int audio_source_connected(audio_source_t *source, const audio_format_t *f);
    78 int audio_source_get_buffer(audio_source_t *source, const void **buffer, size_t *size);
     78int audio_source_add_self(audio_source_t *source, void *buffer, size_t size,
     79    const audio_format_t *f);
    7980static inline const audio_format_t *audio_source_format(const audio_source_t *s)
    8081{
Note: See TracChangeset for help on using the changeset viewer.