1 /*---------------------------------------------------------------------------*
2 Project: NintendoWare
3 File: snd_BasicSound.cpp
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: 22340 $
14 *---------------------------------------------------------------------------*/
15
16 #include "precompiled.h"
17
18 #include <nw/snd/snd_BasicSound.h>
19 #include <nw/snd/snd_BasicSoundPlayer.h>
20 #include <nw/snd/snd_SoundPlayer.h>
21 #include <nw/snd/snd_ExternalSoundPlayer.h>
22 #include <nw/snd/snd_SoundActor.h>
23 #include <cstring> // std::memcpy
24
25 namespace nw {
26 namespace snd {
27 namespace internal {
28
29 NW_UT_RUNTIME_TYPEINFO_ROOT_DEFINITION(BasicSound);
30
31 /*---------------------------------------------------------------------------*
32 Name: BasicSound
33
34 Description: コンストラクタ
35
36 Arguments: None.
37
38 Returns: None.
39 *---------------------------------------------------------------------------*/
BasicSound()40 BasicSound::BasicSound()
41 : m_InitializeFlag(false)
42 {
43 }
44
45 /*---------------------------------------------------------------------------*
46 Name: Initialize
47
48 Description: 初期化
49
50 Arguments: None.
51
52 Returns: None.
53 *---------------------------------------------------------------------------*/
Initialize()54 void BasicSound::Initialize()
55 {
56 driver::BasicSoundPlayer* basicPlayer = GetBasicSoundPlayerHandle();
57 DriverCommandManager& cmdmgr = DriverCommandManager::GetInstance();
58
59 m_pPlayerHeap = NULL;
60 m_pGeneralHandle = NULL;
61 m_pTempGeneralHandle = NULL;
62 m_pSoundPlayer = NULL;
63 m_pSoundActor = NULL;
64 m_pExtSoundPlayer = NULL;
65 m_PlayerState = PLAYER_STATE_INIT;
66 m_Id = INVALID_ID;
67
68 m_AmbientInfo.paramUpdateCallback = NULL;
69 m_AmbientInfo.argUpdateCallback = NULL;
70 m_AmbientInfo.argAllocatorCallback = NULL;
71 m_AmbientInfo.arg = NULL;
72 m_AmbientInfo.argSize = 0;
73
74 m_PlayerState = PLAYER_STATE_INIT;
75 m_PauseState = PAUSE_STATE_NORMAL;
76 m_UnPauseFlag = false;
77 m_StartFlag = false;
78 m_StartedFlag = false;
79 m_AutoStopFlag = false;
80 m_FadeOutFlag = false;
81 m_PlayerAvailableFlag = false;
82
83 m_AutoStopCounter = 0;
84 m_UpdateCounter = 0;
85
86 m_FadeVolume.InitValue( 0.0f );
87 m_PauseFadeVolume.InitValue( 1.0f );
88 m_FadeVolume.SetTarget( 1.0f, 1 );
89
90 m_InitVolume = 1.0f;
91 m_ExtPitch = 1.0f;
92 m_ExtPan = 0.0f;
93 m_ExtMoveVolume.InitValue( 1.0f );
94 m_LpfFreq = 0.0f;
95 m_BiquadFilterType = BIQUAD_FILTER_TYPE_NONE;
96 m_BiquadFilterValue = 0.0f;
97 m_ExtSurroundPan = 0.0f;
98
99 m_MainSend = 0.0f;
100 for ( int i=0; i<AUX_BUS_NUM; i++ )
101 {
102 m_FxSend[i] = 0.0f;
103 }
104
105 // AmbientParam
106 m_AmbientParam.volume = 1.0f;
107 m_AmbientParam.pitch = 1.0f;
108 m_AmbientParam.pan = 0.0f;
109 m_AmbientParam.span = 0.0f;
110 m_AmbientParam.fxSend = 0.0f;
111 m_AmbientParam.lpf = 0.0f;
112 m_AmbientParam.biquadFilterValue = 0.0f;
113 m_AmbientParam.biquadFilterType = 0;
114 m_AmbientParam.priority = 0;
115
116 m_ActorParam.Reset();
117
118 DriverCommandPlayerInit* command =
119 cmdmgr.AllocCommand<DriverCommandPlayerInit>();
120 command->id = DRIVER_COMMAND_PLAYER_INIT;
121 command->player = basicPlayer;
122 command->availableFlagPtr = &m_PlayerAvailableFlag;
123 cmdmgr.PushCommand(command);
124
125 m_InitializeFlag = true;
126 }
127
SetPriority(int priority,int ambientPriority)128 void BasicSound::SetPriority( int priority, int ambientPriority )
129 {
130 NW_MINMAX_ASSERT( priority, PRIORITY_MIN, PRIORITY_MAX );
131
132 m_Priority = static_cast<u8>(priority);
133 m_AmbientParam.priority = ambientPriority;
134 }
135
136 /*---------------------------------------------------------------------------*
137 Name: Finalize
138
139 Description:
140
141 Arguments: None.
142
143 Returns: None.
144 *---------------------------------------------------------------------------*/
Finalize()145 void BasicSound::Finalize()
146 {
147 if ( ! m_InitializeFlag ) return;
148
149 // プレイヤーの停止
150 if ( m_StartedFlag )
151 {
152 DriverCommandManager& cmdmgr = DriverCommandManager::GetInstance();
153
154 DriverCommandPlayer* command =
155 cmdmgr.AllocCommand<DriverCommandPlayer>();
156 command->id = DRIVER_COMMAND_PLAYER_STOP;
157 command->player = GetBasicSoundPlayerHandle();
158 command->flag = m_FadeOutFlag;
159 cmdmgr.PushCommand(command);
160 }
161 m_PlayerAvailableFlag = false;
162 m_PlayerState = PLAYER_STATE_STOP;
163
164 // IDを無効化
165 SetId( INVALID_ID );
166
167 // ハンドルとの切断
168 if ( IsAttachedGeneralHandle() )
169 {
170 DetachGeneralHandle();
171 }
172 if ( IsAttachedTempGeneralHandle() )
173 {
174 DetachTempGeneralHandle();
175 }
176 if ( IsAttachedTempSpecialHandle() )
177 {
178 DetachTempSpecialHandle();
179 }
180
181 if ( m_pPlayerHeap != NULL ) {
182 m_pSoundPlayer->detail_FreePlayerHeap( this );
183 }
184
185 // プレイヤーとの切断
186 if ( m_pSoundPlayer != NULL ) m_pSoundPlayer->detail_RemoveSound( this );
187 if ( m_pExtSoundPlayer != NULL ) m_pExtSoundPlayer->RemoveSound( this );
188
189 if ( m_AmbientInfo.argAllocatorCallback != NULL )
190 {
191 m_AmbientInfo.argAllocatorCallback->detail_FreeAmbientArg( m_AmbientInfo.arg, this );
192 m_AmbientInfo.arg = NULL;
193 }
194
195 // フラグクリア
196 m_StartedFlag = false;
197 m_FadeOutFlag = false;
198
199 DriverCommandManager& cmdmgr = DriverCommandManager::GetInstance();
200 DriverCommandPlayer* command =
201 cmdmgr.AllocCommand<DriverCommandPlayer>();
202 command->id = DRIVER_COMMAND_PLAYER_FINALIZE;
203 command->player = GetBasicSoundPlayerHandle();
204 cmdmgr.PushCommand(command);
205
206 m_InitializeFlag = false;
207 }
208
209 /*---------------------------------------------------------------------------*
210 Name: StartPrepared
211
212 Description: プリペアが完了していたらサウンドをスタートする
213
214 Arguments: None.
215
216 Returns: None.
217 *---------------------------------------------------------------------------*/
StartPrepared()218 void BasicSound::StartPrepared()
219 {
220 m_StartFlag = true;
221 }
222
223 /*---------------------------------------------------------------------------*
224 Name: Stop
225
226 Description: サウンド停止
227
228 Arguments: fadeFrames - フェードアウトフレーム
229
230 Returns: None.
231 *---------------------------------------------------------------------------*/
Stop(int fadeFrames)232 void BasicSound::Stop( int fadeFrames )
233 {
234 if ( ( fadeFrames == 0 ) ||
235 ( m_PlayerState != PLAYER_STATE_PLAY ) ||
236 ( m_PauseState == PAUSE_STATE_PAUSED )
237 )
238 {
239 Finalize();
240 return;
241 }
242
243 int frames = static_cast<int>( fadeFrames * m_FadeVolume.GetValue() );
244 m_FadeVolume.SetTarget( 0.0f, frames );
245 SetPlayerPriority( PRIORITY_MIN );
246 m_AutoStopFlag = false;
247 m_PauseState = PAUSE_STATE_NORMAL;
248 m_UnPauseFlag = false;
249 m_FadeOutFlag = true;
250 }
251
252 /*---------------------------------------------------------------------------*
253 Name: Pause
254
255 Description: サウンドの一時停止または再開
256
257 Arguments: flag - 一時停止または再開
258 fadeFrames - フェードフレーム数
259
260 Returns: None.
261 *---------------------------------------------------------------------------*/
Pause(bool flag,int fadeFrames)262 void BasicSound::Pause( bool flag, int fadeFrames )
263 {
264 int frames;
265 if ( flag )
266 {
267 // 一時停止処理
268 switch( m_PauseState ) {
269 case PAUSE_STATE_NORMAL:
270 case PAUSE_STATE_PAUSING:
271 case PAUSE_STATE_UNPAUSING:
272 frames = static_cast<int>( fadeFrames * m_PauseFadeVolume.GetValue() );
273 if ( frames <= 0 ) frames = 1;
274 m_PauseFadeVolume.SetTarget( 0.0f, frames);
275 m_PauseState = PAUSE_STATE_PAUSING;
276 m_UnPauseFlag = false;
277 break;
278 case PAUSE_STATE_PAUSED:
279 // do nothing
280 return;
281 default:
282 NW_ASSERTMSG( false, "Unexpected pause state %d", m_PauseState );
283 return;
284 }
285 }
286 else
287 {
288 switch( m_PauseState ) {
289 case PAUSE_STATE_NORMAL:
290 // do nothing
291 return;
292 case PAUSE_STATE_PAUSING:
293 case PAUSE_STATE_UNPAUSING:
294 case PAUSE_STATE_PAUSED:
295 frames = static_cast<int>( fadeFrames * ( 1.0f - m_PauseFadeVolume.GetValue() ) );
296 if ( frames <= 0 ) frames = 1;
297 m_PauseFadeVolume.SetTarget( 1.0f, frames);
298 m_PauseState = PAUSE_STATE_UNPAUSING;
299 m_UnPauseFlag = true;
300 break;
301 default:
302 NW_ASSERTMSG( false, "Unexpected pause state %d", m_PauseState );
303 return;
304 }
305 }
306 }
307
308 /*---------------------------------------------------------------------------*
309 Name: SetAutoStopCounter
310
311 Description: サウンドが自動停止するまでのフレーム数を設定する
312
313 Arguments: frames - 自動停止するまでのフーレム数
314
315 Returns: None.
316 *---------------------------------------------------------------------------*/
SetAutoStopCounter(int frames)317 void BasicSound::SetAutoStopCounter( int frames )
318 {
319 m_AutoStopCounter = frames;
320 m_AutoStopFlag = ( frames > 0 );
321 }
322
323 /*---------------------------------------------------------------------------*
324 Name: FadeIn
325
326 Description: フェードイン
327
328 Arguments: frames - 変化フレーム数
329
330 Returns: None.
331 *---------------------------------------------------------------------------*/
FadeIn(int frames)332 void BasicSound::FadeIn( int frames )
333 {
334 if ( m_FadeOutFlag ) return;
335 frames = static_cast<int>( frames * ( 1.0f - m_FadeVolume.GetValue() ) );
336 m_FadeVolume.SetTarget( 1.0f, frames );
337 }
338
339 /*---------------------------------------------------------------------------*
340 Name: IsPause
341
342 Description: 一時停止中かどうかを取得
343
344 Arguments: None.
345
346 Returns: 一時停止中ならば true
347 *---------------------------------------------------------------------------*/
IsPause() const348 bool BasicSound::IsPause() const
349 {
350 return (m_PauseState == PAUSE_STATE_PAUSING) || (m_PauseState == PAUSE_STATE_PAUSED);
351 }
352
353 /*---------------------------------------------------------------------------*
354 Name: Update
355
356 Description: サウンドの更新
357
358 Arguments: None.
359
360 Returns: None.
361 *---------------------------------------------------------------------------*/
Update()362 void BasicSound::Update()
363 {
364 // 自動停止カウンター処理
365 if ( m_AutoStopFlag )
366 {
367 if ( m_AutoStopCounter == 0 )
368 {
369 if ( ( m_PauseState == PAUSE_STATE_NORMAL ) ||
370 ( m_PauseState == PAUSE_STATE_UNPAUSING ) )
371 {
372 Stop( 0 );
373 return;
374 }
375 }
376 else
377 {
378 --m_AutoStopCounter;
379 }
380 }
381
382 // スタート前の処理
383 bool playerStartFlag = false;
384 if ( ! m_StartedFlag )
385 {
386 if ( ! m_StartFlag ) return;
387 if ( ! IsPrepared() ) return;
388
389 m_PlayerState = PLAYER_STATE_PLAY;
390 playerStartFlag = true;
391 }
392
393 // カウンタ更新
394 if ( m_PlayerState == PLAYER_STATE_PLAY )
395 {
396 if ( m_UpdateCounter < 0xffffffff ) m_UpdateCounter++;
397 }
398
399 // 自動停止チェック
400 if ( m_PlayerAvailableFlag && GetBasicSoundPlayerHandle()->IsPlayFinished() )
401 {
402 Finalize();
403 return;
404 }
405
406 // フェードフレームの更新
407 switch ( m_PauseState )
408 {
409 case PAUSE_STATE_PAUSING:
410 m_PauseFadeVolume.Update();
411 break;
412 case PAUSE_STATE_UNPAUSING:
413 m_PauseFadeVolume.Update();
414 UpdateMoveValue();
415 break;
416 case PAUSE_STATE_NORMAL:
417 UpdateMoveValue();
418 break;
419 }
420
421 // 外部パラメータの更新
422 if ( m_AmbientInfo.argUpdateCallback != NULL )
423 {
424 m_AmbientInfo.argUpdateCallback->detail_UpdateAmbientArg(
425 m_AmbientInfo.arg,
426 this
427 );
428 }
429
430 if ( m_AmbientInfo.paramUpdateCallback != NULL )
431 {
432 SoundAmbientParam ambientParam;
433 if ( m_UpdateCounter > 0 )
434 {
435 ambientParam.volume = m_AmbientParam.volume;
436 ambientParam.pitch = m_AmbientParam.pitch;
437 ambientParam.pan = m_AmbientParam.pan;
438 ambientParam.span = m_AmbientParam.span;
439 ambientParam.fxSend = m_AmbientParam.fxSend;
440 ambientParam.lpf = m_AmbientParam.lpf;
441 ambientParam.biquadFilterValue = m_AmbientParam.biquadFilterValue;
442 ambientParam.biquadFilterType = m_AmbientParam.biquadFilterType;
443 ambientParam.priority = m_AmbientParam.priority;
444 ambientParam.userData = m_AmbientParam.userData;
445 }
446 else
447 {
448 ambientParam.userData = 0;
449 }
450 m_AmbientInfo.paramUpdateCallback->detail_UpdateAmbientParam(
451 m_AmbientInfo.arg,
452 m_Id,
453 &ambientParam
454 );
455
456 m_AmbientParam.volume = ambientParam.volume;
457 m_AmbientParam.pitch = ambientParam.pitch;
458 m_AmbientParam.pan = ambientParam.pan;
459 m_AmbientParam.span = ambientParam.span;
460 m_AmbientParam.fxSend = ambientParam.fxSend;
461 m_AmbientParam.lpf = ambientParam.lpf;
462 m_AmbientParam.biquadFilterValue = ambientParam.biquadFilterValue;
463 m_AmbientParam.biquadFilterType = ambientParam.biquadFilterType;
464 m_AmbientParam.priority = ambientParam.priority;
465 m_AmbientParam.userData = ambientParam.userData;
466
467 }
468
469 if ( m_pSoundActor != NULL )
470 {
471 m_ActorParam = m_pSoundActor->detail_GetActorParam();
472 }
473
474 UpdateParam();
475
476 // フェードアウト完了チェック
477 if ( m_FadeOutFlag && m_FadeVolume.IsFinished() )
478 {
479 m_FadeOutFlag = false;
480 Finalize();
481 return;
482 }
483
484 DriverCommandManager& cmdmgr = DriverCommandManager::GetInstance();
485
486 // プレイヤーの開始処理
487 if ( playerStartFlag )
488 {
489 DriverCommandPlayer* command =
490 cmdmgr.AllocCommand<DriverCommandPlayer>();
491 command->id = DRIVER_COMMAND_PLAYER_START;
492 command->player = GetBasicSoundPlayerHandle();
493 cmdmgr.PushCommand(command);
494
495 m_StartedFlag = true;
496 m_StartFlag = false;
497 }
498
499 // ポーズステータスチェック
500 if ( m_PauseState == PAUSE_STATE_PAUSING )
501 {
502 if ( m_PauseFadeVolume.IsFinished() )
503 {
504 DriverCommandPlayer* command =
505 cmdmgr.AllocCommand<DriverCommandPlayer>();
506 command->id = DRIVER_COMMAND_PLAYER_PAUSE;
507 command->player = GetBasicSoundPlayerHandle();
508 command->flag = true;
509 cmdmgr.PushCommand(command);
510
511 m_PauseState = PAUSE_STATE_PAUSED;
512 }
513 }
514 else if ( m_PauseState == PAUSE_STATE_UNPAUSING )
515 {
516 if ( m_PauseFadeVolume.IsFinished() )
517 {
518 m_PauseState = PAUSE_STATE_NORMAL;
519 }
520 }
521 if ( m_UnPauseFlag ) {
522 DriverCommandPlayer* command =
523 cmdmgr.AllocCommand<DriverCommandPlayer>();
524 command->id = DRIVER_COMMAND_PLAYER_PAUSE;
525 command->player = GetBasicSoundPlayerHandle();
526 command->flag = false;
527 cmdmgr.PushCommand(command);
528
529 m_UnPauseFlag = false;
530 }
531 }
532
UpdateMoveValue()533 void BasicSound::UpdateMoveValue()
534 {
535 m_FadeVolume.Update();
536 m_ExtMoveVolume.Update();
537 }
538
UpdateParam()539 void BasicSound::UpdateParam()
540 {
541 // パラメータの更新
542 float volume = 1.0f;
543 volume *= m_InitVolume;
544 volume *= GetSoundPlayer()->GetVolume();
545 volume *= m_ExtMoveVolume.GetValue();
546 volume *= m_FadeVolume.GetValue();
547 volume *= m_PauseFadeVolume.GetValue();
548 volume *= m_AmbientParam.volume;
549 volume *= m_ActorParam.volume;
550
551 float pan = 0.0f;
552 pan += m_ExtPan;
553 pan += m_AmbientParam.pan;
554 pan += m_ActorParam.pan;
555
556 float surroundPan = 0.0f;
557 surroundPan += m_ExtSurroundPan;
558 surroundPan += m_AmbientParam.span;
559
560 float pitch = 1.0f;
561 pitch *= m_ExtPitch;
562 pitch *= m_AmbientParam.pitch;
563 pitch *= m_ActorParam.pitch;
564
565 float lpfFreq = m_LpfFreq;
566 lpfFreq += m_AmbientParam.lpf;
567 lpfFreq += GetSoundPlayer()->GetLpfFreq();
568
569 int biquadFilterType = m_BiquadFilterType;
570 float biquadFilterValue = m_BiquadFilterValue;
571 if ( biquadFilterType == BIQUAD_FILTER_TYPE_NONE )
572 {
573 biquadFilterType = GetSoundPlayer()->GetBiquadFilterType();
574 biquadFilterValue = GetSoundPlayer()->GetBiquadFilterValue();
575
576 if( biquadFilterType == BIQUAD_FILTER_TYPE_NONE )
577 {
578 biquadFilterType = m_AmbientParam.biquadFilterType;
579 biquadFilterValue = m_AmbientParam.biquadFilterValue;
580 }
581 }
582
583 float mainSend = 0.0f;
584 mainSend += m_MainSend;
585 mainSend += GetSoundPlayer()->GetMainSend();
586
587 float fxSend[AUX_BUS_NUM];
588 for ( int i=0; i<AUX_BUS_NUM; i++ )
589 {
590 fxSend[ i ] = 0.0f;
591 fxSend[ i ] += m_FxSend[ i ];
592 fxSend[ i ] += GetSoundPlayer()->GetFxSend( static_cast<AuxBus>( i ) );
593 }
594 fxSend[ 0 ] += m_AmbientParam.fxSend; // AUX A のみ 3D サウンドの影響を受ける
595
596 DriverCommandManager& cmdmgr = DriverCommandManager::GetInstance();
597
598 DriverCommandPlayerParam* command =
599 cmdmgr.AllocCommand<DriverCommandPlayerParam>();
600 command->id = DRIVER_COMMAND_PLAYER_PARAM;
601 command->player = GetBasicSoundPlayerHandle();
602 command->volume = volume;
603 command->pitch = pitch;
604 command->pan = pan ;
605 command->surroundPan = surroundPan;
606 command->lpfFreq = lpfFreq;
607 command->biquadFilterType = biquadFilterType;
608 command->biquadFilterValue = biquadFilterValue;
609 command->mainSend = mainSend;
610 for ( int i=0; i<AUX_BUS_NUM; i++ )
611 {
612 command->fxSend[i] = fxSend[i];
613 }
614
615 cmdmgr.PushCommand(command);
616 }
617
618 /*---------------------------------------------------------------------------*
619 Name: AttachPlayerHeap
620
621 Description: PlayerHeapを結びつける
622
623 Arguments: pHeap - 結びつけるPlayerHeap
624
625 Returns: None.
626 *---------------------------------------------------------------------------*/
AttachPlayerHeap(PlayerHeap * pHeap)627 void BasicSound::AttachPlayerHeap( PlayerHeap* pHeap )
628 {
629 NW_NULL_ASSERT( pHeap );
630 NW_ASSERT( m_pPlayerHeap == NULL );
631
632 m_pPlayerHeap = pHeap;
633 }
634
635 /*---------------------------------------------------------------------------*
636 Name: DetachPlayerHeap
637
638 Description: PlayerHeapを切り離す
639
640 Arguments: heap - 切り離すPlayerHeap
641
642 Returns: None.
643 *---------------------------------------------------------------------------*/
DetachPlayerHeap(PlayerHeap * pHeap)644 void BasicSound::DetachPlayerHeap( PlayerHeap* pHeap )
645 {
646 NW_NULL_ASSERT( pHeap );
647 NW_ASSERT( pHeap == m_pPlayerHeap );
648 (void)pHeap;
649
650 m_pPlayerHeap = NULL;
651 }
652
653 /*---------------------------------------------------------------------------*
654 Name: AttachSoundPlayer
655
656 Description: SoundPlayerを結びつける
657
658 Arguments: player - 結びつけるSoundPlayer
659
660 Returns: None.
661 *---------------------------------------------------------------------------*/
AttachSoundPlayer(SoundPlayer * player)662 void BasicSound::AttachSoundPlayer( SoundPlayer* player )
663 {
664 NW_NULL_ASSERT( player );
665 NW_ASSERT( m_pSoundPlayer == NULL );
666
667 m_pSoundPlayer = player;
668 }
669
670 /*---------------------------------------------------------------------------*
671 Name: DetachSoundPlayer
672
673 Description: SoundPlayerを切り離す
674
675 Arguments: player - 切り離すSoundPlayer
676
677 Returns: None.
678 *---------------------------------------------------------------------------*/
DetachSoundPlayer(SoundPlayer * player)679 void BasicSound::DetachSoundPlayer( SoundPlayer* player )
680 {
681 NW_NULL_ASSERT( player );
682 NW_ASSERT( player == m_pSoundPlayer );
683 (void)player;
684
685 m_pSoundPlayer = NULL;
686 }
687
688 /*---------------------------------------------------------------------------*
689 Name: AttachSoundActor
690
691 Description: SoundActorを結びつける
692
693 Arguments: actor - 結びつけるSoundActor
694
695 Returns: None.
696 *---------------------------------------------------------------------------*/
AttachSoundActor(SoundActor * actor)697 void BasicSound::AttachSoundActor( SoundActor* actor )
698 {
699 NW_NULL_ASSERT( actor );
700 NW_ASSERT( m_pSoundActor == NULL );
701
702 m_pSoundActor = actor;
703 }
704
705 /*---------------------------------------------------------------------------*
706 Name: DetachSoundActor
707
708 Description: SoundActorを切り離す
709
710 Arguments: actor - 切り離すSoundActor
711
712 Returns: None.
713 *---------------------------------------------------------------------------*/
DetachSoundActor(SoundActor * actor)714 void BasicSound::DetachSoundActor( SoundActor* actor )
715 {
716 NW_NULL_ASSERT( actor );
717 NW_ASSERT( actor == m_pSoundActor );
718 (void)actor;
719
720 m_pSoundActor = NULL;
721 }
722
723 /*---------------------------------------------------------------------------*
724 Name: AttachExternalSoundPlayer
725
726 Description: ExternalSoundPlayerを結びつける
727
728 Arguments: extPlayer - 結びつけるExternalSoundPlayer
729
730 Returns: None.
731 *---------------------------------------------------------------------------*/
AttachExternalSoundPlayer(ExternalSoundPlayer * extPlayer)732 void BasicSound::AttachExternalSoundPlayer( ExternalSoundPlayer* extPlayer )
733 {
734 NW_NULL_ASSERT( extPlayer );
735 NW_ASSERT( m_pExtSoundPlayer == NULL );
736
737 m_pExtSoundPlayer = extPlayer;
738 }
739
740 /*---------------------------------------------------------------------------*
741 Name: DetachExternalSoundPlayer
742
743 Description: ExternalSoundPlayerを切り離す
744
745 Arguments: extPlayer - 切り離すExternalSoundPlayer
746
747 Returns: None.
748 *---------------------------------------------------------------------------*/
DetachExternalSoundPlayer(ExternalSoundPlayer * extPlayer)749 void BasicSound::DetachExternalSoundPlayer( ExternalSoundPlayer* extPlayer )
750 {
751 NW_NULL_ASSERT( extPlayer );
752 NW_ASSERT( extPlayer == m_pExtSoundPlayer );
753 (void)extPlayer;
754
755 m_pExtSoundPlayer = NULL;
756 }
757
758 /*---------------------------------------------------------------------------*
759 Name: GetFadeFramesLeft
760
761 Description: フェードの残りフレームを取得する
762
763 Arguments: なし
764
765 Returns: 残りフレーム
766 *---------------------------------------------------------------------------*/
GetRemainingFadeFrames() const767 int BasicSound::GetRemainingFadeFrames() const
768 {
769 return m_FadeVolume.GetRemainingCount();
770 }
771
772 /*---------------------------------------------------------------------------*
773 Name: GetPauseFadeFramesLeft
774
775 Description: 一時停止フェードの残りフレームを取得する
776
777 Arguments: なし
778
779 Returns: 残りフレーム
780 *---------------------------------------------------------------------------*/
GetRemainingPauseFadeFrames() const781 int BasicSound::GetRemainingPauseFadeFrames() const
782 {
783 return m_PauseFadeVolume.GetRemainingCount();
784 }
785
786
787 /*---------------------------------------------------------------------------*
788 Name: SetPlayerPriority
789
790 Description: プレイヤープライオリティを設定する
791
792 Arguments: priority - プレイヤープライオリティ
793
794 Returns: None.
795 *---------------------------------------------------------------------------*/
SetPlayerPriority(int priority)796 void BasicSound::SetPlayerPriority( int priority )
797 {
798 NW_MINMAX_ASSERT( priority, PRIORITY_MIN, PRIORITY_MAX );
799 m_Priority = static_cast<u8>( priority );
800 if ( m_pSoundPlayer != NULL )
801 {
802 m_pSoundPlayer->detail_SortPriorityList( this );
803 }
804
805 OnUpdatePlayerPriority();
806 }
807
808 /*---------------------------------------------------------------------------*
809 Name: SetInitialVolume
810
811 Description: 初期ボリュームの設定
812
813 Arguments: volume - ボリューム
814
815 Returns: None.
816 *---------------------------------------------------------------------------*/
SetInitialVolume(float volume)817 void BasicSound::SetInitialVolume( float volume )
818 {
819 NW_ASSERT( volume >= 0.0f );
820 if ( volume < 0.0f ) volume = 0.0f;
821 m_InitVolume = volume;
822 }
823
824 /*---------------------------------------------------------------------------*
825 Name: SetVolume
826
827 Description: ボリュームの変更
828
829 Arguments: volume - ボリューム
830
831 Returns: None.
832 *---------------------------------------------------------------------------*/
SetVolume(float volume,int frames)833 void BasicSound::SetVolume( float volume, int frames )
834 {
835 NW_ASSERT( volume >= 0.0f );
836 if ( volume < 0.0f ) volume = 0.0f;
837 m_ExtMoveVolume.SetTarget( volume, frames );
838 }
839
840 /*---------------------------------------------------------------------------*
841 Name: SetPitch
842
843 Description: 音程の変更
844
845 Arguments: pitch - 変更する比率
846
847 Returns: None.
848 *---------------------------------------------------------------------------*/
SetPitch(float pitch)849 void BasicSound::SetPitch( float pitch )
850 {
851 NW_ASSERT( pitch >= 0.0f );
852 m_ExtPitch = pitch;
853 }
854
855 /*---------------------------------------------------------------------------*
856 Name: SetPan
857
858 Description: パンの変更
859
860 Arguments: pan - パン
861
862 Returns: None.
863 *---------------------------------------------------------------------------*/
SetPan(float pan)864 void BasicSound::SetPan( float pan )
865 {
866 m_ExtPan = pan;
867 }
868
869 /*---------------------------------------------------------------------------*
870 Name: SetLpfFreq
871
872 Description: ローパスフィルタのカットオフ周波数の変更
873
874 Arguments: lpfFreq - カットオフ
875
876 Returns: None.
877 *---------------------------------------------------------------------------*/
SetLpfFreq(float lpfFreq)878 void BasicSound::SetLpfFreq( float lpfFreq )
879 {
880 m_LpfFreq = lpfFreq;
881 }
882
883 /*---------------------------------------------------------------------------*
884 Name: SetBiquadFilter
885
886 Description: Biquadフィルタの設定
887
888 Arguments: type - フィルタの種類 (0 - 127)
889 value - フィルタの値 (0.0f - 1.0f)
890
891 Returns: None.
892 *---------------------------------------------------------------------------*/
SetBiquadFilter(int type,float value)893 void BasicSound::SetBiquadFilter( int type, float value )
894 {
895 m_BiquadFilterType = static_cast<u8>( type );
896 m_BiquadFilterValue = value;
897 }
898
899 /*---------------------------------------------------------------------------*
900 Name: SetSurroundPan
901
902 Description: サラウンドパンの変更
903
904 Arguments: surroundPan - サラウンドパン
905
906 Returns: None.
907 *---------------------------------------------------------------------------*/
SetSurroundPan(float surroundPan)908 void BasicSound::SetSurroundPan( float surroundPan )
909 {
910 m_ExtSurroundPan = surroundPan;
911 }
912
913 /*---------------------------------------------------------------------------*
914 Name: SetMainSend
915
916 Description: メインセンドバスに送る音量を変更する
917
918 Arguments: send - 音量
919
920 Returns: None.
921 *---------------------------------------------------------------------------*/
SetMainSend(float send)922 void BasicSound::SetMainSend( float send )
923 {
924 m_MainSend = send;
925 }
926
927 /*---------------------------------------------------------------------------*
928 Name: SetFxSend
929
930 Description: エフェクトセンドバスに送る音量を変更する
931
932 Arguments: bus - センドバス
933 send - 音量
934
935 Returns: None.
936 *---------------------------------------------------------------------------*/
SetFxSend(AuxBus bus,float send)937 void BasicSound::SetFxSend( AuxBus bus, float send )
938 {
939 NW_MINMAXLT_ASSERT( bus, 0, AUX_BUS_NUM );
940 m_FxSend[bus] = send;
941 }
942
943 /*---------------------------------------------------------------------------*
944 Name: SetPanMode
945
946 Description: パンモードを変更
947
948 Arguments: panMode - パンモード
949
950 Returns: なし
951 *---------------------------------------------------------------------------*/
SetPanMode(PanMode panMode)952 void BasicSound::SetPanMode( PanMode panMode )
953 {
954 DriverCommandManager& cmdmgr = DriverCommandManager::GetInstance();
955
956 DriverCommandPlayerPanParam* command =
957 cmdmgr.AllocCommand<DriverCommandPlayerPanParam>();
958 command->id = DRIVER_COMMAND_PLAYER_PANMODE;
959 command->player = GetBasicSoundPlayerHandle();
960 command->panMode = panMode;
961 cmdmgr.PushCommand(command);
962 }
963
964 /*---------------------------------------------------------------------------*
965 Name: SetPanCurve
966
967 Description: パンカーブを変更
968
969 Arguments: panCurve - パンカーブ
970
971 Returns: なし
972 *---------------------------------------------------------------------------*/
SetPanCurve(PanCurve panCurve)973 void BasicSound::SetPanCurve( PanCurve panCurve )
974 {
975 DriverCommandManager& cmdmgr = DriverCommandManager::GetInstance();
976
977 DriverCommandPlayerPanParam* command =
978 cmdmgr.AllocCommand<DriverCommandPlayerPanParam>();
979 command->id = DRIVER_COMMAND_PLAYER_PANCURVE;
980 command->player = GetBasicSoundPlayerHandle();
981 command->panCurve = panCurve;
982 cmdmgr.PushCommand(command);
983 }
984
SetFrontBypass(bool isFrontBypass)985 void BasicSound::SetFrontBypass( bool isFrontBypass )
986 {
987 DriverCommandManager& cmdmgr = DriverCommandManager::GetInstance();
988
989 DriverCommandPlayer* command =
990 cmdmgr.AllocCommand<DriverCommandPlayer>();
991 command->id = DRIVER_COMMAND_PLAYER_FRONTBYPASS;
992 command->player = GetBasicSoundPlayerHandle();
993 command->flag = isFrontBypass;
994 cmdmgr.PushCommand(command);
995 }
996
997 /*---------------------------------------------------------------------------*
998 Name: SetAmbientInfo
999
1000 Description: アンビエント情報を設定する
1001
1002 Arguments:
1003
1004 Returns: None.
1005 *---------------------------------------------------------------------------*/
SetAmbientInfo(const AmbientInfo & ambientArgInfo)1006 void BasicSound::SetAmbientInfo( const AmbientInfo& ambientArgInfo )
1007 {
1008 // AmbientArg の複製を作成
1009 NW_NULL_ASSERT( ambientArgInfo.argAllocatorCallback );
1010 void* ambientArg = ambientArgInfo.argAllocatorCallback->detail_AllocAmbientArg( ambientArgInfo.argSize );
1011 if ( ambientArg == NULL ) {
1012 NW_WARNING( ambientArg != NULL, "Failed to alloc AmbientArg." );
1013 return;
1014 }
1015 std::memcpy( ambientArg, ambientArgInfo.arg, ambientArgInfo.argSize );
1016
1017 // AmbientInfo の設定
1018 m_AmbientInfo = ambientArgInfo;
1019 m_AmbientInfo.arg = ambientArg;
1020 }
1021
1022 /*---------------------------------------------------------------------------*
1023 Name: GetAmbientPriority [static]
1024
1025 Description: アンビエントプライオリティの取得
1026
1027 Arguments: ambientInfo - アンビエント情報
1028 soundId - サウンドID
1029
1030 Returns: アンビエントプライオリティ値を返す
1031 *---------------------------------------------------------------------------*/
GetAmbientPriority(const AmbientInfo & ambientInfo,u32 soundId)1032 int BasicSound::GetAmbientPriority( const AmbientInfo& ambientInfo, u32 soundId )
1033 {
1034 if ( ambientInfo.paramUpdateCallback == NULL ) return 0;
1035
1036 int priority = ambientInfo.paramUpdateCallback->detail_GetAmbientPriority(
1037 ambientInfo.arg,
1038 soundId
1039 );
1040
1041 return priority;
1042 }
1043
1044 // ハンドル関数
IsAttachedGeneralHandle()1045 bool BasicSound::IsAttachedGeneralHandle()
1046 {
1047 return m_pGeneralHandle != NULL;
1048 }
1049
IsAttachedTempGeneralHandle()1050 bool BasicSound::IsAttachedTempGeneralHandle()
1051 {
1052 return m_pTempGeneralHandle != NULL;
1053 }
1054
DetachGeneralHandle()1055 void BasicSound::DetachGeneralHandle()
1056 {
1057 m_pGeneralHandle->DetachSound();
1058 }
1059
DetachTempGeneralHandle()1060 void BasicSound::DetachTempGeneralHandle()
1061 {
1062 m_pTempGeneralHandle->DetachSound();
1063 }
1064
SetId(u32 id)1065 void BasicSound::SetId( u32 id )
1066 {
1067 m_Id = id;
1068 }
1069
1070 } // namespace nw::snd::internal
1071 } // namespace nw::snd
1072 } // namespace nw
1073
1074