Cinder  0.8.6
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
FileCoreAudio.h
Go to the documentation of this file.
1 /*
2  Copyright (c) 2014, The Cinder Project
3 
4  This code is intended to be used with the Cinder C++ library, http://libcinder.org
5 
6  Redistribution and use in source and binary forms, with or without modification, are permitted provided that
7  the following conditions are met:
8 
9  * Redistributions of source code must retain the above copyright notice, this list of conditions and
10  the following disclaimer.
11  * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
12  the following disclaimer in the documentation and/or other materials provided with the distribution.
13 
14  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
15  WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
16  PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
17  ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
18  TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
19  HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
20  NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
21  POSSIBILITY OF SUCH DAMAGE.
22 */
23 
24 #pragma once
25 
26 #include "cinder/audio/Source.h"
27 #include "cinder/audio/Target.h"
29 #include "cinder/DataSource.h"
30 
31 #include <AudioToolbox/ExtendedAudioFile.h>
32 
33 namespace cinder { namespace audio { namespace cocoa {
34 
36  void operator()( ::OpaqueExtAudioFile *audioFile )
37  {
38  ::ExtAudioFileDispose( audioFile );
39  }
40 };
41 
42 typedef std::unique_ptr<::OpaqueExtAudioFile, ExtAudioFileDeleter> ExtAudioFilePtr;
43 
45  public:
47  SourceFileCoreAudio( const DataSourceRef &dataSource, size_t sampleRate );
48  virtual ~SourceFileCoreAudio();
49 
50  SourceFileRef cloneWithSampleRate( size_t sampleRate ) const override;
51 
52  size_t getNumChannels() const override { return mNumChannels; }
53  size_t getSampleRateNative() const override { return mSampleRateNative; }
54 
55  static std::vector<std::string> getSupportedExtensions();
56 
57  private:
58  void initImpl();
59 
60  size_t performRead( Buffer *buffer, size_t bufferFrameOffset, size_t numFramesNeeded ) override;
61  void performSeek( size_t readPositionFrames ) override;
62  bool supportsConversion() override { return true; }
63 
64  ExtAudioFilePtr mExtAudioFile;
65  AudioBufferListShallowPtr mBufferList;
66  ci::DataSourceRef mDataSource;
67  size_t mNumChannels, mSampleRateNative;
68 };
69 
71  public:
72  TargetFileCoreAudio( const DataTargetRef &dataTarget, size_t sampleRate, size_t numChannels, SampleType sampleType, const std::string &extension );
73  virtual ~TargetFileCoreAudio() {}
74 
75  void performWrite( const Buffer *buffer, size_t numFrames, size_t frameOffset ) override;
76 
77  private:
78  static ::AudioFileTypeID getFileTypeIdFromExtension( const std::string &ext );
79 
80  ExtAudioFilePtr mExtAudioFile;
81  AudioBufferListShallowPtr mBufferList;
82 };
83 
84 } } } // namespace cinder::audio::cocoa
virtual ~SourceFileCoreAudio()
Definition: FileCoreAudio.cpp:58
SourceFileCoreAudio()
Definition: FileCoreAudio.cpp:41
GLsizei const GLchar ** string
Definition: GLee.h:2427
size_t getNumChannels() const override
Returns the number of channels.
Definition: FileCoreAudio.h:52
Loads and reads from an audio file source.
Definition: Source.h:83
std::shared_ptr< class SourceFile > SourceFileRef
Definition: Source.h:34
TargetFileCoreAudio(const DataTargetRef &dataTarget, size_t sampleRate, size_t numChannels, SampleType sampleType, const std::string &extension)
Definition: FileCoreAudio.cpp:145
static std::vector< std::string > getSupportedExtensions()
Definition: FileCoreAudio.cpp:121
std::unique_ptr<::OpaqueExtAudioFile, ExtAudioFileDeleter > ExtAudioFilePtr
Definition: FileCoreAudio.h:42
Definition: FileCoreAudio.h:44
std::unique_ptr<::AudioBufferList, AudioBufferListShallowDeleter > AudioBufferListShallowPtr
Definition: CinderCoreAudio.h:56
GLuint buffer
Definition: GLee.h:2065
SourceFileRef cloneWithSampleRate(size_t sampleRate) const override
Returns an copy of this Source with all properties identical except the sampleRate. This is useful if the SourceFile must match a samplerate that was unknown when it was first constructed.
Definition: FileCoreAudio.cpp:53
Base class that is used to create and write to an audio destination. Currently only supports ...
Definition: Target.h:36
void performWrite(const Buffer *buffer, size_t numFrames, size_t frameOffset) override
Definition: FileCoreAudio.cpp:181
Definition: FileCoreAudio.h:70
void operator()(::OpaqueExtAudioFile *audioFile)
Definition: FileCoreAudio.h:36
std::shared_ptr< class DataTarget > DataTargetRef
Definition: DataTarget.h:33
size_t getSampleRateNative() const override
Returns the true samplerate of the Source.
Definition: FileCoreAudio.h:53
SampleType
Identifiers sample types. Primarily used for encoding audio at different bitrates.
Definition: SampleType.h:29
Definition: FileCoreAudio.h:35
virtual ~TargetFileCoreAudio()
Definition: FileCoreAudio.h:73
std::shared_ptr< class DataSource > DataSourceRef
Definition: DataSource.h:35