Cinder  0.8.6
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
Target.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/Buffer.h"
28 
29 #include "cinder/DataTarget.h"
30 
31 namespace cinder { namespace audio {
32 
33 typedef std::shared_ptr<class TargetFile> TargetFileRef;
34 
36 class TargetFile {
37  public:
38  static std::unique_ptr<TargetFile> create( const DataTargetRef &dataTarget, size_t sampleRate, size_t numChannels, SampleType sampleType = SampleType::INT_16, const std::string &extension = "" );
39  static std::unique_ptr<TargetFile> create( const fs::path &path, size_t sampleRate, size_t numChannels, SampleType sampleType = SampleType::INT_16, const std::string &extension = "" );
40  virtual ~TargetFile() {}
41 
42  void write( const Buffer *buffer );
43  void write( const Buffer *buffer, size_t numFrames );
44  void write( const Buffer *buffer, size_t numFrames, size_t frameOffset );
45 
46  size_t getSampleRate() const { return mSampleRate; }
47  size_t getNumChannels() const { return mNumChannels; }
48 
49  protected:
50  TargetFile( const DataTargetRef &dataTarget, size_t sampleRate, size_t numChannels, SampleType sampleType )
51  : mSampleRate( sampleRate ), mNumChannels( numChannels ), mSampleType( sampleType )
52  {}
53 
54  // Implement to write \a numFrames frames of \a buffer to file. The writing begins at \a frameOffset.
55  virtual void performWrite( const Buffer *buffer, size_t numFrames, size_t frameOffset ) = 0;
56 
59 };
60 
61 } } // namespace cinder::audio
std::shared_ptr< class TargetFile > TargetFileRef
Definition: Target.h:33
GLsizei const GLchar ** string
Definition: GLee.h:2427
TargetFile(const DataTargetRef &dataTarget, size_t sampleRate, size_t numChannels, SampleType sampleType)
Definition: Target.h:50
size_t mSampleRate
Definition: Target.h:57
virtual ~TargetFile()
Definition: Target.h:40
static std::unique_ptr< TargetFile > create(const DataTargetRef &dataTarget, size_t sampleRate, size_t numChannels, SampleType sampleType=SampleType::INT_16, const std::string &extension="")
Definition: Target.cpp:41
size_t getNumChannels() const
Definition: Target.h:47
virtual void performWrite(const Buffer *buffer, size_t numFrames, size_t frameOffset)=0
size_t getSampleRate() const
Definition: Target.h:46
GLuint buffer
Definition: GLee.h:2065
SampleType mSampleType
Definition: Target.h:58
void write(const Buffer *buffer)
Definition: Target.cpp:57
size_t mNumChannels
Definition: Target.h:57
Base class that is used to create and write to an audio destination. Currently only supports ...
Definition: Target.h:36
std::shared_ptr< class DataTarget > DataTargetRef
Definition: DataTarget.h:33
SampleType
Identifiers sample types. Primarily used for encoding audio at different bitrates.
Definition: SampleType.h:29