SourceFileWav.h
Go to the documentation of this file.
1 /*
2  Copyright (c) 2009, The Barbarian Group
3  All rights reserved.
4 
5  Redistribution and use in source and binary forms, with or without modification, are permitted provided that
6  the following conditions are met:
7 
8  * Redistributions of source code must retain the above copyright notice, this list of conditions and
9  the following disclaimer.
10  * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
11  the following disclaimer in the documentation and/or other materials provided with the distribution.
12 
13  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
14  WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
15  PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
16  ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
17  TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
18  HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
19  NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
20  POSSIBILITY OF SUCH DAMAGE.
21 */
22 #pragma once
23 
24 #include "cinder/Cinder.h"
25 #include "cinder/audio/Io.h"
26 
27 namespace cinder { namespace audio {
28 
29 typedef std::shared_ptr<class SourceFileWav> SourceFileWavRef;
30 typedef std::shared_ptr<class LoaderSourceFileWav> LoaderSourceFileWavRef;
31 
32 class LoaderSourceFileWav : public Loader {
33  public:
34  static LoaderSourceFileWavRef createRef( SourceFileWav *source, Target *target );
36 
37  uint32_t getOptimalBufferSize() const { return 0; }
38  void loadData( BufferList *ioData );
39 
40  uint64_t getSampleOffset() const;
41  void setSampleOffset( uint64_t anOffset );
42 protected:
43  LoaderSourceFileWav( SourceFileWav * source, Target * target );
44 
47  uint64_t mSampleOffset;
48 };
49 
50 class SourceFileWav : public Source {
51  public:
52  static SourceRef createRef( DataSourceRef dataSourceRef ) { return createFileWavRef( dataSourceRef ); }
53  static SourceFileWavRef createFileWavRef( DataSourceRef dataSourceRef );
55 
56  LoaderRef createLoader( Target *target ) { return LoaderSourceFileWav::createRef( this, target ); }
57 
58  uint32_t getLength() const { return mDataLength; };
59  double getDuration() const { /*TODO*/ return 0.0; }
60 
61  static void registerSelf();
62  private:
63  SourceFileWav( DataSourceRef dataSourceRef );
64  void readFormatChunk( IStreamRef stream );
65  IStreamRef createStream();
66 
67  DataSourceRef mDataSource;
68  uint32_t mDataLength;
69  uint32_t mDataStart;
70  uint64_t mSampleCount;
71 
72  uint16_t mAudioFormat;
73  uint32_t mByteRate;
74 
75  friend LoaderSourceFileWav;
76 };
77 
78 REGISTER_AUDIOIO( SourceFileWav )
79 
80 }} //namespace