Skip to content

Commit

Permalink
com.utilities.encoder.wav 2.0.2
Browse files Browse the repository at this point in the history
- added WavEncoder.WriteToFileAsync
  • Loading branch information
StephenHodgson committed Nov 25, 2024
1 parent d5b902e commit d8368e0
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ public async Task<Tuple<string, AudioClip>> StreamSaveToDiskAsync(ClipData clipD

var outputPath = string.Empty;
RecordingManager.IsProcessing = true;
Tuple<string, AudioClip> result = null;
Tuple<string, AudioClip> result;

try
{
Expand Down Expand Up @@ -252,6 +252,25 @@ public async Task<Tuple<string, AudioClip>> StreamSaveToDiskAsync(ClipData clipD
return result;
}

[Preserve]
public static async Task WriteToFileAsync(string path, byte[] pcmData, int channels, int sampleRate, PCMFormatSize bitDepth = PCMFormatSize.SixteenBit, CancellationToken cancellationToken = default)
{
try
{
await Awaiters.BackgroundThread;
var bitsPerSample = 8 * (int)bitDepth;
await using var fileStream = new FileStream(path, FileMode.Create, FileAccess.Write, FileShare.None, 4096, true);
await using var writer = new BinaryWriter(fileStream);
WriteWavHeader(writer, channels, sampleRate, bitsPerSample, pcmData.Length);
writer.Write(pcmData);
writer.Flush();
}
catch (Exception e)
{
Debug.LogException(e);
}
}

private static async Task<(float[], int)> InternalStreamRecordAsync(ClipData clipData, float[] finalSamples, Func<ReadOnlyMemory<byte>, Task> bufferCallback, CancellationToken cancellationToken)
{
try
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.1",
"version": "2.0.2",
"unity": "2021.3",
"documentationUrl": "https://github.com/RageAgainstThePixel/com.utilities.encoder.wav#documentation",
"changelogUrl": "https://github.com/RageAgainstThePixel/com.utilities.encoder.wav/releases",
Expand Down

0 comments on commit d8368e0

Please sign in to comment.