view flattendynamics-ladspa.h @ 5:6b732542a34c

Experiment with permitting some local variation rather than always aiming to flatten
author Chris Cannam
date Mon, 21 Jul 2014 18:01:11 +0100
parents f21753c504e1
children 4d48ab57fbcc
line wrap: on
line source
/* -*- c-basic-offset: 4 indent-tabs-mode: nil -*-  vi:set ts=8 sts=4 sw=4: */

#ifndef FLATTENDYNAMICS_LADSPA_H
#define FLATTENDYNAMICS_LADSPA_H

#include <ladspa.h>

class FlattenDynamics
{
public:
    static const LADSPA_Descriptor *getDescriptor(unsigned long index);

private:
    FlattenDynamics(int sampleRate);
    ~FlattenDynamics();

    enum {
        AudioInputPort     = 0,
	AudioOutputPort    = 1,
        GainOutputPort     = 2,
	PortCount          = 3,
    };

    static const char *const portNames[PortCount];
    static const LADSPA_PortDescriptor ports[PortCount];
    static const LADSPA_PortRangeHint hints[PortCount];
    static const LADSPA_Properties properties;
    static const LADSPA_Descriptor ladspaDescriptor;

    static LADSPA_Handle instantiate(const LADSPA_Descriptor *, unsigned long);
    static void connectPort(LADSPA_Handle, unsigned long, LADSPA_Data *);
    static void activate(LADSPA_Handle);
    static void run(LADSPA_Handle, unsigned long);
    static void deactivate(LADSPA_Handle);
    static void cleanup(LADSPA_Handle);

    void reset();
    void runImpl(unsigned long);
    float process(float);
    void updateRMS(float);
    void updateParameters();

    int m_sampleRate;
    float *m_input;
    float *m_output;
    float *m_pgain;

    float *m_history;
    int m_histlen;
    int m_histwrite;
    int m_histread;

    double m_sumOfSquares;
    float m_rms;
    float m_maxRms;
    float m_gain;
};

#endif