OpenShot Library | OpenShotAudio 0.2.2
juce_AudioFormat.h
1
2/** @weakgroup juce_audio_formats-format
3 * @{
4 */
5/*
6 ==============================================================================
7
8 This file is part of the JUCE library.
9 Copyright (c) 2017 - ROLI Ltd.
10
11 JUCE is an open source library subject to commercial or open-source
12 licensing.
13
14 By using JUCE, you agree to the terms of both the JUCE 5 End-User License
15 Agreement and JUCE 5 Privacy Policy (both updated and effective as of the
16 27th April 2017).
17
18 End User License Agreement: www.juce.com/juce-5-licence
19 Privacy Policy: www.juce.com/juce-5-privacy-policy
20
21 Or: You may also use this code under the terms of the GPL v3 (see
22 www.gnu.org/licenses).
23
24 JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
25 EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
26 DISCLAIMED.
27
28 ==============================================================================
29*/
30
31namespace juce
32{
33
34//==============================================================================
35/**
36 Subclasses of AudioFormat are used to read and write different audio
37 file formats.
38
39 @see AudioFormatReader, AudioFormatWriter, WavAudioFormat, AiffAudioFormat
40
41 @tags{Audio}
42*/
44{
45public:
46 //==============================================================================
47 /** Destructor. */
48 virtual ~AudioFormat();
49
50 //==============================================================================
51 /** Returns the name of this format.
52 e.g. "WAV file" or "AIFF file"
53 */
54 const String& getFormatName() const;
55
56 //==============================================================================
57 /** Returns all the file extensions that might apply to a file of this format.
58 The first item will be the one that's preferred when creating a new file.
59 So for a wav file this might just return ".wav"; for an AIFF file it might
60 return two items, ".aif" and ".aiff"
61 */
62 virtual StringArray getFileExtensions() const;
63
64 /** Returns true if this the given file can be read by this format.
65 Subclasses shouldn't do too much work here, just check the extension or
66 file type. The base class implementation just checks the file's extension
67 against one of the ones that was registered in the constructor.
68 */
69 virtual bool canHandleFile (const File& fileToTest);
70
71 /** Returns a set of sample rates that the format can read and write. */
73
74 /** Returns a set of bit depths that the format can read and write. */
76
77 /** Returns true if the format can do 2-channel audio. */
78 virtual bool canDoStereo() = 0;
79
80 /** Returns true if the format can do 1-channel audio. */
81 virtual bool canDoMono() = 0;
82
83 /** Returns true if the format uses compressed data. */
84 virtual bool isCompressed();
85
86 /** Returns true if the channel layout is supported by this format. */
87 virtual bool isChannelLayoutSupported (const AudioChannelSet& channelSet);
88
89 /** Returns a list of different qualities that can be used when writing.
90
91 Non-compressed formats will just return an empty array, but for something
92 like Ogg-Vorbis or MP3, it might return a list of bit-rates, etc.
93
94 When calling createWriterFor(), an index from this array is passed in to
95 tell the format which option is required.
96 */
97 virtual StringArray getQualityOptions();
98
99 //==============================================================================
100 /** Tries to create an object that can read from a stream containing audio
101 data in this format.
102
103 The reader object that is returned can be used to read from the stream, and
104 should then be deleted by the caller.
105
106 @param sourceStream the stream to read from - the AudioFormatReader object
107 that is returned will delete this stream when it no longer
108 needs it.
109 @param deleteStreamIfOpeningFails if no reader can be created, this determines whether this method
110 should delete the stream object that was passed-in. (If a valid
111 reader is returned, it will always be in charge of deleting the
112 stream, so this parameter is ignored)
113 @see AudioFormatReader
114 */
116 bool deleteStreamIfOpeningFails) = 0;
117
118 /** Attempts to create a MemoryMappedAudioFormatReader, if possible for this format.
119 If the format does not support this, the method will return nullptr;
120 */
121 virtual MemoryMappedAudioFormatReader* createMemoryMappedReader (const File& file);
122 virtual MemoryMappedAudioFormatReader* createMemoryMappedReader (FileInputStream* fin);
123
124 /** Tries to create an object that can write to a stream with this audio format.
125
126 The writer object that is returned can be used to write to the stream, and
127 should then be deleted by the caller.
128
129 If the stream can't be created for some reason (e.g. the parameters passed in
130 here aren't suitable), this will return nullptr.
131
132 @param streamToWriteTo the stream that the data will go to - this will be
133 deleted by the AudioFormatWriter object when it's no longer
134 needed. If no AudioFormatWriter can be created by this method,
135 the stream will NOT be deleted, so that the caller can re-use it
136 to try to open a different format, etc
137 @param sampleRateToUse the sample rate for the file, which must be one of the ones
138 returned by getPossibleSampleRates()
139 @param numberOfChannels the number of channels
140 @param bitsPerSample the bits per sample to use - this must be one of the values
141 returned by getPossibleBitDepths()
142 @param metadataValues a set of metadata values that the writer should try to write
143 to the stream. Exactly what these are depends on the format,
144 and the subclass doesn't actually have to do anything with
145 them if it doesn't want to. Have a look at the specific format
146 implementation classes to see possible values that can be
147 used
148 @param qualityOptionIndex the index of one of compression qualities returned by the
149 getQualityOptions() method. If there aren't any quality options
150 for this format, just pass 0 in this parameter, as it'll be
151 ignored
152 @see AudioFormatWriter
153 */
155 double sampleRateToUse,
156 unsigned int numberOfChannels,
157 int bitsPerSample,
158 const StringPairArray& metadataValues,
159 int qualityOptionIndex) = 0;
160
161 /** Tries to create an object that can write to a stream with this audio format.
162
163 The writer object that is returned can be used to write to the stream, and
164 should then be deleted by the caller.
165
166 If the stream can't be created for some reason (e.g. the parameters passed in
167 here aren't suitable), this will return nullptr.
168
169 @param streamToWriteTo the stream that the data will go to - this will be
170 deleted by the AudioFormatWriter object when it's no longer
171 needed. If no AudioFormatWriter can be created by this method,
172 the stream will NOT be deleted, so that the caller can re-use it
173 to try to open a different format, etc
174 @param sampleRateToUse the sample rate for the file, which must be one of the ones
175 returned by getPossibleSampleRates()
176 @param channelLayout the channel layout for the file. Use isChannelLayoutSupported
177 to check if the writer supports this layout.
178 @param bitsPerSample the bits per sample to use - this must be one of the values
179 returned by getPossibleBitDepths()
180 @param metadataValues a set of metadata values that the writer should try to write
181 to the stream. Exactly what these are depends on the format,
182 and the subclass doesn't actually have to do anything with
183 them if it doesn't want to. Have a look at the specific format
184 implementation classes to see possible values that can be
185 used
186 @param qualityOptionIndex the index of one of compression qualities returned by the
187 getQualityOptions() method. If there aren't any quality options
188 for this format, just pass 0 in this parameter, as it'll be
189 ignored
190 @see AudioFormatWriter
191 */
192 virtual AudioFormatWriter* createWriterFor (OutputStream* streamToWriteTo,
193 double sampleRateToUse,
194 const AudioChannelSet& channelLayout,
195 int bitsPerSample,
196 const StringPairArray& metadataValues,
197 int qualityOptionIndex);
198
199protected:
200 /** Creates an AudioFormat object.
201
202 @param formatName this sets the value that will be returned by getFormatName()
203 @param fileExtensions an array of file extensions - these will be returned by getFileExtensions()
204 */
205 AudioFormat (String formatName, StringArray fileExtensions);
206
207 /** Creates an AudioFormat object.
208
209 @param formatName this sets the value that will be returned by getFormatName()
210 @param fileExtensions a whitespace-separated list of file extensions - these will
211 be returned by getFileExtensions()
212 */
213 AudioFormat (StringRef formatName, StringRef fileExtensions);
214
215private:
216 //==============================================================================
217 String formatName;
218 StringArray fileExtensions;
219};
220
221} // namespace juce
222
223/** @}*/
Represents a set of audio channel types.
Reads samples from an audio file stream.
Writes samples to an audio file stream.
Subclasses of AudioFormat are used to read and write different audio file formats.
virtual AudioFormatWriter * createWriterFor(OutputStream *streamToWriteTo, double sampleRateToUse, unsigned int numberOfChannels, int bitsPerSample, const StringPairArray &metadataValues, int qualityOptionIndex)=0
Tries to create an object that can write to a stream with this audio format.
virtual bool canDoStereo()=0
Returns true if the format can do 2-channel audio.
virtual bool canDoMono()=0
Returns true if the format can do 1-channel audio.
virtual Array< int > getPossibleBitDepths()=0
Returns a set of bit depths that the format can read and write.
virtual AudioFormatReader * createReaderFor(InputStream *sourceStream, bool deleteStreamIfOpeningFails)=0
Tries to create an object that can read from a stream containing audio data in this format.
virtual Array< int > getPossibleSampleRates()=0
Returns a set of sample rates that the format can read and write.
An input stream that reads from a local file.
Represents a local file or directory.
Definition: juce_File.h:45
The base class for streams that read data.
A specialised type of AudioFormatReader that uses a MemoryMappedFile to read directly from an audio f...
The base class for streams that write data to some kind of destination.
A special array for holding a list of strings.
A container for holding a set of strings which are keyed by another string.
A simple class for holding temporary references to a string literal or String.
The JUCE String class!
Definition: juce_String.h:43
#define JUCE_API
This macro is added to all JUCE public class declarations.