OpenShot Library | libopenshot-audio 0.2.0
juce_AudioFormat.cpp
1/*
2 ==============================================================================
3
4 This file is part of the JUCE library.
5 Copyright (c) 2017 - ROLI Ltd.
6
7 JUCE is an open source library subject to commercial or open-source
8 licensing.
9
10 By using JUCE, you agree to the terms of both the JUCE 5 End-User License
11 Agreement and JUCE 5 Privacy Policy (both updated and effective as of the
12 27th April 2017).
13
14 End User License Agreement: www.juce.com/juce-5-licence
15 Privacy Policy: www.juce.com/juce-5-privacy-policy
16
17 Or: You may also use this code under the terms of the GPL v3 (see
18 www.gnu.org/licenses).
19
20 JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
21 EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
22 DISCLAIMED.
23
24 ==============================================================================
25*/
26
27namespace juce
28{
29
31 : formatName (name), fileExtensions (extensions)
32{
33}
34
36 : formatName (name.text), fileExtensions (StringArray::fromTokens (extensions, false))
37{
38}
39
41{
42}
43
45{
46 for (auto& e : getFileExtensions())
47 if (f.hasFileExtension (e))
48 return true;
49
50 return false;
51}
52
53const String& AudioFormat::getFormatName() const { return formatName; }
54StringArray AudioFormat::getFileExtensions() const { return fileExtensions; }
55bool AudioFormat::isCompressed() { return false; }
57
59{
60 return nullptr;
61}
62
64{
65 delete fin;
66 return nullptr;
67}
68
70{
71 if (channelSet == AudioChannelSet::mono()) return canDoMono();
72 if (channelSet == AudioChannelSet::stereo()) return canDoStereo();
73
74 return false;
75}
76
78 double sampleRateToUse,
79 const AudioChannelSet& channelLayout,
80 int bitsPerSample,
81 const StringPairArray& metadataValues,
82 int qualityOptionIndex)
83{
84 if (isChannelLayoutSupported (channelLayout))
85 return createWriterFor (streamToWriteTo, sampleRateToUse,
86 static_cast<unsigned int> (channelLayout.size()),
87 bitsPerSample, metadataValues, qualityOptionIndex);
88
89 return nullptr;
90}
91
92} // namespace juce
Represents a set of audio channel types.
int size() const noexcept
Returns the number of channels in the set.
static AudioChannelSet JUCE_CALLTYPE mono()
Creates a one-channel mono set (centre).
static AudioChannelSet JUCE_CALLTYPE stereo()
Creates a set containing a stereo set (left, right).
Writes samples to an audio file stream.
virtual StringArray getFileExtensions() const
Returns all the file extensions that might apply to a file of this format.
virtual bool isChannelLayoutSupported(const AudioChannelSet &channelSet)
Returns true if the channel layout is supported by this format.
virtual MemoryMappedAudioFormatReader * createMemoryMappedReader(const File &file)
Attempts to create a MemoryMappedAudioFormatReader, if possible for this format.
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 StringArray getQualityOptions()
Returns a list of different qualities that can be used when writing.
virtual bool canDoMono()=0
Returns true if the format can do 1-channel audio.
virtual bool canHandleFile(const File &fileToTest)
Returns true if this the given file can be read by this format.
AudioFormat(String formatName, StringArray fileExtensions)
Creates an AudioFormat object.
virtual ~AudioFormat()
Destructor.
const String & getFormatName() const
Returns the name of this format.
virtual bool isCompressed()
Returns true if the format uses compressed data.
An input stream that reads from a local file.
Represents a local file or directory.
Definition juce_File.h:45
bool hasFileExtension(StringRef extensionToTest) const
Checks whether the file has a given extension.
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