/*---------------------------------------------------------------------------* Project: Horizon File: snd_Bcwav.h Copyright (C)2009 Nintendo Co., Ltd. All rights reserved. These coded instructions, statements, and computer programs contain proprietary information of Nintendo of America Inc. and/or Nintendo Company Ltd., and are protected by Federal copyright law. They may not be disclosed to third parties or copied or duplicated in any form, in whole or in part, without the prior written consent of Nintendo. $Rev: 25790 $ *---------------------------------------------------------------------------*/ #ifndef NN_SND_BCWAV_H_ #define NN_SND_BCWAV_H_ #include /*! @file @brief Bcwav 構造体に関する定義 */ #ifdef __cplusplus namespace nn { namespace snd { namespace CTR { /*! @brief bcwav フォーマットのファイルを扱うクラスの定義です。 */ class Bcwav { private: Bcwav() {} ~Bcwav() {} public: // --- 基本型 --- struct Reference { u16 typeId; // ユーザーには非公開 u16 padding; u32 offset; }; struct ReferenceWithSize : public Reference { u32 size; }; template< typename ITEM_TYPE > struct Table { u32 count; ITEM_TYPE item[1]; }; // --- ファイルデータ構造 --- struct FileHeader { u32 signature; // 必ず 'CWAV' u16 byteOrderMark; u16 headerSize; u32 version; u32 fileSize; u16 dataBlocks; u16 reserved; }; struct BlockInfo { ReferenceWithSize infoBlockReference; ReferenceWithSize dataBlockReference; }; struct FileInfo { FileHeader header; BlockInfo blockInfo; }; // --- ブロックデータ構造 --- struct BlockHeader { u32 kind; // 'INFO' や 'DATA' u32 size; }; /*! @brief 波形に関する情報 */ struct WaveInfo { u8 encoding; //!< エンコードフォーマット (@ref nn::snd::Bcwav::Encoding) u8 isLoop; //!< ループの指定 (0: noloop, 1: loop) u16 padding; u32 sampleRate; //!< サンプルレート u32 loopStartFrame; //!< ループ開始位置 u32 loopEndFrame; //!< ループ終了位置 }; struct InfoBlockBody { WaveInfo waveInfo; u32 reserved; Table channelInfoReferenceTable; }; struct ChannelInfo { Reference toSamples; // 起点はデータブロックボディ (BlockHeader 以降) Reference toAdpcmInfo; u32 reserved; }; /*! @brief DspAdpcm 情報 */ struct DspAdpcmInfo { AdpcmParam param; //!< Adpcm パラメータ AdpcmContext context; //!< 初回再生時コンテキスト情報 AdpcmContext loopContext; //!< ループ再生時コンテキスト情報 }; /*! :private @brief ImaAdpcm コンテキスト */ struct ImaAdpcmContext { s16 data; u8 tableIndex; u8 padding; }; /*! :private @brief ImaAdpcm 情報 */ struct ImaAdpcmInfo { ImaAdpcmContext context; //!< 初回再生時コンテキスト情報 ImaAdpcmContext loopContext; //!< ループ再生時コンテキスト情報 }; struct InfoBlock { BlockHeader header; InfoBlockBody body; }; /*! @brief エンコードフォーマットを表す列挙型です。 */ typedef enum { ENCODING_PCM8 = 0, //!< 8 ビット PCM フォーマットを表します。 ENCODING_PCM16 = 1, //!< 16 ビット PCM フォーマットを表します。 ENCODING_DSP_ADPCM = 2, //!< DSP ADPCM フォーマットを表します。 ENCODING_IMA_ADPCM = 3, //!< IMA ADPCM フォーマットを表します。 ENCODING_NUM = 4 } Encoding; /*! @brief チャンネルを表す列挙型です。 */ typedef enum { CHANNEL_INDEX_L = 0, //!< 左チャンネルを表します。 CHANNEL_INDEX_R = 1 //!< 右チャンネルを表します。 } ChannelIndex; /*! @name bcwav ファイル操作 @{ */ /*! @brief 波形の基本情報を取得します。 @param[in] bcwav データバッファ @return 波形情報。 */ static const WaveInfo& GetWaveInfo(const void* bcwav); /*! @brief 波形のチャンネル数を取得します。 @param[in] bcwav データバッファ @return チャンネル数。 */ static int GetChannelCount(const void* bcwav); /*! @brief ヘッダを除いた波形データを取得します。 @param[in] bcwav データバッファ @param[in] channelNo チャンネル数 @return 波形データ。 */ static const void* GetWave(const void* bcwav, int channelNo); /*! @brief DSP ADPCM 情報を取得します。 @param[in] bcwav データバッファ @param[in] channelNo チャンネル数 @return DSP ADPCM 情報。 */ static const DspAdpcmInfo* GetDspAdpcmInfo(const void* bcwav, int channelNo); /*! :private @brief 再生開始時の IMA ADPCM コンテキストを取得します。 @param[in] bcwav データバッファ @param[in] channelNo チャンネル数 @return IMA ADPCM コンテキスト。 */ static const ImaAdpcmContext* GetImaAdpcmContext(const void* bcwav, int channelNo); /*! :private @brief 繰り返し時の IMA ADPCM コンテキストを取得します。bcwav ファイルバージョン 2.1.0.0 未満では NULL を返します。 @param[in] bcwav データバッファ @param[in] channelNo チャンネル数 @return IMA ADPCM コンテキスト。 */ static const ImaAdpcmContext* GetImaAdpcmLoopContext(const void* bcwav, int channelNo); /*! @brief 各フォーマットのサンプル数をバイト数に換算します。 @param[in] encoding bcwav 内圧縮方式 (WaveInfo::encoding) @param[in] frame サンプル数 @return バイト数。 */ static u32 FrameToByte(u8 encoding, u32 frame); /*! @brief ポインタにオフセットを加えた値を返します。 @param[in] ptr 基準ポインタ @param[in] offset オフセット @return オフセットを加えたポインタ。 */ static const void* AddOffsetToPtr(const void* ptr, int offset); /*! @brief bcwav ファイルかどうかを判別します。 @param[in] bcwav データバッファ @return bcwav ファイルであれば true を、そうでなければ false を返します。 */ static bool IsBcwav(const void* bcwav); /*! @} */ }; }}} // namespace nn::snd::CTR #endif // __cplusplus typedef enum { NN_SND_BCWAV_ENCODING_PCM8 = 0, //!< 8 ビット PCM フォーマットを表します。 NN_SND_BCWAV_ENCODING_PCM16 = 1, //!< 16 ビット PCM フォーマットを表します。 NN_SND_BCWAV_ENCODING_DSP_ADPCM = 2, //!< DSP ADPCM フォーマットを表します。 NN_SND_BCWAV_ENCODING_IMA_ADPCM = 3, //!< IMA ADPCM フォーマットを表します。 NN_SND_BCWAV_ENCODING_NUM = 4 } nnsndBcwavEncoding; typedef enum { NN_SND_BCWAV_CHANNEL_INDEX_L = 0, //!< 左チャンネルを表します。 NN_SND_BCWAV_CHANNEL_INDEX_R = 1 //!< 右チャンネルを表します。 } nnsndBcwavChannelIndex; #endif /* NN_SND_BCWAV_H_ */