バージョン
menu_open
Wwise SDK 2023.1.3
サウンドエンジンモジュールの初期化

Wwiseサウンドエンジン統合の最初のステップは、ゲーム起動時にサウンドエンジンを構成する各種モジュールを適切に初期化することです。

このサンプルプロジェクトでは、サウンドエンジンの初期化に関する全ての操作を実行するために次の関数が定義されています:

bool InitSoundEngine()
{
... Initialization will be done here ...
return true;
}

これは、メイン関数の開始時に呼び出されます。初期化の必要な各種モジュールを見てみましょう:

メモリマネージャの初期化

まず始めに初期化しなければならないのは、Memory Manager(メモリマネージャ)です。次のコードにより、デフォルトのMemory Managerが作成されます:

#include <AK/SoundEngine/Common/AkMemoryMgr.h> // Memory Manager interface
#include <AK/SoundEngine/Common/AkModule.h> // Default memory manager
(...)
bool InitSoundEngine()
{
AkMemSettings memSettings;
if ( AK::MemoryMgr::Init( &memSettings ) != AK_Success )
{
assert( !"Could not create the memory manager." );
return false;
}
(...)
}
注釈: メモリマネージャはオーバーライドすることができますが、その場合は、上記のコードを必要に応じて適合させる必要があります。詳細は、メモリマネージャのオーバーライド を参照してください。

メモリマネージャに関する詳細は、メモリマネージャ を参照してください。

ストリーミングマネージャの初期化

メモリマネージャの初期化が完了したら、今度は Streaming Manager(ストリーミングマネージャ)を初期化します。

次のコードにより、デフォルトのストリーミングマネージャが初期化されます。これには AK::StreamMgr::IAkFileLocationResolver のインスタンスが必要で、これによりストリーミングデバイスが作成されます。This requires an instance of AK::StreamMgr::IAkLowLevelIOHook. This interface is defined in AkStreamMgrModule.h, which contains all definitions that are specific to the default Stream Manager implementation provided with the SDK.

ディスクI/Oに関しては、デフォルトのストリームマネージャ実装を使用し、AkStreamMgrModule.h で定義されているインターフェースを実装するサウンドエンジン統合方法をお勧めします。これらのインターフェースは、低レベルI/Oサブモジュールを構成しています。詳細は、ストリーミング/ストリームマネージャ を参照してください。

This example uses the sample CAkFilePackageLowLevelIODeferred as is. This class implements both AK::StreamMgr::IAkFileLocationResolver and AK::StreamMgr::IAkLowLevelIOHook interfaces, and is able to load file packages generated with the File Packager utility (refer to ファイルパッケージ低レベルI/Oの実装 and File Packager ユーティリティ for more information about the File Packager and how it works in the Low-Level I/O).

低レベルI/Oに関する詳細は、低レベル I/O を参照してください。

#include <AK/SoundEngine/Common/IAkStreamMgr.h> // Streaming Manager
#include <AK/Tools/Common/AkPlatformFuncs.h> // Thread defines
#include <AkFilePackageLowLevelIODeferred.h> // Sample low-level I/O implementation
(...)
// We're using the default Low-Level I/O implementation that's part
// of the SDK's sample code, with the file package extension
CAkFilePackageLowLevelIODeferred g_lowLevelIO;
(...)
bool InitSoundEngine()
{
(...)
//
// Create and initialize an instance of the default streaming manager. Note
// that you can override the default streaming manager with your own.
//
AkStreamMgrSettings stmSettings;
// Customize the Stream Manager settings here.
if ( !AK::StreamMgr::Create( stmSettings ) )
{
assert( !"Could not create the Streaming Manager" );
return false;
}
//
// Create a streaming device.
// Note that you can override the default low-level I/O module with your own.
//
AkDeviceSettings deviceSettings;
// Customize the streaming device settings here.
// CAkFilePackageLowLevelIODeferred::Init() creates a streaming device
// in the Stream Manager, and registers itself as the File Location Resolver.
if ( g_lowLevelIO.Init( deviceSettings ) != AK_Success )
{
assert( !"Could not create the streaming device and Low-Level I/O system" );
return false;
}
(...)
}

デフォルトストリームマネージャとストリーミングデバイスの初期設定に関する詳細は、Audiokinetic ストリームマネージャ初期化設定 を参照してください。

注意: 初期設定の一部は、 AkThreadProperties のようにプラットフォーム固有のメンバ構造体を使用します。

デフォルトの低レベルI/Oの実装、または、完全なストリーミングマネージャをオーバーライドする場合、必要に応じてこのコードを適合させる必要があります。詳細は、ストリーミング/ストリームマネージャ を参照してください。

サウンドエンジンの初期化

基本的なモジュールの初期化が終わったので、サウンドエンジンそのものを初期化する準備ができました:

#include <AK/SoundEngine/Common/AkSoundEngine.h> // Sound engine
(...)
bool InitSoundEngine()
{
(...)
//
// Create the Sound Engine
// Using default initialization parameters
//
AkInitSettings initSettings;
AkPlatformInitSettings platformInitSettings;
if ( AK::SoundEngine::Init( &initSettings, &platformInitSettings ) != AK_Success )
{
assert( !"Could not initialize the Sound Engine." );
return false;
}
(...)
}

サウンドエンジン初期化に関する詳細は、サウンドエンジン統合の詳細 を参照してください。

ミュージックエンジンの初期化

プロジェクトがインタラクティブミュージック(Interactive Music)機能を使用する場合、サウンドエンジンに続いてミュージックエンジンも初期化する必要があります。

#include <AK/MusicEngine/Common/AkMusicEngine.h> // Music Engine
(...)
bool InitSoundEngine()
{
(...)
//
// Initialize the music engine
// Using default initialization parameters
//
AkMusicSettings musicInit;
if ( AK::MusicEngine::Init( &musicInit ) != AK_Success )
{
assert( !"Could not initialize the Music Engine." );
return false;
}
(...)
}

Spatial Audioの初期化

あなたのプロジェクトにWwise Spatial Audioが使われる場合、サウンドエンジンに続いてSpatial Audioライブラリも初期化する必要があります。Spatial Audioの一般的な使い方については、 APIのセットアップ を参照してください。Spatial Audioで設定できる様々なパラメータを確認するには、 AkSpatialAudioInitSettings を参照してください。

注釈: Spatial Audioを使うには、Spatial Audioモジュールとリンクする必要があります。
#include <AK/SpatialAudio/Common/AkSpatialAudio.h> // Spatial Audio
(...)
bool InitSoundEngine()
{
(...)
//
// Initialize Spatial Audio
// Using default initialization parameters
//
AkSpatialAudioInitSettings settings; // The constructor fills AkSpatialAudioInitSettings with the recommended default settings.
if ( AK::SpatialAudio::Init( &settings ) != AK_Success )
{
assert( !"Could not initialize the Spatial Audio." );
return false;
}
(...)
}

通信の初期化

Wwiseオーサリングアプリケーションを、ゲームに接続してゲーム内でミキシング、プロファイリングやトラブルシューティングを実行したい場合、次のステップは通信の初期化です。ゲーム内ミキシング、プロファイリングとトラブルシューティングは、サウンドエンジニアにとって、より効率的にゲームオーディオに取り組むための極めて強力な方法なので、通信の初期化を強くお勧めします。

注釈: 通信を使用するには、CommunicationCentral モジュールとリンクする必要があります。
注釈: 通信は、サウンドエンジンの Debug および Profile コンフィギュレーションでのみご利用可能で、ゲームのリーテルバージョンでは必要とされません。従って、これはサウンドエンジンの Release ビルドには含まれていません。以下のコードは、Release ビルドから通信に固有のコードを除外するために AK_OPTIMIZED シンボルを使用しています。
// Include for communication between Wwise and the game -- Not needed in the release version
#ifndef AK_OPTIMIZED
#endif // AK_OPTIMIZED
(...)
bool InitSoundEngine()
{
(...)
#ifndef AK_OPTIMIZED
//
// Initialize communications (not in release build!)
//
AkCommSettings commSettings;
if ( AK::Comm::Init( commSettings ) != AK_Success )
{
assert( !"Could not initialize communication." );
return false;
}
#endif // AK_OPTIMIZED
(...)
}

これで、サウンドエンジンの全モジュール初期化が完了しました。次に、プラグイン(プラグイン統合例 を参照)を登録する必要があります。オーディオを処理するために、ゲームループ内に作成する必要のある呼び出しの詳細については、オーディオ処理実行の反復呼び出し作成 を参照してください。

コンソール固有の通信ライブラリ

一部のコンソールの通信ライブラリは、初期化/終了 呼び出しのバランスを適切に保たないため、 AK::Comm::Term の呼び出しにより、コンソール用の基本的な低レベル通信ライブラリを終了させます。これは、ゲームに対するの全てのTCP/IP通信を効果的に閉じます。終了後もゲーム側が通信ライブラリを有効に保つ必要がある場合は、( Ak::Comm:Init と一緒に使用される)AkCommSettingsに、システムライブラリを初期化するかどうかを決めるパラメータがあります。通信ライブラリ自体を初期化する場合、Wwiseサウンドエンジンに使用される以下のコードを確認してください。ゲームは、同様の動作をするはずです。

Windows ソケットの初期化:

WSAData wsaData = { 0 };
::WSAStartup( MAKEWORD( 2, 2 ), &wsaData )

終了:

::WSACleanup();

通信ポート

AkCommSettings 構造体の AkCommSettings::ports メンバは、Wwiseオーサリングアプリケーションとサウンドエンジン間の通信に使用されるネットワークポートを表します。Wwise 通信が有効にされると、これらの全てのポートがゲーム側で開かれます。

固定ポート:ディスカバリブロードキャスト

ポート AkCommSettings::Ports::uDiscoveryBroadcast は、動的にすることができません(0に設定することができません)。オーサリングアプリケーションがこのポートを認識し、ネットワーク上でゲームを検出する必要があるからです。更に、ここで指定する値は、オーサリングアプリケーション内 Project Settings(プロジェクト設定)の Network タブで指定した値と同じでなければなりません。

Tip: チームがWwiseを使用して複数のゲームに取り組んでいる場合、ゲームごとに異なるディスカバリブロードキャストポートを使用することができます。Wwiseオーサリングアプリケーションの Remote Connections(リモート接続)ウインドウを開いた時に、現在開いている Wwise プロジェクトに対応するゲームのみが表示されます。このポートを変更する場合は、必ずオーサリングアプリケーションの Project Settings およびゲーム内で AK::Comm::Init() に渡す AkCommSettings 構造体の両方において変更を行うようにしてください。

One Dynamic Port

The other port in the structure can be dynamic (or "ephemeral"). すなわち、固定ポートを使用する代わりに、オペレーティングシステムによって自動的にいずれかのポートが選択されるようにできます。

This ports is dynamic by default. It is recommended to keep it dynamic in order to minimize chances of conflicts with other applications.

If it conflicts with ports used by other components of your game, change it in the AkCommSettings structure before calling AK::Comm::Init().

注釈: In a multi-platform game, it is valid to use different ports on different platforms for AkCommSettings::Ports::uCommand.

Tip: 動的/エフェメラルポートの詳細については、以下の記事を参照してください。

もう1つのポート(オーサリングアプリケーションのみ)

Wwise通信に関与するポートがもう1つありますが、このポートはオーサリングアプリケーションのみで開かれるので、AkCommSettings::Ports 構造体の一部ではありません。

このポートは、ネットワーク上で実行されているゲームを検出するために送信される Discovery Broadcast メッセージへの応答を受信するために、オーサリングアプリケーションによって使用されます。このポートは、デフォルトでは動的(0に設定)ですが、オーサリングアプリケーション内のProject Settingsから変更可能です。

AKSOUNDENGINE_API AKRESULT Init(AkInitSettings *in_pSettings, AkPlatformInitSettings *in_pPlatformSettings)
AKSOUNDENGINE_API AKRESULT Init(const AkSpatialAudioInitSettings &in_initSettings)
Initialize the SpatialAudio API.
AKSOUNDENGINE_API AKRESULT Init(AkMemSettings *in_pSettings)
AKSOUNDENGINE_API void GetDefaultSettings(AkStreamMgrSettings &out_settings)
AKSOUNDENGINE_API AKRESULT Init(const AkCommSettings &in_settings)
AKSOUNDENGINE_API void GetDefaultInitSettings(AkMusicSettings &out_settings)
@ AK_Success
The operation was successful.
Definition: AkTypes.h:215
AKSOUNDENGINE_API void GetDefaultInitSettings(AkInitSettings &out_settings)
AKSOUNDENGINE_API void GetDefaultSettings(AkMemSettings &out_pMemSettings)
Obtain the default initialization settings for the default implementation of the Memory Manager.
AKSOUNDENGINE_API void GetDefaultInitSettings(AkCommSettings &out_settings)
Initialization settings of the spatial audio module.
AKSOUNDENGINE_API void GetDefaultPlatformInitSettings(AkPlatformInitSettings &out_platformSettings)
AKSOUNDENGINE_API IAkStreamMgr * Create(const AkStreamMgrSettings &in_settings)
AKSOUNDENGINE_API void GetDefaultDeviceSettings(AkDeviceSettings &out_settings)
AKSOUNDENGINE_API AKRESULT Init(AkMusicSettings *in_pSettings)

このページはお役に立ちましたか?

サポートは必要ですか?

ご質問や問題、ご不明点はございますか?お気軽にお問い合わせください。

サポートページをご確認ください

あなたのプロジェクトについて教えてください。ご不明な点はありませんか。

プロジェクトを登録していただくことで、ご利用開始のサポートをいたします。

Wwiseからはじめよう