13
0

NO-OP: clang-format

This commit is contained in:
Robin Gareus 2023-05-22 04:38:35 +02:00
parent 5cca7e31e6
commit e9dc1335f9
Signed by: rgareus
GPG Key ID: A090BCE02CF57F04
2 changed files with 382 additions and 385 deletions

View File

@ -29,17 +29,17 @@
#define _ISOC9X_SOURCE 1
#define _ISOC99_SOURCE 1
#ifdef __cplusplus
#include <cmath>
# include <cmath>
#else
#include <math.h>
# include <math.h>
#endif
#undef __USE_SVID
#define __USE_SVID 1
#ifdef __cplusplus
#include <cstdlib>
# include <cstdlib>
#else
#include <stdlib.h>
# include <stdlib.h>
#endif
#include <assert.h>
@ -61,21 +61,23 @@ static const float shaped_bs[] = { 2.033f, -2.165f, 1.959f, -1.590f, 0.6149f };
#define MIN_S24 -8388608
#define SCALE_S24 8388608.0f
inline static float gdither_noise ()
inline static float
gdither_noise ()
{
static uint32_t rnd = 23232323;
rnd = (rnd * 196314165) + 907633515;
return rnd * 2.3283064365387e-10f;
}
GDither gdither_new(GDitherType type, uint32_t channels,
GDither
gdither_new (GDitherType type, uint32_t channels,
GDitherSize bit_depth, int dither_depth)
{
GDither s;
s = (GDither)calloc(1, sizeof(struct GDither_s));
s = (GDither)calloc (1, sizeof (struct GDither_s));
s->type = type;
s->channels = channels;
s->bit_depth = (int)bit_depth;
@ -116,14 +118,14 @@ GDither gdither_new(GDitherType type, uint32_t channels,
case GDitherFloat:
/* normalised float */
s->bias = 0.0f;
s->clamp_u = lrintf(s->scale);
s->clamp_l = lrintf(-s->scale);
s->clamp_u = lrintf (s->scale);
s->clamp_l = lrintf (-s->scale);
break;
case GDitherDouble:
/* normalised float */
s->bias = 0.0f;
s->clamp_u = lrintf(s->scale);
s->clamp_l = lrintf(-s->scale);
s->clamp_u = lrintf (s->scale);
s->clamp_l = lrintf (-s->scale);
break;
case GDitherPerformanceTest:
/* special performance test case */
@ -135,7 +137,7 @@ GDither gdither_new(GDitherType type, uint32_t channels,
break;
default:
/* Not a bit depth we can handle */
free(s);
free (s);
return NULL;
break;
@ -149,42 +151,44 @@ GDither gdither_new(GDitherType type, uint32_t channels,
case GDitherTri:
/* The last whitenoise sample */
s->tri_state = (float *) calloc(channels, sizeof(float));
s->tri_state = (float*)calloc (channels, sizeof (float));
break;
case GDitherShaped:
/* The error from the last few samples encoded */
s->shaped_state = (GDitherShapedState*)
calloc(channels, sizeof(GDitherShapedState));
calloc (channels, sizeof (GDitherShapedState));
break;
}
return s;
}
void gdither_free(GDither s)
void
gdither_free (GDither s)
{
if (s) {
free(s->tri_state);
free(s->shaped_state);
free(s);
free (s->tri_state);
free (s->shaped_state);
free (s);
}
}
inline static void gdither_innner_loop(const GDitherType dt,
inline static void
gdither_innner_loop (const GDitherType dt,
const uint32_t stride, const float bias, const float scale,
const uint32_t post_scale, const int bit_depth,
const uint32_t channel, const uint32_t length, float *ts,
const uint32_t channel, const uint32_t length, float* ts,
GDitherShapedState *ss, float const *x, void *y, const int clamp_u,
GDitherShapedState* ss, float const* x, void* y, const int clamp_u,
const int clamp_l)
{
uint32_t pos, i;
uint8_t *o8 = (uint8_t*) y;
int16_t *o16 = (int16_t*) y;
int32_t *o32 = (int32_t*) y;
uint8_t* o8 = (uint8_t*)y;
int16_t* o16 = (int16_t*)y;
int32_t* o32 = (int32_t*)y;
float tmp, r, ideal;
int64_t clamped;
@ -211,22 +215,18 @@ inline static void gdither_innner_loop(const GDitherType dt,
/* Run FIR and add white noise */
ss->buffer[ss->phase] = gdither_noise () * 0.5f;
tmp += ss->buffer[ss->phase] * shaped_bs[0]
+ ss->buffer[(ss->phase - 1) & GDITHER_SH_BUF_MASK]
* shaped_bs[1]
+ ss->buffer[(ss->phase - 2) & GDITHER_SH_BUF_MASK]
* shaped_bs[2]
+ ss->buffer[(ss->phase - 3) & GDITHER_SH_BUF_MASK]
* shaped_bs[3]
+ ss->buffer[(ss->phase - 4) & GDITHER_SH_BUF_MASK]
* shaped_bs[4];
+ ss->buffer[(ss->phase - 1) & GDITHER_SH_BUF_MASK] * shaped_bs[1]
+ ss->buffer[(ss->phase - 2) & GDITHER_SH_BUF_MASK] * shaped_bs[2]
+ ss->buffer[(ss->phase - 3) & GDITHER_SH_BUF_MASK] * shaped_bs[3]
+ ss->buffer[(ss->phase - 4) & GDITHER_SH_BUF_MASK] * shaped_bs[4];
/* Roll buffer and store last error */
ss->phase = (ss->phase + 1) & GDITHER_SH_BUF_MASK;
ss->buffer[ss->phase] = (float)lrintf(tmp) - ideal;
ss->buffer[ss->phase] = (float)lrintf (tmp) - ideal;
break;
}
clamped = lrintf(tmp);
clamped = lrintf (tmp);
if (clamped > clamp_u) {
clamped = clamp_u;
} else if (clamped < clamp_l) {
@ -248,19 +248,17 @@ inline static void gdither_innner_loop(const GDitherType dt,
}
/* floating pint version of the inner loop function */
inline static void gdither_innner_loop_fp(const GDitherType dt,
inline static void
gdither_innner_loop_fp (const GDitherType dt,
const uint32_t stride, const float bias, const float scale,
const float post_scale, const int bit_depth,
const uint32_t channel, const uint32_t length, float *ts,
GDitherShapedState *ss, float const *x, void *y, const int clamp_u,
const uint32_t channel, const uint32_t length, float* ts,
GDitherShapedState* ss, float const* x, void* y, const int clamp_u,
const int clamp_l)
{
uint32_t pos, i;
float *oflt = (float*) y;
double *odbl = (double*) y;
float* oflt = (float*)y;
double* odbl = (double*)y;
float tmp, r, ideal;
double clamped;
@ -287,22 +285,18 @@ inline static void gdither_innner_loop_fp(const GDitherType dt,
/* Run FIR and add white noise */
ss->buffer[ss->phase] = gdither_noise () * 0.5f;
tmp += ss->buffer[ss->phase] * shaped_bs[0]
+ ss->buffer[(ss->phase - 1) & GDITHER_SH_BUF_MASK]
* shaped_bs[1]
+ ss->buffer[(ss->phase - 2) & GDITHER_SH_BUF_MASK]
* shaped_bs[2]
+ ss->buffer[(ss->phase - 3) & GDITHER_SH_BUF_MASK]
* shaped_bs[3]
+ ss->buffer[(ss->phase - 4) & GDITHER_SH_BUF_MASK]
* shaped_bs[4];
+ ss->buffer[(ss->phase - 1) & GDITHER_SH_BUF_MASK] * shaped_bs[1]
+ ss->buffer[(ss->phase - 2) & GDITHER_SH_BUF_MASK] * shaped_bs[2]
+ ss->buffer[(ss->phase - 3) & GDITHER_SH_BUF_MASK] * shaped_bs[3]
+ ss->buffer[(ss->phase - 4) & GDITHER_SH_BUF_MASK] * shaped_bs[4];
/* Roll buffer and store last error */
ss->phase = (ss->phase + 1) & GDITHER_SH_BUF_MASK;
ss->buffer[ss->phase] = (float)lrintf(tmp) - ideal;
ss->buffer[ss->phase] = (float)lrintf (tmp) - ideal;
break;
}
clamped = (double)lrintf(tmp);
clamped = (double)lrintf (tmp);
if (clamped > clamp_u) {
clamped = clamp_u;
} else if (clamped < clamp_l) {
@ -311,10 +305,10 @@ inline static void gdither_innner_loop_fp(const GDitherType dt,
switch (bit_depth) {
case GDitherFloat:
oflt[i] = (float) (clamped * post_scale);
oflt[i] = (float)(clamped * post_scale);
break;
case GDitherDouble:
odbl[i] = (double) (clamped * post_scale);
odbl[i] = (double)(clamped * post_scale);
break;
}
}
@ -322,12 +316,13 @@ inline static void gdither_innner_loop_fp(const GDitherType dt,
#define GDITHER_CONV_BLOCK 512
void gdither_run(GDither s, uint32_t channel, uint32_t length,
double const *x, void *y)
void
gdither_run (GDither s, uint32_t channel, uint32_t length,
double const* x, void* y)
{
float conv[GDITHER_CONV_BLOCK];
uint32_t i, pos;
char *ycast = (char *)y;
char* ycast = (char*)y;
int step;
@ -352,21 +347,22 @@ void gdither_run(GDither s, uint32_t channel, uint32_t length,
pos = 0;
while (pos < length) {
for (i=0; (i + pos) < length && i < GDITHER_CONV_BLOCK; i++) {
for (i = 0; (i + pos) < length && i < GDITHER_CONV_BLOCK; i++) {
conv[i] = x[pos + i];
}
gdither_runf(s, channel, i, conv, ycast + s->channels * step);
gdither_runf (s, channel, i, conv, ycast + s->channels * step);
pos += i;
}
}
void gdither_runf(GDither s, uint32_t channel, uint32_t length,
float const *x, void *y)
void
gdither_runf (GDither s, uint32_t channel, uint32_t length,
float const* x, void* y)
{
uint32_t pos, i;
float tmp;
int64_t clamped;
GDitherShapedState *ss = NULL;
GDitherShapedState* ss = NULL;
if (!s || channel >= s->channels) {
return;
@ -377,13 +373,13 @@ void gdither_runf(GDither s, uint32_t channel, uint32_t length,
}
if (s->type == GDitherNone && s->bit_depth == 23) {
int32_t *o32 = (int32_t*) y;
int32_t* o32 = (int32_t*)y;
for (pos = 0; pos < length; pos++) {
i = channel + (pos * s->channels);
tmp = x[i] * 8388608.0f;
clamped = lrintf(tmp);
clamped = lrintf (tmp);
if (clamped > 8388607) {
clamped = 8388607;
} else if (clamped < -8388608) {
@ -401,22 +397,22 @@ void gdither_runf(GDither s, uint32_t channel, uint32_t length,
if (s->bit_depth == 8 && s->dither_depth == 8) {
switch (s->type) {
case GDitherNone:
gdither_innner_loop(GDitherNone, s->channels, 128.0f, SCALE_U8,
gdither_innner_loop (GDitherNone, s->channels, 128.0f, SCALE_U8,
1, 8, channel, length, NULL, NULL, x, y,
MAX_U8, MIN_U8);
break;
case GDitherRect:
gdither_innner_loop(GDitherRect, s->channels, 128.0f, SCALE_U8,
gdither_innner_loop (GDitherRect, s->channels, 128.0f, SCALE_U8,
1, 8, channel, length, NULL, NULL, x, y,
MAX_U8, MIN_U8);
break;
case GDitherTri:
gdither_innner_loop(GDitherTri, s->channels, 128.0f, SCALE_U8,
gdither_innner_loop (GDitherTri, s->channels, 128.0f, SCALE_U8,
1, 8, channel, length, s->tri_state,
NULL, x, y, MAX_U8, MIN_U8);
break;
case GDitherShaped:
gdither_innner_loop(GDitherShaped, s->channels, 128.0f, SCALE_U8,
gdither_innner_loop (GDitherShaped, s->channels, 128.0f, SCALE_U8,
1, 8, channel, length, NULL,
ss, x, y, MAX_U8, MIN_U8);
break;
@ -424,22 +420,22 @@ void gdither_runf(GDither s, uint32_t channel, uint32_t length,
} else if (s->bit_depth == 16 && s->dither_depth == 16) {
switch (s->type) {
case GDitherNone:
gdither_innner_loop(GDitherNone, s->channels, 0.0f, SCALE_S16,
gdither_innner_loop (GDitherNone, s->channels, 0.0f, SCALE_S16,
1, 16, channel, length, NULL, NULL, x, y,
MAX_S16, MIN_S16);
break;
case GDitherRect:
gdither_innner_loop(GDitherRect, s->channels, 0.0f, SCALE_S16,
gdither_innner_loop (GDitherRect, s->channels, 0.0f, SCALE_S16,
1, 16, channel, length, NULL, NULL, x, y,
MAX_S16, MIN_S16);
break;
case GDitherTri:
gdither_innner_loop(GDitherTri, s->channels, 0.0f, SCALE_S16,
gdither_innner_loop (GDitherTri, s->channels, 0.0f, SCALE_S16,
1, 16, channel, length, s->tri_state,
NULL, x, y, MAX_S16, MIN_S16);
break;
case GDitherShaped:
gdither_innner_loop(GDitherShaped, s->channels, 0.0f,
gdither_innner_loop (GDitherShaped, s->channels, 0.0f,
SCALE_S16, 1, 16, channel, length, NULL,
ss, x, y, MAX_S16, MIN_S16);
break;
@ -447,34 +443,34 @@ void gdither_runf(GDither s, uint32_t channel, uint32_t length,
} else if (s->bit_depth == 32 && s->dither_depth == 24) {
switch (s->type) {
case GDitherNone:
gdither_innner_loop(GDitherNone, s->channels, 0.0f, SCALE_S24,
gdither_innner_loop (GDitherNone, s->channels, 0.0f, SCALE_S24,
256, 32, channel, length, NULL, NULL, x,
y, MAX_S24, MIN_S24);
break;
case GDitherRect:
gdither_innner_loop(GDitherRect, s->channels, 0.0f, SCALE_S24,
gdither_innner_loop (GDitherRect, s->channels, 0.0f, SCALE_S24,
256, 32, channel, length, NULL, NULL, x,
y, MAX_S24, MIN_S24);
break;
case GDitherTri:
gdither_innner_loop(GDitherTri, s->channels, 0.0f, SCALE_S24,
gdither_innner_loop (GDitherTri, s->channels, 0.0f, SCALE_S24,
256, 32, channel, length, s->tri_state,
NULL, x, y, MAX_S24, MIN_S24);
break;
case GDitherShaped:
gdither_innner_loop(GDitherShaped, s->channels, 0.0f, SCALE_S24,
gdither_innner_loop (GDitherShaped, s->channels, 0.0f, SCALE_S24,
256, 32, channel, length,
NULL, ss, x, y, MAX_S24, MIN_S24);
break;
}
} else if (s->bit_depth == GDitherFloat || s->bit_depth == GDitherDouble) {
gdither_innner_loop_fp(s->type, s->channels, s->bias, s->scale,
gdither_innner_loop_fp (s->type, s->channels, s->bias, s->scale,
s->post_scale_fp, s->bit_depth, channel, length,
s->tri_state, ss, x, y, s->clamp_u, s->clamp_l);
} else {
/* no special case handling, just process it from the struct */
gdither_innner_loop(s->type, s->channels, s->bias, s->scale,
gdither_innner_loop (s->type, s->channels, s->bias, s->scale,
s->post_scale, s->bit_depth, channel,
length, s->tri_state, ss, x, y, s->clamp_u,
s->clamp_l);

View File

@ -24,6 +24,7 @@
extern "C" {
#endif
#include <stdint.h>
#include "gdither_types.h"
/* Create and initialise a state structure, takes a dither type, a number of