1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-08-01 16:39:30 +02:00

Dither.cpp and SampleFormat.cpp have fewer dependencies...

... Notably they longer depend indirectly on AudioIO.cpp (via QualityPrefs)

This frees nine files from dependency cycles
This commit is contained in:
Paul Licameli 2019-05-11 14:52:42 -04:00
parent d68db39b5c
commit 82f4948360
5 changed files with 63 additions and 57 deletions

View File

@ -37,6 +37,9 @@ and get deterministic behaviour.
#include "Dither.h"
#include "Internat.h"
#include "Prefs.h"
// Erik de Castro Lopo's header file that
// makes sure that we have lrint and lrintf
// (Note: this file should be included first)
@ -393,3 +396,50 @@ inline float Dither::ShapedDither(float sample)
return result;
}
static const EnumValueSymbol choicesDither[] = {
{ XO("None") },
{ XO("Rectangle") },
{ XO("Triangle") },
{ XO("Shaped") },
};
static const size_t nChoicesDither = WXSIZEOF( choicesDither );
static const int intChoicesDither[] = {
(int) DitherType::none,
(int) DitherType::rectangle,
(int) DitherType::triangle,
(int) DitherType::shaped,
};
static_assert(
nChoicesDither == WXSIZEOF( intChoicesDither ),
"size mismatch"
);
static const size_t defaultFastDither = 0; // none
EnumSetting Dither::FastSetting{
wxT("Quality/DitherAlgorithmChoice"),
choicesDither, nChoicesDither, defaultFastDither,
intChoicesDither,
wxT("Quality/DitherAlgorithm")
};
static const size_t defaultBestDither = 3; // shaped
EnumSetting Dither::BestSetting{
wxT("Quality/HQDitherAlgorithmChoice"),
choicesDither, nChoicesDither, defaultBestDither,
intChoicesDither,
wxT("Quality/HQDitherAlgorithm")
};
DitherType Dither::FastDitherChoice()
{
return (DitherType) FastSetting.ReadInt();
}
DitherType Dither::BestDitherChoice()
{
return (DitherType) BestSetting.ReadInt();
}

View File

@ -10,7 +10,9 @@
#ifndef __AUDACITY_DITHER_H__
#define __AUDACITY_DITHER_H__
#include "SampleFormat.h"
#include "audacity/Types.h" // for samplePtr
class EnumSetting;
/// These ditherers are currently available:
@ -20,6 +22,11 @@ enum DitherType : unsigned {
class Dither
{
public:
static DitherType FastDitherChoice();
static DitherType BestDitherChoice();
static EnumSetting FastSetting, BestSetting;
/// Default constructor
Dither();

View File

@ -44,7 +44,7 @@
#include "Prefs.h"
#include "Dither.h"
#include "prefs/QualityPrefs.h"
#include "Internat.h"
static DitherType gLowQualityDither = DitherType::none;
static DitherType gHighQualityDither = DitherType::none;
@ -53,8 +53,8 @@ static Dither gDitherAlgorithm;
void InitDitherers()
{
// Read dither preferences
gLowQualityDither = QualityPrefs::FastDitherChoice();
gHighQualityDither = QualityPrefs::BestDitherChoice();
gLowQualityDither = Dither::FastDitherChoice();
gHighQualityDither = Dither::BestDitherChoice();
}
const wxChar *GetSampleFormatStr(sampleFormat format)

View File

@ -55,44 +55,6 @@ static EnumSetting formatSetting{
wxT("/SamplingRate/DefaultProjectSampleFormat"),
};
//////////
static const EnumValueSymbol choicesDither[] = {
{ XO("None") },
{ XO("Rectangle") },
{ XO("Triangle") },
{ XO("Shaped") },
};
static const size_t nChoicesDither = WXSIZEOF( choicesDither );
static const int intChoicesDither[] = {
(int) DitherType::none,
(int) DitherType::rectangle,
(int) DitherType::triangle,
(int) DitherType::shaped,
};
static_assert(
nChoicesDither == WXSIZEOF( intChoicesDither ),
"size mismatch"
);
static const size_t defaultFastDither = 0; // none
static EnumSetting fastDitherSetting{
wxT("Quality/DitherAlgorithmChoice"),
choicesDither, nChoicesDither, defaultFastDither,
intChoicesDither,
wxT("Quality/DitherAlgorithm")
};
static const size_t defaultBestDither = 3; // shaped
static EnumSetting bestDitherSetting{
wxT("Quality/HQDitherAlgorithmChoice"),
choicesDither, nChoicesDither, defaultBestDither,
intChoicesDither,
wxT("Quality/HQDitherAlgorithm")
};
//////////
BEGIN_EVENT_TABLE(QualityPrefs, PrefsPanel)
EVT_CHOICE(ID_SAMPLE_RATE_CHOICE, QualityPrefs::OnSampleRateChoice)
@ -225,7 +187,7 @@ void QualityPrefs::PopulateOrExchange(ShuttleGui & S)
/* i18n-hint: technical term for randomization to reduce undesirable resampling artifacts */
S.TieChoice(_("&Dither:"),
fastDitherSetting);
Dither::FastSetting);
}
S.EndMultiColumn();
}
@ -240,7 +202,7 @@ void QualityPrefs::PopulateOrExchange(ShuttleGui & S)
/* i18n-hint: technical term for randomization to reduce undesirable resampling artifacts */
S.TieChoice(_("Dit&her:"),
bestDitherSetting);
Dither::BestSetting);
}
S.EndMultiColumn();
}
@ -287,13 +249,3 @@ sampleFormat QualityPrefs::SampleFormatChoice()
return (sampleFormat)formatSetting.ReadInt();
}
DitherType QualityPrefs::FastDitherChoice()
{
return (DitherType) fastDitherSetting.ReadInt();
}
DitherType QualityPrefs::BestDitherChoice()
{
return (DitherType) bestDitherSetting.ReadInt();
}

View File

@ -41,9 +41,6 @@ class QualityPrefs final : public PrefsPanel
static sampleFormat SampleFormatChoice();
static DitherType FastDitherChoice();
static DitherType BestDitherChoice();
private:
void Populate();
void GetNamesAndLabels();