Cinder  0.8.6
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
FileOggVorbis.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 
29 #define OV_EXCLUDE_STATIC_CALLBACKS
30 
31 #include "vorbis/codec.h"
32 #include "vorbis/vorbisfile.h"
33 
34 namespace cinder { namespace audio {
35 
36 namespace dsp {
37  class Converter;
38 }
39 
42  public:
44  SourceFileOggVorbis( const DataSourceRef &dataSource, size_t sampleRate );
45  virtual ~SourceFileOggVorbis();
46 
47  SourceFileRef cloneWithSampleRate( size_t sampleRate ) const override;
48 
49  size_t getNumChannels() const override { return mNumChannels; }
50  size_t getSampleRateNative() const override { return mSampleRate; }
51 
52  size_t performRead( Buffer *buffer, size_t bufferFrameOffset, size_t numFramesNeeded ) override;
53  void performSeek( size_t readPositionFrames ) override;
54  std::string getMetaData() const override;
55 
56  private:
57  void init();
58  void setupConversionImpl();
59 
60  // ov_callbacks
61  static size_t readFn( void *ptr, size_t size, size_t count, void *datasource );
62  static int seekFn( void *datasource, ogg_int64_t offset, int whence );
63  static int closeFn( void *datasource );
64  static long tellFn( void *datasource );
65 
66  ::OggVorbis_File mOggVorbisFile;
67 
68  ci::DataSourceRef mDataSource;
69  ci::IStreamRef mStream;
70  size_t mNumChannels, mSampleRate;
71 };
72 
73 //class TargetFileImplOggVorbis : public TargetFile {
74 //public:
75 // TargetFileImplOggVorbis( const DataTargetRef &dataTarget, size_t sampleRate, size_t numChannels, const std::string &extension );
76 // virtual TargetFileImplOggVorbis() {}
77 //
78 // void write( const Buffer *buffer, size_t frameOffset, size_t numFrames ) override;
79 //
80 //private:
81 //};
82 
83 } } // namespace cinder::audio
SourceFile implementation for decoding ogg vorbis files.
Definition: FileOggVorbis.h:41
size_t performRead(Buffer *buffer, size_t bufferFrameOffset, size_t numFramesNeeded) override
Definition: FileOggVorbis.cpp:93
GLsizei const GLchar ** string
Definition: GLee.h:2427
SourceFileOggVorbis()
Definition: FileOggVorbis.cpp:35
Loads and reads from an audio file source.
Definition: Source.h:83
std::shared_ptr< class SourceFile > SourceFileRef
Definition: Source.h:34
size_t getNumChannels() const override
Returns the number of channels.
Definition: FileOggVorbis.h:49
std::shared_ptr< IStreamCinder > IStreamRef
Definition: Stream.h:142
std::string getMetaData() const override
Returns the metadata, if any, as a string.
Definition: FileOggVorbis.cpp:126
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: FileOggVorbis.cpp:46
GLintptr offset
Definition: GLee.h:2095
GLuint GLuint GLsizei count
Definition: GLee.h:963
virtual ~SourceFileOggVorbis()
Definition: FileOggVorbis.cpp:59
size_t getSampleRateNative() const override
Returns the true samplerate of the Source.
Definition: FileOggVorbis.h:50
void performSeek(size_t readPositionFrames) override
Implement to perform seek. readPositionFrames is in native file units.
Definition: FileOggVorbis.cpp:120
std::shared_ptr< class DataSource > DataSourceRef
Definition: DataSource.h:35
GLsizeiptr size
Definition: GLee.h:2089