annotate data/fileio/AudioFileReaderFactory.h @ 1853:f36fef97ac81

Add isSupported
author Chris Cannam
date Wed, 06 May 2020 09:08:06 +0100
parents f8e3dcbafb4d
children
rev   line source
Chris@148 1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
Chris@148 2
Chris@148 3 /*
Chris@148 4 Sonic Visualiser
Chris@148 5 An audio file viewer and annotation editor.
Chris@148 6 Centre for Digital Music, Queen Mary, University of London.
Chris@148 7 This file copyright 2006 Chris Cannam.
Chris@148 8
Chris@148 9 This program is free software; you can redistribute it and/or
Chris@148 10 modify it under the terms of the GNU General Public License as
Chris@148 11 published by the Free Software Foundation; either version 2 of the
Chris@148 12 License, or (at your option) any later version. See the file
Chris@148 13 COPYING included with this distribution for more information.
Chris@148 14 */
Chris@148 15
Chris@1098 16 #ifndef AUDIO_FILE_READER_FACTORY_H
Chris@1098 17 #define AUDIO_FILE_READER_FACTORY_H
Chris@148 18
Chris@290 19 #include <QString>
Chris@148 20
Chris@317 21 #include "FileSource.h"
Chris@1040 22 #include "base/BaseTypes.h"
Chris@316 23
Chris@148 24 class AudioFileReader;
Chris@392 25 class ProgressReporter;
Chris@148 26
Chris@148 27 class AudioFileReaderFactory
Chris@148 28 {
Chris@148 29 public:
Chris@148 30 /**
Chris@148 31 * Return the file extensions that we have audio file readers for,
Chris@148 32 * in a format suitable for use with QFileDialog. For example,
Chris@148 33 * "*.wav *.aiff *.ogg".
Chris@148 34 */
Chris@290 35 static QString getKnownExtensions();
Chris@148 36
Chris@1313 37 enum class Normalisation {
Chris@1313 38
Chris@1313 39 /**
Chris@1313 40 * Do not normalise file data.
Chris@1313 41 */
Chris@1313 42 None,
Chris@1313 43
Chris@1313 44 /**
Chris@1313 45 * Normalise file data to abs(max) == 1.0.
Chris@1313 46 */
Chris@1313 47 Peak
Chris@1313 48 };
Chris@1313 49
Chris@1313 50 enum class GaplessMode {
Chris@1313 51
Chris@1313 52 /**
Chris@1313 53 * Any encoder delay and padding found in file metadata will
Chris@1313 54 * be compensated for, giving gapless decoding (assuming the
Chris@1313 55 * metadata are correct). This is currently only applicable to
Chris@1313 56 * mp3 files: all other supported files are always gapless
Chris@1313 57 * where the file metadata provides for it. See documentation
Chris@1313 58 * for MP3FileReader::GaplessMode for details of the specific
Chris@1313 59 * implementation.
Chris@1313 60 */
Chris@1313 61 Gapless,
Chris@1313 62
Chris@1313 63 /**
Chris@1313 64 * No delay compensation will happen and the results will be
Chris@1313 65 * equivalent to the behaviour of audio readers before the
Chris@1313 66 * compensation logic was implemented. This is currently only
Chris@1313 67 * applicable to mp3 files: all other supported files are
Chris@1313 68 * always gapless where the file metadata provides for it. See
Chris@1313 69 * documentation for MP3FileReader::GaplessMode for details of
Chris@1313 70 * the specific implementation.
Chris@1313 71 */
Chris@1313 72 Gappy
Chris@1313 73 };
Chris@1313 74
Chris@1313 75 enum class ThreadingMode {
Chris@1313 76
Chris@1313 77 /**
Chris@1313 78 * Any necessary decoding will happen synchronously when the
Chris@1313 79 * reader is created.
Chris@1313 80 */
Chris@1313 81 NotThreaded,
Chris@1313 82
Chris@1313 83 /**
Chris@1313 84 * If the reader supports threaded decoding, it will be used
Chris@1313 85 * and the file will be decoded in a background thread. If the
Chris@1313 86 * reader does not support threaded decoding, behaviour will
Chris@1313 87 * be as for NotThreaded.
Chris@1313 88 */
Chris@1313 89 Threaded
Chris@1313 90 };
Chris@1313 91
Chris@1313 92 struct Parameters {
Chris@1313 93
Chris@1313 94 /**
Chris@1313 95 * Sample rate to open the file at. If zero (the default), the
Chris@1313 96 * file's native rate will be used. If non-zero, the file will
Chris@1313 97 * be automatically resampled to that rate. You can query
Chris@1313 98 * reader->getNativeRate() if you want to find out whether the
Chris@1313 99 * file needed to be resampled.
Chris@1313 100 */
Chris@1313 101 sv_samplerate_t targetRate;
Chris@1313 102
Chris@1313 103 /**
Chris@1313 104 * Normalisation to use. The default is Normalisation::None.
Chris@1313 105 */
Chris@1313 106 Normalisation normalisation;
Chris@1313 107
Chris@1313 108 /**
Chris@1313 109 * Gapless mode to use. The default is GaplessMode::Gapless.
Chris@1313 110 */
Chris@1313 111 GaplessMode gaplessMode;
Chris@1313 112
Chris@1313 113 /**
Chris@1313 114 * Threading mode. The default is ThreadingMode::NotThreaded.
Chris@1313 115 */
Chris@1313 116 ThreadingMode threadingMode;
Chris@1313 117
Chris@1313 118 Parameters() :
Chris@1313 119 targetRate(0),
Chris@1313 120 normalisation(Normalisation::None),
Chris@1313 121 gaplessMode(GaplessMode::Gapless),
Chris@1313 122 threadingMode(ThreadingMode::NotThreaded)
Chris@1313 123 { }
Chris@1313 124 };
Chris@1313 125
Chris@148 126 /**
Chris@148 127 * Return an audio file reader initialised to the file at the
Chris@148 128 * given path, or NULL if no suitable reader for this path is
Chris@148 129 * available or the file cannot be opened.
Chris@297 130 *
Chris@392 131 * If a ProgressReporter is provided, it will be updated with
Chris@1313 132 * progress status. This will only be meaningful if decoding is
Chris@1313 133 * being carried out in non-threaded mode (either because the
Chris@1313 134 * threaded parameter was not supplied or because the specific
Chris@1313 135 * file reader used does not support it); in threaded mode,
Chris@1313 136 * reported progress will jump straight to 100% before threading
Chris@1313 137 * takes over. Caller retains ownership of the reporter object.
Chris@392 138 *
Chris@148 139 * Caller owns the returned object and must delete it after use.
Chris@148 140 */
Chris@327 141 static AudioFileReader *createReader(FileSource source,
Chris@1313 142 Parameters parameters,
Chris@392 143 ProgressReporter *reporter = 0);
Chris@1592 144
Chris@1592 145 /**
Chris@1592 146 * Return true if the given source has a file extension that
Chris@1592 147 * indicates a supported file type. This does not necessarily mean
Chris@1592 148 * that it can be opened; conversely it may theoretically be
Chris@1592 149 * possible to open some files without supported extensions,
Chris@1592 150 * depending on the readers available.
Chris@1592 151 */
Chris@1592 152 static bool isSupported(FileSource source);
Chris@148 153 };
Chris@148 154
Chris@148 155 #endif
Chris@148 156