Changeset 43c40a3 in mainline


Ignore:
Timestamp:
2012-07-13T21:13:15Z (12 years ago)
Author:
Jan Vesely <jano.vesely@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
6906f61
Parents:
13df13c8
Message:

hound: Fix mixing.

Use clipping with float conversion

File:
1 edited

Legend:

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

    r13df13c8 r43c40a3  
    3737#include <byteorder.h>
    3838#include <errno.h>
     39#include <macros.h>
    3940
    4041#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)
    4165
    4266bool audio_format_same(const audio_format_t *a, const audio_format_t* b)
     
    6185         * and all little fluffy things...
    6286         * AND it does not check for overflows (FIXME)*/
    63 #define LOOP_ADD(type, endian) \
     87#define LOOP_ADD(type, endian, max) \
    6488do { \
    6589        const type *src_buff = src; \
    6690        type *dst_buff = dst; \
    6791        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; \
    7196                dst_buff[i] = host2 ## type ## _ ## endian(c); \
    7297        } \
     
    89114                }
    90115        case PCM_SAMPLE_UINT16_LE:
     116                LOOP_ADD(uint16_t, le, UINT16_MAX); break;
    91117        case PCM_SAMPLE_SINT16_LE:
    92                 LOOP_ADD(uint16_t, le); break;
     118                LOOP_ADD(int16_t, le, INT16_MAX); break;
    93119        case PCM_SAMPLE_UINT16_BE:
     120                LOOP_ADD(uint16_t, be, UINT16_MAX); break;
    94121        case PCM_SAMPLE_SINT16_BE:
    95                 LOOP_ADD(uint16_t, be); break;
     122                LOOP_ADD(int16_t, be, INT16_MAX); break;
    96123        case PCM_SAMPLE_UINT24_32_LE:
     124        case PCM_SAMPLE_UINT32_LE:
     125                LOOP_ADD(uint32_t, le, UINT32_MAX); break;
    97126        case PCM_SAMPLE_SINT24_32_LE:
    98         case PCM_SAMPLE_UINT32_LE:
    99127        case PCM_SAMPLE_SINT32_LE:
    100                 LOOP_ADD(uint32_t, le); break;
     128                LOOP_ADD(int32_t, le, INT32_MAX); break;
    101129        case PCM_SAMPLE_UINT24_32_BE:
     130        case PCM_SAMPLE_UINT32_BE:
     131                LOOP_ADD(uint32_t, be, UINT32_MAX); break;
    102132        case PCM_SAMPLE_SINT24_32_BE:
    103         case PCM_SAMPLE_UINT32_BE:
    104133        case PCM_SAMPLE_SINT32_BE:
    105                 LOOP_ADD(uint32_t, be); break;
     134                LOOP_ADD(int32_t, be, INT32_MAX); break;
    106135        case PCM_SAMPLE_UINT24_LE:
    107136        case PCM_SAMPLE_SINT24_LE:
Note: See TracChangeset for help on using the changeset viewer.