00001 /* 00002 Copyright (c) 2009, The Barbarian Group 00003 All rights reserved. 00004 00005 Redistribution and use in source and binary forms, with or without modification, are permitted provided that 00006 the following conditions are met: 00007 00008 * Redistributions of source code must retain the above copyright notice, this list of conditions and 00009 the following disclaimer. 00010 * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and 00011 the following disclaimer in the documentation and/or other materials provided with the distribution. 00012 00013 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED 00014 WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A 00015 PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 00016 ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED 00017 TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 00018 HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 00019 NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 00020 POSSIBILITY OF SUCH DAMAGE. 00021 */ 00022 00023 #pragma once 00024 00025 #include "cinder/Cinder.h" 00026 #include "cinder/audio/Io.h" 00027 #include "cinder/Exception.h" 00028 00029 #if defined( CINDER_MSW ) && ( _MSC_VER >= 1700 ) && ( _WIN32_WINNT < 0x0602 ) && ( ! defined( _USING_V110_SDK71_ ) ) 00030 #error "Cinder Audio is only supported targeting Windows 8 with Visual C++ 2012 v110 compiler. Please see 'Windows Notes' in the docs." 00031 #elif defined( CINDER_MSW ) && ( _WIN32_WINNT >= 0x0602 ) && ( ! defined( _USING_V110_SDK71_ ) ) 00032 #pragma comment( lib, "xaudio2.lib" ) 00033 #endif 00034 00035 namespace cinder { namespace audio { 00036 00037 class Track; 00038 00039 typedef int32_t TrackId; 00040 typedef std::shared_ptr<class cinder::audio::Track> TrackRef; 00041 00042 class OutputImpl; 00043 00044 //TODO: add a track 'controller' that talks to tracks through their Output owner 00045 /*class TrackController { 00046 public: 00047 ~TrackController() {} 00048 private: 00049 TrackController( OutputImpl * output, TrackId track ) : mOutput( output ), mTrackId( trackId ) {} 00050 00051 TrackId mTrackId; 00052 OutputImpl * mOutput; 00053 }*/ 00054 00055 class Track { 00056 public: 00057 virtual ~Track() {} 00058 virtual void play() = 0; 00059 virtual void stop() = 0; 00060 virtual bool isPlaying() const = 0; 00061 00062 virtual void setVolume( float aVolume ) = 0; 00063 virtual float getVolume() const = 0; 00064 00065 virtual double getTime() const = 0; 00066 virtual void setTime( double aTime ) = 0; 00067 00068 virtual void setLooping( bool isLooping ) = 0; 00069 virtual bool isLooping() const = 0; 00070 00071 virtual void enablePcmBuffering( bool isBuffering ) = 0; 00072 virtual bool isPcmBuffering() = 0; 00073 virtual PcmBuffer32fRef getPcmBuffer() = 0; 00074 protected: 00075 Track() {} 00076 }; 00077 00078 class OutputImpl { 00079 public: 00080 virtual ~OutputImpl() {} 00081 00082 virtual void play( SourceRef aSource ) { addTrack( aSource, true ); } 00083 virtual TrackRef addTrack( SourceRef aSource, bool autoplay ) = 0; 00084 virtual void removeTrack( TrackId trackId ) = 0; 00085 00086 virtual float getVolume() const = 0; 00087 virtual void setVolume( float aVolume ) = 0; 00088 00089 //virtual TargetRef getTarget() = 0; 00090 protected: 00091 OutputImpl(); 00092 virtual TrackId availableTrackId() { return mNextTrackId++; } 00093 00094 /*void retainTrack( TrackId trackId ) {} 00095 void releaseTrack( TrackId trackId ) {} 00096 void playTrack( TrackId trackId ) {} 00097 void stopTrack( TrackId trackId ) {} 00098 void setTrackVolume( TrackId trackId, float aVolume ) {} 00099 float getTrackVolume( TrackId trackId ) {} 00100 void setTrackTime( TrackId trackId, double aTime ) {} 00101 float getTrackTime( TrackId trackId ) {}*/ 00102 00103 00104 TrackId mNextTrackId; 00105 00106 friend class Track; 00107 //friend class TrackController; 00108 }; 00109 00110 class Output { 00111 public: 00112 static void play( SourceRef aSource ) { instance()->play( aSource ); } 00113 00114 static TrackRef addTrack( SourceRef aSource, bool autoplay = true ) { return instance()->addTrack( aSource, autoplay ); } 00115 static void removeTrack( TrackId trackId ) { instance()->removeTrack( trackId ); } 00116 00117 static float getVolume() { return instance()->getVolume(); } 00118 static void setVolume( float aVolume ) { instance()->setVolume( aVolume ); } 00119 00120 //static TargetRef getTarget() { return instance()->getTarget(); } 00121 private: 00122 static OutputImpl* instance(); 00123 }; 00124 00125 class OutputException : public Exception {}; 00126 class OutOfTracksException : public Exception {}; 00127 00128 00129 00130 }} //namespace