player/Thread: add option "mixramp_analyzer"

This commit is contained in:
Max Kellermann
2021-12-03 19:59:54 +01:00
parent c884e2f285
commit 35c11afd54
11 changed files with 248 additions and 3 deletions
+105
View File
@@ -0,0 +1,105 @@
/*
* Copyright 2003-2021 The Music Player Daemon Project
* http://www.musicpd.org
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#include "MixRampGlue.hxx"
#include "MixRampAnalyzer.hxx"
#include "AudioFormat.hxx"
#include "MusicPipe.hxx"
#include "MusicChunk.hxx"
#include "util/Compiler.h"
#include <stdio.h>
static std::string
StartToString(const MixRampArray &a) noexcept
{
std::string s;
MixRampItem last{};
for (const auto &i : a) {
if (i.time < FloatDuration{} || i == last)
continue;
char buffer[64];
sprintf(buffer, "%.2f %.2f;", i.volume, i.time.count());
last = i;
s.append(buffer);
}
return s;
}
static std::string
EndToString(const MixRampArray &a, FloatDuration total_time) noexcept
{
std::string s;
MixRampItem last{};
for (const auto &i : a) {
if (i.time < FloatDuration{} || i == last)
continue;
char buffer[64];
sprintf(buffer, "%.2f %.2f;",
i.volume, (total_time - i.time).count());
last = i;
s.append(buffer);
}
return s;
}
static std::string
ToString(const MixRampData &mr, FloatDuration total_time,
MixRampDirection direction) noexcept
{
switch (direction) {
case MixRampDirection::START:
return StartToString(mr.start);
case MixRampDirection::END:
return EndToString(mr.end, total_time);
}
gcc_unreachable();
}
std::string
AnalyzeMixRamp(const MusicPipe &pipe, const AudioFormat &audio_format,
MixRampDirection direction) noexcept
{
if (audio_format.sample_rate != ReplayGainAnalyzer::SAMPLE_RATE ||
audio_format.channels != ReplayGainAnalyzer::CHANNELS ||
audio_format.format != SampleFormat::FLOAT)
// TODO: auto-convert
return {};
const auto *chunk = pipe.Peek();
if (chunk == nullptr)
return {};
MixRampAnalyzer a;
do {
a.Process(ConstBuffer<ReplayGainAnalyzer::Frame>::FromVoid({chunk->data, chunk->length}));
} while ((chunk = chunk->next.get()) != nullptr);
return ToString(a.GetResult(), a.GetTime(), direction);
}
+34
View File
@@ -0,0 +1,34 @@
/*
* Copyright 2003-2021 The Music Player Daemon Project
* http://www.musicpd.org
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#pragma once
#include <string>
struct AudioFormat;
class MusicPipe;
enum class MixRampDirection {
START, END
};
[[gnu::pure]]
std::string
AnalyzeMixRamp(const MusicPipe &pipe, const AudioFormat &audio_format,
MixRampDirection direction) noexcept;
+1
View File
@@ -49,6 +49,7 @@ pcm_sources = [
'AudioCompress/compress.c',
'ReplayGainAnalyzer.cxx',
'MixRampAnalyzer.cxx',
'MixRampGlue.cxx',
]
libsamplerate_dep = dependency('samplerate', version: '>= 0.1.3', required: get_option('libsamplerate'))