teratail header banner
teratail header banner
質問するログイン新規登録

質問編集履歴

2

エラーの詳細を表示

2018/12/07 04:57

投稿

yosugi
yosugi

スコア18

title CHANGED
@@ -1,1 +1,1 @@
1
- unityのAudioListener.GetOutputData()で取得した配列をCSVで書き出したい
1
+ unityのAudioListener.GetOutputData()で取得した配列をtxtで書き出したい
body CHANGED
@@ -1,31 +1,42 @@
1
1
  現在unityについて学んでいるものです
2
- 今回,AudioListenerに入力された音の波形を表示するシーンを作成したのですがその値を実際の数値として確認したいため,CSVに書き出してみたいと考えました.
2
+ 今回,AudioListenerに入力された音の波形を表示するシーンを作成したのですがその値を実際の数値として確認したいため,txtに書き出してみたいと考えました.
3
- 以下のようなプログラムを書きましたがうまくいきません
3
+ 以下のようなプログラムを書きました
4
-
5
4
  using System.Collections;
6
5
  using System.Collections.Generic;
7
6
  using UnityEngine;
8
7
  using System.Text;
9
8
  using System.IO;
10
9
 
11
- public class CSVmaker : MonoBehaviour {
10
+ public class CSVmaker : MonoBehaviour
11
+ {
12
12
  private int index;
13
13
  private int count;
14
14
  // Use this for initialization
15
15
  public float[] data = new float[1024];
16
16
  public int channel = 1;
17
-
17
+ StreamWriter sw = new StreamWriter(@"C:\data\test.txt", false, System.Text.Encoding.GetEncoding("shift_jis"));
18
18
  internal float output;
19
- void Start () {
19
+ void Start()
20
+ {
20
21
  index = 0;
21
22
  count = 0;
22
- using(StreamWriter file = new StreamWriter("hakei.csv", false, System.Text.Encoding.GetEncoding("shift_jis")))
23
+
23
24
  }
24
-
25
+
25
- // Update is called once per frame
26
+ // Update is called once per frame
26
- void Update () {
27
+ void Update()
28
+ {
27
29
  AudioListener.GetOutputData(data, channel);
28
- file.WriteLine(data);
30
+ sw.WriteLine(data);
29
31
  }
30
32
  }
33
+
31
- を変更すればいいでしょ
34
+ このままだと以下のよなエラーが出ます
35
+ IOException: Sharing violation on path C:\data\test.txt
36
+ CSVmaker..ctor () (at Assets/CSVmaker.cs:14)
37
+
38
+ NullReferenceException: Object reference not set to an instance of an object
39
+ CSVmaker.Update () (at Assets/CSVmaker.cs:36)
40
+
41
+ エラーの意味をググってみたのですがよくわかりませんでした
42
+ ファイルの指定先のtest.txtは作成済みです

1

プログラムの提示

2018/12/07 04:57

投稿

yosugi
yosugi

スコア18

title CHANGED
File without changes
body CHANGED
@@ -1,3 +1,31 @@
1
1
  現在unityについて学んでいるものです
2
2
  今回,AudioListenerに入力された音の波形を表示するシーンを作成したのですがその値を実際の数値として確認したいため,CSVに書き出してみたいと考えました.
3
- のような関数用いればよいか知恵をお貸しくださ
3
+ 以下のようなプログラム書きまたがうまくいきません
4
+
5
+ using System.Collections;
6
+ using System.Collections.Generic;
7
+ using UnityEngine;
8
+ using System.Text;
9
+ using System.IO;
10
+
11
+ public class CSVmaker : MonoBehaviour {
12
+ private int index;
13
+ private int count;
14
+ // Use this for initialization
15
+ public float[] data = new float[1024];
16
+ public int channel = 1;
17
+
18
+ internal float output;
19
+ void Start () {
20
+ index = 0;
21
+ count = 0;
22
+ using(StreamWriter file = new StreamWriter("hakei.csv", false, System.Text.Encoding.GetEncoding("shift_jis")))
23
+ }
24
+
25
+ // Update is called once per frame
26
+ void Update () {
27
+ AudioListener.GetOutputData(data, channel);
28
+ file.WriteLine(data);
29
+ }
30
+ }
31
+ どこを変更すればいいのでしょうか