Skip to content

Commit

Permalink
com.utilities.encoder.wav 2.0.1 (#23)
Browse files Browse the repository at this point in the history
- fixed missing reference exception when cancelling streaming
- com.utilities.audio -> 2.0.2
  • Loading branch information
StephenHodgson authored Nov 14, 2024
1 parent ff50972 commit d5b902e
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 14 deletions.
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

0 comments on commit d5b902e

Please sign in to comment.