view flattendynamics-ladspa.h @ 13:98fd2543a5f2

Slightly more effective max rms
author Chris Cannam
date Tue, 22 Jul 2014 13:49:46 +0100
parents 355fb9ea3888
children 7bb35203a7bd
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_sumOfSquaresLongTerm;
    double m_sumOfSquaresShortTerm;

    float m_rmsLongTerm;
    float m_rmsShortTerm;

    float m_maxRmsLongTerm;
    float m_maxRmsShortTerm;

    float m_gain;
};

#endif