Skip to content

Commit

Permalink
+ Implemented Wave Encoder.
Browse files Browse the repository at this point in the history
  • Loading branch information
MineCake147E committed Mar 12, 2021
1 parent 39cf50d commit fc16613
Show file tree
Hide file tree
Showing 56 changed files with 4,905 additions and 340 deletions.
6 changes: 6 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -283,3 +283,9 @@ dotnet_naming_style.asyncで終わる.required_prefix =
dotnet_naming_style.asyncで終わる.required_suffix = Async
dotnet_naming_style.asyncで終わる.word_separator =
dotnet_naming_style.asyncで終わる.capitalization = pascal_case

# CS1591: 公開されている型またはメンバーの XML コメントがありません
dotnet_diagnostic.CS1591.severity = error

# CS1998: 非同期メソッドは、'await' 演算子がないため、同期的に実行されます
dotnet_diagnostic.CS1998.severity = suggestion
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ bld/
[Bb]in/
[Oo]bj/
[Ll]og/
[Tt]est[Rr]esult/

# Visual Studio 2015/2017 cache/options directory
.vs/
Expand Down
3 changes: 2 additions & 1 deletion Shamisen/Codecs/CodecUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@
using System.IO;
using System.Text;
using System.Threading.Tasks;

using Shamisen.Data;

namespace Shamisen.Codecs
{
/// <summary>
/// Provides some utility functions for <see cref="IEncoder"/> and <see cref="IDecoder"/>.
/// Provides some utility functions for <see cref="IEncoder{TEncodingOptions}"/> and <see cref="IDecoder"/>.
/// </summary>
public static class CodecUtils
{
Expand Down
32 changes: 32 additions & 0 deletions Shamisen/Codecs/Composing/IComposable.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Shamisen.Codecs.Composing
{
/// <summary>
/// Defines a base infrastructure of a composable object.
/// </summary>
public interface IComposable
{
/// <summary>
/// Writes this <see cref="IComposable"/> instance to <see cref="IDataSink{TSample}"/>.
/// </summary>
/// <param name="sink">The sink.</param>
void WriteTo(IDataSink<byte> sink);
}

/// <summary>
/// Defines a base infrastructure of an asynchronously composable object.
/// </summary>
public interface IAsyncComposable
{
/// <summary>
/// Writes this <see cref="IComparable"/> instance to <see cref="IDataSink{TSample}"/>.
/// </summary>
/// <param name="sink">The sink.</param>
ValueTask WriteTo(IDataSink<byte> sink);
}
}
34 changes: 34 additions & 0 deletions Shamisen/Codecs/IComposer.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Threading.Tasks;

namespace Shamisen.Codecs
{
/// <summary>
/// Defines a base infrastructure of an instance of encoder.
/// </summary>
public interface IComposer<TSample, TFormat> : IDisposable
where TSample : unmanaged
where TFormat : IAudioFormat<TSample>
{
/// <summary>
/// Gets the frames written to the <see cref="IDataSink{TSample}"/>.
/// </summary>
/// <value>
/// The frames written.
/// </value>
ulong FramesWritten { get; }

/// <summary>
/// Gets the theoretical maximum capacity of the codec.<br/>
/// The <see langword="null"/> means the codec doesn't have any limitation of size.
/// </summary>
/// <value>
/// The theoretical maximum capacity of the file format.
/// </value>
BigInteger? TheoreticalMaxCapacity { get; }
}
}
57 changes: 28 additions & 29 deletions Shamisen/Codecs/IEncoder.cs
Original file line number Diff line number Diff line change
@@ -1,53 +1,52 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Shamisen.Codecs
{
/// <summary>
/// Defines a base infrastructure of an audio encoder.
/// Defines a base infrastructure of an audio encoder that handles <see cref="IReadableAudioSource{TSample, TFormat}"/> and <see cref="ISampleSource"/>.
/// </summary>
public interface IEncoder
public interface IEncoder<TSample, TFormat, TEncodingOptions> : ISampleEncoder<TEncodingOptions>
where TEncodingOptions : struct
where TSample : unmanaged
where TFormat : IAudioFormat<TSample>
{
/// <summary>
/// Determines whether the <paramref name="format"/> can be encoded by this codec.
/// Determines whether the <paramref name="source"/> can be encoded to <paramref name="sink"/> by this codec.
/// </summary>
/// <param name="format">The input data's format.</param>
/// <returns><c>true</c> if the <paramref name="format"/> can be supported by this encoder, otherwise, <c>false</c>.</returns>
bool IsEncodable(WaveFormat format);
/// <param name="source">The <see cref="IReadableAudioSource{TSample, TFormat}"/> to read the data to encode from.</param>
/// <param name="sink">The destination.</param>
/// <param name="options">The encoding options.</param>
/// <returns><c>true</c> if the <paramref name="source"/> is supported by this encoder and <paramref name="sink"/> meets the requirement of encoding, otherwise, <c>false</c>.</returns>
bool IsEncodable(IReadableAudioSource<TSample, TFormat> source, IDataSink<byte> sink, TEncodingOptions options = default);

/// <summary>
/// Encodes <paramref name="source"/> with the given <paramref name="writeAction"/>.
/// Determines whether the <paramref name="source"/> can be encoded to <paramref name="sink"/> by this codec.
/// </summary>
/// <param name="source">The <see cref="IWaveSource"/> to read the data to encode from.</param>
/// <param name="writeAction">The destination.</param>
void Encode(IWaveSource source, WriteAction<byte> writeAction);
/// <param name="source">The <see cref="IAsyncReadableAudioSource{TSample, TFormat}"/> to read the data to encode from.</param>
/// <param name="sink">The destination.</param>
/// <param name="options">The encoding options.</param>
/// <returns><c>true</c> if the <paramref name="source"/> is supported by this encoder and <paramref name="sink"/> meets the requirement of encoding, otherwise, <c>false</c>.</returns>
ValueTask<bool> IsEncodableAsync(IAsyncReadableAudioSource<TSample, TFormat> source, IDataSink<byte> sink, TEncodingOptions options = default);

/// <summary>
/// Encodes <paramref name="source"/> with the given <paramref name="writeAction"/>.
/// Encodes <paramref name="source"/> to the specified <paramref name="sink"/>.
/// </summary>
/// <param name="source">The <see cref="IWaveSource"/> to read the data to encode from.</param>
/// <param name="parameter">The <typeparamref name="TParam"/> value to call the <paramref name="writeAction"/> with.</param>
/// <param name="writeAction">The destination.</param>
void Encode<TParam>(IWaveSource source, TParam parameter, WriteWithParameterAction<byte, TParam> writeAction);
/// <param name="source">The <see cref="IReadableAudioSource{TSample, TFormat}"/> to read the data to encode from.</param>
/// <param name="sink">The destination.</param>
/// <param name="options">The encoding options.</param>
void Encode(IReadableAudioSource<TSample, TFormat> source, IDataSink<byte> sink, TEncodingOptions options = default);

/// <summary>
/// Encodes <paramref name="source"/> with the given <paramref name="writeAsyncFunc"/> asynchronously.
/// Encodes <paramref name="source"/> to the specified <paramref name="sink"/> asynchronously.
/// </summary>
/// <param name="source">The <see cref="IAsyncWaveSource"/> to read the data to encode from.</param>
/// <param name="writeAsyncFunc">The destination.</param>
/// <param name="source">The <see cref="IAsyncReadableAudioSource{TSample, TFormat}"/> to read the data to encode from.</param>
/// <param name="sink">The destination.</param>
/// <param name="options">The encoding options.</param>
/// <returns>The whole encoding task.</returns>
Task EncodeAsync(IAsyncWaveSource source, WriteAsyncFunc<byte> writeAsyncFunc);

/// <summary>
/// Encodes <paramref name="source"/> with the given <paramref name="writeAsyncFunc"/> asynchronously.
/// </summary>
/// <param name="source">The <see cref="IAsyncWaveSource"/> to read the data to encode from.</param>
/// <param name="parameter">The <typeparamref name="TParam"/> value to call the <paramref name="writeAsyncFunc"/> with.</param>
/// <param name="writeAsyncFunc">The destination.</param>
/// <returns>The whole encoding task.</returns>
Task EncodeAsync<TParam>(IAsyncWaveSource source, TParam parameter, WriteAsyncFunc<byte> writeAsyncFunc);
ValueTask EncodeAsync(IAsyncReadableAudioSource<TSample, TFormat> source, IDataSink<byte> sink, TEncodingOptions options = default);
}
}
49 changes: 49 additions & 0 deletions Shamisen/Codecs/ISampleEncoder.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Shamisen.Codecs
{
/// <summary>
/// Defines a base infrastructure of an audio encoder that handles <see cref="ISampleSource"/>.
/// </summary>
public interface ISampleEncoder<TEncodingOptions> where TEncodingOptions : struct
{
/// <summary>
/// Determines whether the <paramref name="source"/> can be encoded to <paramref name="sink"/> by this codec.
/// </summary>
/// <param name="source">The <see cref="ISampleSource"/> to read the data to encode from.</param>
/// <param name="sink">The destination.</param>
/// <param name="options">The encoding options.</param>
/// <returns><c>true</c> if the <paramref name="source"/> is supported by this encoder and <paramref name="sink"/> meets the requirement of encoding, otherwise, <c>false</c>.</returns>
bool IsEncodable(ISampleSource source, IDataSink<byte> sink, TEncodingOptions options = default);

/// <summary>
/// Determines whether the <paramref name="source"/> can be encoded to <paramref name="sink"/> by this codec.
/// </summary>
/// <param name="source">The <see cref="IAsyncSampleSource"/> to read the data to encode from.</param>
/// <param name="sink">The destination.</param>
/// <param name="options">The encoding options.</param>
/// <returns><c>true</c> if the <paramref name="source"/> is supported by this encoder and <paramref name="sink"/> meets the requirement of encoding, otherwise, <c>false</c>.</returns>
ValueTask<bool> IsEncodableAsync(IAsyncSampleSource source, IDataSink<byte> sink, TEncodingOptions options = default);

/// <summary>
/// Encodes <paramref name="source"/> to the specified <paramref name="sink"/>.
/// </summary>
/// <param name="source">The <see cref="ISampleSource"/> to read the data to encode from.</param>
/// <param name="sink">The destination.</param>
/// <param name="options">The encoding options.</param>
void Encode(ISampleSource source, IDataSink<byte> sink, TEncodingOptions options = default);

/// <summary>
/// Encodes <paramref name="source"/> to the specified <paramref name="sink"/> asynchronously.
/// </summary>
/// <param name="source">The <see cref="IAsyncSampleSource"/> to read the data to encode from.</param>
/// <param name="sink">The destination.</param>
/// <param name="options">The encoding options.</param>
/// <returns>The whole encoding task.</returns>
ValueTask EncodeAsync(IAsyncSampleSource source, IDataSink<byte> sink, TEncodingOptions options = default);
}
}
50 changes: 50 additions & 0 deletions Shamisen/Codecs/IWaveEncoder.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using System.Threading.Tasks;

namespace Shamisen.Codecs
{
/// <summary>
/// Defines a base infrastructure of an <see cref="IWaveSource"/> encoder.
/// </summary>
public interface IWaveEncoder<TEncodingOptions> : IEncoder<byte, IWaveFormat, TEncodingOptions>
where TEncodingOptions : struct
{
/// <summary>
/// Determines whether the <paramref name="source"/> can be encoded to <paramref name="sink"/> by this codec.
/// </summary>
/// <param name="source">The <see cref="IWaveSource"/> to read the data to encode from.</param>
/// <param name="sink">The destination.</param>
/// <param name="options">The encoding options.</param>
/// <returns><c>true</c> if the <paramref name="source"/> is supported by this encoder and <paramref name="sink"/> meets the requirement of encoding, otherwise, <c>false</c>.</returns>
bool IsEncodable(IWaveSource source, IDataSink<byte> sink, TEncodingOptions options = default);

/// <summary>
/// Determines whether the <paramref name="source"/> can be encoded to <paramref name="sink"/> by this codec.
/// </summary>
/// <param name="source">The <see cref="IAsyncWaveSource"/> to read the data to encode from.</param>
/// <param name="sink">The destination.</param>
/// <param name="options">The encoding options.</param>
/// <returns><c>true</c> if the <paramref name="source"/> is supported by this encoder and <paramref name="sink"/> meets the requirement of encoding, otherwise, <c>false</c>.</returns>
ValueTask<bool> IsEncodableAsync(IAsyncWaveSource source, IDataSink<byte> sink, TEncodingOptions options = default);

/// <summary>
/// Encodes <paramref name="source"/> to the specified <paramref name="sink"/>.
/// </summary>
/// <param name="source">The <see cref="IWaveSource"/> to read the data to encode from.</param>
/// <param name="sink">The destination.</param>
/// <param name="options">The encoding options.</param>
void Encode(IWaveSource source, IDataSink<byte> sink, TEncodingOptions options = default);

/// <summary>
/// Encodes <paramref name="source"/> to the specified <paramref name="sink"/> asynchronously.
/// </summary>
/// <param name="source">The <see cref="IAsyncWaveSource"/> to read the data to encode from.</param>
/// <param name="sink">The destination.</param>
/// <param name="options">The encoding options.</param>
/// <returns>The whole encoding task.</returns>
ValueTask EncodeAsync(IAsyncWaveSource source, IDataSink<byte> sink, TEncodingOptions options = default);
}
}
Loading

0 comments on commit fc16613

Please sign in to comment.