Added DaisySP
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
#include <math.h>
|
||||
#include "crossfade.h"
|
||||
#include "dsp.h"
|
||||
|
||||
#define REALLYSMALLFLOAT 0.000001f
|
||||
|
||||
using namespace daisysp;
|
||||
|
||||
const float kCrossLogMin = logf(REALLYSMALLFLOAT);
|
||||
const float kCrossLogMax = logf(1.0f);
|
||||
|
||||
float CrossFade::Process(float &in1, float &in2)
|
||||
{
|
||||
float scalar_1, scalar_2;
|
||||
switch(curve_)
|
||||
{
|
||||
case CROSSFADE_LIN:
|
||||
scalar_1 = pos_;
|
||||
return (in1 * (1.0f - scalar_1)) + (in2 * scalar_1);
|
||||
|
||||
case CROSSFADE_CPOW:
|
||||
scalar_1 = sinf(pos_ * HALFPI_F);
|
||||
scalar_2 = sinf((1.0f - pos_) * HALFPI_F);
|
||||
return (in1 * scalar_2) + (in2 * scalar_1);
|
||||
|
||||
case CROSSFADE_LOG:
|
||||
scalar_1
|
||||
= expf(pos_ * (kCrossLogMax - kCrossLogMin) + kCrossLogMin);
|
||||
return (in1 * (1.0f - scalar_1)) + (in2 * scalar_1);
|
||||
|
||||
case CROSSFADE_EXP:
|
||||
scalar_1 = pos_ * pos_;
|
||||
return (in1 * (1.0f - scalar_1)) + (in2 * scalar_1);
|
||||
|
||||
default: return 0;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,86 @@
|
||||
/*
|
||||
Copyright (c) 2020 Electrosmith, Corp, Paul Batchelor
|
||||
|
||||
Use of this source code is governed by an MIT-style
|
||||
license that can be found in the LICENSE file or at
|
||||
https://opensource.org/licenses/MIT.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#ifndef DSY_CROSSFADE_H
|
||||
#define DSY_CROSSFADE_H
|
||||
#include <stdint.h>
|
||||
#ifdef __cplusplus
|
||||
|
||||
namespace daisysp
|
||||
{
|
||||
/** Curve applied to the CrossFade
|
||||
- LIN = linear
|
||||
- CPOW = constant power
|
||||
- LOG = logarithmic
|
||||
- EXP exponential
|
||||
- LAST = end of enum (used for array indexing)
|
||||
*/
|
||||
enum
|
||||
{
|
||||
CROSSFADE_LIN,
|
||||
CROSSFADE_CPOW,
|
||||
CROSSFADE_LOG,
|
||||
CROSSFADE_EXP,
|
||||
CROSSFADE_LAST,
|
||||
};
|
||||
|
||||
/** Performs a CrossFade between two signals
|
||||
|
||||
Original author: Paul Batchelor
|
||||
|
||||
Ported from Soundpipe by Andrew Ikenberry
|
||||
|
||||
added curve option for constant power, etc.
|
||||
*/
|
||||
class CrossFade
|
||||
{
|
||||
public:
|
||||
CrossFade() {}
|
||||
~CrossFade() {}
|
||||
/** Initializes CrossFade module
|
||||
Defaults
|
||||
- current position = .5
|
||||
- curve = linear
|
||||
*/
|
||||
inline void Init(int curve)
|
||||
{
|
||||
pos_ = 0.5f;
|
||||
curve_ = curve < CROSSFADE_LAST ? curve : CROSSFADE_LIN;
|
||||
}
|
||||
|
||||
/** Initialize with default linear curve
|
||||
*/
|
||||
inline void Init() { Init(CROSSFADE_LIN); }
|
||||
/** processes CrossFade and returns single sample
|
||||
*/
|
||||
float Process(float &in1, float &in2);
|
||||
|
||||
|
||||
/** Sets position of CrossFade between two input signals
|
||||
Input range: 0 to 1
|
||||
*/
|
||||
inline void SetPos(float pos) { pos_ = pos; }
|
||||
/** Sets current curve applied to CrossFade
|
||||
Expected input: See [Curve Options](##curve-options)
|
||||
*/
|
||||
inline void SetCurve(uint8_t curve) { curve_ = curve; }
|
||||
/** Returns current position
|
||||
*/
|
||||
inline float GetPos(float pos) { return pos_; }
|
||||
/** Returns current curve
|
||||
*/
|
||||
inline uint8_t GetCurve(uint8_t curve) { return curve_; }
|
||||
|
||||
private:
|
||||
float pos_;
|
||||
uint8_t curve_;
|
||||
};
|
||||
} // namespace daisysp
|
||||
#endif
|
||||
#endif
|
||||
@@ -0,0 +1,29 @@
|
||||
#include "dsp.h"
|
||||
#include "limiter.h"
|
||||
|
||||
#define SLOPE(out, in, positive, negative) \
|
||||
{ \
|
||||
float error = (in)-out; \
|
||||
out += (error > 0 ? positive : negative) * error; \
|
||||
}
|
||||
|
||||
namespace daisysp
|
||||
{
|
||||
void Limiter::Init()
|
||||
{
|
||||
peak_ = 0.5f;
|
||||
}
|
||||
|
||||
void Limiter::ProcessBlock(float *in, size_t size, float pre_gain)
|
||||
{
|
||||
while(size--)
|
||||
{
|
||||
float pre = *in * pre_gain;
|
||||
float peak = fabsf(pre);
|
||||
SLOPE(peak_, peak, 0.05f, 0.00002f);
|
||||
float gain = (peak_ <= 1.0f ? 1.0f : 1.0f / peak_);
|
||||
*in++ = SoftLimit(pre * gain * 0.7f);
|
||||
}
|
||||
}
|
||||
|
||||
} //namespace daisysp
|
||||
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
Copyright (c) 2020 Electrosmith, Corp, Emilie Gillet
|
||||
|
||||
Use of this source code is governed by an MIT-style
|
||||
license that can be found in the LICENSE file or at
|
||||
https://opensource.org/licenses/MIT.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#ifndef LIMITER_H
|
||||
#define LIMITER_H
|
||||
#include <stdlib.h>
|
||||
namespace daisysp
|
||||
{
|
||||
/** Simple Peak Limiter
|
||||
|
||||
This was extracted from pichenettes/stmlib.
|
||||
|
||||
Credit to pichenettes/Mutable Instruments
|
||||
*/
|
||||
class Limiter
|
||||
{
|
||||
public:
|
||||
Limiter() {}
|
||||
~Limiter() {}
|
||||
/** Initializes the Limiter instance.
|
||||
*/
|
||||
void Init();
|
||||
|
||||
/** Processes a block of audio through the limiter.
|
||||
\param in - pointer to a block of audio samples to be processed. The buffer is operated on directly.
|
||||
\param size - size of the buffer "in"
|
||||
\param pre_gain - amount of pre_gain applied to the signal.
|
||||
*/
|
||||
void ProcessBlock(float *in, size_t size, float pre_gain);
|
||||
|
||||
private:
|
||||
float peak_;
|
||||
};
|
||||
} // namespace daisysp
|
||||
#endif
|
||||
Reference in New Issue
Block a user