4 using System.Runtime.InteropServices;
21 public enum StreamCategory { LOW_QUALITY_VOICE, HIGH_QUALITY_VOICE, ROOM_CAPTURE }
23 public enum ErrorCodes { ALREADY_RUNNING = -10, NO_AUDIO_DEVICE, NO_INPUT_DEVICE, ALREADY_RECORDING, GRAPH_NOT_EXIST, CHANNEL_COUNT_MISMATCH, FILE_CREATION_PERMISSION_ERROR, NOT_ENOUGH_DATA, NEED_ENABLED_MIC_CAPABILITY };
25 const int MAX_PATH = 260;
27 [UnmanagedFunctionPointer(CallingConvention.StdCall)]
28 public delegate
void LiveMicCallback();
35 [DllImport(
"MicStreamSelector", ExactSpelling =
true)]
36 public static extern int MicInitializeDefault(
int category);
44 [DllImport(
"MicStreamSelector", ExactSpelling =
true)]
45 public static extern int MicInitializeCustomRate(
int category,
int samplerate);
54 [DllImport(
"MicStreamSelector", ExactSpelling =
true)]
55 public static extern int MicStartStream(
bool keepData,
bool previewOnDevice, LiveMicCallback micsignal);
65 return MicStartStream(keepData, previewOnDevice, null);
72 [DllImport(
"MicStreamSelector", ExactSpelling =
true)]
73 public static extern int MicStopStream();
81 [DllImport(
"MicStreamSelector", ExactSpelling =
true)]
82 public static extern int MicStartRecording(
string filename,
bool previewOnDevice);
88 [DllImport(
"MicStreamSelector", ExactSpelling =
true)]
89 public static extern void MicStopRecording(StringBuilder sb);
97 StringBuilder builder =
new StringBuilder(MAX_PATH);
98 MicStopRecording(builder);
99 return builder.ToString();
106 [DllImport(
"MicStreamSelector", ExactSpelling =
true)]
107 public static extern int MicDestroy();
113 [DllImport(
"MicStreamSelector", ExactSpelling =
true)]
115 public static extern int MicPause();
121 [DllImport(
"MicStreamSelector", ExactSpelling =
true)]
122 public static extern int MicResume();
129 [DllImport(
"MicStreamSelector", ExactSpelling =
true)]
130 public static extern int MicSetGain(
float g);
136 [DllImport(
"MicStreamSelector", ExactSpelling =
true)]
137 private static extern int MicGetDefaultBufferSize();
143 [DllImport(
"MicStreamSelector", ExactSpelling =
true)]
144 private static extern int MicGetDefaultNumChannels();
153 [DllImport(
"MicStreamSelector", ExactSpelling =
true)]
154 public static extern int MicGetFrame(
float[] buffer,
int length,
int numchannels);
166 Debug.LogWarning(
"WARNING: Tried to start recording when you were already doing so. You need to stop your previous recording before you can start again.");
169 Debug.LogWarning(
"WARNING: Tried to initialize microphone more than once");
172 Debug.LogError(
"ERROR: Tried to do microphone things without a properly initialized microphone. \n Do you have a mic plugged into a functional audio system and did you call MicInitialize() before anything else ??");
175 Debug.LogError(
"ERROR: Tried to start microphone, but you don't appear to have a functional audio device. check your OS audio settings.");
178 Debug.LogError(
"ERROR: Tried to start microphone, but you don't have one plugged in, do you?");
181 Debug.LogError(
"ERROR: Microphone had a channel count mismatch internally on device. Try setting different mono/stereo options in OS mic settings.");
183 case (
int)
ErrorCodes.FILE_CREATION_PERMISSION_ERROR:
184 Debug.LogError(
"ERROR: Didn't have access to create file in Music library. Make sure permissions to write to Music library are set granted.");
189 case (
int)
ErrorCodes.NEED_ENABLED_MIC_CAPABILITY:
190 Debug.LogError(
"ERROR: Seems like you forgot to enable the microphone capabilities in your Unity permissions");