我要做的是从用户音频输出中获取原始音频,获取该数据并获得类似于unity3d的音频频谱和输出数组,并将该数据传递给我的可视化工具。
所以我需要知道一些事情:
我是编码naudio的新手,而Unity的API和极其全面的文档使它更容易,naudio似乎有一些教程和示例,没有我需要的东西,也没有API定义。我最终会弄清楚,但我需要知道的是,如果我尝试的是可能的,除了任何帮助之外,我都会感激。
我提供了我对问题1的尝试,它提供了看似随机的数据,我试图理解使用WaveFileReader但崩溃
using UnityEngine;
using System.Collections;
using System;
using NAudio.Wave;
using NAudio.CoreAudioApi;
using NAudio.Utils;
public class myNAudio : MonoBehaviour {
private WaveIn waveInStream;
private WaveFileReader reader;
private WaveStream readerStream;
void waveInStream_DataAvailable(object sender, WaveInEventArgs e){
//reader.Read(e.Buffer,0,e.BytesRecorded);
//Debug.Log(e.Buffer);
float tempDB = 0;
for(int i = 0; i < e.Buffer.Length; i++){
//Debug.Log(i + " = " +e.Buffer[i]);
tempDB += (float)e.Buffer[i]/255;
}
Debug.Log(e.Buffer.Length + ", " +tempDB);
}
void OnApplicationQuit(){
waveInStream.StopRecording();
waveInStream.Dispose();
waveInStream = null;
}
void OnDisable(){
waveInStream.StopRecording();
waveInStream.Dispose();
waveInStream = null;
}
// Use this for initialization
void Start () {
waveInStream = new WaveIn();
waveInStream.DeviceNumber = 0;
waveInStream.DataAvailable += new EventHandler<WaveInEventArgs>(waveInStream_DataAvailable);
waveInStream.StartRecording();
}
// Update is called once per frame
void Update () {
}
}