mirror of
https://github.com/cookiengineer/audacity
synced 2025-06-16 16:10:06 +02:00
Choice of format for imported tracks now in just one place...
... Doing the widening as needed to match Quality preference. Fewer direct dependencies on QualityPrefs.h. FLAC and OGG may import as float where before it was 24 bits; only 16 bits or float. This makes them behave consistently with Raw and PCM.
This commit is contained in:
parent
85eb3dbf46
commit
31b391737f
@ -42,7 +42,6 @@
|
||||
#include "ImportPlugin.h"
|
||||
|
||||
#include "../Tags.h"
|
||||
#include "../prefs/QualityPrefs.h"
|
||||
#include "../widgets/ProgressDialog.h"
|
||||
|
||||
#define FLAC_HEADER "fLaC"
|
||||
@ -192,14 +191,11 @@ void MyFLACFile::metadata_callback(const FLAC__StreamMetadata *metadata)
|
||||
mFile->mBitsPerSample=metadata->data.stream_info.bits_per_sample;
|
||||
mFile->mNumSamples=metadata->data.stream_info.total_samples;
|
||||
|
||||
// Widen mFormat after examining the file header
|
||||
if (mFile->mBitsPerSample<=16) {
|
||||
if (mFile->mFormat<int16Sample) {
|
||||
mFile->mFormat=int16Sample;
|
||||
}
|
||||
mFile->mFormat=int16Sample;
|
||||
} else if (mFile->mBitsPerSample<=24) {
|
||||
if (mFile->mFormat<int24Sample) {
|
||||
mFile->mFormat=int24Sample;
|
||||
}
|
||||
mFile->mFormat=int24Sample;
|
||||
} else {
|
||||
mFile->mFormat=floatSample;
|
||||
}
|
||||
@ -337,7 +333,8 @@ FLACImportFileHandle::FLACImportFileHandle(const FilePath & name)
|
||||
mStreamInfoDone(false),
|
||||
mUpdateResult(ProgressResult::Success)
|
||||
{
|
||||
mFormat = QualityPrefs::SampleFormatChoice();
|
||||
// Initialize mFormat as narrowest
|
||||
mFormat = narrowestSampleFormat;
|
||||
mFile = std::make_unique<MyFLACFile>(this);
|
||||
}
|
||||
|
||||
@ -421,7 +418,7 @@ ProgressResult FLACImportFileHandle::Import(WaveTrackFactory *trackFactory,
|
||||
{
|
||||
auto iter = mChannels.begin();
|
||||
for (size_t c = 0; c < mNumChannels; ++iter, ++c)
|
||||
*iter = trackFactory->NewWaveTrack(mFormat, mSampleRate);
|
||||
*iter = NewWaveTrack(*trackFactory, mFormat, mSampleRate);
|
||||
}
|
||||
|
||||
// TODO: Vigilant Sentry: Variable res unused after assignment (error code DA1)
|
||||
|
@ -41,7 +41,6 @@
|
||||
#include "Import.h"
|
||||
#include "../Prefs.h"
|
||||
#include "../Tags.h"
|
||||
#include "../prefs/QualityPrefs.h"
|
||||
#include "../widgets/ProgressDialog.h"
|
||||
|
||||
|
||||
@ -107,8 +106,6 @@ public:
|
||||
mVorbisFile(std::move(vorbisFile))
|
||||
, mStreamUsage{ static_cast<size_t>(mVorbisFile->links) }
|
||||
{
|
||||
mFormat = QualityPrefs::SampleFormatChoice();
|
||||
|
||||
for (int i = 0; i < mVorbisFile->links; i++)
|
||||
{
|
||||
auto strinfo = XO("Index[%02x] Version[%d], Channels[%d], Rate[%ld]")
|
||||
@ -158,8 +155,6 @@ private:
|
||||
ArrayOf<int> mStreamUsage;
|
||||
TranslatableStrings mStreamInfo;
|
||||
std::list<NewChannelGroup> mChannels;
|
||||
|
||||
sampleFormat mFormat;
|
||||
};
|
||||
|
||||
|
||||
@ -262,7 +257,8 @@ ProgressResult OggImportFileHandle::Import(
|
||||
link.resize(vi->channels);
|
||||
|
||||
for (auto &channel : link)
|
||||
channel = trackFactory->NewWaveTrack(mFormat, vi->rate);
|
||||
// The format agrees with what is always passed to Append() below
|
||||
channel = NewWaveTrack(*trackFactory, int16Sample, vi->rate);
|
||||
}
|
||||
|
||||
/* The number of bytes to get from the codec in each run */
|
||||
|
@ -38,7 +38,6 @@
|
||||
|
||||
#include "../ShuttleGui.h"
|
||||
|
||||
#include "../prefs/QualityPrefs.h"
|
||||
#include "../widgets/ProgressDialog.h"
|
||||
|
||||
#ifndef SNDFILE_1
|
||||
@ -202,11 +201,8 @@ PCMImportFileHandle::PCMImportFileHandle(const FilePath &name,
|
||||
// the quality of the original file.
|
||||
//
|
||||
|
||||
mFormat = QualityPrefs::SampleFormatChoice();
|
||||
|
||||
if (mFormat != floatSample &&
|
||||
sf_subtype_more_than_16_bits(mInfo.format))
|
||||
mFormat = floatSample;
|
||||
mFormat =
|
||||
ChooseFormat(sf_subtype_to_effective_format(mInfo.format));
|
||||
}
|
||||
|
||||
TranslatableString PCMImportFileHandle::GetFileDescription()
|
||||
@ -305,7 +301,7 @@ ProgressResult PCMImportFileHandle::Import(WaveTrackFactory *trackFactory,
|
||||
// iter not used outside this scope.
|
||||
auto iter = channels.begin();
|
||||
for (int c = 0; c < mInfo.channels; ++iter, ++c)
|
||||
*iter = trackFactory->NewWaveTrack(mFormat, mInfo.samplerate);
|
||||
*iter = NewWaveTrack(*trackFactory, mFormat, mInfo.samplerate);
|
||||
}
|
||||
|
||||
auto fileTotalFrames =
|
||||
|
@ -11,7 +11,9 @@ Paul Licameli split from Import.cpp
|
||||
#include "ImportPlugin.h"
|
||||
|
||||
#include <wx/filename.h>
|
||||
#include "../WaveTrack.h"
|
||||
#include "../widgets/ProgressDialog.h"
|
||||
#include "../prefs/QualityPrefs.h"
|
||||
|
||||
ImportFileHandle::ImportFileHandle(const FilePath & filename)
|
||||
: mFilename(filename)
|
||||
@ -31,3 +33,23 @@ void ImportFileHandle::CreateProgress()
|
||||
title, Verbatim( ff.GetFullName() ) );
|
||||
}
|
||||
|
||||
sampleFormat ImportFileHandle::ChooseFormat(sampleFormat effectiveFormat)
|
||||
{
|
||||
// Consult user preference
|
||||
auto defaultFormat = QualityPrefs::SampleFormatChoice();
|
||||
|
||||
// Don't choose format narrower than effective or default
|
||||
auto format = std::max(effectiveFormat, defaultFormat);
|
||||
|
||||
// But also always promote 24 bits to float
|
||||
if (format > int16Sample)
|
||||
format = floatSample;
|
||||
|
||||
return format;
|
||||
}
|
||||
|
||||
std::shared_ptr<WaveTrack> ImportFileHandle::NewWaveTrack(
|
||||
WaveTrackFactory &trackFactory, sampleFormat effectiveFormat, double rate)
|
||||
{
|
||||
return trackFactory.NewWaveTrack(ChooseFormat(effectiveFormat), rate);
|
||||
}
|
||||
|
@ -152,6 +152,13 @@ public:
|
||||
// Set stream "import/don't import" flag
|
||||
virtual void SetStreamUsage(wxInt32 StreamID, bool Use) = 0;
|
||||
|
||||
//! Choose appropriate format, which will not be narrower than the specified one
|
||||
static sampleFormat ChooseFormat(sampleFormat effectiveFormat);
|
||||
|
||||
//! Build a wave track with appropriate format, which will not be narrower than the specified one
|
||||
std::shared_ptr<WaveTrack> NewWaveTrack( WaveTrackFactory &trackFactory,
|
||||
sampleFormat effectiveFormat, double rate);
|
||||
|
||||
protected:
|
||||
FilePath mFilename;
|
||||
std::unique_ptr<ProgressDialog> mProgress;
|
||||
|
@ -24,6 +24,8 @@ and sample size to help you importing data of an unknown format.
|
||||
#include "../Audacity.h"
|
||||
#include "ImportRaw.h"
|
||||
|
||||
#include "ImportPlugin.h"
|
||||
|
||||
#include "../AudioIOBase.h"
|
||||
#include "../FileFormats.h"
|
||||
#include "../Prefs.h"
|
||||
@ -31,7 +33,6 @@ and sample size to help you importing data of an unknown format.
|
||||
#include "../ShuttleGui.h"
|
||||
#include "../UserException.h"
|
||||
#include "../WaveTrack.h"
|
||||
#include "../prefs/QualityPrefs.h"
|
||||
#include "../widgets/ProgressDialog.h"
|
||||
|
||||
#include <cmath>
|
||||
@ -100,7 +101,6 @@ void ImportRaw(const AudacityProject &project, wxWindow *parent, const wxString
|
||||
{
|
||||
outTracks.clear();
|
||||
int encoding = 0; // Guess Format
|
||||
sampleFormat format;
|
||||
sf_count_t offset = 0;
|
||||
double rate = 44100.0;
|
||||
double percent = 100.0;
|
||||
@ -193,11 +193,8 @@ void ImportRaw(const AudacityProject &project, wxWindow *parent, const wxString
|
||||
// the quality of the original file.
|
||||
//
|
||||
|
||||
format = QualityPrefs::SampleFormatChoice();
|
||||
|
||||
if (format != floatSample &&
|
||||
sf_subtype_more_than_16_bits(encoding))
|
||||
format = floatSample;
|
||||
auto format = ImportFileHandle::ChooseFormat(
|
||||
sf_subtype_to_effective_format(encoding));
|
||||
|
||||
results.resize(1);
|
||||
auto &channels = results[0];
|
||||
|
Loading…
x
Reference in New Issue
Block a user