diff --git a/CHANGELOG.md b/CHANGELOG.md index 17b059f..fafb5d8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,35 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). +## [5-r.1] - 2024-05-30 + +### Added + +* Add right orientation to the fixed orientations in the iOS and Android app. + +### Changed + +* Disabled `stat` due to effect of Apple Privacy Manifests. +* Cleaned up the include directives. +* Change functions used to ensure line breaks are done correctly. +* Change the usage part of function `fmod()` to function `CubismMath.ModF()`. +* Change the Japanese sound file to one with a sampling frequency of 48 kHz. +* Change so that the sound file does not automatically play when loading the model. +* `MotionSyncAnalysisConfig_CRI::AudioLevelEffectRatio` has been marked as `Unused`. + +### Fixed + +* Fix `EXC_BAD_ACCESS` when running on iOS. + * The reason is that recording and playback are separate threads and access the buffer at the same time. + * Therefore, mutexes were used to prevent simultaneous access. +* Fix an issue that sample audio output is only for speakers on iOS. +* Fix the method of locking the app to prevent the model from being cut off on the iPad. + +### Removed + +* Remove `CubismMotionSync::SetAudioLevelEffectRatio` function. + + ## [5-r.1-beta.2] - 2024-01-25 ### Added @@ -34,4 +63,5 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). * New released! +[5-r.1]: https://github.com/Live2D/CubismNativeMotionSyncComponentsDev/compare/5-r.1-beta.2...5-r.1 [5-r.1-beta.2]: https://github.com/Live2D/CubismNativeMotionSyncComponentsDev/compare/5-r.1-beta.1...5-r.1-beta.2 diff --git a/Core/README.ja.md b/Core/README.ja.md new file mode 100644 index 0000000..090e4b5 --- /dev/null +++ b/Core/README.ja.md @@ -0,0 +1,34 @@ +[English](README.md) / [日本語](README.ja.md) + +--- + +# Live2D Cubism MotionSync Core + +このフォルダーには、モーションシンクを利用したネイティブアプリケーションを開発するためのヘッダーおよびプラットフォーム固有のライブラリファイルが含まれています。 + + +## Library List + +| プラットフォーム | アーキテクチャ | dll | lib | パス | 注記 | +| --- | --- | --- | --- | --- | --- | +| Android | ARM64 | ✓ | | Android/arm64-v8a | | +| Android | ARMv7 | ✓ | | Android/armeabi-v7a | このライブラリは現在非推奨で、近日中に削除される予定です。 | +| Android | x86 | ✓ | | Android/x86 | | +| Android | x86_64 | ✓ | | Android/x86_64 | | +| iOS | ARM64 | | ✓ | iOS/xxx-iphoneos | iOS Devices | +| iOS | x86_64 | | ✓ | iOS/xxx-iphonesimulator | iOS Simulator | +| macOS | ARM64 | ✓ | | macOS | | +| macOS | x86_64 | ✓ | | macOS | | +| Windows | x86 | ✓ | | Windows/x86 | | +| Windows | x86_64 | ✓ | | Windows/x86_64 | | + + +### 呼び出し規約 + +*Windows/x86*のダイナミックリンクライブラリを使用する場合は、呼び出し規約として明示的に`__stdcall`を使用してください。 + +--- + +[![CRIWARE for Games](CRIWARELOGO_1.png)](https://game.criware.jp/) + +このソフトウェアには、(株)CRI・ミドルウェアの「CRIWARE (R)」が使用されています。 diff --git a/Core/README.md b/Core/README.md index 4d233e7..0c85c54 100644 --- a/Core/README.md +++ b/Core/README.md @@ -1,6 +1,8 @@ -# Live2D Cubism MotionSync Engine +[English](README.md) / [日本語](README.ja.md) -This folder contains header files and platform-specific library files for using the motion sync plug-in. +# Live2D Cubism MotionSync Core + +This folder contains header files and platform-specific library files for developing native applications with using the motion sync. ## Library List diff --git a/Framework/src/CubismMotionSync.cpp b/Framework/src/CubismMotionSync.cpp index 00d75e6..f459070 100644 --- a/Framework/src/CubismMotionSync.cpp +++ b/Framework/src/CubismMotionSync.cpp @@ -120,7 +120,7 @@ void CubismMotionSync::UpdateParameters(CubismModel *model, csmFloat32 deltaTime Analyze(model, processIndex); // Reset counter. - _processorInfoList[processIndex]._currentRemainTime = fmod(_processorInfoList[processIndex]._currentRemainTime, processorDeltaTime); + _processorInfoList[processIndex]._currentRemainTime = CubismMath::ModF(_processorInfoList[processIndex]._currentRemainTime, processorDeltaTime); for (csmUint32 targetIndex = 0; targetIndex < _data->GetSetting(processIndex).cubismParameterList.GetSize(); targetIndex++) { @@ -159,14 +159,6 @@ void CubismMotionSync::SetSampleRate(csmUint32 processIndex, csmFloat32 sampleRa } } -void CubismMotionSync::SetAudioLevelEffectRatio(csmUint32 processIndex, csmFloat32 audioLevelEffectRatio) -{ - if (processIndex < _processorInfoList.GetSize()) - { - _processorInfoList[processIndex]._audioLevelEffectRatio = audioLevelEffectRatio; - } -} - EngineType CubismMotionSync::ToEngineType(csmString engineName) { EngineType engineType = EngineType_Unknown; diff --git a/Framework/src/CubismMotionSync.hpp b/Framework/src/CubismMotionSync.hpp index 1b39a70..f01a830 100644 --- a/Framework/src/CubismMotionSync.hpp +++ b/Framework/src/CubismMotionSync.hpp @@ -90,14 +90,6 @@ class CubismMotionSync */ void SetSampleRate(csmUint32 processIndex, csmFloat32 sampleRate); - /** - * @brief プロセッサのaudioLevelEffectRatioを設定 - * - * @param[in] processIndex インデックス - * @param[in] audioLevelEffectRatio 設定する値 - */ - void SetAudioLevelEffectRatio(csmUint32 processIndex, csmFloat32 audioLevelEffectRatio); - private: struct CubismProcessorInfo { diff --git a/Framework/src/CubismMotionSyncAudioBuffer.hpp b/Framework/src/CubismMotionSyncAudioBuffer.hpp index 40fa4db..bab7bae 100644 --- a/Framework/src/CubismMotionSyncAudioBuffer.hpp +++ b/Framework/src/CubismMotionSyncAudioBuffer.hpp @@ -145,33 +145,33 @@ void CubismMotionSyncAudioBuffer::Resize(csmUint32 bufferSize, csmBool useOut // 満タン状態かどうか判断するためにbuffer + 1の大きさで確保する _ringBuffer = static_cast(CSM_MALLOC(sizeof(T) * (_ringBufferSize))); - for (csmUint32 i = 0; i < _ringBufferSize; i++) - { - CSM_PLACEMENT_NEW(&_ringBuffer[i]) T(); - } - + // メモリ確保確認 if (!_ringBuffer) { _ringBufferSize = 0; return; } + + for (csmUint32 i = 0; i < _ringBufferSize; i++) + { + CSM_PLACEMENT_NEW(&_ringBuffer[i]) T(); + } if (useOutputBuffer) { // リングバッファで使用するバッファは必ず一つ空ける必要がある _outputBuffer = static_cast(CSM_MALLOC(sizeof(T) * _ringBufferSize - 1)); - for (csmUint32 i = 0; i < _ringBufferSize - 1; i++) - { - CSM_PLACEMENT_NEW(&_outputBuffer[i]) T(); - } - + // メモリ確保確認 if (!_outputBuffer) { - _ringBufferSize = 0; Release(); - _ringBuffer = NULL; + } + + for (csmUint32 i = 0; i < _ringBufferSize - 1; i++) + { + CSM_PLACEMENT_NEW(&_outputBuffer[i]) T(); } } } @@ -261,6 +261,7 @@ void CubismMotionSyncAudioBuffer::Release() _outputBuffer[i].~T(); } CSM_FREE(_outputBuffer); + _outputBuffer = NULL; _outputBufferSize = 0; } if (_ringBuffer) @@ -270,7 +271,8 @@ void CubismMotionSyncAudioBuffer::Release() _ringBuffer[i].~T(); } CSM_FREE(_ringBuffer); - _ringBufferSize = 1; + _ringBuffer = NULL; + _ringBufferSize = 0; _begin = 0; _end = 0; _usingBufferSize = 0; diff --git a/Framework/src/CubismMotionSyncData.cpp b/Framework/src/CubismMotionSyncData.cpp index ecda194..bc9b008 100644 --- a/Framework/src/CubismMotionSyncData.cpp +++ b/Framework/src/CubismMotionSyncData.cpp @@ -6,7 +6,7 @@ */ #include "CubismMotionSyncData.hpp" -#include +#include "CubismMotionSyncDataJson.hpp" //--------- LIVE2D NAMESPACE ------------ namespace Live2D { namespace Cubism { namespace Framework { namespace MotionSync { diff --git a/Framework/src/CubismMotionSyncEngineController.cpp b/Framework/src/CubismMotionSyncEngineController.cpp index 5a9ff31..062208a 100644 --- a/Framework/src/CubismMotionSyncEngineController.cpp +++ b/Framework/src/CubismMotionSyncEngineController.cpp @@ -5,12 +5,18 @@ * that can be found at https://www.live2d.com/eula/live2d-open-software-license-agreement_en.html. */ + // Apple Privacy Manifestsの影響のため無効化 +#define USE_STAT_LIB 0 + #include "CubismMotionSyncEngineController.hpp" +#if USE_STAT_LIB #include +#endif #include "CubismMotionSyncEngineVersion.hpp" #include "CubismMotionSyncEngineCri.hpp" +#ifndef CSM_MOTIONSYNC_USE_STATIC_LIB #include "Lib/CubismMotionSyncEngineLib.hpp" -#ifdef CSM_MOTIONSYNC_USE_STATIC_LIB +#else #include "Lib/CubismMotionSyncEngineStaticLib.hpp" #endif @@ -20,16 +26,18 @@ csmMap CubismMotionSyncEngineController::_ ICubismMotionSyncEngine* CubismMotionSyncEngineController::InstallEngine(csmString dllFilePath) { - struct stat statBuf; - #ifndef CSM_MOTIONSYNC_USE_STATIC_LIB // 動的ライブラリの使用 +#if USE_STAT_LIB + struct stat statBuf; + // 渡されたパスにファイルが存在するかチェック if (stat(dllFilePath.GetRawString(), &statBuf) != 0) { return NULL; } +#endif ICubismMotionSyncEngineLib* engineHandle = CSM_NEW CubismMotionSyncEngineLib(); if (!engineHandle->LoadLibrary(dllFilePath.GetRawString())) diff --git a/Framework/src/CubismMotionSyncProcessorCRI.hpp b/Framework/src/CubismMotionSyncProcessorCRI.hpp index a4ff3e6..9c7cfc1 100644 --- a/Framework/src/CubismMotionSyncProcessorCRI.hpp +++ b/Framework/src/CubismMotionSyncProcessorCRI.hpp @@ -53,7 +53,7 @@ class CubismMotionSyncProcessorCri : public ICubismMotionSyncProcessor * @param samples 解析したい音声データ * @param blendRatio ブレンド率(0.0f~1.0f) * @param smoothing スムージングの値(1~100) - * @param audioLevelEffectRatio 音量の大きさが口の開閉に与える影響度(0.0~1.0) + * @param audioLevelEffectRatio 音量の大きさが口の開閉に与える影響度(0.0~1.0) ※現在未使用。互換性のため残される * * @return 解析結果のインスタンス */ diff --git a/Framework/src/CubismMotionSyncProcessorCri.hpp b/Framework/src/CubismMotionSyncProcessorCri.hpp index a4ff3e6..9c7cfc1 100644 --- a/Framework/src/CubismMotionSyncProcessorCri.hpp +++ b/Framework/src/CubismMotionSyncProcessorCri.hpp @@ -53,7 +53,7 @@ class CubismMotionSyncProcessorCri : public ICubismMotionSyncProcessor * @param samples 解析したい音声データ * @param blendRatio ブレンド率(0.0f~1.0f) * @param smoothing スムージングの値(1~100) - * @param audioLevelEffectRatio 音量の大きさが口の開閉に与える影響度(0.0~1.0) + * @param audioLevelEffectRatio 音量の大きさが口の開閉に与える影響度(0.0~1.0) ※現在未使用。互換性のため残される * * @return 解析結果のインスタンス */ diff --git a/Framework/src/ICubismMotionSyncEngine.hpp b/Framework/src/ICubismMotionSyncEngine.hpp index a597848..dfceb78 100644 --- a/Framework/src/ICubismMotionSyncEngine.hpp +++ b/Framework/src/ICubismMotionSyncEngine.hpp @@ -8,7 +8,7 @@ #pragma once #include "CubismMotionSyncEngineVersion.hpp" -#include "Lib/CubismMotionSyncEngineLib.hpp" +#include "Lib/ICubismMotionSyncEngineLib.hpp" #include "Lib/CubismMotionSyncUtil.hpp" #include "Type/csmVector.hpp" diff --git a/Framework/src/Lib/CubismMotionSyncConfig.hpp b/Framework/src/Lib/CubismMotionSyncConfig.hpp index 06f03fc..8f53812 100644 --- a/Framework/src/Lib/CubismMotionSyncConfig.hpp +++ b/Framework/src/Lib/CubismMotionSyncConfig.hpp @@ -75,6 +75,7 @@ struct MotionSyncAnalysisConfig_CRI Csm::csmInt32 Smoothing; /** Audio level effect ratio. */ + /** Unused */ Csm::csmFloat32 AudioLevelEffectRatio; }; diff --git a/Framework/src/Lib/CubismMotionSyncUtil.hpp b/Framework/src/Lib/CubismMotionSyncUtil.hpp index 25649bf..7f21b11 100644 --- a/Framework/src/Lib/CubismMotionSyncUtil.hpp +++ b/Framework/src/Lib/CubismMotionSyncUtil.hpp @@ -9,7 +9,7 @@ #define _CRT_SECURE_NO_WARNINGS -#include "CubismMotionSyncEngineLib.hpp" +#include "ICubismMotionSyncEngineLib.hpp" #include "CubismMotionSyncEngineMappingInfo.hpp" //--------- LIVE2D NAMESPACE ------------ diff --git a/NOTICE.ja.md b/NOTICE.ja.md index 105b0ec..b547243 100644 --- a/NOTICE.ja.md +++ b/NOTICE.ja.md @@ -6,9 +6,16 @@ ## [制限事項] Cubism SDK MotionSync Plugin for Native の対応環境について (2023-12-21) - iPhoneSimulator環境でマイク入力を動作させる場合は、事前に入力デバイスの接続をしてください。 + +## [制限事項] Visual Studio 2022 17.10以降での動作について (2024-05-30) + +Visual C++ コンパイラのバージョンの変更により、Visual Studio 2022 17.10を利用したWindowsビルドが一部エラーとなる問題を確認しております。 + +この問題は次回リリースバージョンで修正される予定です。 +ご利用の際は修正をお待ちいただくか、Visual Studio 2022 17.9 以前のバージョンをご利用ください。 + --- ©Live2D diff --git a/NOTICE.md b/NOTICE.md index 9a537ec..74651ed 100644 --- a/NOTICE.md +++ b/NOTICE.md @@ -8,6 +8,14 @@ When executing microphone input in iPhoneSimulator, please connect the input device in advance. + +## [Limitations] Regarding operation with Visual Studio 2022 17.10 and later (2024-05-30) + +We have confirmed an issue where the Windows build using Visual Studio 2022 17.10 results in errors due to a change in the Visual C++ compiler version. + +This issue is planned to be fixed in the next release version. When using this, please wait for the fix or use a version of Visual Studio 2022 prior to 17.9. + + --- ©Live2D diff --git a/README.ja.md b/README.ja.md index 1dc0d39..dd0a984 100644 --- a/README.ja.md +++ b/README.ja.md @@ -92,20 +92,20 @@ Demo | 開発ツール | バージョン | | --- | --- | -| Android Studio | Hedgehog 2023.1.1 | -| CMake | 3.28.1 | +| Android Studio | Jellyfish 2023.3.1 | +| CMake | 3.29.3 | | Visual Studio 2013 | Update 5 | | Visual Studio 2015 | Update 3 | -| Visual Studio 2017 | 15.9.59 | -| Visual Studio 2019 | 16.11.33 | -| Visual Studio 2022 | 17.8.4 | -| Xcode | 15.1 | +| Visual Studio 2017 | 15.9.62 | +| Visual Studio 2019 | 16.11.34 | +| Visual Studio 2022 | 17.9.7 | +| Xcode | 15.4 | ### Android | Android SDK tools | バージョン | | --- | --- | -| Android NDK | 25.2.9519653 | +| Android NDK | 26.2.11394342 | | Android SDK | 34.0.0 | | CMake | 3.22.1 | @@ -114,18 +114,22 @@ Demo | プラットフォーム | バージョン | | --- | --- | -| iOS / iPadOS | 16.6.1 | -| macOS | 14.1.1 | +| iOS / iPadOS | 17.5.1 | +| macOS | 14.5 | | Windows 10 | 22H2 | -| Windows 11 | 22H2 | +| Windows 11 | 23H2 | ### Android | バージョン | デバイス | Tegra | | --- | --- | --- | -| 13 | Pixel 7a | | +| 14 | Pixel 7a | | | 7.1.1 | Nexus 9 | ✔︎ | +### Cubism SDK for Native + +[Cubism 5 SDK for Native R1](https://github.com/Live2D/CubismNativeSamples/releases/tag/5-r.1) + ## サウンドデバイス @@ -142,22 +146,22 @@ Demo ### フォークとプルリクエスト -修正、改善、さらには新機能をもたらすかどうかにかかわらず、プルリクエストに感謝します。ただし、ラッパーは可能な限り軽量で浅くなるように設計されているため、バグ修正とメモリ/パフォーマンスの改善のみを行う必要があることに注意してください。メインリポジトリを可能な限りクリーンに保つために、必要に応じて個人用フォークと機能ブランチを作成してください。 +修正、改善、さらには新機能をもたらすかどうかにかかわらず、プルリクエストに感謝します。メインリポジトリを可能な限りクリーンに保つために、必要に応じて個人用フォークと機能ブランチを作成してください。 ### バグ -Live2Dコミュニティでは、問題のレポートと機能リクエストを定期的にチェックしています。バグレポートを提出する前に、Live2Dコミュニティで検索して、問題のレポートまたは機能リクエストがすでに投稿されているかどうかを確認してください。問題がすでに存在する場合は、関連するコメントを追記してください。 +Live2Dフォーラムでは、問題のレポートと機能リクエストを定期的にチェックしています。バグレポートを提出する前に、Live2Dコミュニティで検索して、問題のレポートまたは機能リクエストがすでに投稿されているかどうかを確認してください。問題がすでに存在する場合は、関連するコメントを追記してください。 ### 提案 -SDKの将来についてのフィードバックにも関心があります。Live2Dコミュニティで提案や機能のリクエストを送信できます。このプロセスをより効果的にするために、それらをより明確に定義するのに役立つより多くの情報を含めるようお願いしています。 +SDKの将来についてのフィードバックにも関心があります。Live2Dフォーラムで提案や機能のリクエストを送信できます。このプロセスをより効果的にするために、それらをより明確に定義するのに役立つより多くの情報を含めるようお願いしています。 -## コミュニティ +## フォーラム -ユーザー同士でCubism SDKの活用方法の提案や質問をしたい場合は、是非コミュニティをご活用ください。 +ユーザー同士でCubism SDKの活用方法の提案や質問をしたい場合は、是非公式クリエイターズフォーラムをご活用ください。 -- [Live2D 公式コミュニティ](https://creatorsforum.live2d.com/) -- [Live2D community(English)](https://community.live2d.com/) +- [Live2D 公式クリエイターズフォーラム](https://creatorsforum.live2d.com/) +- [Live2D Creators Forum(English)](https://community.live2d.com/) diff --git a/README.md b/README.md index 35efb09..c16746e 100644 --- a/README.md +++ b/README.md @@ -84,14 +84,14 @@ Please refer to [CHANGELOG.md](CHANGELOG.md) for the changelog of this repositor | Development Tool | Version | | --- | --- | -| Android Studio | Hedgehog 2023.1.1 | -| CMake | 3.28.1 | +| Android Studio | Jellyfish 2023.3.1 | +| CMake | 3.29.3 | | Visual Studio 2013 | Update 5 | | Visual Studio 2015 | Update 3 | -| Visual Studio 2017 | 15.9.59 | -| Visual Studio 2019 | 16.11.33 | -| Visual Studio 2022 | 17.8.4 | -| Xcode | 15.1 | +| Visual Studio 2017 | 15.9.62 | +| Visual Studio 2019 | 16.11.34 | +| Visual Studio 2022 | 17.9.7 | +| Xcode | 15.4 | ### Android @@ -106,18 +106,22 @@ Please refer to [CHANGELOG.md](CHANGELOG.md) for the changelog of this repositor | Platform | Version | | --- | --- | -| iOS / iPadOS | 16.6.1 | -| macOS | 14.1.1 | +| iOS / iPadOS | 17.5.1 | +| macOS | 14.5 | | Windows 10 | 22H2 | -| Windows 11 | 22H2 | +| Windows 11 | 23H2 | ### Android | Version | Device | Tegra | | --- | --- | --- | -| 13 | Pixel 7a | | +| 14 | Pixel 7a | | | 7.1.1 | Nexus 9 | ✔︎ | +### Cubism SDK for Native + +[Cubism 5 SDK for Native R1](https://github.com/Live2D/CubismNativeSamples/releases/tag/5-r.1) + ## Sound device @@ -129,19 +133,19 @@ In this sample, the input sound is played directly through the device's sound pl ## Contribution to the project -There are many ways to contribute to the project: logging bugs, submitting pull requests on this GitHub, and reporting issues and making suggestions in Live2D Community. +There are many ways to contribute to the project: logging bugs, submitting pull requests on this GitHub, and reporting issues and making suggestions in Live2D Forum. ### Forking and Pull Requests -We very much appreciate your pull requests, whether they bring fixes, improvements, or even new features. Note, however, that the wrapper is designed to be as lightweight and shallow as possible and should therefore only be subject to bug fixes and memory/performance improvements. To keep the main repository as clean as possible, please create a personal fork and feature branch as needed. +We very much appreciate your pull requests, whether they bring fixes, improvements, or even new features. To keep the main repository as clean as possible, create a personal fork and feature branches there as needed. ### Bugs -We are regularly checking bug reports and feature requests at Live2D Community. Before submitting a bug report, please search the Live2D Community to see if the bug report or feature request has already been submitted. Add your comment to the relevant issue if it already exists. +We are regularly checking bug reports and feature requests at Live2D Forum. Before submitting a bug report, please search the Live2D Forum to see if the bug report or feature request has already been submitted. Add your comment to the relevant issue if it already exists. ### Suggestions -We're also interested in your feedback for the future of the SDK. You can submit a suggestion or feature request at Live2D Community. To make this process more effective, we're asking that you include more information to help define them more clearly. +We're also interested in your feedback for the future of the SDK. You can submit a suggestion or feature request at Live2D Forum. To make this process more effective, we're asking that you include more information to help define them more clearly. ## Coding Guidelines @@ -159,5 +163,5 @@ Try to stick to the [Microsoft guidelines](https://msdn.microsoft.com/en-us/libr If you have any questions, please join the official Live2D forum and discuss with other users. -- [Live2D Creator's Forum](https://community.live2d.com/) +- [Live2D Creators Forum](https://community.live2d.com/) - [Live2D 公式クリエイターズフォーラム (Japanese)](https://creatorsforum.live2d.com/) diff --git a/Samples/OpenGL/Demo/proj.android.cmake/MotionSync/app/src/Microphone/AndroidManifest.xml b/Samples/OpenGL/Demo/proj.android.cmake/MotionSync/app/src/Microphone/AndroidManifest.xml index 956980e..305aaa0 100644 --- a/Samples/OpenGL/Demo/proj.android.cmake/MotionSync/app/src/Microphone/AndroidManifest.xml +++ b/Samples/OpenGL/Demo/proj.android.cmake/MotionSync/app/src/Microphone/AndroidManifest.xml @@ -15,7 +15,7 @@ diff --git a/Samples/OpenGL/Demo/proj.android.cmake/MotionSync/app/src/Microphone/cpp/LAppMotionSyncModel.cpp b/Samples/OpenGL/Demo/proj.android.cmake/MotionSync/app/src/Microphone/cpp/LAppMotionSyncModel.cpp index e524185..b69f7c3 100644 --- a/Samples/OpenGL/Demo/proj.android.cmake/MotionSync/app/src/Microphone/cpp/LAppMotionSyncModel.cpp +++ b/Samples/OpenGL/Demo/proj.android.cmake/MotionSync/app/src/Microphone/cpp/LAppMotionSyncModel.cpp @@ -25,7 +25,7 @@ namespace { { if (LAppDefine::DebugLogEnable) { - LAppPal::PrintLog("[APP]create buffer: %s ", path); + LAppPal::PrintLogLn("[APP]create buffer: %s ", path); } return LAppPal::LoadFileAsBytes(path, size); } @@ -34,7 +34,7 @@ namespace { { if (DebugLogEnable) { - LAppPal::PrintLog("[APP]delete buffer: %s", path); + LAppPal::PrintLogLn("[APP]delete buffer: %s", path); } LAppPal::ReleaseBytes(buffer); } @@ -68,7 +68,7 @@ void LAppMotionSyncModel::LoadAssets(const csmString fileName) if (_debugMode) { - LAppPal::PrintLog("[APP]load model setting: %s", fileName.GetRawString()); + LAppPal::PrintLogLn("[APP]load model setting: %s", fileName.GetRawString()); } csmSizeInt size; @@ -82,7 +82,7 @@ void LAppMotionSyncModel::LoadAssets(const csmString fileName) if (_model == NULL) { - LAppPal::PrintLog("Failed to LoadAssets()."); + LAppPal::PrintLogLn("Failed to LoadAssets()."); return; } @@ -142,7 +142,7 @@ void LAppMotionSyncModel::SetupModel() if (_debugMode) { - LAppPal::PrintLog("[APP]create model: %s", _modelSetting->GetModelFileName()); + LAppPal::PrintLogLn("[APP]create model: %s", _modelSetting->GetModelFileName()); } buffer = CreateBuffer(path.GetRawString(), &size); @@ -152,7 +152,7 @@ void LAppMotionSyncModel::SetupModel() if (_modelSetting == NULL || _modelMatrix == NULL) { - LAppPal::PrintLog("Failed to SetupModel()."); + LAppPal::PrintLogLn("Failed to SetupModel()."); return; } @@ -174,7 +174,7 @@ void LAppMotionSyncModel::SetupModel() { if (_debugMode) { - LAppPal::PrintLog("[APP]load motionSync setting: %s", fileName); + LAppPal::PrintLogLn("[APP]load motionSync setting: %s", fileName); } const csmString path = csmString(_modelHomeDir) + fileName; @@ -184,7 +184,7 @@ void LAppMotionSyncModel::SetupModel() if (!_motionSync) { - LAppPal::PrintLog("Failed to SetupModel()."); + LAppPal::PrintLogLn("Failed to SetupModel()."); return; } diff --git a/Samples/OpenGL/Demo/proj.android.cmake/MotionSync/app/src/SoundFile/AndroidManifest.xml b/Samples/OpenGL/Demo/proj.android.cmake/MotionSync/app/src/SoundFile/AndroidManifest.xml index 13e5431..b419876 100644 --- a/Samples/OpenGL/Demo/proj.android.cmake/MotionSync/app/src/SoundFile/AndroidManifest.xml +++ b/Samples/OpenGL/Demo/proj.android.cmake/MotionSync/app/src/SoundFile/AndroidManifest.xml @@ -13,7 +13,7 @@ diff --git a/Samples/OpenGL/Demo/proj.android.cmake/MotionSync/app/src/SoundFile/cpp/LAppAudioManager.cpp b/Samples/OpenGL/Demo/proj.android.cmake/MotionSync/app/src/SoundFile/cpp/LAppAudioManager.cpp index 2aeecde..0596d80 100644 --- a/Samples/OpenGL/Demo/proj.android.cmake/MotionSync/app/src/SoundFile/cpp/LAppAudioManager.cpp +++ b/Samples/OpenGL/Demo/proj.android.cmake/MotionSync/app/src/SoundFile/cpp/LAppAudioManager.cpp @@ -8,6 +8,7 @@ #include "LAppAudioManager.hpp" #include "LAppWavFileHandler.hpp" #include "../../main/cpp/JniBridgeC.hpp" +#include "LAppPal.hpp" using namespace Csm; @@ -15,6 +16,7 @@ csmBool LAppAudioManager::LoadFile(csmString path, csmUint32 useChannel) { // 初期化 Release(); + _isLoadFile = true; // WAVファイルをロード LAppWavFileHandler wavHandler; @@ -30,7 +32,7 @@ csmBool LAppAudioManager::LoadFile(csmString path, csmUint32 useChannel) _data = reinterpret_cast(CSM_MALLOC(sizeof(csmByte) * _dataSize)); if (!_data) { - CubismLogError("[APP]Failed malloc to '_data' in LAppAudioManager::LoadFile()"); + LAppPal::PrintLogLn("[APP]Failed malloc to '_data' in LAppAudioManager::LoadFile()"); return false; } for (csmUint32 i = 0; i < _dataSize; i++) @@ -50,7 +52,7 @@ csmBool LAppAudioManager::LoadFile(csmString path, csmUint32 useChannel) _samples = reinterpret_cast(CSM_MALLOC(sizeof(csmFloat32) * _samplesSize)); if (!_samples) { - CubismLogError("[APP]Failed malloc to '_samples' in LAppAudioManager::LoadFile()"); + LAppPal::PrintLogLn("[APP]Failed malloc to '_samples' in LAppAudioManager::LoadFile()"); return false; } wavHandler.GetPcmDataChannel(_samples, useChannel); @@ -66,10 +68,16 @@ csmBool LAppAudioManager::LoadFile(csmString path, csmUint32 useChannel) csmBool LAppAudioManager::Update() { + if (!_isLoadFile) + { + // 早送りボタンが押されていないため音声の再生がない + return true; + } + csmInt32 playPosition = JniBridgeC::GetAudioOutputBufferPosition(_audioId); if (playPosition < 0) { - CubismLogError("[APP]Failed to GetAudioOutputBufferPosition() in LAppAudioManager::Update()"); + LAppPal::PrintLogLn("[APP]Failed to GetAudioOutputBufferPosition() in LAppAudioManager::Update()"); return false; } @@ -120,7 +128,8 @@ LAppAudioManager::LAppAudioManager() : _samples(NULL), _samplesSize(0), _samplesPos(0), - _buffer() + _buffer(), + _isLoadFile(false) { } diff --git a/Samples/OpenGL/Demo/proj.android.cmake/MotionSync/app/src/SoundFile/cpp/LAppAudioManager.hpp b/Samples/OpenGL/Demo/proj.android.cmake/MotionSync/app/src/SoundFile/cpp/LAppAudioManager.hpp index c3ed5e7..6378063 100644 --- a/Samples/OpenGL/Demo/proj.android.cmake/MotionSync/app/src/SoundFile/cpp/LAppAudioManager.hpp +++ b/Samples/OpenGL/Demo/proj.android.cmake/MotionSync/app/src/SoundFile/cpp/LAppAudioManager.hpp @@ -74,4 +74,6 @@ class LAppAudioManager Csm::csmUint32 _samplesPos; // MotionSyncで使用するバッファ Csm::MotionSync::CubismMotionSyncAudioBuffer _buffer; + // 音声ファイル読み込み済か + Csm::csmBool _isLoadFile; }; diff --git a/Samples/OpenGL/Demo/proj.android.cmake/MotionSync/app/src/SoundFile/cpp/LAppMotionSyncModel.cpp b/Samples/OpenGL/Demo/proj.android.cmake/MotionSync/app/src/SoundFile/cpp/LAppMotionSyncModel.cpp index eb07b0f..58edd87 100644 --- a/Samples/OpenGL/Demo/proj.android.cmake/MotionSync/app/src/SoundFile/cpp/LAppMotionSyncModel.cpp +++ b/Samples/OpenGL/Demo/proj.android.cmake/MotionSync/app/src/SoundFile/cpp/LAppMotionSyncModel.cpp @@ -25,7 +25,7 @@ namespace { { if (LAppDefine::DebugLogEnable) { - LAppPal::PrintLog("[APP]create buffer: %s ", path); + LAppPal::PrintLogLn("[APP]create buffer: %s ", path); } return LAppPal::LoadFileAsBytes(path, size); } @@ -34,7 +34,7 @@ namespace { { if (DebugLogEnable) { - LAppPal::PrintLog("[APP]delete buffer: %s", path); + LAppPal::PrintLogLn("[APP]delete buffer: %s", path); } LAppPal::ReleaseBytes(buffer); } @@ -69,7 +69,7 @@ void LAppMotionSyncModel::LoadAssets(const csmString fileName) if (_debugMode) { - LAppPal::PrintLog("[APP]load model setting: %s", fileName.GetRawString()); + LAppPal::PrintLogLn("[APP]load model setting: %s", fileName.GetRawString()); } csmSizeInt size; @@ -83,7 +83,7 @@ void LAppMotionSyncModel::LoadAssets(const csmString fileName) if (_model == NULL) { - LAppPal::PrintLog("Failed to LoadAssets()."); + LAppPal::PrintLogLn("Failed to LoadAssets()."); return; } @@ -152,7 +152,7 @@ void LAppMotionSyncModel::SetupModel() if (_debugMode) { - LAppPal::PrintLog("[APP]create model: %s", _modelSetting->GetModelFileName()); + LAppPal::PrintLogLn("[APP]create model: %s", _modelSetting->GetModelFileName()); } buffer = CreateBuffer(path.GetRawString(), &size); @@ -162,7 +162,7 @@ void LAppMotionSyncModel::SetupModel() if (_modelSetting == NULL || _modelMatrix == NULL) { - LAppPal::PrintLog("Failed to SetupModel()."); + LAppPal::PrintLogLn("Failed to SetupModel()."); return; } @@ -184,7 +184,7 @@ void LAppMotionSyncModel::SetupModel() { if (_debugMode) { - LAppPal::PrintLog("[APP]load motionSync setting: %s", fileName); + LAppPal::PrintLogLn("[APP]load motionSync setting: %s", fileName); } const csmString path = csmString(_modelHomeDir) + fileName; @@ -194,7 +194,7 @@ void LAppMotionSyncModel::SetupModel() if (!_motionSync) { - LAppPal::PrintLog("Failed to SetupModel()."); + LAppPal::PrintLogLn("Failed to SetupModel()."); return; } @@ -202,8 +202,7 @@ void LAppMotionSyncModel::SetupModel() // 音声データ _soundFileList = _modelSetting->GetMotionSyncSoundFileList(); - _soundIndex = 0; - PlayIndexSound(); + _soundIndex = _soundFileList.GetSize() - 1; _isMotionSync = true; } } diff --git a/Samples/OpenGL/Demo/proj.android.cmake/MotionSync/app/src/main/cpp/LAppDelegate.cpp b/Samples/OpenGL/Demo/proj.android.cmake/MotionSync/app/src/main/cpp/LAppDelegate.cpp index 589d99a..0c1cf11 100644 --- a/Samples/OpenGL/Demo/proj.android.cmake/MotionSync/app/src/main/cpp/LAppDelegate.cpp +++ b/Samples/OpenGL/Demo/proj.android.cmake/MotionSync/app/src/main/cpp/LAppDelegate.cpp @@ -142,7 +142,7 @@ LAppDelegate::LAppDelegate(): _height = height; // Setup Cubism - _cubismOption.LogFunction = LAppPal::PrintMessage; + _cubismOption.LogFunction = LAppPal::PrintMessageLn; _cubismOption.LoggingLevel = LAppDefine::CubismLoggingLevel; CubismFramework::CleanUp(); CubismFramework::StartUp(&_cubismAllocator, &_cubismOption); diff --git a/Samples/OpenGL/Demo/proj.ios.cmake/CMakeLists.txt b/Samples/OpenGL/Demo/proj.ios.cmake/CMakeLists.txt index fc5d549..e882271 100644 --- a/Samples/OpenGL/Demo/proj.ios.cmake/CMakeLists.txt +++ b/Samples/OpenGL/Demo/proj.ios.cmake/CMakeLists.txt @@ -90,6 +90,7 @@ find_library(GLKIT_LIBRARY GLKit) find_library(OPENGLES_LIBRARY OpenGLES) find_library(QUARTZCORE_LIBRARY QuartzCore) find_library(UIKIT_LIBRARY UIKit) +find_library(AVFOUNDATION_LIBRARY AVFoundation) find_library(AUDIOTOOLBOX_LIBRARY AudioToolBox) # Make executable app. @@ -106,6 +107,7 @@ target_link_libraries(${APP_NAME} ${OPENGLES_LIBRARY} ${QUARTZCORE_LIBRARY} ${UIKIT_LIBRARY} + ${AVFOUNDATION_LIBRARY} ${AUDIOTOOLBOX_LIBRARY} ) # Specify include directories. diff --git a/Samples/OpenGL/Demo/proj.ios.cmake/src/AppDelegate.mm b/Samples/OpenGL/Demo/proj.ios.cmake/src/AppDelegate.mm index 2f0f1eb..5e469aa 100644 --- a/Samples/OpenGL/Demo/proj.ios.cmake/src/AppDelegate.mm +++ b/Samples/OpenGL/Demo/proj.ios.cmake/src/AppDelegate.mm @@ -81,7 +81,7 @@ - (void)applicationWillTerminate:(UIApplication *)application { - (void)initializeCubism { - _cubismOption.LogFunction = LAppPal::PrintMessage; + _cubismOption.LogFunction = LAppPal::PrintMessageLn; _cubismOption.LoggingLevel = LAppDefine::CubismLoggingLevel; Csm::CubismFramework::StartUp(&_cubismAllocator,&_cubismOption); diff --git a/Samples/OpenGL/Demo/proj.ios.cmake/src/AppMicrophoneDelegate.mm b/Samples/OpenGL/Demo/proj.ios.cmake/src/AppMicrophoneDelegate.mm index 7df3e41..5b18f1d 100644 --- a/Samples/OpenGL/Demo/proj.ios.cmake/src/AppMicrophoneDelegate.mm +++ b/Samples/OpenGL/Demo/proj.ios.cmake/src/AppMicrophoneDelegate.mm @@ -81,7 +81,7 @@ - (void)applicationWillTerminate:(UIApplication *)application { - (void)initializeCubism { - _cubismOption.LogFunction = LAppPal::PrintMessage; + _cubismOption.LogFunction = LAppPal::PrintMessageLn; _cubismOption.LoggingLevel = LAppDefine::CubismLoggingLevel; Csm::CubismFramework::StartUp(&_cubismAllocator,&_cubismOption); diff --git a/Samples/OpenGL/Demo/proj.ios.cmake/src/CMakeLists.txt b/Samples/OpenGL/Demo/proj.ios.cmake/src/CMakeLists.txt index aa05cd8..5d0eb31 100644 --- a/Samples/OpenGL/Demo/proj.ios.cmake/src/CMakeLists.txt +++ b/Samples/OpenGL/Demo/proj.ios.cmake/src/CMakeLists.txt @@ -17,6 +17,8 @@ if (CSM_MOTIONSYNC_MICROPHONE_DEMO) ${CMAKE_CURRENT_SOURCE_DIR}/LAppMotionSyncMicrophoneModel.mm ${NATIVE_SRC_PATH}/LAppPal.h ${NATIVE_SRC_PATH}/LAppPal.mm + ${CMAKE_CURRENT_SOURCE_DIR}/LAppMutex.h + ${CMAKE_CURRENT_SOURCE_DIR}/LAppMutex.mm ${CMAKE_CURRENT_SOURCE_DIR}/LAppMicrophoneAudioManager.h ${CMAKE_CURRENT_SOURCE_DIR}/LAppMicrophoneAudioManager.mm ${NATIVE_SRC_PATH}/LAppSprite.h diff --git a/Samples/OpenGL/Demo/proj.ios.cmake/src/Info.plist b/Samples/OpenGL/Demo/proj.ios.cmake/src/Info.plist index 4229d08..77b31e3 100644 --- a/Samples/OpenGL/Demo/proj.ios.cmake/src/Info.plist +++ b/Samples/OpenGL/Demo/proj.ios.cmake/src/Info.plist @@ -31,11 +31,10 @@ UISupportedInterfaceOrientations UIInterfaceOrientationLandscapeLeft + UIInterfaceOrientationLandscapeRight UISupportedInterfaceOrientations~ipad - UIInterfaceOrientationPortrait - UIInterfaceOrientationPortraitUpsideDown UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight diff --git a/Samples/OpenGL/Demo/proj.ios.cmake/src/LAppAudioManager.mm b/Samples/OpenGL/Demo/proj.ios.cmake/src/LAppAudioManager.mm index 6066a9e..2218874 100644 --- a/Samples/OpenGL/Demo/proj.ios.cmake/src/LAppAudioManager.mm +++ b/Samples/OpenGL/Demo/proj.ios.cmake/src/LAppAudioManager.mm @@ -7,6 +7,7 @@ #import "LAppAudioManager.h" #import "LAppWavFileHandler.h" +#import "LAppPal.h" using namespace Csm; @@ -59,7 +60,7 @@ if (status != noErr) { - CubismLogError("[APP]Failed to AudioQueueNewOutput() in LAppAudioManager::LoadFile()"); + LAppPal::PrintLogLn("[APP]Failed to AudioQueueNewOutput() in LAppAudioManager::LoadFile()"); return false; } @@ -70,7 +71,7 @@ if (status != noErr) { - CubismLogError("[APP]Failed to AudioQueueAllocateBuffer() in LAppAudioManager::LoadFile()"); + LAppPal::PrintLogLn("[APP]Failed to AudioQueueAllocateBuffer() in LAppAudioManager::LoadFile()"); return false; } @@ -85,7 +86,7 @@ if (status != noErr) { - CubismLogError("[APP]Failed to AudioQueueStart() in LAppAudioManager::LoadFile()"); + LAppPal::PrintLogLn("[APP]Failed to AudioQueueStart() in LAppAudioManager::LoadFile()"); return false; } diff --git a/Samples/OpenGL/Demo/proj.ios.cmake/src/LAppMicrophoneAudioManager.h b/Samples/OpenGL/Demo/proj.ios.cmake/src/LAppMicrophoneAudioManager.h index 88c7f37..e0f3373 100644 --- a/Samples/OpenGL/Demo/proj.ios.cmake/src/LAppMicrophoneAudioManager.h +++ b/Samples/OpenGL/Demo/proj.ios.cmake/src/LAppMicrophoneAudioManager.h @@ -12,6 +12,7 @@ #import "CubismMotionSyncAudioBuffer.hpp" #import "Type/csmString.hpp" #import "Type/csmVector.hpp" +#import "LAppMutex.h" class LAppMicrophoneAudioManager { @@ -64,6 +65,22 @@ class LAppMicrophoneAudioManager Csm::csmInt32 _channels; // MotionSyncで使用するバッファ Csm::MotionSync::CubismMotionSyncAudioBuffer _buffer; + // mutex + LAppMutex _mutex; + + /** + * @brief 録音データをバッファに格納する + * + * @param[in] samples 録音データ + */ + void WriteInputBuffer(Csm::csmFloat32* samples); + + /** + * @brief 録音データをバッファから取り出す + * + * @param[in] samples 録音データの取り出し先 + */ + void ReadInputBuffer(Csm::csmFloat32* samples); /** * @brief 録音時のコールバック処理 diff --git a/Samples/OpenGL/Demo/proj.ios.cmake/src/LAppMicrophoneAudioManager.mm b/Samples/OpenGL/Demo/proj.ios.cmake/src/LAppMicrophoneAudioManager.mm index baf9f35..6f26c76 100644 --- a/Samples/OpenGL/Demo/proj.ios.cmake/src/LAppMicrophoneAudioManager.mm +++ b/Samples/OpenGL/Demo/proj.ios.cmake/src/LAppMicrophoneAudioManager.mm @@ -6,7 +6,9 @@ */ #import "LAppMicrophoneAudioManager.h" +#import #import "LAppWavFileHandler.h" +#import "LAppPal.h" using namespace Csm; @@ -19,7 +21,18 @@ AudioQueueBufferRef inputBuffers[LAppMotionSyncDefine::AudioQueueBufferCount]; AudioQueueBufferRef outputBuffers[LAppMotionSyncDefine::AudioQueueBufferCount]; OSStatus status; - + + AVAudioSession* audioSession = [AVAudioSession sharedInstance]; + BOOL success = [audioSession setCategory:AVAudioSessionCategoryPlayAndRecord + mode:AVAudioSessionModeDefault + options:AVAudioSessionCategoryOptionAllowBluetooth + error:nil]; + if (!success) + { + CubismLogError("[APP]Failed to AVAudioSession.setCategory() in LAppMicrophoneAudioManager::SetupMicrophone()"); + return false; + } + csmUint32 blockAlign = channels * (bitDepth / 8); // オーディオ設定 @@ -57,7 +70,7 @@ status = AudioQueueNewInput(&format, InputCallBack, this, NULL, NULL, 0, &_inputQueue); if (status != noErr) { - CubismLogError("[APP]Failed to AudioQueueNewInput() in LAppMicrophoneAudioManager::SetupMicrophone()"); + LAppPal::PrintLogLn("[APP]Failed to AudioQueueNewInput() in LAppMicrophoneAudioManager::SetupMicrophone()"); return false; } @@ -66,7 +79,7 @@ status = AudioQueueAllocateBuffer(_inputQueue, _queueBufferSize, &inputBuffers[i]); if (status != noErr) { - CubismLogError("[APP]Failed to AudioQueueAllocateBuffer() in LAppMicrophoneAudioManager::SetupMicrophone()"); + LAppPal::PrintLogLn("[APP]Failed to AudioQueueAllocateBuffer() in LAppMicrophoneAudioManager::SetupMicrophone()"); return false; } @@ -79,7 +92,7 @@ status = AudioQueueNewOutput(&format, OutputCallBack, this, CFRunLoopGetCurrent(), kCFRunLoopCommonModes, 0, &_outputQueue); if (status != noErr) { - CubismLogError("[APP]Failed to AudioQueueNewOutput() in LAppMicrophoneAudioManager::SetupMicrophone()"); + LAppPal::PrintLogLn("[APP]Failed to AudioQueueNewOutput() in LAppMicrophoneAudioManager::SetupMicrophone()"); return false; } @@ -88,7 +101,7 @@ status = AudioQueueAllocateBuffer(_outputQueue, _queueBufferSize, &outputBuffers[i]); if (status != noErr) { - CubismLogError("[APP]Failed to AudioQueueAllocateBuffer() in LAppMicrophoneAudioManager::SetupMicrophone()"); + LAppPal::PrintLogLn("[APP]Failed to AudioQueueAllocateBuffer() in LAppMicrophoneAudioManager::SetupMicrophone()"); return false; } @@ -101,7 +114,7 @@ status = AudioQueueStart(_inputQueue, NULL); if (status != noErr) { - CubismLogError("[APP]Failed to AudioQueueStart() in LAppMicrophoneAudioManager::SetupMicrophone()"); + LAppPal::PrintLogLn("[APP]Failed to AudioQueueStart() in LAppMicrophoneAudioManager::SetupMicrophone()"); return false; } @@ -109,7 +122,7 @@ status = AudioQueueStart(_outputQueue, NULL); if (status != noErr) { - CubismLogError("[APP]Failed to AudioQueueStart() in LAppMicrophoneAudioManager::SetupMicrophone()"); + LAppPal::PrintLogLn("[APP]Failed to AudioQueueStart() in LAppMicrophoneAudioManager::SetupMicrophone()"); return false; } @@ -143,48 +156,71 @@ Release(); } -void LAppMicrophoneAudioManager::InputCallBack(void* customData, AudioQueueRef queue, AudioQueueBufferRef buffer, const AudioTimeStamp *startTime, UInt32 packetNum, const AudioStreamPacketDescription *packetDesc) +void LAppMicrophoneAudioManager::WriteInputBuffer(csmFloat32* samples) { - LAppMicrophoneAudioManager* data = reinterpret_cast(customData); - csmFloat32 *samples = reinterpret_cast(buffer->mAudioData); - if (0 < packetNum && data->_inputQueue) + _mutex.Lock(); + + if (_inputQueue) { // マイク入力の内容を受け取る。 csmVector inputData; - for (csmUint32 i = 0; i < data->_queueBufferSampleCount * data->_channels; i ++) + for (csmUint32 i = 0; i < _queueBufferSampleCount * _channels; i++) { inputData.PushBack(samples[i]); } - data->_inputDataList.AddValue(inputData); + _inputDataList.AddValue(inputData); } - AudioQueueEnqueueBuffer(queue, buffer, 0, NULL); + + _mutex.Unlock(); } -void LAppMicrophoneAudioManager::OutputCallBack(void* customData, AudioQueueRef queue, AudioQueueBufferRef buffer) +void LAppMicrophoneAudioManager::ReadInputBuffer(csmFloat32* samples) { - LAppMicrophoneAudioManager* data = reinterpret_cast(customData); - csmFloat32 *samples = reinterpret_cast(buffer->mAudioData); - if (0 < data->_inputDataList.GetSize()) + _mutex.Lock(); + + if (0 < _inputDataList.GetSize()) { // 録音した音声を送る。 - for (csmUint32 i = 0; i < data->_queueBufferSampleCount * data->_channels && i < data->_inputDataList[0].GetSize(); i++) + for (csmUint32 i = 0; i < _queueBufferSampleCount * _channels && i < _inputDataList[0].GetSize(); i++) { - samples[i] = data->_inputDataList[0][i]; + samples[i] = _inputDataList[0][i]; // 解析に指定しているチャンネルのサンプルを送る。 - if ((i % 2) == data->_useChannel) + if ((i % 2) == _useChannel) { - data->_buffer.AddValue(samples[i]); + _buffer.AddValue(samples[i]); } } - data->_inputDataList.Remove(1); + _inputDataList.Remove(1); } else { - for (csmUint32 i = 0; i < data->_queueBufferSampleCount * data->_channels; i ++) + for (csmUint32 i = 0; i < _queueBufferSampleCount * _channels; i++) { samples[i] = 0.0f; } } + + _mutex.Unlock(); +} + +void LAppMicrophoneAudioManager::InputCallBack(void* customData, AudioQueueRef queue, AudioQueueBufferRef buffer, const AudioTimeStamp *startTime, UInt32 packetNum, const AudioStreamPacketDescription *packetDesc) +{ + LAppMicrophoneAudioManager* data = reinterpret_cast(customData); + csmFloat32 *samples = reinterpret_cast(buffer->mAudioData); + if (0 < packetNum) + { + data->WriteInputBuffer(samples); + } + AudioQueueEnqueueBuffer(queue, buffer, 0, NULL); +} + +void LAppMicrophoneAudioManager::OutputCallBack(void* customData, AudioQueueRef queue, AudioQueueBufferRef buffer) +{ + LAppMicrophoneAudioManager* data = reinterpret_cast(customData); + csmFloat32 *samples = reinterpret_cast(buffer->mAudioData); + + data->ReadInputBuffer(samples); + AudioQueueEnqueueBuffer(queue, buffer, 0, NULL); } diff --git a/Samples/OpenGL/Demo/proj.ios.cmake/src/LAppMotionSyncMicrophoneModel.mm b/Samples/OpenGL/Demo/proj.ios.cmake/src/LAppMotionSyncMicrophoneModel.mm index aa14497..e67c5e8 100644 --- a/Samples/OpenGL/Demo/proj.ios.cmake/src/LAppMotionSyncMicrophoneModel.mm +++ b/Samples/OpenGL/Demo/proj.ios.cmake/src/LAppMotionSyncMicrophoneModel.mm @@ -24,7 +24,7 @@ { if (LAppDefine::DebugLogEnable) { - LAppPal::PrintLog("[APP]create buffer: %s ", path); + LAppPal::PrintLogLn("[APP]create buffer: %s ", path); } return LAppPal::LoadFileAsBytes(path, size); } @@ -33,7 +33,7 @@ void DeleteBuffer(csmByte* buffer, const csmChar* path = "") { if (DebugLogEnable) { - LAppPal::PrintLog("[APP]delete buffer: %s", path); + LAppPal::PrintLogLn("[APP]delete buffer: %s", path); } LAppPal::ReleaseBytes(buffer); } @@ -66,7 +66,7 @@ void DeleteBuffer(csmByte* buffer, const csmChar* path = "") if (_debugMode) { - LAppPal::PrintLog("[APP]load model setting: %s", fileName.GetRawString()); + LAppPal::PrintLogLn("[APP]load model setting: %s", fileName.GetRawString()); } csmSizeInt size; @@ -80,7 +80,7 @@ void DeleteBuffer(csmByte* buffer, const csmChar* path = "") if (_model == NULL) { - LAppPal::PrintLog("Failed to LoadAssets()."); + LAppPal::PrintLogLn("Failed to LoadAssets()."); return; } @@ -135,7 +135,7 @@ void DeleteBuffer(csmByte* buffer, const csmChar* path = "") if (_debugMode) { - LAppPal::PrintLog("[APP]create model: %s", _modelSetting->GetModelFileName()); + LAppPal::PrintLogLn("[APP]create model: %s", _modelSetting->GetModelFileName()); } buffer = CreateBuffer(path.GetRawString(), &size); @@ -145,7 +145,7 @@ void DeleteBuffer(csmByte* buffer, const csmChar* path = "") if (_modelSetting == NULL || _modelMatrix == NULL) { - LAppPal::PrintLog("Failed to SetupModel()."); + LAppPal::PrintLogLn("Failed to SetupModel()."); return; } @@ -167,7 +167,7 @@ void DeleteBuffer(csmByte* buffer, const csmChar* path = "") { if (_debugMode) { - LAppPal::PrintLog("[APP]load motionSync setting: %s", fileName); + LAppPal::PrintLogLn("[APP]load motionSync setting: %s", fileName); } const csmString path = csmString(_modelHomeDir) + fileName; @@ -177,7 +177,7 @@ void DeleteBuffer(csmByte* buffer, const csmChar* path = "") if (!_motionSync) { - LAppPal::PrintLog("Failed to SetupModel()."); + LAppPal::PrintLogLn("Failed to SetupModel()."); return; } diff --git a/Samples/OpenGL/Demo/proj.ios.cmake/src/LAppMotionSyncModel.mm b/Samples/OpenGL/Demo/proj.ios.cmake/src/LAppMotionSyncModel.mm index faeac6d..d3a26a0 100644 --- a/Samples/OpenGL/Demo/proj.ios.cmake/src/LAppMotionSyncModel.mm +++ b/Samples/OpenGL/Demo/proj.ios.cmake/src/LAppMotionSyncModel.mm @@ -24,7 +24,7 @@ { if (LAppDefine::DebugLogEnable) { - LAppPal::PrintLog("[APP]create buffer: %s ", path); + LAppPal::PrintLogLn("[APP]create buffer: %s ", path); } return LAppPal::LoadFileAsBytes(path, size); } @@ -33,7 +33,7 @@ void DeleteBuffer(csmByte* buffer, const csmChar* path = "") { if (DebugLogEnable) { - LAppPal::PrintLog("[APP]delete buffer: %s", path); + LAppPal::PrintLogLn("[APP]delete buffer: %s", path); } LAppPal::ReleaseBytes(buffer); } @@ -67,7 +67,7 @@ void DeleteBuffer(csmByte* buffer, const csmChar* path = "") if (_debugMode) { - LAppPal::PrintLog("[APP]load model setting: %s", fileName.GetRawString()); + LAppPal::PrintLogLn("[APP]load model setting: %s", fileName.GetRawString()); } csmSizeInt size; @@ -81,7 +81,7 @@ void DeleteBuffer(csmByte* buffer, const csmChar* path = "") if (_model == NULL) { - LAppPal::PrintLog("Failed to LoadAssets()."); + LAppPal::PrintLogLn("Failed to LoadAssets()."); return; } @@ -145,7 +145,7 @@ void DeleteBuffer(csmByte* buffer, const csmChar* path = "") if (_debugMode) { - LAppPal::PrintLog("[APP]create model: %s", _modelSetting->GetModelFileName()); + LAppPal::PrintLogLn("[APP]create model: %s", _modelSetting->GetModelFileName()); } buffer = CreateBuffer(path.GetRawString(), &size); @@ -155,7 +155,7 @@ void DeleteBuffer(csmByte* buffer, const csmChar* path = "") if (_modelSetting == NULL || _modelMatrix == NULL) { - LAppPal::PrintLog("Failed to SetupModel()."); + LAppPal::PrintLogLn("Failed to SetupModel()."); return; } @@ -177,7 +177,7 @@ void DeleteBuffer(csmByte* buffer, const csmChar* path = "") { if (_debugMode) { - LAppPal::PrintLog("[APP]load motionSync setting: %s", fileName); + LAppPal::PrintLogLn("[APP]load motionSync setting: %s", fileName); } const csmString path = csmString(_modelHomeDir) + fileName; @@ -187,7 +187,7 @@ void DeleteBuffer(csmByte* buffer, const csmChar* path = "") if (!_motionSync) { - LAppPal::PrintLog("Failed to SetupModel()."); + LAppPal::PrintLogLn("Failed to SetupModel()."); return; } @@ -195,8 +195,7 @@ void DeleteBuffer(csmByte* buffer, const csmChar* path = "") // 音声データ _soundFileList = _modelSetting->GetMotionSyncSoundFileList(); - _soundIndex = 0; - PlayIndexSound(); + _soundIndex = _soundFileList.GetSize() - 1; } } diff --git a/Samples/OpenGL/Demo/proj.ios.cmake/src/LAppMutex.h b/Samples/OpenGL/Demo/proj.ios.cmake/src/LAppMutex.h new file mode 100644 index 0000000..341f160 --- /dev/null +++ b/Samples/OpenGL/Demo/proj.ios.cmake/src/LAppMutex.h @@ -0,0 +1,39 @@ +/** + * Copyright(c) Live2D Inc. All rights reserved. + * + * Use of this source code is governed by the Live2D Open Software license + * that can be found at https://www.live2d.com/eula/live2d-open-software-license-agreement_en.html. + */ +#pragma once + +#import + +class LAppMutex +{ +public: + /** + * @brief コンストラクタ + * + */ + LAppMutex(); + + /** + * @brief デストラクタ + */ + ~LAppMutex(); + + /** + * @brief ロック処理 + */ + void Lock(); + + /** + * @brief ロック解除 + */ + void Unlock(); + +private: + // mutex + pthread_mutex_t _mutex; + +}; diff --git a/Samples/OpenGL/Demo/proj.ios.cmake/src/LAppMutex.mm b/Samples/OpenGL/Demo/proj.ios.cmake/src/LAppMutex.mm new file mode 100644 index 0000000..25ce100 --- /dev/null +++ b/Samples/OpenGL/Demo/proj.ios.cmake/src/LAppMutex.mm @@ -0,0 +1,28 @@ +/** + * Copyright(c) Live2D Inc. All rights reserved. + * + * Use of this source code is governed by the Live2D Open Software license + * that can be found at https://www.live2d.com/eula/live2d-open-software-license-agreement_en.html. + */ + +#import "LAppMutex.h" + +LAppMutex::LAppMutex() +{ + pthread_mutex_init(&_mutex, NULL); +} + +LAppMutex::~LAppMutex() +{ + pthread_mutex_destroy(&_mutex); +} + +void LAppMutex::Lock() +{ + pthread_mutex_lock(&_mutex); +} + +void LAppMutex::Unlock() +{ + pthread_mutex_unlock(&_mutex); +} diff --git a/Samples/OpenGL/Demo/proj.mac.cmake/src/CMakeLists.txt b/Samples/OpenGL/Demo/proj.mac.cmake/src/CMakeLists.txt index e76be3d..c89d3c0 100644 --- a/Samples/OpenGL/Demo/proj.mac.cmake/src/CMakeLists.txt +++ b/Samples/OpenGL/Demo/proj.mac.cmake/src/CMakeLists.txt @@ -17,6 +17,8 @@ if (CSM_MOTIONSYNC_MICROPHONE_DEMO) ${CMAKE_CURRENT_SOURCE_DIR}/LAppMotionSyncMicrophoneModel.hpp ${NATIVE_SRC_PATH}/LAppPal.cpp ${NATIVE_SRC_PATH}/LAppPal.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/LAppMutex.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/LAppMutex.hpp ${CMAKE_CURRENT_SOURCE_DIR}/LAppMicrophoneAudioManager.cpp ${CMAKE_CURRENT_SOURCE_DIR}/LAppMicrophoneAudioManager.hpp ${NATIVE_SRC_PATH}/LAppSprite.cpp diff --git a/Samples/OpenGL/Demo/proj.mac.cmake/src/LAppAudioManager.cpp b/Samples/OpenGL/Demo/proj.mac.cmake/src/LAppAudioManager.cpp index a236dc2..eb5fc58 100644 --- a/Samples/OpenGL/Demo/proj.mac.cmake/src/LAppAudioManager.cpp +++ b/Samples/OpenGL/Demo/proj.mac.cmake/src/LAppAudioManager.cpp @@ -7,6 +7,7 @@ #include "LAppAudioManager.hpp" #include "LAppWavFileHandler.hpp" +#include "LAppPal.hpp" using namespace Csm; @@ -59,7 +60,7 @@ csmBool LAppAudioManager::LoadFile(csmString path, csmUint32 useChannel) if (status != noErr) { - CubismLogError("[APP]Failed to AudioQueueNewOutput() in LAppAudioManager::LoadFile()"); + LAppPal::PrintLogLn("[APP]Failed to AudioQueueNewOutput() in LAppAudioManager::LoadFile()"); return false; } @@ -70,7 +71,7 @@ csmBool LAppAudioManager::LoadFile(csmString path, csmUint32 useChannel) if (status != noErr) { - CubismLogError("[APP]Failed to AudioQueueAllocateBuffer() in LAppAudioManager::LoadFile()"); + LAppPal::PrintLogLn("[APP]Failed to AudioQueueAllocateBuffer() in LAppAudioManager::LoadFile()"); return false; } @@ -85,7 +86,7 @@ csmBool LAppAudioManager::LoadFile(csmString path, csmUint32 useChannel) if (status != noErr) { - CubismLogError("[APP]Failed to AudioQueueStart() in LAppAudioManager::LoadFile()"); + LAppPal::PrintLogLn("[APP]Failed to AudioQueueStart() in LAppAudioManager::LoadFile()"); return false; } diff --git a/Samples/OpenGL/Demo/proj.mac.cmake/src/LAppDelegate.cpp b/Samples/OpenGL/Demo/proj.mac.cmake/src/LAppDelegate.cpp index 0aa7f7c..5c7c8c6 100644 --- a/Samples/OpenGL/Demo/proj.mac.cmake/src/LAppDelegate.cpp +++ b/Samples/OpenGL/Demo/proj.mac.cmake/src/LAppDelegate.cpp @@ -1,4 +1,4 @@ -/** +/** * Copyright(c) Live2D Inc. All rights reserved. * * Use of this source code is governed by the Live2D Open Software license @@ -56,12 +56,12 @@ void LAppDelegate::ReleaseInstance() bool LAppDelegate::Initialize() { - LAppPal::PrintLog("START"); + LAppPal::PrintLogLn("START"); // GLFWの初期化 if (glfwInit() == GL_FALSE) { - LAppPal::PrintLog("Can't initilize GLFW"); + LAppPal::PrintLogLn("Can't initilize GLFW"); return GL_FALSE; } @@ -70,7 +70,7 @@ bool LAppDelegate::Initialize() _window = glfwCreateWindow(LAppDefine::RenderTargetWidth, LAppDefine::RenderTargetHeight, "SIMPLE_SAMPLE", NULL, NULL); if (_window == NULL) { - LAppPal::PrintLog("Can't create GLFW window."); + LAppPal::PrintLogLn("Can't create GLFW window."); glfwTerminate(); return GL_FALSE; @@ -81,7 +81,7 @@ bool LAppDelegate::Initialize() glfwSwapInterval(1); if (glewInit() != GLEW_OK) { - LAppPal::PrintLog("Can't initilize glew."); + LAppPal::PrintLogLn("Can't initilize glew."); glfwTerminate(); return GL_FALSE; @@ -233,7 +233,7 @@ LAppDelegate::~LAppDelegate() void LAppDelegate::InitializeCubism() { //setup cubism - _cubismOption.LogFunction = LAppPal::PrintMessage; + _cubismOption.LogFunction = LAppPal::PrintMessageLn; _cubismOption.LoggingLevel = Csm::CubismFramework::Option::LogLevel_Verbose; Csm::CubismFramework::StartUp(&_cubismAllocator, &_cubismOption); diff --git a/Samples/OpenGL/Demo/proj.mac.cmake/src/LAppMicrophoneAudioManager.cpp b/Samples/OpenGL/Demo/proj.mac.cmake/src/LAppMicrophoneAudioManager.cpp index f722239..34f4c0b 100644 --- a/Samples/OpenGL/Demo/proj.mac.cmake/src/LAppMicrophoneAudioManager.cpp +++ b/Samples/OpenGL/Demo/proj.mac.cmake/src/LAppMicrophoneAudioManager.cpp @@ -7,6 +7,7 @@ #include "LAppMicrophoneAudioManager.hpp" #include "LAppWavFileHandler.hpp" +#include "LAppPal.hpp" using namespace Csm; @@ -57,7 +58,7 @@ csmBool LAppMicrophoneAudioManager::SetupMicrophone(Csm::csmUint32 channels, Csm status = AudioQueueNewInput(&format, InputCallBack, this, NULL, NULL, 0, &_inputQueue); if (status != noErr) { - CubismLogError("[APP]Failed to AudioQueueNewInput() in LAppMicrophoneAudioManager::SetupMicrophone()"); + LAppPal::PrintLogLn("[APP]Failed to AudioQueueNewInput() in LAppMicrophoneAudioManager::SetupMicrophone()"); return false; } @@ -66,7 +67,7 @@ csmBool LAppMicrophoneAudioManager::SetupMicrophone(Csm::csmUint32 channels, Csm status = AudioQueueAllocateBuffer(_inputQueue, _queueBufferSize, &inputBuffers[i]); if (status != noErr) { - CubismLogError("[APP]Failed to AudioQueueAllocateBuffer() in LAppMicrophoneAudioManager::SetupMicrophone()"); + LAppPal::PrintLogLn("[APP]Failed to AudioQueueAllocateBuffer() in LAppMicrophoneAudioManager::SetupMicrophone()"); return false; } @@ -79,7 +80,7 @@ csmBool LAppMicrophoneAudioManager::SetupMicrophone(Csm::csmUint32 channels, Csm status = AudioQueueNewOutput(&format, OutputCallBack, this, CFRunLoopGetCurrent(), kCFRunLoopCommonModes, 0, &_outputQueue); if (status != noErr) { - CubismLogError("[APP]Failed to AudioQueueNewOutput() in LAppMicrophoneAudioManager::SetupMicrophone()"); + LAppPal::PrintLogLn("[APP]Failed to AudioQueueNewOutput() in LAppMicrophoneAudioManager::SetupMicrophone()"); return false; } @@ -88,7 +89,7 @@ csmBool LAppMicrophoneAudioManager::SetupMicrophone(Csm::csmUint32 channels, Csm status = AudioQueueAllocateBuffer(_outputQueue, _queueBufferSize, &outputBuffers[i]); if (status != noErr) { - CubismLogError("[APP]Failed to AudioQueueAllocateBuffer() in LAppMicrophoneAudioManager::SetupMicrophone()"); + LAppPal::PrintLogLn("[APP]Failed to AudioQueueAllocateBuffer() in LAppMicrophoneAudioManager::SetupMicrophone()"); return false; } @@ -101,7 +102,7 @@ csmBool LAppMicrophoneAudioManager::SetupMicrophone(Csm::csmUint32 channels, Csm status = AudioQueueStart(_inputQueue, NULL); if (status != noErr) { - CubismLogError("[APP]Failed to AudioQueueStart() in LAppMicrophoneAudioManager::SetupMicrophone()"); + LAppPal::PrintLogLn("[APP]Failed to AudioQueueStart() in LAppMicrophoneAudioManager::SetupMicrophone()"); return false; } @@ -109,7 +110,7 @@ csmBool LAppMicrophoneAudioManager::SetupMicrophone(Csm::csmUint32 channels, Csm status = AudioQueueStart(_outputQueue, NULL); if (status != noErr) { - CubismLogError("[APP]Failed to AudioQueueStart() in LAppMicrophoneAudioManager::SetupMicrophone()"); + LAppPal::PrintLogLn("[APP]Failed to AudioQueueStart() in LAppMicrophoneAudioManager::SetupMicrophone()"); return false; } @@ -143,49 +144,72 @@ LAppMicrophoneAudioManager::~LAppMicrophoneAudioManager() Release(); } -void LAppMicrophoneAudioManager::InputCallBack(void* customData, AudioQueueRef queue, AudioQueueBufferRef buffer, const AudioTimeStamp *startTime, UInt32 packetNum, const AudioStreamPacketDescription *packetDesc) +void LAppMicrophoneAudioManager::WriteInputBuffer(Csm::csmFloat32* samples) { - LAppMicrophoneAudioManager* data = reinterpret_cast(customData); - csmFloat32 *samples = reinterpret_cast(buffer->mAudioData); - if (0 < packetNum && data->_inputQueue) + _mutex.Lock(); + + if (_inputQueue) { // マイク入力の内容を受け取る。 csmVector inputData; - for (csmUint32 i = 0; i < data->_queueBufferSampleCount * data->_channels; i ++) + for (csmUint32 i = 0; i < _queueBufferSampleCount * _channels; i ++) { inputData.PushBack(samples[i]); } - data->_inputDataList.AddValue(inputData); + _inputDataList.AddValue(inputData); } - AudioQueueEnqueueBuffer(queue, buffer, 0, NULL); + + _mutex.Unlock(); } -void LAppMicrophoneAudioManager::OutputCallBack(void* customData, AudioQueueRef queue, AudioQueueBufferRef buffer) +void LAppMicrophoneAudioManager::ReadInputBuffer(Csm::csmFloat32* samples) { - LAppMicrophoneAudioManager* data = reinterpret_cast(customData); - csmFloat32 *samples = reinterpret_cast(buffer->mAudioData); - if (0 < data->_inputDataList.GetSize()) + _mutex.Lock(); + + if (0 < _inputDataList.GetSize()) { // 録音した音声を送る。 - for (csmUint32 i = 0; i < data->_queueBufferSampleCount * data->_channels && i < data->_inputDataList[0].GetSize(); i++) + for (csmUint32 i = 0; i < _queueBufferSampleCount * _channels && i < _inputDataList[0].GetSize(); i++) { - samples[i] = data->_inputDataList[0][i]; + samples[i] = _inputDataList[0][i]; // 解析に指定しているチャンネルのサンプルを送る。 - if ((i % 2) == data->_useChannel) + if ((i % 2) == _useChannel) { - data->_buffer.AddValue(samples[i]); + _buffer.AddValue(samples[i]); } } - data->_inputDataList.Remove(1); + _inputDataList.Remove(1); } else { - for (csmUint32 i = 0; i < data->_queueBufferSampleCount * data->_channels; i ++) + for (csmUint32 i = 0; i < _queueBufferSampleCount * _channels; i ++) { samples[i] = 0.0f; } } + + _mutex.Unlock(); +} + +void LAppMicrophoneAudioManager::InputCallBack(void* customData, AudioQueueRef queue, AudioQueueBufferRef buffer, const AudioTimeStamp *startTime, UInt32 packetNum, const AudioStreamPacketDescription *packetDesc) +{ + LAppMicrophoneAudioManager* data = reinterpret_cast(customData); + csmFloat32 *samples = reinterpret_cast(buffer->mAudioData); + if (0 < packetNum) + { + data->WriteInputBuffer(samples); + } + AudioQueueEnqueueBuffer(queue, buffer, 0, NULL); +} + +void LAppMicrophoneAudioManager::OutputCallBack(void* customData, AudioQueueRef queue, AudioQueueBufferRef buffer) +{ + LAppMicrophoneAudioManager* data = reinterpret_cast(customData); + csmFloat32 *samples = reinterpret_cast(buffer->mAudioData); + + data->ReadInputBuffer(samples); + AudioQueueEnqueueBuffer(queue, buffer, 0, NULL); } diff --git a/Samples/OpenGL/Demo/proj.mac.cmake/src/LAppMicrophoneAudioManager.hpp b/Samples/OpenGL/Demo/proj.mac.cmake/src/LAppMicrophoneAudioManager.hpp index 447db9e..77828bb 100644 --- a/Samples/OpenGL/Demo/proj.mac.cmake/src/LAppMicrophoneAudioManager.hpp +++ b/Samples/OpenGL/Demo/proj.mac.cmake/src/LAppMicrophoneAudioManager.hpp @@ -12,6 +12,7 @@ #include "CubismMotionSyncAudioBuffer.hpp" #include "Type/csmString.hpp" #include "Type/csmVector.hpp" +#include "LAppMutex.hpp" class LAppMicrophoneAudioManager { @@ -64,6 +65,22 @@ class LAppMicrophoneAudioManager Csm::csmInt32 _channels; // MotionSyncで使用するバッファ Csm::MotionSync::CubismMotionSyncAudioBuffer _buffer; + // mutex + LAppMutex _mutex; + + /** + * @brief 録音データをバッファに格納する + * + * @param[in] samples 録音データ + */ + void WriteInputBuffer(Csm::csmFloat32* samples); + + /** + * @brief 録音データをバッファから取り出す + * + * @param[in] samples 録音データの取り出し先 + */ + void ReadInputBuffer(Csm::csmFloat32* samples); /** * @brief 録音時のコールバック処理 diff --git a/Samples/OpenGL/Demo/proj.mac.cmake/src/LAppMicrophoneDelegate.cpp b/Samples/OpenGL/Demo/proj.mac.cmake/src/LAppMicrophoneDelegate.cpp index 02cb552..04f238c 100644 --- a/Samples/OpenGL/Demo/proj.mac.cmake/src/LAppMicrophoneDelegate.cpp +++ b/Samples/OpenGL/Demo/proj.mac.cmake/src/LAppMicrophoneDelegate.cpp @@ -1,4 +1,4 @@ -/** +/** * Copyright(c) Live2D Inc. All rights reserved. * * Use of this source code is governed by the Live2D Open Software license @@ -55,12 +55,12 @@ void LAppMicrophoneDelegate::ReleaseInstance() bool LAppMicrophoneDelegate::Initialize() { - LAppPal::PrintLog("START"); + LAppPal::PrintLogLn("START"); // GLFWの初期化 if (glfwInit() == GL_FALSE) { - LAppPal::PrintLog("Can't initilize GLFW"); + LAppPal::PrintLogLn("Can't initilize GLFW"); return GL_FALSE; } @@ -69,7 +69,7 @@ bool LAppMicrophoneDelegate::Initialize() _window = glfwCreateWindow(LAppDefine::RenderTargetWidth, LAppDefine::RenderTargetHeight, "SIMPLE_SAMPLE", NULL, NULL); if (_window == NULL) { - LAppPal::PrintLog("Can't create GLFW window."); + LAppPal::PrintLogLn("Can't create GLFW window."); glfwTerminate(); return GL_FALSE; @@ -81,7 +81,7 @@ bool LAppMicrophoneDelegate::Initialize() if (glewInit() != GLEW_OK) { - LAppPal::PrintLog("Can't initilize glew."); + LAppPal::PrintLogLn("Can't initilize glew."); glfwTerminate(); return GL_FALSE; @@ -228,7 +228,7 @@ LAppMicrophoneDelegate::~LAppMicrophoneDelegate() void LAppMicrophoneDelegate::InitializeCubism() { //setup cubism - _cubismOption.LogFunction = LAppPal::PrintMessage; + _cubismOption.LogFunction = LAppPal::PrintMessageLn; _cubismOption.LoggingLevel = Csm::CubismFramework::Option::LogLevel_Verbose; Csm::CubismFramework::StartUp(&_cubismAllocator, &_cubismOption); diff --git a/Samples/OpenGL/Demo/proj.mac.cmake/src/LAppMotionSyncMicrophoneModel.cpp b/Samples/OpenGL/Demo/proj.mac.cmake/src/LAppMotionSyncMicrophoneModel.cpp index e5de896..d136ad9 100644 --- a/Samples/OpenGL/Demo/proj.mac.cmake/src/LAppMotionSyncMicrophoneModel.cpp +++ b/Samples/OpenGL/Demo/proj.mac.cmake/src/LAppMotionSyncMicrophoneModel.cpp @@ -24,7 +24,7 @@ namespace { { if (LAppDefine::DebugLogEnable) { - LAppPal::PrintLog("[APP]create buffer: %s ", path); + LAppPal::PrintLogLn("[APP]create buffer: %s ", path); } return LAppPal::LoadFileAsBytes(path, size); } @@ -33,7 +33,7 @@ namespace { { if (DebugLogEnable) { - LAppPal::PrintLog("[APP]delete buffer: %s", path); + LAppPal::PrintLogLn("[APP]delete buffer: %s", path); } LAppPal::ReleaseBytes(buffer); } @@ -67,7 +67,7 @@ void LAppMotionSyncMicrophoneModel::LoadAssets(const csmString fileName) if (_debugMode) { - LAppPal::PrintLog("[APP]load model setting: %s", fileName.GetRawString()); + LAppPal::PrintLogLn("[APP]load model setting: %s", fileName.GetRawString()); } csmSizeInt size; @@ -81,7 +81,7 @@ void LAppMotionSyncMicrophoneModel::LoadAssets(const csmString fileName) if (_model == NULL) { - LAppPal::PrintLog("Failed to LoadAssets()."); + LAppPal::PrintLogLn("Failed to LoadAssets()."); return; } @@ -135,7 +135,7 @@ void LAppMotionSyncMicrophoneModel::SetupModel() if (_debugMode) { - LAppPal::PrintLog("[APP]create model: %s", _modelSetting->GetModelFileName()); + LAppPal::PrintLogLn("[APP]create model: %s", _modelSetting->GetModelFileName()); } buffer = CreateBuffer(path.GetRawString(), &size); @@ -145,7 +145,7 @@ void LAppMotionSyncMicrophoneModel::SetupModel() if (_modelSetting == NULL || _modelMatrix == NULL) { - LAppPal::PrintLog("Failed to SetupModel()."); + LAppPal::PrintLogLn("Failed to SetupModel()."); return; } @@ -167,7 +167,7 @@ void LAppMotionSyncMicrophoneModel::SetupModel() { if (_debugMode) { - LAppPal::PrintLog("[APP]load motionSync setting: %s", fileName); + LAppPal::PrintLogLn("[APP]load motionSync setting: %s", fileName); } const csmString path = csmString(_modelHomeDir) + fileName; @@ -177,7 +177,7 @@ void LAppMotionSyncMicrophoneModel::SetupModel() if (!_motionSync) { - LAppPal::PrintLog("Failed to SetupModel()."); + LAppPal::PrintLogLn("Failed to SetupModel()."); return; } diff --git a/Samples/OpenGL/Demo/proj.mac.cmake/src/LAppMotionSyncModel.cpp b/Samples/OpenGL/Demo/proj.mac.cmake/src/LAppMotionSyncModel.cpp index e5abb73..a1d028a 100644 --- a/Samples/OpenGL/Demo/proj.mac.cmake/src/LAppMotionSyncModel.cpp +++ b/Samples/OpenGL/Demo/proj.mac.cmake/src/LAppMotionSyncModel.cpp @@ -24,7 +24,7 @@ namespace { { if (LAppDefine::DebugLogEnable) { - LAppPal::PrintLog("[APP]create buffer: %s ", path); + LAppPal::PrintLogLn("[APP]create buffer: %s ", path); } return LAppPal::LoadFileAsBytes(path, size); } @@ -33,7 +33,7 @@ namespace { { if (DebugLogEnable) { - LAppPal::PrintLog("[APP]delete buffer: %s", path); + LAppPal::PrintLogLn("[APP]delete buffer: %s", path); } LAppPal::ReleaseBytes(buffer); } @@ -68,7 +68,7 @@ void LAppMotionSyncModel::LoadAssets(const csmString fileName) if (_debugMode) { - LAppPal::PrintLog("[APP]load model setting: %s", fileName.GetRawString()); + LAppPal::PrintLogLn("[APP]load model setting: %s", fileName.GetRawString()); } csmSizeInt size; @@ -82,7 +82,7 @@ void LAppMotionSyncModel::LoadAssets(const csmString fileName) if (_model == NULL) { - LAppPal::PrintLog("Failed to LoadAssets()."); + LAppPal::PrintLogLn("Failed to LoadAssets()."); return; } @@ -145,7 +145,7 @@ void LAppMotionSyncModel::SetupModel() if (_debugMode) { - LAppPal::PrintLog("[APP]create model: %s", _modelSetting->GetModelFileName()); + LAppPal::PrintLogLn("[APP]create model: %s", _modelSetting->GetModelFileName()); } buffer = CreateBuffer(path.GetRawString(), &size); @@ -155,7 +155,7 @@ void LAppMotionSyncModel::SetupModel() if (_modelSetting == NULL || _modelMatrix == NULL) { - LAppPal::PrintLog("Failed to SetupModel()."); + LAppPal::PrintLogLn("Failed to SetupModel()."); return; } @@ -177,7 +177,7 @@ void LAppMotionSyncModel::SetupModel() { if (_debugMode) { - LAppPal::PrintLog("[APP]load motionSync setting: %s", fileName); + LAppPal::PrintLogLn("[APP]load motionSync setting: %s", fileName); } const csmString path = csmString(_modelHomeDir) + fileName; @@ -187,7 +187,7 @@ void LAppMotionSyncModel::SetupModel() if (!_motionSync) { - LAppPal::PrintLog("Failed to SetupModel()."); + LAppPal::PrintLogLn("Failed to SetupModel()."); return; } @@ -195,8 +195,7 @@ void LAppMotionSyncModel::SetupModel() // 音声データ _soundFileList = _modelSetting->GetMotionSyncSoundFileList(); - _soundIndex = 0; - PlayIndexSound(); + _soundIndex = _soundFileList.GetSize()- 1; } } diff --git a/Samples/OpenGL/Demo/proj.mac.cmake/src/LAppMutex.cpp b/Samples/OpenGL/Demo/proj.mac.cmake/src/LAppMutex.cpp new file mode 100644 index 0000000..99e5344 --- /dev/null +++ b/Samples/OpenGL/Demo/proj.mac.cmake/src/LAppMutex.cpp @@ -0,0 +1,28 @@ +/** + * Copyright(c) Live2D Inc. All rights reserved. + * + * Use of this source code is governed by the Live2D Open Software license + * that can be found at https://www.live2d.com/eula/live2d-open-software-license-agreement_en.html. + */ + +#include "LAppMutex.hpp" + +LAppMutex::LAppMutex() +{ + pthread_mutex_init(&_mutex, NULL); +} + +LAppMutex::~LAppMutex() +{ + pthread_mutex_destroy(&_mutex); +} + +void LAppMutex::Lock() +{ + pthread_mutex_lock(&_mutex); +} + +void LAppMutex::Unlock() +{ + pthread_mutex_unlock(&_mutex); +} diff --git a/Samples/OpenGL/Demo/proj.mac.cmake/src/LAppMutex.hpp b/Samples/OpenGL/Demo/proj.mac.cmake/src/LAppMutex.hpp new file mode 100644 index 0000000..10b9f4a --- /dev/null +++ b/Samples/OpenGL/Demo/proj.mac.cmake/src/LAppMutex.hpp @@ -0,0 +1,39 @@ +/** + * Copyright(c) Live2D Inc. All rights reserved. + * + * Use of this source code is governed by the Live2D Open Software license + * that can be found at https://www.live2d.com/eula/live2d-open-software-license-agreement_en.html. + */ +#pragma once + +#include + +class LAppMutex +{ +public: + /** + * @brief コンストラクタ + * + */ + LAppMutex(); + + /** + * @brief デストラクタ + */ + ~LAppMutex(); + + /** + * @brief ロック処理 + */ + void Lock(); + + /** + * @brief ロック解除 + */ + void Unlock(); + +private: + // mutex + pthread_mutex_t _mutex; + +}; diff --git a/Samples/OpenGL/Demo/proj.win.cmake/src/LAppAudioManager.cpp b/Samples/OpenGL/Demo/proj.win.cmake/src/LAppAudioManager.cpp index 302d731..f3ed9d8 100644 --- a/Samples/OpenGL/Demo/proj.win.cmake/src/LAppAudioManager.cpp +++ b/Samples/OpenGL/Demo/proj.win.cmake/src/LAppAudioManager.cpp @@ -8,6 +8,7 @@ #include "LAppAudioManager.hpp" #include #include "LAppWavFileHandler.hpp" +#include "LAppPal.hpp" #pragma comment(lib, "dsound.lib") @@ -27,7 +28,7 @@ csmBool LAppAudioManager::Init(HWND window, csmInt32 channels, csmInt32 samplesP result = CoInitialize(NULL); if (FAILED(result)) { - CubismLogError("[APP]Failed to CoInitialize() in LAppAudioManager::Init()"); + LAppPal::PrintLogLn("[APP]Failed to CoInitialize() in LAppAudioManager::Init()"); return false; } @@ -35,7 +36,7 @@ csmBool LAppAudioManager::Init(HWND window, csmInt32 channels, csmInt32 samplesP result = DirectSoundCreate8(NULL, &_directSound, NULL); if (FAILED(result)) { - CubismLogError("[APP]Failed to DirectSoundCreate8() in LAppAudioManager::Init()"); + LAppPal::PrintLogLn("[APP]Failed to DirectSoundCreate8() in LAppAudioManager::Init()"); return false; } @@ -43,7 +44,7 @@ csmBool LAppAudioManager::Init(HWND window, csmInt32 channels, csmInt32 samplesP result = _directSound->SetCooperativeLevel(window, DSSCL_EXCLUSIVE | DSSCL_PRIORITY); if (FAILED(result)) { - CubismLogError("[APP]Failed to SetCooperativeLevel() in LAppAudioManager::Init()"); + LAppPal::PrintLogLn("[APP]Failed to SetCooperativeLevel() in LAppAudioManager::Init()"); return false; } @@ -58,7 +59,7 @@ csmBool LAppAudioManager::Init(HWND window, csmInt32 channels, csmInt32 samplesP result = _directSound->CreateSoundBuffer(&dsdesc, &_primary, NULL); if (FAILED(result)) { - CubismLogError("[APP]Failed to CreateSoundBuffer() in LAppAudioManager::Init()"); + LAppPal::PrintLogLn("[APP]Failed to CreateSoundBuffer() in LAppAudioManager::Init()"); return false; } @@ -73,7 +74,7 @@ csmBool LAppAudioManager::Init(HWND window, csmInt32 channels, csmInt32 samplesP result = _primary->SetFormat(&waveFormat); if (FAILED(result)) { - CubismLogError("[APP]Failed to SetFormat() in LAppAudioManager::Init()"); + LAppPal::PrintLogLn("[APP]Failed to SetFormat() in LAppAudioManager::Init()"); return false; } @@ -104,6 +105,7 @@ csmBool LAppAudioManager::LoadFile(csmString path, csmUint32 useChannel) { // 初期化 Release(); + _isLoadFile = true; HRESULT result; LPWAVEFORMATEX waveFormat; @@ -117,7 +119,7 @@ csmBool LAppAudioManager::LoadFile(csmString path, csmUint32 useChannel) waveFormat = reinterpret_cast(CSM_MALLOC(sizeof(WAVEFORMATEX))); if (!waveFormat) { - CubismLogError("[APP]Failed malloc to 'waveFormat' in LAppAudioManager::LoadFile()"); + LAppPal::PrintLogLn("[APP]Failed malloc to 'waveFormat' in LAppAudioManager::LoadFile()"); return false; } waveFormat->wFormatTag = WAVE_FORMAT_PCM; @@ -139,7 +141,7 @@ csmBool LAppAudioManager::LoadFile(csmString path, csmUint32 useChannel) _data = reinterpret_cast(CSM_MALLOC(sizeof(csmByte) * _dataSize)); if (!_data) { - CubismLogError("[APP]Failed malloc to '_data' in LAppAudioManager::LoadFile()"); + LAppPal::PrintLogLn("[APP]Failed malloc to '_data' in LAppAudioManager::LoadFile()"); CSM_FREE(waveFormat); return false; } @@ -159,7 +161,7 @@ csmBool LAppAudioManager::LoadFile(csmString path, csmUint32 useChannel) result = _directSound->CreateSoundBuffer(&dsdesc, &_secondary, NULL); if (FAILED(result)) { - CubismLogError("[APP]Failed to CreateSoundBuffer() in LAppAudioManager::LoadFile()"); + LAppPal::PrintLogLn("[APP]Failed to CreateSoundBuffer() in LAppAudioManager::LoadFile()"); CSM_FREE(waveFormat); return false; } @@ -173,7 +175,7 @@ csmBool LAppAudioManager::LoadFile(csmString path, csmUint32 useChannel) result = _secondary->Lock(0, bufferBytes, &soundBuffer1, &soundBufferSize1, &soundBuffer2, &soundBufferSize2, DSBLOCK_ENTIREBUFFER); if (FAILED(result)) { - CubismLogError("[APP]Failed to Lock() in LAppAudioManager::LoadFile()"); + LAppPal::PrintLogLn("[APP]Failed to Lock() in LAppAudioManager::LoadFile()"); return false; } for (DWORD i = 0; i < soundBufferSize1 && _dataPos < _dataSize; i++) @@ -189,7 +191,7 @@ csmBool LAppAudioManager::LoadFile(csmString path, csmUint32 useChannel) result = _secondary->Unlock(soundBuffer1, soundBufferSize1, soundBuffer2, soundBufferSize2); if (FAILED(result)) { - CubismLogError("[APP]Failed to Unlock() in LAppMicrophoneAudioManager::Update()"); + LAppPal::PrintLogLn("[APP]Failed to Unlock() in LAppMicrophoneAudioManager::Update()"); return false; } @@ -203,7 +205,7 @@ csmBool LAppAudioManager::LoadFile(csmString path, csmUint32 useChannel) _samples = reinterpret_cast(CSM_MALLOC(sizeof(csmFloat32) * _samplesSize)); if (!_samples) { - CubismLogError("[APP]Failed malloc to '_samples' in LAppAudioManager::LoadFile()"); + LAppPal::PrintLogLn("[APP]Failed malloc to '_samples' in LAppAudioManager::LoadFile()"); CSM_FREE(waveFormat); return false; } @@ -217,7 +219,7 @@ csmBool LAppAudioManager::LoadFile(csmString path, csmUint32 useChannel) result = _secondary->SetCurrentPosition(0); if (FAILED(result)) { - CubismLogError("[APP]Failed to SetCurrentPosition() in LAppAudioManager::LoadFile()"); + LAppPal::PrintLogLn("[APP]Failed to SetCurrentPosition() in LAppAudioManager::LoadFile()"); } return true; @@ -231,16 +233,22 @@ csmBool LAppAudioManager::Update() DWORD soundBufferSize1, soundBufferSize2; csmUint32 bufferBytes = _bufferSampleBytes / 2; + if (!_isLoadFile) + { + // 早送りボタンが押されていないため音声の再生がない + return true; + } + if (!_secondary) { - CubismLogError("[APP]_secondary is null in LAppAudioManager::Update()"); + LAppPal::PrintLogLn("[APP]_secondary is null in LAppAudioManager::Update()"); return false; } result = _secondary->GetCurrentPosition(&playCursor, NULL); if (FAILED(result)) { - CubismLogError("[APP]Failed to GetCurrentPosition() in LAppAudioManager::Update()"); + LAppPal::PrintLogLn("[APP]Failed to GetCurrentPosition() in LAppAudioManager::Update()"); return false; } @@ -252,7 +260,7 @@ csmBool LAppAudioManager::Update() result = _secondary->Lock(0, bufferBytes, &soundBuffer1, &soundBufferSize1, &soundBuffer2, &soundBufferSize2, 0); if (FAILED(result)) { - CubismLogError("[APP]Failed to Lock() in LAppAudioManager::Update()"); + LAppPal::PrintLogLn("[APP]Failed to Lock() in LAppAudioManager::Update()"); return false; } for (DWORD i = 0; i < soundBufferSize1 && _dataPos < _dataSize; i++) @@ -268,7 +276,7 @@ csmBool LAppAudioManager::Update() result = _secondary->Unlock(soundBuffer1, soundBufferSize1, soundBuffer2, soundBufferSize2); if (FAILED(result)) { - CubismLogError("[APP]Failed to Unlock() in LAppMicrophoneAudioManager::Update()"); + LAppPal::PrintLogLn("[APP]Failed to Unlock() in LAppMicrophoneAudioManager::Update()"); return false; } @@ -285,7 +293,7 @@ csmBool LAppAudioManager::Update() result = _secondary->Lock(bufferBytes, bufferBytes, &soundBuffer1, &soundBufferSize1, &soundBuffer2, &soundBufferSize2, 0); if (FAILED(result)) { - CubismLogError("[APP]Failed to Lock() in LAppAudioManager::Update()"); + LAppPal::PrintLogLn("[APP]Failed to Lock() in LAppAudioManager::Update()"); return false; } for (DWORD i = 0; i < soundBufferSize1 && _dataPos < _dataSize; i++) @@ -301,7 +309,7 @@ csmBool LAppAudioManager::Update() result = _secondary->Unlock(soundBuffer1, soundBufferSize1, soundBuffer2, soundBufferSize2); if (FAILED(result)) { - CubismLogError("[APP]Failed to Unlock() in LAppMicrophoneAudioManager::Update()"); + LAppPal::PrintLogLn("[APP]Failed to Unlock() in LAppMicrophoneAudioManager::Update()"); return false; } @@ -375,7 +383,8 @@ LAppAudioManager::LAppAudioManager() : _samples(NULL), _samplesSize(0), _samplesPos(0), - _buffer() + _buffer(), + _isLoadFile(false) { } diff --git a/Samples/OpenGL/Demo/proj.win.cmake/src/LAppAudioManager.hpp b/Samples/OpenGL/Demo/proj.win.cmake/src/LAppAudioManager.hpp index d979257..9d58a00 100644 --- a/Samples/OpenGL/Demo/proj.win.cmake/src/LAppAudioManager.hpp +++ b/Samples/OpenGL/Demo/proj.win.cmake/src/LAppAudioManager.hpp @@ -114,4 +114,6 @@ class LAppAudioManager Csm::csmUint32 _samplesPos; // MotionSyncで使用するバッファ Csm::MotionSync::CubismMotionSyncAudioBuffer _buffer; + // 音声ファイル読み込み済か + Csm::csmBool _isLoadFile; }; diff --git a/Samples/OpenGL/Demo/proj.win.cmake/src/LAppDelegate.cpp b/Samples/OpenGL/Demo/proj.win.cmake/src/LAppDelegate.cpp index 425761a..19cadfb 100644 --- a/Samples/OpenGL/Demo/proj.win.cmake/src/LAppDelegate.cpp +++ b/Samples/OpenGL/Demo/proj.win.cmake/src/LAppDelegate.cpp @@ -55,12 +55,12 @@ void LAppDelegate::ReleaseInstance() bool LAppDelegate::Initialize() { - LAppPal::PrintLog("START"); + LAppPal::PrintLogLn("START"); // GLFWの初期化 if (glfwInit() == GL_FALSE) { - LAppPal::PrintLog("Can't initilize GLFW"); + LAppPal::PrintLogLn("Can't initilize GLFW"); return GL_FALSE; } @@ -69,7 +69,7 @@ bool LAppDelegate::Initialize() _window = glfwCreateWindow(LAppDefine::RenderTargetWidth, LAppDefine::RenderTargetHeight, "SOUND_FILE_SAMPLE", NULL, NULL); if (_window == NULL) { - LAppPal::PrintLog("Can't create GLFW window."); + LAppPal::PrintLogLn("Can't create GLFW window."); glfwTerminate(); return GL_FALSE; @@ -80,7 +80,7 @@ bool LAppDelegate::Initialize() glfwSwapInterval(1); if (glewInit() != GLEW_OK) { - LAppPal::PrintLog("Can't initilize glew."); + LAppPal::PrintLogLn("Can't initilize glew."); glfwTerminate(); return GL_FALSE; @@ -373,7 +373,7 @@ bool LAppDelegate::CheckShader(GLuint shaderId) { GLchar* log = reinterpret_cast(CSM_MALLOC(logLength)); glGetShaderInfoLog(shaderId, logLength, &logLength, log); - CubismLogError("Shader compile log: %s", log); + LAppPal::PrintLogLn("Shader compile log: %s", log); CSM_FREE(log); } diff --git a/Samples/OpenGL/Demo/proj.win.cmake/src/LAppMicrophoneAudioManager.cpp b/Samples/OpenGL/Demo/proj.win.cmake/src/LAppMicrophoneAudioManager.cpp index 93e215a..8cd9a1d 100644 --- a/Samples/OpenGL/Demo/proj.win.cmake/src/LAppMicrophoneAudioManager.cpp +++ b/Samples/OpenGL/Demo/proj.win.cmake/src/LAppMicrophoneAudioManager.cpp @@ -8,6 +8,7 @@ #include "LAppMicrophoneAudioManager.hpp" #include #include "LAppWavFileHandler.hpp" +#include "LAppPal.hpp" #pragma comment(lib, "dsound.lib") @@ -27,7 +28,7 @@ csmBool LAppMicrophoneAudioManager::Init(HWND window, csmInt32 channels, csmInt3 result = CoInitialize(NULL); if (FAILED(result)) { - CubismLogError("[APP]Failed to CoInitialize() in LAppMicrophoneAudioManager::Init()"); + LAppPal::PrintLogLn("[APP]Failed to CoInitialize() in LAppMicrophoneAudioManager::Init()"); return false; } @@ -35,7 +36,7 @@ csmBool LAppMicrophoneAudioManager::Init(HWND window, csmInt32 channels, csmInt3 result = DirectSoundCreate8(NULL, &_directSound, NULL); if (FAILED(result)) { - CubismLogError("[APP]Failed to DirectSoundCreate8() in LAppMicrophoneAudioManager::Init()"); + LAppPal::PrintLogLn("[APP]Failed to DirectSoundCreate8() in LAppMicrophoneAudioManager::Init()"); return false; } @@ -43,7 +44,7 @@ csmBool LAppMicrophoneAudioManager::Init(HWND window, csmInt32 channels, csmInt3 result = _directSound->SetCooperativeLevel(window, DSSCL_EXCLUSIVE | DSSCL_PRIORITY); if (FAILED(result)) { - CubismLogError("[APP]Failed to SetCooperativeLevel() in LAppMicrophoneAudioManager::Init()"); + LAppPal::PrintLogLn("[APP]Failed to SetCooperativeLevel() in LAppMicrophoneAudioManager::Init()"); return false; } @@ -58,7 +59,7 @@ csmBool LAppMicrophoneAudioManager::Init(HWND window, csmInt32 channels, csmInt3 result = _directSound->CreateSoundBuffer(&dsdesc, &_primary, NULL); if (FAILED(result)) { - CubismLogError("[APP]Failed to CreateSoundBuffer() in LAppMicrophoneAudioManager::Init()"); + LAppPal::PrintLogLn("[APP]Failed to CreateSoundBuffer() in LAppMicrophoneAudioManager::Init()"); return false; } @@ -73,7 +74,7 @@ csmBool LAppMicrophoneAudioManager::Init(HWND window, csmInt32 channels, csmInt3 result = _primary->SetFormat(&waveFormat); if (FAILED(result)) { - CubismLogError("[APP]Failed to SetFormat() in LAppMicrophoneAudioManager::Init()"); + LAppPal::PrintLogLn("[APP]Failed to SetFormat() in LAppMicrophoneAudioManager::Init()"); return false; } @@ -123,7 +124,7 @@ csmBool LAppMicrophoneAudioManager::SetupMicrophone(csmUint32 channels, csmUint3 result = DirectSoundCaptureCreate8(NULL, &_soundCapture, NULL); if (FAILED(result)) { - CubismLogError("[APP]Failed to DirectSoundCaptureCreate8() in LAppMicrophoneAudioManager::SetupMicrophone()"); + LAppPal::PrintLogLn("[APP]Failed to DirectSoundCaptureCreate8() in LAppMicrophoneAudioManager::SetupMicrophone()"); return false; } @@ -153,7 +154,7 @@ csmBool LAppMicrophoneAudioManager::SetupMicrophone(csmUint32 channels, csmUint3 result = _soundCapture->CreateCaptureBuffer(&inputBufferSetting, &_captureBuffer, NULL); if (FAILED(result)) { - CubismLogError("[APP]Failed to CreateCaptureBuffer() in LAppMicrophoneAudioManager::SetupMicrophone()"); + LAppPal::PrintLogLn("[APP]Failed to CreateCaptureBuffer() in LAppMicrophoneAudioManager::SetupMicrophone()"); return false; } @@ -162,7 +163,7 @@ csmBool LAppMicrophoneAudioManager::SetupMicrophone(csmUint32 channels, csmUint3 outputWaveFormat = reinterpret_cast(CSM_MALLOC(sizeof(WAVEFORMATEX))); if (!outputWaveFormat) { - CubismLogError("[APP]Failed malloc to 'waveFormat' in LAppMicrophoneAudioManager::SetupMicrophone()"); + LAppPal::PrintLogLn("[APP]Failed malloc to 'waveFormat' in LAppMicrophoneAudioManager::SetupMicrophone()"); return false; } outputWaveFormat->wFormatTag = WAVE_FORMAT_PCM; @@ -184,7 +185,7 @@ csmBool LAppMicrophoneAudioManager::SetupMicrophone(csmUint32 channels, csmUint3 result = _directSound->CreateSoundBuffer(&outputBufferSetting, &_secondary, NULL); if (FAILED(result)) { - CubismLogError("[APP]Failed to CreateSoundBuffer() in LAppMicrophoneAudioManager::SetupMicrophone()"); + LAppPal::PrintLogLn("[APP]Failed to CreateSoundBuffer() in LAppMicrophoneAudioManager::SetupMicrophone()"); CSM_FREE(outputWaveFormat); return false; } @@ -206,7 +207,7 @@ csmBool LAppMicrophoneAudioManager::SetupMicrophone(csmUint32 channels, csmUint3 result = _secondary->SetCurrentPosition(_outputPos); if (FAILED(result)) { - CubismLogError("[APP]Failed to SetCurrentPosition() in LAppAudioManager::SetupMicrophone()"); + LAppPal::PrintLogLn("[APP]Failed to SetCurrentPosition() in LAppAudioManager::SetupMicrophone()"); } return true; @@ -223,7 +224,7 @@ csmBool LAppMicrophoneAudioManager::Update() if (!_captureBuffer) { - CubismLogError("[APP]_captureBuffer is null in LAppMicrophoneAudioManager::Update()"); + LAppPal::PrintLogLn("[APP]_captureBuffer is null in LAppMicrophoneAudioManager::Update()"); return false; } @@ -231,7 +232,7 @@ csmBool LAppMicrophoneAudioManager::Update() result = _captureBuffer->GetCurrentPosition(NULL, &inputReadPos); if (FAILED(result)) { - CubismLogError("[APP]Failed to GetCurrentPosition() in LAppMicrophoneAudioManager::Update()"); + LAppPal::PrintLogLn("[APP]Failed to GetCurrentPosition() in LAppMicrophoneAudioManager::Update()"); return false; } @@ -251,7 +252,7 @@ csmBool LAppMicrophoneAudioManager::Update() result = _captureBuffer->Lock(_inputPos, inputSize, &inputSoundBuffer1, &inputSoundBufferSize1, &inputSoundBuffer2, &inputSoundBufferSize2, NULL); if (FAILED(result)) { - CubismLogError("[APP]Failed to Lock() in LAppMicrophoneAudioManager::Update()"); + LAppPal::PrintLogLn("[APP]Failed to Lock() in LAppMicrophoneAudioManager::Update()"); return false; } @@ -264,7 +265,7 @@ csmBool LAppMicrophoneAudioManager::Update() if (!_secondary) { - CubismLogError("[APP]_secondary is null in LAppMicrophoneAudioManager::Update()"); + LAppPal::PrintLogLn("[APP]_secondary is null in LAppMicrophoneAudioManager::Update()"); return false; } @@ -272,7 +273,7 @@ csmBool LAppMicrophoneAudioManager::Update() result = _secondary->Lock(_outputPos, inputSoundBufferSize1 + inputSoundBufferSize2, &outputSoundBuffer1, &outputSoundBufferSize1, &outputSoundBuffer2, &outputSoundBufferSize2, 0); if (FAILED(result)) { - CubismLogError("[APP]Failed to Lock() in LAppMicrophoneAudioManager::Update()"); + LAppPal::PrintLogLn("[APP]Failed to Lock() in LAppMicrophoneAudioManager::Update()"); return false; } @@ -290,7 +291,7 @@ csmBool LAppMicrophoneAudioManager::Update() result = _secondary->Unlock(outputSoundBuffer1, outputSoundBufferSize1, outputSoundBuffer2, outputSoundBufferSize2); if (FAILED(result)) { - CubismLogError("[APP]Failed to Unlock() in LAppMicrophoneAudioManager::Update()"); + LAppPal::PrintLogLn("[APP]Failed to Unlock() in LAppMicrophoneAudioManager::Update()"); return false; } @@ -320,7 +321,7 @@ csmBool LAppMicrophoneAudioManager::Update() result = _captureBuffer->Unlock(inputSoundBuffer1, inputSoundBufferSize1, inputSoundBuffer2, inputSoundBufferSize2); if (FAILED(result)) { - CubismLogError("[APP]Failed to Unlock() in LAppMicrophoneAudioManager::Update()"); + LAppPal::PrintLogLn("[APP]Failed to Unlock() in LAppMicrophoneAudioManager::Update()"); return false; } diff --git a/Samples/OpenGL/Demo/proj.win.cmake/src/LAppMicrophoneDelegate.cpp b/Samples/OpenGL/Demo/proj.win.cmake/src/LAppMicrophoneDelegate.cpp index 76e604c..a0ba511 100644 --- a/Samples/OpenGL/Demo/proj.win.cmake/src/LAppMicrophoneDelegate.cpp +++ b/Samples/OpenGL/Demo/proj.win.cmake/src/LAppMicrophoneDelegate.cpp @@ -55,12 +55,12 @@ void LAppMicrophoneDelegate::ReleaseInstance() bool LAppMicrophoneDelegate::Initialize() { - LAppPal::PrintLog("START"); + LAppPal::PrintLogLn("START"); // GLFWの初期化 if (glfwInit() == GL_FALSE) { - LAppPal::PrintLog("Can't initilize GLFW"); + LAppPal::PrintLogLn("Can't initilize GLFW"); return GL_FALSE; } @@ -69,7 +69,7 @@ bool LAppMicrophoneDelegate::Initialize() _window = glfwCreateWindow(LAppDefine::RenderTargetWidth, LAppDefine::RenderTargetHeight, "MICROPHONE_SAMPLE", NULL, NULL); if (_window == NULL) { - LAppPal::PrintLog("Can't create GLFW window."); + LAppPal::PrintLogLn("Can't create GLFW window."); glfwTerminate(); return GL_FALSE; @@ -80,7 +80,7 @@ bool LAppMicrophoneDelegate::Initialize() glfwSwapInterval(1); if (glewInit() != GLEW_OK) { - LAppPal::PrintLog("Can't initilize glew."); + LAppPal::PrintLogLn("Can't initilize glew."); glfwTerminate(); return GL_FALSE; @@ -362,7 +362,7 @@ bool LAppMicrophoneDelegate::CheckShader(GLuint shaderId) { GLchar* log = reinterpret_cast(CSM_MALLOC(logLength)); glGetShaderInfoLog(shaderId, logLength, &logLength, log); - CubismLogError("Shader compile log: %s", log); + LAppPal::PrintLogLn("Shader compile log: %s", log); CSM_FREE(log); } diff --git a/Samples/OpenGL/Demo/proj.win.cmake/src/LAppMotionSyncMicrophoneModel.cpp b/Samples/OpenGL/Demo/proj.win.cmake/src/LAppMotionSyncMicrophoneModel.cpp index 6de9415..0ea53f3 100644 --- a/Samples/OpenGL/Demo/proj.win.cmake/src/LAppMotionSyncMicrophoneModel.cpp +++ b/Samples/OpenGL/Demo/proj.win.cmake/src/LAppMotionSyncMicrophoneModel.cpp @@ -24,7 +24,7 @@ namespace { { if (LAppDefine::DebugLogEnable) { - LAppPal::PrintLog("[APP]create buffer: %s ", path); + LAppPal::PrintLogLn("[APP]create buffer: %s ", path); } return LAppPal::LoadFileAsBytes(path, size); } @@ -33,7 +33,7 @@ namespace { { if (DebugLogEnable) { - LAppPal::PrintLog("[APP]delete buffer: %s", path); + LAppPal::PrintLogLn("[APP]delete buffer: %s", path); } LAppPal::ReleaseBytes(buffer); } @@ -67,7 +67,7 @@ void LAppMotionSyncMicrophoneModel::LoadAssets(const csmString fileName) if (_debugMode) { - LAppPal::PrintLog("[APP]load model setting: %s", fileName); + LAppPal::PrintLogLn("[APP]load model setting: %s", fileName); } csmSizeInt size; @@ -81,7 +81,7 @@ void LAppMotionSyncMicrophoneModel::LoadAssets(const csmString fileName) if (_model == NULL) { - LAppPal::PrintLog("Failed to LoadAssets()."); + LAppPal::PrintLogLn("Failed to LoadAssets()."); return; } @@ -141,7 +141,7 @@ void LAppMotionSyncMicrophoneModel::SetupModel() if (_debugMode) { - LAppPal::PrintLog("[APP]create model: %s", _modelSetting->GetModelFileName()); + LAppPal::PrintLogLn("[APP]create model: %s", _modelSetting->GetModelFileName()); } buffer = CreateBuffer(path.GetRawString(), &size); @@ -151,7 +151,7 @@ void LAppMotionSyncMicrophoneModel::SetupModel() if (_modelSetting == NULL || _modelMatrix == NULL) { - LAppPal::PrintLog("Failed to SetupModel()."); + LAppPal::PrintLogLn("Failed to SetupModel()."); return; } @@ -173,7 +173,7 @@ void LAppMotionSyncMicrophoneModel::SetupModel() { if (_debugMode) { - LAppPal::PrintLog("[APP]load motionSync setting: %s", fileName); + LAppPal::PrintLogLn("[APP]load motionSync setting: %s", fileName); } const csmString path = csmString(_modelHomeDir) + fileName; @@ -183,7 +183,7 @@ void LAppMotionSyncMicrophoneModel::SetupModel() if (!_motionSync) { - LAppPal::PrintLog("Failed to SetupModel()."); + LAppPal::PrintLogLn("Failed to SetupModel()."); return; } diff --git a/Samples/OpenGL/Demo/proj.win.cmake/src/LAppMotionSyncModel.cpp b/Samples/OpenGL/Demo/proj.win.cmake/src/LAppMotionSyncModel.cpp index 1b36024..e80ce7d 100644 --- a/Samples/OpenGL/Demo/proj.win.cmake/src/LAppMotionSyncModel.cpp +++ b/Samples/OpenGL/Demo/proj.win.cmake/src/LAppMotionSyncModel.cpp @@ -24,7 +24,7 @@ namespace { { if (LAppDefine::DebugLogEnable) { - LAppPal::PrintLog("[APP]create buffer: %s ", path); + LAppPal::PrintLogLn("[APP]create buffer: %s ", path); } return LAppPal::LoadFileAsBytes(path, size); } @@ -33,7 +33,7 @@ namespace { { if (DebugLogEnable) { - LAppPal::PrintLog("[APP]delete buffer: %s", path); + LAppPal::PrintLogLn("[APP]delete buffer: %s", path); } LAppPal::ReleaseBytes(buffer); } @@ -68,7 +68,7 @@ void LAppMotionSyncModel::LoadAssets(const csmString fileName) if (_debugMode) { - LAppPal::PrintLog("[APP]load model setting: %s", fileName); + LAppPal::PrintLogLn("[APP]load model setting: %s", fileName); } csmSizeInt size; @@ -82,7 +82,7 @@ void LAppMotionSyncModel::LoadAssets(const csmString fileName) if (_model == NULL) { - LAppPal::PrintLog("Failed to LoadAssets()."); + LAppPal::PrintLogLn("Failed to LoadAssets()."); return; } @@ -151,7 +151,7 @@ void LAppMotionSyncModel::SetupModel() if (_debugMode) { - LAppPal::PrintLog("[APP]create model: %s", _modelSetting->GetModelFileName()); + LAppPal::PrintLogLn("[APP]create model: %s", _modelSetting->GetModelFileName()); } buffer = CreateBuffer(path.GetRawString(), &size); @@ -161,7 +161,7 @@ void LAppMotionSyncModel::SetupModel() if (_modelSetting == NULL || _modelMatrix == NULL) { - LAppPal::PrintLog("Failed to SetupModel()."); + LAppPal::PrintLogLn("Failed to SetupModel()."); return; } @@ -183,7 +183,7 @@ void LAppMotionSyncModel::SetupModel() { if (_debugMode) { - LAppPal::PrintLog("[APP]load motionSync setting: %s", fileName); + LAppPal::PrintLogLn("[APP]load motionSync setting: %s", fileName); } const csmString path = csmString(_modelHomeDir) + fileName; @@ -193,7 +193,7 @@ void LAppMotionSyncModel::SetupModel() if (!_motionSync) { - LAppPal::PrintLog("Failed to SetupModel()."); + LAppPal::PrintLogLn("Failed to SetupModel()."); return; } @@ -201,8 +201,7 @@ void LAppMotionSyncModel::SetupModel() // 音声データ _soundFileList = _modelSetting->GetMotionSyncSoundFileList(); - _soundIndex = 0; - PlayIndexSound(); + _soundIndex = _soundFileList.GetSize() - 1; _isMotionSync = true; } } diff --git a/Samples/Resources/Kei_basic/sounds/01_kei_jp.wav b/Samples/Resources/Kei_basic/sounds/01_kei_jp.wav index d1b3876..9c79d2d 100644 Binary files a/Samples/Resources/Kei_basic/sounds/01_kei_jp.wav and b/Samples/Resources/Kei_basic/sounds/01_kei_jp.wav differ diff --git a/Samples/Resources/Kei_vowels/sounds/01_kei_jp.wav b/Samples/Resources/Kei_vowels/sounds/01_kei_jp.wav index d1b3876..9c79d2d 100644 Binary files a/Samples/Resources/Kei_vowels/sounds/01_kei_jp.wav and b/Samples/Resources/Kei_vowels/sounds/01_kei_jp.wav differ