view src/dmcurves.h @ 980:43594ac98f91

Move dmClamp*() functions back to dmlib.h
author Matti Hamalainen <ccr@tnsp.org>
date Fri, 27 Feb 2015 16:25:02 +0200
parents 1b439304ff3c
children 7df95aefb9c6
line wrap: on
line source

/*
 * DMLib
 * -- Wav file writing
 * Programmed and designed by Matti 'ccr' Hamalainen
 * (C) Copyright 2012 Tecnic Software productions (TNSP)
 */
#ifndef DMCURVES_H
#define DMCURVES_H

#include "dmlib.h"
#include "dmvecmat.h"

#ifdef __cplusplus
extern "C" {
#endif

/* Generic parameter interpolation
 */
#define DMM_S_CURVE(t)     ((t) * (t) * (3.0f - 2.0f * (t)))
#define DMM_LERP(t, a, b)  ((a) + (t) * ((b) - (a)))

typedef struct
{
    DMFloat start, end, nsteps;
} DMLerpContext;


void       dmLerpInit(DMLerpContext *ctx, DMFloat start, DMFloat end, DMFloat nsteps);
DMFloat    dmCatmullRom(const DMFloat t, const DMFloat p0, const DMFloat p1, const DMFloat p2, const DMFloat p3);


static inline DMFloat dmLerpSCurve(DMLerpContext *ctx, const DMFloat step)
{
    const DMFloat n = step / ctx->nsteps;
    const DMFloat v = DMM_S_CURVE(n);
    return DMM_LERP(v, ctx->start, ctx->end);
}


static inline DMFloat dmLerpSCurveClamp(DMLerpContext *ctx, const DMFloat step)
{
    const DMFloat n = dmClamp10(step / ctx->nsteps);
    const DMFloat v = DMM_S_CURVE(n);
    return DMM_LERP(v, ctx->start, ctx->end);
}


static inline DMFloat dmLerp1(DMLerpContext *ctx, const DMFloat step)
{
    const DMFloat v = step / ctx->nsteps;
    return DMM_LERP(v, ctx->start, ctx->end);
}


static inline DMFloat dmLerp1Clamp(DMLerpContext *ctx, const DMFloat step)
{
    const DMFloat v = dmClamp10(step / ctx->nsteps);
    return DMM_LERP(v, ctx->start, ctx->end);
}


static inline DMFloat dmCatmullRomClamp(const DMFloat t, const DMFloat p0, const DMFloat p1, const DMFloat p2, const DMFloat p3)
{
    return dmCatmullRom(dmClamp10(t), p0, p1, p2, p3);
}


static inline int dmBSplineGetNPoints(const int npoints, const int slod)
{
    return npoints * slod;
}

int dmBSplineGenerateAlloc(DMVector **dst, int *ndst, const DMVector *points, const int npoints, const int slod);
int dmBSplineGenerate(DMVector *dst, const int ndst, const DMVector *points, const int npoints, const int slod);


#ifdef __cplusplus
}
#endif

#endif // DMCURVES_H