Last active
January 28, 2020 02:33
-
-
Save TakaakiIchijo/5e5f5c27ad3b694a432aae856175f66e to your computer and use it in GitHub Desktop.
ADX2の出力音声をwaveファイルで保存するスクリプト 要 WaveFileCreator.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections; | |
using System.IO; | |
using UnityEngine; | |
public class CriAtomRecoder: MonoBehaviour | |
{ | |
private WaveFileCreator waveFileCreator; | |
public string fileName = "recordedaudio"; | |
public const string Wavext = ".wav"; | |
public bool addTimeStampToFileName = true; | |
private CriAtomExOutputAnalyzer analyzer; | |
private bool IsRecording = false; | |
private int numSamples = 512; | |
public void Start() | |
{ | |
var path = Directory.GetParent(Application.dataPath) + "/"+ fileName; | |
if (addTimeStampToFileName) | |
{ | |
path += "_" + DateTime.Now.ToString("yyyyMMdd_hh_mm_ss"); | |
} | |
waveFileCreator = new WaveFileCreator( | |
path + Wavext, | |
numChannels:2, | |
samplingRate:32000, | |
numbites:16 | |
); | |
IsRecording = false; | |
StartCoroutine(Record()); | |
} | |
IEnumerator Record() | |
{ | |
// Wait for Loading ACB... | |
while (CriAtom.CueSheetsAreLoading) { | |
yield return null; | |
} | |
/* Initialize CriAtomExOutputAnalyzer for PCM capture. */ | |
CriAtomExOutputAnalyzer.Config config = new CriAtomExOutputAnalyzer.Config | |
{ | |
enablePcmCapture = true, | |
enablePcmCaptureCallback = true, | |
numCapturedPcmSamples = numSamples | |
}; | |
analyzer = new CriAtomExOutputAnalyzer(config); | |
analyzer.SetPcmCaptureCallback(PcmCapture); | |
analyzer.AttachDspBus("MasterOut"); | |
IsRecording = true; | |
} | |
public void PcmCapture(float[] dataL, float[] dataR, int numChannels, int numData) | |
{ | |
if (!IsRecording || waveFileCreator == null) | |
return; | |
waveFileCreator.CapturePcm(dataL, dataR, numData); | |
//Debug.Log(numData); | |
} | |
private void Update() | |
{ | |
if (IsRecording) | |
{ | |
analyzer.ExecutePcmCaptureCallback(); | |
} | |
} | |
private void OnDisable() | |
{ | |
waveFileCreator.StopAndWrite(); | |
if (analyzer != null) { | |
analyzer.DetachDspBus(); | |
analyzer.Dispose(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment