pipewire/spa/plugins/audioconvert/dither-ops.h

92 lines
2.9 KiB
C
Raw Normal View History

2022-06-24 14:15:17 +02:00
/* Spa
*
* Copyright © 2022 Wim Taymans
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice (including the next
* paragraph) shall be included in all copies or substantial portions of the
* Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/
#include <string.h>
#include <stdio.h>
#include <spa/utils/defs.h>
#include <spa/utils/string.h>
2022-06-24 14:15:17 +02:00
#include <spa/param/audio/raw.h>
#define DITHER_SIZE (1<<8)
#define DITHER_MOD (DITHER_SIZE-1)
2022-06-24 14:15:17 +02:00
struct dither {
2022-06-24 14:15:17 +02:00
uint32_t intensity;
#define DITHER_METHOD_NONE 0
#define DITHER_METHOD_RECTANGULAR 2
#define DITHER_METHOD_TRIANGULAR 3
#define DITHER_METHOD_SHAPED_5 4
uint32_t method;
2022-06-24 14:15:17 +02:00
uint32_t n_channels;
uint32_t cpu_flags;
struct spa_log *log;
void (*process) (struct dither *d, void * SPA_RESTRICT dst[],
const void * SPA_RESTRICT src[], uint32_t n_samples);
void (*free) (struct dither *d);
2022-06-24 14:15:17 +02:00
float tab[DITHER_SIZE];
2022-06-24 14:15:17 +02:00
int tab_idx;
};
int dither_init(struct dither *d);
2022-06-24 14:15:17 +02:00
static const struct dither_method_info {
const char *label;
const char *description;
uint32_t method;
} dither_method_info[] = {
[DITHER_METHOD_NONE] = { "none", "Disabled", DITHER_METHOD_NONE },
[DITHER_METHOD_RECTANGULAR] = { "rectangular", "Rectangular dithering", DITHER_METHOD_RECTANGULAR },
[DITHER_METHOD_TRIANGULAR] = { "triangular", "Triangular dithering", DITHER_METHOD_TRIANGULAR },
[DITHER_METHOD_SHAPED_5] = { "shaped5", "Shaped 5 dithering", DITHER_METHOD_SHAPED_5 }
};
static inline uint32_t dither_method_from_label(const char *label)
{
uint32_t i;
for (i = 0; i < SPA_N_ELEMENTS(dither_method_info); i++) {
if (spa_streq(dither_method_info[i].label, label))
return dither_method_info[i].method;
}
return DITHER_METHOD_NONE;
}
#define dither_process(d,...) (d)->process(d, __VA_ARGS__)
#define dither_free(d) (d)->free(d)
2022-06-24 14:15:17 +02:00
#define DEFINE_FUNCTION(name,arch) \
void dither_##name##_##arch(struct dither *d, \
2022-06-24 14:15:17 +02:00
void * SPA_RESTRICT dst[], \
const void * SPA_RESTRICT src[], \
2022-06-24 14:15:17 +02:00
uint32_t n_samples);
#define DITHER_OPS_MAX_ALIGN 16
2022-06-24 14:15:17 +02:00
DEFINE_FUNCTION(f32, c);
#undef DEFINE_FUNCTION