Skip to content
This repository has been archived by the owner on Jan 15, 2023. It is now read-only.

Commit

Permalink
Klassediagrammer, StyleCop analyzer, og har tilføjet kommentarer til …
Browse files Browse the repository at this point in the history
…hele Aud.IO.
  • Loading branch information
krestenlaust committed Dec 20, 2021
1 parent 339eac2 commit 6b4c882
Show file tree
Hide file tree
Showing 14 changed files with 258 additions and 53 deletions.
4 changes: 4 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[*.cs]

# SA1101: Prefix local calls with this
dotnet_diagnostic.SA1101.severity = silent
60 changes: 60 additions & 0 deletions Aud.IO/Aud.IO.ClassDiagram.cd
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<?xml version="1.0" encoding="utf-8"?>
<ClassDiagram MajorVersion="1" MinorVersion="1">
<Class Name="Aud.IO.Exceptions.MissingSubchunkException" Collapsed="true">
<Position X="1.25" Y="4.5" Width="1.5" />
<TypeIdentifier>
<HashCode>AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=</HashCode>
<FileName>Exceptions\MissingSubchunkException.cs</FileName>
</TypeIdentifier>
</Class>
<Class Name="Aud.IO.Exceptions.UnknownFileFormatDescriptorException" Collapsed="true">
<Position X="3" Y="4.5" Width="1.5" />
<TypeIdentifier>
<HashCode>AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=</HashCode>
<FileName>Exceptions\UnknownFileFormatDescriptorException.cs</FileName>
</TypeIdentifier>
</Class>
<Class Name="Aud.IO.Exceptions.UnknownFileFormatException" Collapsed="true">
<Position X="1.25" Y="3.5" Width="1.5" />
<TypeIdentifier>
<HashCode>AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=</HashCode>
<FileName>Exceptions\UnknownFileFormatException.cs</FileName>
</TypeIdentifier>
</Class>
<Class Name="Aud.IO.Formats.WaveFile">
<Position X="3" Y="0.5" Width="1.5" />
<TypeIdentifier>
<HashCode>BAAAAAABQAAAAAAAgAEAAAAAAABAAgQgAAAAAAAAAAA=</HashCode>
<FileName>Formats\WaveFile.cs</FileName>
</TypeIdentifier>
</Class>
<Class Name="Aud.IO.AudioFile">
<Position X="1.25" Y="0.5" Width="1.5" />
<TypeIdentifier>
<HashCode>BAAAAAAAQAAAAAAAgAAAAAAAAABAAgQgAAAAAAAAAAA=</HashCode>
<FileName>AudioFile.cs</FileName>
</TypeIdentifier>
</Class>
<Struct Name="Aud.IO.Formats.WaveStructure">
<Position X="4.75" Y="0.5" Width="1.5" />
<TypeIdentifier>
<HashCode>AAAAAAAACAAAAAAEIAAAAAAAAAgAAAAAAAAAAAAEAAA=</HashCode>
<FileName>Formats\WaveStructure.cs</FileName>
</TypeIdentifier>
</Struct>
<Struct Name="Aud.IO.Formats.FormatSubchunk">
<Position X="6.5" Y="0.5" Width="1.5" />
<TypeIdentifier>
<HashCode>BAAAAAAAAAAAgAAgAAAAAAAAACABAgAAAAAAAAAACAA=</HashCode>
<FileName>Formats\WaveStructure.cs</FileName>
</TypeIdentifier>
</Struct>
<Struct Name="Aud.IO.Formats.DataSubchunk">
<Position X="4.75" Y="3.5" Width="1.5" />
<TypeIdentifier>
<HashCode>AAAAAAAAAAAAgAAAAAAAAAAAAAAAABAAAAAAAAAAAAA=</HashCode>
<FileName>Formats\WaveStructure.cs</FileName>
</TypeIdentifier>
</Struct>
<Font Name="Segoe UI" Size="9" />
</ClassDiagram>
4 changes: 4 additions & 0 deletions Aud.IO/Aud.IO.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="StyleCop.Analyzers" Version="1.2.0-beta.376">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="System.Memory" Version="4.5.4" />
</ItemGroup>

Expand Down
33 changes: 24 additions & 9 deletions Aud.IO/AudioFile.cs
Original file line number Diff line number Diff line change
@@ -1,38 +1,53 @@
namespace Aud.IO
{
/// <summary>
/// An abstract class for implementing audio formats.
/// </summary>
public abstract class AudioFile
{
/// <summary>
/// Audio duration in seconds.
/// Initializes a new instance of the <see cref="AudioFile"/> class.
/// Constructor parameters to enforce design pattern.
/// </summary>
/// <param name="filePath">File to load.</param>
public AudioFile(string filePath) { }

/// <summary>
/// Gets audio duration in seconds.
/// </summary>
public abstract double AudioDuration { get; }

/// <summary>
/// The rate at which the audio is sampled.
/// Gets the rate at which the audio is sampled.
/// </summary>
public abstract uint SampleRate { get; }

/// <summary>
/// The amount of samples, (including all channels).
/// Gets the amount of samples, (including all channels).
/// </summary>
public abstract int Samples { get; }

/// <summary>
/// The amount of bits that store a single sample.
/// Gets the amount of bits that store a single sample.
/// </summary>
public abstract uint BitsPerSample { get; }

public AudioFile(string filePath) { }

/// <summary>
/// Writes the audio file to the specified file path (doesn't add extension).
/// </summary>
/// <param name="filePath">The file to load.</param>
public abstract void WriteAudioFile(string filePath);

/// <summary>
/// Returns the audio data in analog (demodulated from LPCM).
/// </summary>
/// <returns></returns>
/// <returns>LPCM demodulated audio.</returns>
public abstract double[] GetDemodulatedAudio();

/// <summary>
/// Set audio by audio data not modulated using LPCM.
/// Sets audio by audio data not modulated using LPCM.
/// </summary>
/// <param name="audio"></param>
/// <param name="audio">LPCM modulated audio.</param>
public abstract void SetDemodulatedAudio(double[] audio);
}
}
9 changes: 4 additions & 5 deletions Aud.IO/Exceptions/MissingSubchunkException.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
using System;

namespace Aud.IO.Exceptions
namespace Aud.IO.Exceptions
{
public class MissingSubchunkException : Exception
public class MissingSubchunkException : System.Exception
{
public MissingSubchunkException(string message) : base(message) { }
public MissingSubchunkException(string message)
: base(message) { }
}
}
9 changes: 4 additions & 5 deletions Aud.IO/Exceptions/UnknownFileFormatDescriptorException.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
using System;

namespace Aud.IO.Exceptions
namespace Aud.IO.Exceptions
{
public class UnknownFileFormatDescriptorException : Exception
public class UnknownFileFormatDescriptorException : System.Exception
{
public UnknownFileFormatDescriptorException(string message) : base(message) { }
public UnknownFileFormatDescriptorException(string message)
: base(message) { }
}
}
12 changes: 7 additions & 5 deletions Aud.IO/Exceptions/UnknownFileFormatException.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
using System;

namespace Aud.IO.Exceptions
namespace Aud.IO.Exceptions
{
public class UnknownFileFormatException : Exception
/// <summary>
/// Exception thrown when the file format declared in the file is unexpected.
/// </summary>
public class UnknownFileFormatException : System.Exception
{
public UnknownFileFormatException(string message) : base(message) { }
public UnknownFileFormatException(string message)
: base(message) { }
}
}
39 changes: 26 additions & 13 deletions Aud.IO/Formats/WaveFile.cs
Original file line number Diff line number Diff line change
@@ -1,34 +1,29 @@
using System;
using System.IO;
using System.Runtime.InteropServices;
using System.Text;
using Aud.IO.Exceptions;

namespace Aud.IO.Formats
{
/// <summary>
/// Wave fil formatet lavet til at følge standarden.
/// </summary>
public class WaveFile : AudioFile
{
/// <inheritdoc/>
public override uint SampleRate => waveData.Subchunk1.SampleRate;
/// <inheritdoc/>
public override uint BitsPerSample => waveData.Subchunk1.BitsPerSample;
/// <inheritdoc/>
public override int Samples => waveData.Subchunk2.Data.Length / (int)(BitsPerSample / 8);
/// <inheritdoc/>
public override double AudioDuration => (Samples / waveData.Subchunk1.NumChannels) / (double)SampleRate;

private WaveStructure waveData;

/// <summary>
/// Initializes a new instance of the <see cref="WaveFile"/> class.
/// Læser og behandler lydfilen.
/// </summary>
/// <param name="filePath"></param>
/// <param name="filePath">Non-null string containing path to wavefile.</param>
/// <exception cref="ArgumentNullException">filePath er null.</exception>
/// <exception cref="FileNotFoundException">Filen blev ikke fundet.</exception>
/// <exception cref="UnknownFileFormatDescriptorException">Filens chunk ID var ikke 'RIFF'.</exception>
/// <exception cref="UnknownFileFormatException">Filens format ID var ikke 'WAVE'.</exception>
/// <exception cref="MissingSubchunkException">Filen indeholder ikke alle de nødvendige subchunks.</exception>
public WaveFile(string filePath) : base(filePath)
public WaveFile(string filePath)
: base(filePath)
{
if (filePath is null)
{
Expand Down Expand Up @@ -78,7 +73,7 @@ public WaveFile(string filePath) : base(filePath)
switch (subchunkID)
{
case "fmt ":
byte[] formatSubchunkBytes = new byte[sizeof(ushort) * 4 + sizeof(uint) * 2];
byte[] formatSubchunkBytes = new byte[(sizeof(ushort) * 4) + (sizeof(uint) * 2)];
stream.Read(formatSubchunkBytes, 0, formatSubchunkBytes.Length);

formatSubchunk = new FormatSubchunk(
Expand All @@ -95,6 +90,7 @@ public WaveFile(string filePath) : base(filePath)
// Spring over dem.
stream.Seek(subchunkSize - formatSubchunkBytes.Length, SeekOrigin.Current);
}

break;
case "data":
byte[] dataSubchunkBytes = new byte[subchunkSize];
Expand Down Expand Up @@ -123,6 +119,22 @@ public WaveFile(string filePath) : base(filePath)
}
}

/// <inheritdoc/>
public override uint SampleRate => waveData.Subchunk1.SampleRate;

/// <inheritdoc/>
public override uint BitsPerSample => waveData.Subchunk1.BitsPerSample;

/// <inheritdoc/>
public override int Samples => waveData.Subchunk2.Data.Length / (int)(BitsPerSample / 8);

/// <inheritdoc/>
public override double AudioDuration => (Samples / waveData.Subchunk1.NumChannels) / (double)SampleRate;

/// <summary>
/// Returnerer den struktur wave-filen er gemt i.
/// </summary>
/// <returns>Returnerer værdi-type.</returns>
public WaveStructure GetWaveData() => waveData;

/// <inheritdoc/>
Expand Down Expand Up @@ -164,6 +176,7 @@ public override void SetDemodulatedAudio(double[] audio)
waveData = new WaveStructure(waveData.Subchunk1.NumChannels, waveData.Subchunk1.SampleRate, waveData.Subchunk1.BitsPerSample, audioBytes);
}

/// <inheritdoc/>
public override void WriteAudioFile(string filePath)
{
if (filePath is null)
Expand Down
Loading

0 comments on commit 6b4c882

Please sign in to comment.