Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

com.utilities.encoder.wav 2.0.1 #23

Merged
merged 2 commits into from
Nov 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,16 @@ public async Task StreamRecordingAsync(ClipData clipData, Func<ReadOnlyMemory<by
}
catch (Exception e)
{
Debug.LogException(e);
switch (e)
{
case TaskCanceledException:
case OperationCanceledException:
// ignore
break;
default:
Debug.LogException(e);
break;
}
}
finally
{
Expand Down Expand Up @@ -151,8 +160,8 @@ public async Task<Tuple<string, AudioClip>> StreamSaveToDiskAsync(ClipData clipD
outStream = new MemoryStream();
}

int totalSampleCount;
var finalSamples = new float[clipData.MaxSamples];
var totalSampleCount = 0;
var finalSamples = new float[clipData.MaxSamples ?? clipData.SampleRate * RecordingManager.MaxRecordingLength];
var writer = new BinaryWriter(outStream);

try
Expand Down Expand Up @@ -194,10 +203,16 @@ public async Task<Tuple<string, AudioClip>> StreamSaveToDiskAsync(ClipData clipD
}
catch (Exception e)
{
Debug.LogError($"[{nameof(RecordingManager)}] Failed to record clip!\n{e}");
RecordingManager.IsRecording = false;
RecordingManager.IsProcessing = false;
return null;
switch (e)
{
case TaskCanceledException:
case OperationCanceledException:
// ignore
break;
default:
Debug.LogError($"[{nameof(RecordingManager)}] Failed to record clip!\n{e}");
break;
}
}
finally
{
Expand Down Expand Up @@ -225,10 +240,6 @@ public async Task<Tuple<string, AudioClip>> StreamSaveToDiskAsync(ClipData clipD
result = new Tuple<string, AudioClip>(outputPath, newClip);
callback?.Invoke(result);
}
catch (Exception e)
{
Debug.LogException(e);
}
finally
{
RecordingManager.IsProcessing = false;
Expand Down Expand Up @@ -282,6 +293,7 @@ public async Task<Tuple<string, AudioClip>> StreamSaveToDiskAsync(ClipData clipD

if (samplesToWrite > 0)
{
cancellationToken.ThrowIfCancellationRequested();
clipData.Clip.GetData(sampleBuffer, 0);

for (var i = 0; i < samplesToWrite; i++)
Expand Down Expand Up @@ -319,7 +331,7 @@ public async Task<Tuple<string, AudioClip>> StreamSaveToDiskAsync(ClipData clipD
}
}

if (sampleCount >= clipData.MaxSamples || cancellationToken.IsCancellationRequested)
if (clipData.MaxSamples.HasValue && sampleCount >= clipData.MaxSamples || cancellationToken.IsCancellationRequested)
{
if (RecordingManager.EnableDebug)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"displayName": "Utilities.Encoder.Wav",
"description": "Simple library for WAV encoding support.",
"keywords": [],
"version": "2.0.0",
"version": "2.0.1",
"unity": "2021.3",
"documentationUrl": "https://github.com/RageAgainstThePixel/com.utilities.encoder.wav#documentation",
"changelogUrl": "https://github.com/RageAgainstThePixel/com.utilities.encoder.wav/releases",
Expand All @@ -17,7 +17,7 @@
"url": "https://github.com/StephenHodgson"
},
"dependencies": {
"com.utilities.audio": "2.0.1"
"com.utilities.audio": "2.0.2"
},
"samples": [
{
Expand Down
Loading