virtual protected void OnAudioFilterRead(float[] data, int channels) { // 再生状態の更新 this.UpdatePlaying(); if (_isPlaying && (OggCall.COggEncodIsEnded() == 0)) { _tmpWavBuffer = data; OggCall.COggEncodUpdate(data.Length / channels); _tmpWavBuffer = null; } // フラグが立っていれば大本の再生をしない if (_mute) { for (int i = 0; i < data.Length; i++) { data[i] = 0.0f; } } }
// 再生状態の変更 private void UpdatePlaying() { // 前回と状態が変わっていないなら無処理 if (_isPlaying == _reqPlaying) { return; } // 再生要求 if (_reqPlaying) { OggCall.COggEncodSetting(2, _sampleRate, 0.1f); if (_read == null) { _read = new OggCall.OnEncodeRead(this.OnEncodeRead); } if (_write == null) { _write = new OggCall.OnEncodeWrite(this.OnEncodeWrite); } if (OggCall.COggEncodBegin(_read, _write) == 0) { Debug.Log("初期化エラー"); _reqPlaying = false; return; } } // 停止要求 else { OggCall.COggEncodClose(); } _isPlaying = _reqPlaying; }