Skip to content

Commit

Permalink
Added an interface for Recording.
Browse files Browse the repository at this point in the history
  • Loading branch information
MineCake147E committed Jul 6, 2019
1 parent abfd411 commit 732f381
Show file tree
Hide file tree
Showing 11 changed files with 197 additions and 6 deletions.
49 changes: 49 additions & 0 deletions MonoAudio.Core/IO/DataAvailableEventArgs.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
using System;
using System.Collections.Generic;
using System.Text;
using MonoAudio.Formats;

namespace MonoAudio.IO
{
/// <summary>
/// Represents an event handler that holds recorded audio data.
/// </summary>
/// <param name="sender">The sender.</param>
/// <param name="e">The <see cref="DataAvailableEventArgs"/> instance containing the event data.</param>
public delegate void DataAvailableEventHandler(object sender, DataAvailableEventArgs e);

/// <summary>
/// Represents an event arguments that holds recorded audio data.<br/>
/// It is a <c>struct</c> which has <c>ref</c> and <c>readonly</c> modifier because the event occurs frequently and has a <see cref="Span{T}"/> to deliver a raw buffer.<br/>
/// <b>CAUTION! REF STRUCT! IT CANNOT BE STORED ON HEAPS!</b>
/// </summary>
public readonly ref struct DataAvailableEventArgs
{
/// <summary>
/// Initializes a new instance of the <see cref="DataAvailableEventArgs" /> struct.
/// </summary>
/// <param name="data">The data.</param>
/// <param name="format">The format.</param>
public DataAvailableEventArgs(Span<byte> data, WaveFormat format)
{
Data = data;
Format = format;
}

/// <summary>
/// Gets the data.
/// </summary>
/// <value>
/// The data.
/// </value>
public Span<byte> Data { get; }

/// <summary>
/// Gets the format of the available <see cref="Data"/>.
/// </summary>
/// <value>
/// The format.
/// </value>
public WaveFormat Format { get; }
}
}
47 changes: 47 additions & 0 deletions MonoAudio.Core/IO/ISoundIn.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
using System;
using System.Collections.Generic;
using System.Text;
using MonoAudio.Formats;

namespace MonoAudio.IO
{
/// <summary>
/// Defines a base infrastructure of a sound input.<br/>
/// CAUTION! IT HAS SOME EVENT HANDLERS! IMPLEMENTERS MUST NOT FORGET TO RELEASE THEM!
/// </summary>
public interface ISoundIn : IDisposable
{
/// <summary>
/// Occurs when some data are available.
/// </summary>
event DataAvailableEventHandler DataAvailable;

/// <summary>
/// Occurs when the recording stopped.
/// </summary>
event EventHandler<RecordingStoppedEventArgs> Stopped;

/// <summary>
/// Starts recording.
/// </summary>
void Start();

/// <summary>
/// Stops recording.
/// </summary>
void Stop();

/// <summary>
/// Initializes the recorder.
/// </summary>
void Initialize();

/// <summary>
/// Gets the state of the recording.
/// </summary>
/// <value>
/// The state of the recording.
/// </value>
RecordingState RecordingState { get; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
using System.Collections.Generic;
using System.Text;

namespace MonoAudio.IO.SoundOut
namespace MonoAudio.IO
{
/// <summary>
/// Defines a base infrastructure of a sound output.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace MonoAudio.IO.SoundOut
namespace MonoAudio.IO
{
/// <summary>
/// Represents a state of playback.
Expand Down
22 changes: 22 additions & 0 deletions MonoAudio.Core/IO/RecordingState.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using System;
using System.Collections.Generic;
using System.Text;

namespace MonoAudio.IO
{
/// <summary>
/// Represents a state of recording.
/// </summary>
public enum RecordingState
{
/// <summary>
/// The recording is stopped.
/// </summary>
Stopped,

/// <summary>
/// The recording is in progress.
/// </summary>
Recording
}
}
28 changes: 28 additions & 0 deletions MonoAudio.Core/IO/RecordingStoppedEventArgs.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using System;
using System.Collections.Generic;
using System.Text;

namespace MonoAudio.IO
{
/// <summary>
/// Represents an event arguments that tells you that the recording has (been) stopped and holds why.<br/>
/// </summary>
/// <seealso cref="StoppedEventArgs" />
public class RecordingStoppedEventArgs : StoppedEventArgs
{
/// <summary>
/// Initializes a new instance of the <see cref="RecordingStoppedEventArgs"/> class.
/// </summary>
public RecordingStoppedEventArgs() : this(null)
{
}

/// <summary>
/// Initializes a new instance of the <see cref="RecordingStoppedEventArgs"/> class.
/// </summary>
/// <param name="exception">The exception.</param>
public RecordingStoppedEventArgs(Exception exception) : base(exception)
{
}
}
}
45 changes: 45 additions & 0 deletions MonoAudio.Core/StoppedEventArgs.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
using System;
using System.Collections.Generic;
using System.Text;

namespace MonoAudio
{
/// <summary>
/// Represents an event arguments that tells you that something has (been) stopped and holds why.<br/>
/// </summary>
/// <seealso cref="EventArgs" />
public class StoppedEventArgs : EventArgs
{
/// <summary>
/// Initializes a new instance of the <see cref="StoppedEventArgs"/> class.
/// </summary>
public StoppedEventArgs() : this(null)
{
}

/// <summary>
/// Initializes a new instance of the <see cref="StoppedEventArgs"/> class.
/// </summary>
/// <param name="exception">The exception.</param>
public StoppedEventArgs(Exception exception)
{
Exception = exception;
}

/// <summary>
/// Gets the exception.
/// </summary>
/// <value>
/// The exception.
/// </value>
public Exception Exception { get; }

/// <summary>
/// Gets a value indicating whether this instance has error.
/// </summary>
/// <value>
/// <c>true</c> if this instance has error; otherwise, <c>false</c>.
/// </value>
public bool HasError => !(Exception is null);
}
}
2 changes: 1 addition & 1 deletion MonoAudio.UWP/SoundOut/AudioGraphOutput.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using MonoAudio.IO.SoundOut;
using MonoAudio.IO;
using Windows.Foundation;
using Windows.Media;
using Windows.Media.Audio;
Expand Down
2 changes: 1 addition & 1 deletion MonoAudio.Windows/SoundOut/CSCoreSoundOut.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
using System.Threading.Tasks;
using CSCore.SoundOut;
using MonoAudio.Interop;
using MonoAudio.IO.SoundOut;
using MonoAudio.IO;

namespace MonoAudio.SoundOut
{
Expand Down
2 changes: 1 addition & 1 deletion MonoAudio.Windows/SoundOut/PlaybackStateUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;
using MonoAudio.IO.SoundOut;
using MonoAudio.IO;

namespace MonoAudio.SoundOut
{
Expand Down
2 changes: 1 addition & 1 deletion Tests/MonoAudio.Output.Tests.UWP/MainPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
using MonoAudio.Formats;
using MonoAudio.Conversion.Resampling.Sample;
using MonoAudio.Conversion.SampleToWaveConverters;
using MonoAudio.IO.SoundOut;
using MonoAudio.IO;

// 空白ページの項目テンプレートについては、https://go.microsoft.com/fwlink/?LinkId=402352&clcid=0x411 を参照してください

Expand Down

0 comments on commit 732f381

Please sign in to comment.