2023-03-13 11:39:47 +01:00
|
|
|
// SPDX-License-Identifier: LGPL-2.1
|
2023-03-13 11:56:06 +01:00
|
|
|
// Copyright The Music Player Daemon Project
|
|
|
|
// Based on AudioCompress (c)2007 busybee (http://beesbuzz.biz/
|
2009-12-02 18:11:53 +01:00
|
|
|
|
2023-03-13 11:56:06 +01:00
|
|
|
#pragma once
|
2009-12-02 18:11:53 +01:00
|
|
|
|
2023-03-13 11:56:06 +01:00
|
|
|
#include <cstdint>
|
2009-12-02 18:11:53 +01:00
|
|
|
|
2023-03-13 12:12:47 +01:00
|
|
|
class PcmNormalizer {
|
|
|
|
///! Target level (on a scale of 0-32767)
|
|
|
|
static constexpr int target = 16384;
|
|
|
|
|
|
|
|
//! The maximum amount to amplify by
|
|
|
|
static constexpr int maxgain = 32;
|
|
|
|
|
|
|
|
//! How much inertia ramping has
|
|
|
|
static constexpr int smooth = 8;
|
|
|
|
|
|
|
|
//! History of the peak values
|
|
|
|
int *const peaks;
|
|
|
|
|
|
|
|
//! History of the gain values
|
|
|
|
int *const gain;
|
|
|
|
|
|
|
|
//! History of clip amounts
|
|
|
|
int *const clipped;
|
|
|
|
|
|
|
|
unsigned int pos = 0;
|
|
|
|
const unsigned int bufsz;
|
|
|
|
|
|
|
|
public:
|
|
|
|
PcmNormalizer(unsigned history=400) noexcept
|
|
|
|
:peaks(new int[history]{}),
|
|
|
|
gain(new int[history]{}),
|
|
|
|
clipped(new int[history]{}),
|
|
|
|
bufsz(history)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
~PcmNormalizer() noexcept {
|
|
|
|
delete[] peaks;
|
|
|
|
delete[] gain;
|
|
|
|
delete[] clipped;
|
|
|
|
}
|
|
|
|
|
|
|
|
//! Process 16-bit signed data
|
|
|
|
void ProcessS16(int16_t *data, unsigned int count) noexcept;
|
|
|
|
};
|
2009-12-02 18:11:53 +01:00
|
|
|
|
|
|
|
//! TODO: Compressor_Process_int32, Compressor_Process_float, others as needed
|
|
|
|
|
|
|
|
//! TODO: functions for getting at the peak/gain/clip history buffers (for monitoring)
|