Chris@49: /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ Chris@0: Chris@0: /* Chris@52: Sonic Visualiser Chris@52: An audio file viewer and annotation editor. Chris@52: Centre for Digital Music, Queen Mary, University of London. Chris@0: Chris@52: This program is free software; you can redistribute it and/or Chris@52: modify it under the terms of the GNU General Public License as Chris@52: published by the Free Software Foundation; either version 2 of the Chris@52: License, or (at your option) any later version. See the file Chris@52: COPYING included with this distribution for more information. Chris@0: */ Chris@0: Chris@0: /* Chris@0: This is a modified version of a source file from the Chris@0: Rosegarden MIDI and audio sequencer and notation editor. Chris@17: This file copyright 2000-2006 Chris Cannam. Chris@0: */ Chris@0: Chris@0: #ifndef _AUDIO_LEVEL_H_ Chris@0: #define _AUDIO_LEVEL_H_ Chris@0: Chris@0: /** Chris@0: * AudioLevel converts audio sample levels between various scales: Chris@0: * Chris@0: * - dB values (-inf -> 0dB) Chris@0: * - floating-point values (-1.0 -> 1.0) such as used for a Chris@0: * multiplier for gain or in floating-point WAV files Chris@0: * - integer values intended to correspond to pixels on a fader Chris@0: * or vu level scale. Chris@0: */ Chris@0: Chris@0: class AudioLevel Chris@0: { Chris@0: public: Chris@0: Chris@0: static const float DB_FLOOR; Chris@0: Chris@0: enum FaderType { Chris@0: ShortFader = 0, // -40 -> +6 dB Chris@0: LongFader = 1, // -70 -> +10 dB Chris@0: IEC268Meter = 2, // -70 -> 0 dB Chris@0: IEC268LongMeter = 3, // -70 -> +10 dB (0dB aligns with LongFader) Chris@0: PreviewLevel = 4 Chris@0: }; Chris@0: Chris@0: static float multiplier_to_dB(float multiplier); Chris@0: static float dB_to_multiplier(float dB); Chris@0: Chris@0: static float fader_to_dB(int level, int maxLevel, FaderType type); Chris@0: static int dB_to_fader(float dB, int maxFaderLevel, FaderType type); Chris@0: Chris@0: static float fader_to_multiplier(int level, int maxLevel, FaderType type); Chris@0: static int multiplier_to_fader(float multiplier, int maxFaderLevel, Chris@0: FaderType type); Chris@0: Chris@0: // fast if "levels" doesn't change often -- for audio segment previews Chris@0: static int multiplier_to_preview(float multiplier, int levels); Chris@0: static float preview_to_multiplier(int level, int levels); Chris@0: }; Chris@0: Chris@0: Chris@0: #endif Chris@0: