OpenShot Library | libopenshot-audio  0.2.0
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 
31 namespace 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 {
45 public:
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. */
72  virtual Array<int> getPossibleSampleRates() = 0;
73 
74  /** Returns a set of bit depths that the format can read and write. */
75  virtual Array<int> getPossibleBitDepths() = 0;
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  */
115  virtual AudioFormatReader* createReaderFor (InputStream* sourceStream,
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 - this must be either 1 or 2, and
140  the choice will depend on the results of canDoMono() and
141  canDoStereo()
142  @param bitsPerSample the bits per sample to use - this must be one of the values
143  returned by getPossibleBitDepths()
144  @param metadataValues a set of metadata values that the writer should try to write
145  to the stream. Exactly what these are depends on the format,
146  and the subclass doesn't actually have to do anything with
147  them if it doesn't want to. Have a look at the specific format
148  implementation classes to see possible values that can be
149  used
150  @param qualityOptionIndex the index of one of compression qualities returned by the
151  getQualityOptions() method. If there aren't any quality options
152  for this format, just pass 0 in this parameter, as it'll be
153  ignored
154  @see AudioFormatWriter
155  */
156  virtual AudioFormatWriter* createWriterFor (OutputStream* streamToWriteTo,
157  double sampleRateToUse,
158  unsigned int numberOfChannels,
159  int bitsPerSample,
160  const StringPairArray& metadataValues,
161  int qualityOptionIndex) = 0;
162 
163  /** Tries to create an object that can write to a stream with this audio format.
164 
165  The writer object that is returned can be used to write to the stream, and
166  should then be deleted by the caller.
167 
168  If the stream can't be created for some reason (e.g. the parameters passed in
169  here aren't suitable), this will return nullptr.
170 
171  @param streamToWriteTo the stream that the data will go to - this will be
172  deleted by the AudioFormatWriter object when it's no longer
173  needed. If no AudioFormatWriter can be created by this method,
174  the stream will NOT be deleted, so that the caller can re-use it
175  to try to open a different format, etc
176  @param sampleRateToUse the sample rate for the file, which must be one of the ones
177  returned by getPossibleSampleRates()
178  @param channelLayout the channel layout for the file. Use isChannelLayoutSupported
179  to check if the writer supports this layout.
180  @param bitsPerSample the bits per sample to use - this must be one of the values
181  returned by getPossibleBitDepths()
182  @param metadataValues a set of metadata values that the writer should try to write
183  to the stream. Exactly what these are depends on the format,
184  and the subclass doesn't actually have to do anything with
185  them if it doesn't want to. Have a look at the specific format
186  implementation classes to see possible values that can be
187  used
188  @param qualityOptionIndex the index of one of compression qualities returned by the
189  getQualityOptions() method. If there aren't any quality options
190  for this format, just pass 0 in this parameter, as it'll be
191  ignored
192  @see AudioFormatWriter
193  */
194  virtual AudioFormatWriter* createWriterFor (OutputStream* streamToWriteTo,
195  double sampleRateToUse,
196  const AudioChannelSet& channelLayout,
197  int bitsPerSample,
198  const StringPairArray& metadataValues,
199  int qualityOptionIndex);
200 
201 protected:
202  /** Creates an AudioFormat object.
203 
204  @param formatName this sets the value that will be returned by getFormatName()
205  @param fileExtensions an array of file extensions - these will be returned by getFileExtensions()
206  */
207  AudioFormat (String formatName, StringArray fileExtensions);
208 
209  /** Creates an AudioFormat object.
210 
211  @param formatName this sets the value that will be returned by getFormatName()
212  @param fileExtensions a whitespace-separated list of file extensions - these will
213  be returned by getFileExtensions()
214  */
215  AudioFormat (StringRef formatName, StringRef fileExtensions);
216 
217 private:
218  //==============================================================================
219  String formatName;
220  StringArray fileExtensions;
221 };
222 
223 } // namespace juce
224 
225 /** @}*/
Represents a set of audio channel types.
#define JUCE_API
This macro is added to all JUCE public class declarations.
A simple class for holding temporary references to a string literal or String.
The base class for streams that read data.
A special array for holding a list of strings.
The JUCE String class!
Definition: juce_String.h:42
Subclasses of AudioFormat are used to read and write different audio file formats.
Represents a local file or directory.
Definition: juce_File.h:44
The base class for streams that write data to some kind of destination.
An input stream that reads from a local file.
Writes samples to an audio file stream.
A container for holding a set of strings which are keyed by another string.
Reads samples from an audio file stream.
A specialised type of AudioFormatReader that uses a MemoryMappedFile to read directly from an audio f...