Skip to content

Commit c0e7f4c

Browse files
committed
v3.3.0: StreamedAudioSource improvements
Several improvements to StreamedAudioSource: - target latency for defining audio buffer duration - audio frame lifetime and expiration to prevent looping - audio pitch/speech manipulation to handle latency fluctuations - IsBuffering property re-added Deprecations: - Play and Stop methods. Audio will always be playing as long as there is buffered audio to play. It automatically stops when it's played all the audio. If you want to Stop playback, starve the instance instead of feeding it audio. - FrameCountForPlay. Target latency provides much more intuitive control over how much audio should be buffered before playback begins. Huge thanks to [Metater's MetaVoiceChat](https://github.com/Metater/MetaVoiceChat) repository and the helpful discussion we had on Discord! The MetaVoiceChat project does these things really well and made it really easy for me to refer and implement in UniMic. Also, added an asmdef for the samples.
1 parent 375ba75 commit c0e7f4c

File tree

5 files changed

+235
-197
lines changed

5 files changed

+235
-197
lines changed

Assets/UniMic/Runtime/MicAudioSource.cs

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -12,24 +12,14 @@ public Mic.Device Device {
1212
get => device;
1313
set {
1414
if (device != null) {
15-
device.OnStartRecording -= OnStartRecording;
1615
device.OnFrameCollected -= OnFrameCollected;
17-
device.OnStopRecording -= OnStopRecording;
1816
Debug.Log("Device removed from MicAudioSource", gameObject);
1917
}
20-
if(value != null) {
18+
if (value != null) {
2119
device = value;
22-
device.OnStartRecording += OnStartRecording;
2320
device.OnFrameCollected += OnFrameCollected;
24-
device.OnStopRecording += OnStopRecording;
25-
if (device.IsRecording)
26-
StreamedAudioSource.Play();
27-
else
28-
StreamedAudioSource.Stop();
2921
Debug.Log("MicAudioSource shifted to " + device.Name, gameObject);
3022
}
31-
else
32-
StreamedAudioSource.Stop();
3323
}
3424
}
3525

@@ -44,16 +34,8 @@ public StreamedAudioSource StreamedAudioSource {
4434
}
4535
}
4636

47-
void OnStartRecording() {
48-
StreamedAudioSource.Play();
49-
}
50-
5137
void OnFrameCollected(int frequency, int channels, float[] samples) {
5238
StreamedAudioSource.Feed(frequency, channels, samples);
5339
}
54-
55-
void OnStopRecording() {
56-
StreamedAudioSource.Stop();
57-
}
5840
}
5941
}

0 commit comments

Comments
 (0)