Skip to content

Commit b24a1fb

Browse files
author
Stephen Hodgson
committed
Cleaned up MicStreamDemo so it supports better editor testing.
1 parent 442fa6b commit b24a1fb

File tree

1 file changed

+12
-29
lines changed

1 file changed

+12
-29
lines changed

Assets/HoloToolkit/Input/Tests/Scripts/MicStreamDemo.cs

Lines changed: 12 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,7 @@
11
// Copyright (c) Microsoft Corporation. All rights reserved.
22
// Licensed under the MIT License. See LICENSE in the project root for license information.
33

4-
using System;
5-
using System.Collections;
6-
using System.Collections.Generic;
7-
using System.Runtime.CompilerServices;
8-
using System.Runtime.InteropServices;
9-
using System.Threading;
104
using UnityEngine;
11-
using UnityEngine.UI;
12-
using UnityEngine.Assertions;
13-
using System.Text;
145

156
namespace HoloToolkit.Unity.InputModule.Tests
167
{
@@ -31,7 +22,7 @@ public class MicStreamDemo : MonoBehaviour
3122
/// if keepAllData==false, you'll always get the newest data no matter how long the program hangs for any reason, but will lose some data if the program does hang
3223
/// can only be set on initialization
3324
/// </summary>
34-
public bool KeepAllData = false;
25+
public bool KeepAllData;
3526

3627
/// <summary>
3728
/// Should the mic stream start automatically when this component is enabled?
@@ -51,7 +42,7 @@ public class MicStreamDemo : MonoBehaviour
5142
/// <summary>
5243
/// Records estimation of volume from the microphone to affect other elements of the game object
5344
/// </summary>
54-
private float averageAmplitude = 0;
45+
private float averageAmplitude;
5546

5647
/// <summary>
5748
/// how small can our object be in this demo?
@@ -64,8 +55,9 @@ private void OnAudioFilterRead(float[] buffer, int numChannels)
6455
CheckForErrorOnCall(MicStream.MicGetFrame(buffer, buffer.Length, numChannels));
6556

6657
float sumOfValues = 0;
58+
6759
// figure out the average amplitude from this new data
68-
for (int i=0; i<buffer.Length; i++)
60+
for (int i = 0; i < buffer.Length; i++)
6961
{
7062
sumOfValues += Mathf.Abs(buffer[i]);
7163
}
@@ -79,7 +71,7 @@ private void Awake()
7971

8072
if (!ListenToAudioSource)
8173
{
82-
this.gameObject.GetComponent<AudioSource>().volume = 0; // can set to zero to mute mic monitoring
74+
gameObject.GetComponent<AudioSource>().volume = 0; // can set to zero to mute mic monitoring
8375
}
8476

8577
if (AutomaticallyStartStream)
@@ -122,42 +114,33 @@ private void Update()
122114
CheckForErrorOnCall(MicStream.MicStopStream());
123115
}
124116

125-
this.gameObject.transform.localScale = new Vector3(minSize + averageAmplitude, minSize + averageAmplitude, minSize + averageAmplitude);
117+
gameObject.transform.localScale = new Vector3(minSize + averageAmplitude, minSize + averageAmplitude, minSize + averageAmplitude);
126118
}
127119

128-
private void CheckForErrorOnCall(int returnCode)
120+
private static void CheckForErrorOnCall(int returnCode)
129121
{
130122
MicStream.CheckForErrorOnCall(returnCode);
131123
}
132124

133-
#if DOTNET_FX
134-
// on device, deal with all the ways that we could suspend our program in as few lines as possible
125+
// Deal with all the ways that we could suspend our program in as few lines as possible
135126
private void OnApplicationPause(bool pause)
136127
{
137-
if (pause)
138-
{
139-
CheckForErrorOnCall(MicStream.MicPause());
140-
}
141-
else
142-
{
143-
CheckForErrorOnCall(MicStream.MicResume());
144-
}
128+
CheckForErrorOnCall(pause ? MicStream.MicPause() : MicStream.MicResume());
145129
}
146130

147131
private void OnApplicationFocus(bool focused)
148132
{
149-
this.OnApplicationPause(!focused);
133+
OnApplicationPause(!focused);
150134
}
151135

152136
private void OnDisable()
153137
{
154-
this.OnApplicationPause(true);
138+
OnApplicationPause(true);
155139
}
156140

157141
private void OnEnable()
158142
{
159-
this.OnApplicationPause(false);
143+
OnApplicationPause(false);
160144
}
161-
#endif
162145
}
163146
}

0 commit comments

Comments
 (0)