質問編集履歴

2

エラーの詳細を表示

2018/12/07 04:57

投稿

yosugi
yosugi

スコア18

test CHANGED
@@ -1 +1 @@
1
- unityのAudioListener.GetOutputData()で取得した配列をCSVで書き出したい
1
+ unityのAudioListener.GetOutputData()で取得した配列をtxtで書き出したい
test CHANGED
@@ -1,10 +1,8 @@
1
1
  現在unityについて学んでいるものです
2
2
 
3
- 今回,AudioListenerに入力された音の波形を表示するシーンを作成したのですがその値を実際の数値として確認したいため,CSVに書き出してみたいと考えました.
3
+ 今回,AudioListenerに入力された音の波形を表示するシーンを作成したのですがその値を実際の数値として確認したいため,txtに書き出してみたいと考えました.
4
4
 
5
- 以下のようなプログラムを書きましたがうまくいきません
5
+ 以下のようなプログラムを書きました
6
-
7
-
8
6
 
9
7
  using System.Collections;
10
8
 
@@ -18,7 +16,9 @@
18
16
 
19
17
 
20
18
 
21
- public class CSVmaker : MonoBehaviour {
19
+ public class CSVmaker : MonoBehaviour
20
+
21
+ {
22
22
 
23
23
  private int index;
24
24
 
@@ -30,32 +30,54 @@
30
30
 
31
31
  public int channel = 1;
32
32
 
33
-
33
+ StreamWriter sw = new StreamWriter(@"C:\data\test.txt", false, System.Text.Encoding.GetEncoding("shift_jis"));
34
34
 
35
35
  internal float output;
36
36
 
37
- void Start () {
37
+ void Start()
38
+
39
+ {
38
40
 
39
41
  index = 0;
40
42
 
41
43
  count = 0;
42
44
 
43
- using(StreamWriter file = new StreamWriter("hakei.csv", false, System.Text.Encoding.GetEncoding("shift_jis")))
45
+
44
46
 
45
47
  }
46
48
 
47
-
48
49
 
49
- // Update is called once per frame
50
50
 
51
+ // Update is called once per frame
52
+
51
- void Update () {
53
+ void Update()
54
+
55
+ {
52
56
 
53
57
  AudioListener.GetOutputData(data, channel);
54
58
 
55
- file.WriteLine(data);
59
+ sw.WriteLine(data);
56
60
 
57
61
  }
58
62
 
59
63
  }
60
64
 
65
+
66
+
61
- を変更すればいいでしょ
67
+ このままだと以下のよなエラーが出ます
68
+
69
+ IOException: Sharing violation on path C:\data\test.txt
70
+
71
+ CSVmaker..ctor () (at Assets/CSVmaker.cs:14)
72
+
73
+
74
+
75
+ NullReferenceException: Object reference not set to an instance of an object
76
+
77
+ CSVmaker.Update () (at Assets/CSVmaker.cs:36)
78
+
79
+
80
+
81
+ エラーの意味をググってみたのですがよくわかりませんでした
82
+
83
+ ファイルの指定先のtest.txtは作成済みです

1

プログラムの提示

2018/12/07 04:57

投稿

yosugi
yosugi

スコア18

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