1 /*---------------------------------------------------------------------------* 2 Project: NintendoWare 3 File: snd_SequenceSound.h 4 5 Copyright (C)2009-2010 Nintendo Co., Ltd./HAL Laboratory, Inc. All rights reserved. 6 7 These coded instructions, statements, and computer programs contain 8 proprietary information of Nintendo of America Inc. and/or Nintendo 9 Company Ltd., and are protected by Federal copyright law. They may 10 not be disclosed to third parties or copied or duplicated in any form, 11 in whole or in part, without the prior written consent of Nintendo. 12 13 $Revision: 20021 $ 14 *---------------------------------------------------------------------------*/ 15 16 #ifndef NW_SND_SEQUENCE_SOUND_H_ 17 #define NW_SND_SEQUENCE_SOUND_H_ 18 19 #include <nw/snd/snd_BasicSound.h> 20 #include <nw/snd/snd_BasicSoundPlayer.h> 21 #include <nw/snd/snd_SequenceSoundPlayer.h> 22 #include <nw/snd/snd_SoundInstanceManager.h> 23 #include <nw/snd/snd_Task.h> 24 #include <nw/snd/snd_Debug.h> 25 #include <nw/io/io_FileStream.h> 26 27 namespace nw { 28 namespace snd { 29 30 /* ======================================================================== 31 type declarataion 32 ======================================================================== */ 33 34 class SequenceSoundHandle; 35 36 37 namespace internal { 38 39 namespace driver { 40 41 class NoteOnCallback; 42 43 } 44 45 class SequenceSound; 46 47 typedef SoundInstanceManager<SequenceSound, driver::SequenceSoundPlayer> SequenceSoundInstanceManager; 48 49 50 class SequenceSound : public BasicSound 51 { 52 friend class SequenceSoundHandle; 53 54 public: 55 NW_UT_RUNTIME_TYPEINFO; // ダウンキャスト用の実行時型情報を埋め込みます 56 57 static const size_t FILE_STREAM_BUFFER_SIZE = 512; 58 /* ------------------------------------------------------------------------ 59 SeqLoadTask class 60 ------------------------------------------------------------------------ */ 61 private: 62 typedef void (*NotifyAsyncEndCallback)( 63 bool result, 64 const void* seqBase, 65 void* userData 66 ); 67 68 class SeqLoadTask : public Task 69 { 70 public: 71 SeqLoadTask(); 72 virtual void Execute(); 73 74 io::FileStream* m_pFileStream; 75 void* m_pBuffer; 76 int m_BufferSize; 77 NotifyAsyncEndCallback m_Callback; 78 void* m_CallbackData; 79 }; 80 81 /* ------------------------------------------------------------------------ 82 class member 83 ------------------------------------------------------------------------ */ 84 public: 85 SequenceSound( SequenceSoundInstanceManager& manager ); 86 87 void Setup( 88 driver::SequenceTrackAllocator* trackAllocator, 89 u32 allocTracks, 90 driver::NoteOnCallback* callback, 91 const void* bankFiles[], 92 u32 bankFileCount 93 ); 94 void Prepare( 95 const void* seqBase, 96 s32 seqOffset, 97 driver::SequenceSoundPlayer::OffsetType startOffsetType, 98 int startOffset 99 ); 100 void Prepare( 101 io::FileStream* fileStream, 102 s32 seqOffset, 103 driver::SequenceSoundPlayer::OffsetType startOffsetType, 104 int startOffset 105 ); 106 virtual void Initialize(); 107 virtual void Finalize(); IsPrepared()108 virtual bool IsPrepared() const { return m_PreparedFlag; } 109 GetFileStreamBuffer()110 void* GetFileStreamBuffer() { return m_FileStreamBuffer; } GetFileStreamBufferSize()111 size_t GetFileStreamBufferSize() { return FILE_STREAM_BUFFER_SIZE; } 112 113 // パラメータ設定 114 void SetTempoRatio( f32 tempoRatio ); 115 void SetChannelPriority( int priority ); 116 void SetReleasePriorityFix( bool fix ); 117 void SetSequenceUserprocCallback( SequenceUserprocCallback callback, void* arg ); 118 119 // パラメータ取得 120 u32 GetTick() const; 121 122 // トラックパラメータ設定 123 void SetTrackMute( u32 trackBitFlag, SeqMute mute ); 124 void SetTrackMute( u32 trackBitFlag, bool muteFlag ); 125 void SetTrackSilence( u32 trackBitFlag, bool silenceFlag, int fadeTimes ); 126 127 void SetTrackBiquadFilter( u32 trackBitFlag, int type, f32 value ); 128 void SetTrackBankIndex( u32 trackBitFlag, int bankIndex ); 129 130 void SetTrackVolume( u32 trackBitFlag, f32 volume ); 131 void SetTrackPitch( u32 trackBitFlag, f32 pitch ); 132 void SetTrackPan( u32 trackBitFlag, f32 pan ); 133 void SetTrackSurroundPan( u32 trackBitFlag, f32 surroundPan ); 134 void SetTrackLpfFreq( u32 trackBitFlag, f32 lpfFreq ); 135 void SetTrackPanRange( u32 trackBitFlag, f32 panRange ); 136 void SetTrackModDepth( u32 trackBitFlag, f32 depth ); 137 void SetTrackModSpeed( u32 trackBitFlag, f32 speed ); 138 139 // シーケンス変数 140 bool ReadVariable( int varNo, s16* var ) const; 141 static bool ReadGlobalVariable( int varNo, s16* var ); 142 bool ReadTrackVariable( int trackNo, int varNo, s16* var ) const; 143 void WriteVariable( int varNo, s16 var ); 144 static void WriteGlobalVariable( int varNo, s16 var ); 145 void WriteTrackVariable( int trackNo, int varNo, s16 var ); 146 147 // const driver::SequenceSoundPlayer& GetSequenceSoundPlayer() const { return m_SequenceSoundPlayer; } 148 149 // デバッグ関数 GetSoundType()150 DebugSoundType GetSoundType() const { return DEBUG_SOUND_TYPE_SEQSOUND; } 151 152 protected: 153 virtual bool IsAttachedTempSpecialHandle(); 154 virtual void DetachTempSpecialHandle(); 155 GetBasicSoundPlayerHandle()156 virtual driver::BasicSoundPlayer* GetBasicSoundPlayerHandle() { return &m_SequenceSoundPlayerInstance; } 157 158 virtual void OnUpdatePlayerPriority(); 159 160 private: 161 162 bool LoadData( 163 NotifyAsyncEndCallback callback, 164 void* callbackArg 165 ); 166 167 void Skip( driver::SequenceSoundPlayer::OffsetType offsetType, int offset ); 168 169 // プレイヤーヒープロードの完了コールバック 170 static void NotifyLoadAsyncEndSeqData( 171 bool result, 172 const void* seqBase, 173 void* userData 174 ); 175 176 driver::SequenceSoundPlayer m_SequenceSoundPlayerInstance; 177 SequenceSoundHandle* m_pTempSpecialHandle; 178 SequenceSoundInstanceManager& m_Manager; 179 180 s32 m_SeqOffset; 181 driver::SequenceSoundPlayer::OffsetType m_StartOffsetType; 182 int m_StartOffset; 183 184 volatile bool m_LoadingFlag; 185 volatile bool m_PreparedFlag; 186 187 io::FileStream* m_pFileStream; 188 int m_FileStreamBuffer[ FILE_STREAM_BUFFER_SIZE/sizeof(int) ]; 189 190 SeqLoadTask m_SeqLoadTask; 191 192 bool m_InitializeFlag; 193 }; 194 195 } // namespace nw::snd::internal 196 } // namespace nw::snd 197 } // namespace nw 198 199 200 #endif /* NW_SND_SEQUENCE_SOUND_H_ */ 201 202