@@ -27,53 +27,144 @@ class AudioFormatWriter;
2727
2828// ==============================================================================
2929/* *
30- Base class for audio format descriptions .
30+ Abstract base class for audio format implementations .
3131
32- This class represents a type of audio file format, and can create
33- reader and writer objects for parsing and writing that format.
32+ This class serves as the foundation for all audio file format handlers within
33+ the YUP library. Each concrete implementation represents a specific audio file
34+ format (such as WAV, FLAC, or MP3) and provides the necessary functionality to
35+ create reader and writer objects for parsing and writing files in that particular
36+ format.
37+
38+ The AudioFormat class defines a common interface for:
39+ - Identifying supported file extensions
40+ - Creating format-specific readers and writers
41+ - Querying format capabilities (sample rates, bit depths, channel configurations)
42+ - Handling format-specific metadata and quality settings
43+
44+ Subclasses must implement all pure virtual methods to provide format-specific
45+ behavior. The AudioFormatManager typically manages instances of AudioFormat
46+ subclasses to provide a unified interface for handling multiple audio formats
47+ in an application.
48+
49+ @see AudioFormatReader, AudioFormatWriter, AudioFormatManager
50+
51+ @tags{Audio}
3452*/
3553class YUP_API AudioFormat
3654{
3755public:
3856 /* * Destructor. */
3957 virtual ~AudioFormat () = default ;
4058
41- /* * Returns the name of this format. */
59+ /* * Returns the descriptive name of this audio format.
60+
61+ @returns A string containing the human-readable name of the format (e.g., "Wave file", "FLAC Audio")
62+ */
4263 virtual const String& getFormatName () const = 0;
4364
44- /* * Returns the file extensions associated with this format. */
65+ /* * Returns the file extensions associated with this format.
66+
67+ @returns An array of file extensions (including the dot) that this format can handle
68+ (e.g., {".wav", ".wave"} for WAV format)
69+ */
4570 virtual Array<String> getFileExtensions () const = 0;
4671
47- /* * Tests whether this format can handle the given file extension. */
72+ /* * Tests whether this format can handle files with the given file extension.
73+
74+ This method provides a convenient way to check if a file can be processed by this format
75+ based on its extension, without needing to attempt to open the file.
76+
77+ @param file The file to test for compatibility
78+
79+ @returns true if this format can potentially handle the file, false otherwise
80+ */
4881 virtual bool canHandleFile (const File& file) const ;
4982
50- /* * Creates a reader for this format. */
83+ /* * Creates a reader object capable of parsing audio data from the given stream.
84+
85+ This method attempts to create a format-specific reader for the provided input stream.
86+ The reader will be configured with the appropriate parameters extracted from the stream's
87+ audio data (sample rate, channels, bit depth, etc.).
88+
89+ @param sourceStream The input stream containing audio data to be read. The AudioFormat
90+ takes ownership of this stream if successful.
91+
92+ @returns A unique pointer to an AudioFormatReader if successful, nullptr if the stream
93+ cannot be parsed by this format
94+ */
5195 virtual std::unique_ptr<AudioFormatReader> createReaderFor (InputStream* sourceStream) = 0;
5296
53- /* * Creates a writer for this format. */
97+ /* * Creates a writer object capable of writing audio data to the given stream.
98+
99+ This method creates a format-specific writer configured with the specified audio parameters.
100+ The writer will encode audio data according to the format's specifications and write it
101+ to the provided output stream.
102+
103+ @param streamToWriteTo The output stream where audio data will be written
104+ @param sampleRate The sample rate of the audio data (e.g., 44100, 48000)
105+ @param numberOfChannels The number of audio channels (1 for mono, 2 for stereo, etc.)
106+ @param bitsPerSample The bit depth for each sample (e.g., 16, 24, 32)
107+ @param metadataValues A collection of metadata key-value pairs to embed in the file
108+ @param qualityOptionIndex Index into the quality options array for compressed formats
109+
110+ @returns A unique pointer to an AudioFormatWriter if successful, nullptr if the
111+ parameters are not supported by this format
112+ */
54113 virtual std::unique_ptr<AudioFormatWriter> createWriterFor (OutputStream* streamToWriteTo,
55114 double sampleRate,
56115 int numberOfChannels,
57116 int bitsPerSample,
58117 const StringPairArray& metadataValues,
59118 int qualityOptionIndex) = 0;
60119
61- /* * Returns a set of bit depths that the format can write. */
120+ /* * Returns the set of bit depths that this format supports for writing.
121+
122+ Different audio formats support different bit depths. This method allows clients
123+ to query which bit depths are available before attempting to create a writer.
124+
125+ @returns An array of supported bit depths in bits per sample (e.g., {8, 16, 24, 32})
126+ */
62127 virtual Array<int > getPossibleBitDepths () const = 0;
63128
64- /* * Returns a set of sample rates that the format can write. */
129+ /* * Returns the set of sample rates that this format supports for writing.
130+
131+ Audio formats may have limitations on supported sample rates. This method provides
132+ a way to discover these limitations before attempting to create a writer.
133+
134+ @returns An array of supported sample rates in Hz (e.g., {44100, 48000, 96000})
135+ */
65136 virtual Array<int > getPossibleSampleRates () const = 0;
66137
67- /* * Returns true if this format can write files with multiple channels. */
138+ /* * Returns true if this format supports writing mono (single-channel) audio files.
139+
140+ @returns true if mono files can be written, false otherwise
141+ */
68142 virtual bool canDoMono () const = 0;
69143
70- /* * Returns true if this format can write stereo files. */
144+ /* * Returns true if this format supports writing stereo (two-channel) audio files.
145+
146+ @returns true if stereo files can be written, false otherwise
147+ */
71148 virtual bool canDoStereo () const = 0;
72149
73- /* * Returns true if the format can encode at different qualities. */
150+ /* * Returns true if this format supports compression with variable quality settings.
151+
152+ Formats like MP3, OGG Vorbis, and FLAC support different compression levels or quality
153+ settings. Uncompressed formats like WAV typically return false.
154+
155+ @returns true if the format supports quality options, false for uncompressed formats
156+ */
74157 virtual bool isCompressed () const { return false ; }
75158
76- /* * Returns a list of different qualities that can be used when writing. */
159+ /* * Returns a list of quality option descriptions for compressed formats.
160+
161+ For compressed formats that support multiple quality levels, this method returns
162+ human-readable descriptions of the available quality options. The index of the
163+ desired quality can be passed to createWriterFor().
164+
165+ @returns An array of quality descriptions (e.g., {"Low", "Medium", "High"}) or
166+ empty array for formats that don't support quality options
167+ */
77168 virtual StringArray getQualityOptions () const { return {}; }
78169};
79170
0 commit comments