Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix a bug of scale number #17

Merged
merged 1 commit into from
Mar 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 38 additions & 9 deletions src/SoundMaker/Sounds/Score/Note.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,43 @@ namespace SoundMaker.Sounds.Score;
/// </summary>
public class Note : BasicSoundComponentBase
{
private static readonly IReadOnlyDictionary<(Scale, int), double> _hertz = new Dictionary<(Scale, int), double>()
{
// A0 ~
{(Scale.A, 0), 27.500 },
{(Scale.ASharp, 0), 29.135 },
{(Scale.B, 0), 30.868 },
// C1 ~ C2 ~ C3 ~ C4 ~
{(Scale.C, 1), 32.703 }, {(Scale.C, 2), 65.406 }, {(Scale.C, 3), 130.813 }, {(Scale.C, 4), 261.626 },
{(Scale.CSharp, 1), 34.648 }, {(Scale.CSharp, 2), 69.296 }, {(Scale.CSharp, 3), 138.591 }, {(Scale.CSharp, 4), 277.183 },
{(Scale.D, 1), 36.708 }, {(Scale.D, 2), 73.416 }, {(Scale.D, 3), 146.832 }, {(Scale.D, 4), 293.665 },
{(Scale.DSharp, 1), 38.891 }, {(Scale.DSharp, 2), 77.782 }, {(Scale.DSharp, 3), 155.563 }, {(Scale.DSharp, 4), 311.127 },
{(Scale.E, 1), 41.203 }, {(Scale.E, 2), 82.407 }, {(Scale.E, 3), 164.814 }, {(Scale.E, 4), 329.628 },
{(Scale.F, 1), 43.654 }, {(Scale.F, 2), 87.307 }, {(Scale.F, 3), 174.614 }, {(Scale.F, 4), 349.228 },
{(Scale.FSharp, 1), 46.249 }, {(Scale.FSharp, 2), 92.499 }, {(Scale.FSharp, 3), 184.997 }, {(Scale.FSharp, 4), 369.994 },
{(Scale.G, 1), 48.999 }, {(Scale.G, 2), 97.999 }, {(Scale.G, 3), 195.998 }, {(Scale.G, 4), 391.995 },
{(Scale.GSharp, 1), 51.913 }, {(Scale.GSharp, 2), 103.826 }, {(Scale.GSharp, 3), 207.652 }, {(Scale.GSharp, 4), 415.305 },
{(Scale.A, 1), 55.000 }, {(Scale.A, 2), 110.000 }, {(Scale.A, 3), 220.000 }, {(Scale.A, 4), 440.000 },
{(Scale.ASharp, 1), 58.270 }, {(Scale.ASharp, 2), 116.541 }, {(Scale.ASharp, 3), 233.082 }, {(Scale.ASharp, 4), 466.164 },
{(Scale.B, 1), 61.735 }, {(Scale.B, 2), 123.471 }, {(Scale.B, 3), 246.942 }, {(Scale.B, 4), 493.883 },
// C5 ~ C6 ~ C7 ~
{(Scale.C, 5), 523.251 }, {(Scale.C, 6), 1046.502 }, {(Scale.C, 7), 2093.005 },
{(Scale.CSharp, 5), 554.365 }, {(Scale.CSharp, 6), 1108.731 }, {(Scale.CSharp, 7), 2217.461 },
{(Scale.D, 5), 587.330 }, {(Scale.D, 6), 1174.659 }, {(Scale.D, 7), 2349.318 },
{(Scale.DSharp, 5), 622.254 }, {(Scale.DSharp, 6), 1244.508 }, {(Scale.DSharp, 7), 2489.016 },
{(Scale.E, 5), 659.255 }, {(Scale.E, 6), 1318.510 }, {(Scale.E, 7), 2637.020 },
{(Scale.F, 5), 698.456 }, {(Scale.F, 6), 1396.913 }, {(Scale.F, 7), 2793.826 },
{(Scale.FSharp, 5), 739.989 }, {(Scale.FSharp, 6), 1479.978 }, {(Scale.FSharp, 7), 2959.955 },
{(Scale.G, 5), 783.991 }, {(Scale.G, 6), 1567.982 }, {(Scale.G, 7), 3135.963 },
{(Scale.GSharp, 5), 830.609 }, {(Scale.GSharp, 6), 1661.219 }, {(Scale.GSharp, 7), 3322.438 },
{(Scale.A, 5), 880.000 }, {(Scale.A, 6), 1760.000 }, {(Scale.A, 7), 3520.000 },
{(Scale.ASharp, 5), 932.328 }, {(Scale.ASharp, 6), 1864.655 }, {(Scale.ASharp, 7), 3729.310 },
{(Scale.B, 5), 987.767 }, {(Scale.B, 6), 1975.533 }, {(Scale.B, 7), 3951.066 },
// C8
{(Scale.C, 8), 4186.009 },
};


/// <summary>
/// constructor コンストラクタ
/// </summary>
Expand All @@ -18,15 +55,7 @@ public Note(Scale scale, int scaleNumber, LengthType length, bool isDotted = fal
: base(length, isDotted)
{
CheckArgument(scale, scaleNumber);
if ((int)scale >= 3)
{
scaleNumber--;
}
Hertz += AHertz[scaleNumber];
for (var i = 0; i < (int)scale; i++)
{
Hertz *= 1.059463094;
}
Hertz += _hertz[(scale, scaleNumber)];
Scale = scale;
ScaleNumber = scaleNumber;
}
Expand Down
2 changes: 1 addition & 1 deletion test/IntegrationTests/TestFormatBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public void TestToSoundFormat()
}

[Fact()]
public void TestToFormatChunc()
public void TestToFormatChunk()
{
var formatBuilder = FormatBuilder.Create()
.WithFrequency(48000)
Expand Down
10 changes: 6 additions & 4 deletions test/SoundMakerTests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@
<IsPackable>false</IsPackable>
</PropertyGroup>

<ItemGroup>
<Compile Remove="IntegrationTests\WaveFile\**" />
<EmbeddedResource Remove="IntegrationTests\WaveFile\**" />
<None Remove="IntegrationTests\WaveFile\**" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.1.0" />
<PackageReference Include="xunit" Version="2.4.1" />
Expand All @@ -21,10 +27,6 @@
</PackageReference>
</ItemGroup>

<ItemGroup>
<Folder Include="IntegrationTests\WaveFile\" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\src\SoundMaker\SoundMaker.csproj" />
</ItemGroup>
Expand Down
21 changes: 13 additions & 8 deletions test/UnitTests/Sounds/Score/TestNote.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,31 @@
namespace SoundMakerTests.UnitTests.Sounds.Score;
public class TestNote
{
[Fact(DisplayName = "初期化が正しく行えるかのテスト")]
public void InitializeTest()
[Theory(DisplayName = "初期化が正しく行えるかのテスト")]
[InlineData(Scale.A, 4, LengthType.Whole, true)]
[InlineData(Scale.C, 4, LengthType.SixtyFourth, true)]
public void InitializeTest(Scale scale, int scaleNumber, LengthType lengthType, bool isDotted)
{
var isDotted = true;
var lengthType = LengthType.Whole;
var scaleNum = 4;
var scale = Scale.A;
var note = new Note(scale, scaleNum, lengthType, isDotted);
var note = new Note(scale, scaleNumber, lengthType, isDotted);
Assert.Equal(scale, note.Scale);
Assert.Equal(scaleNum, note.ScaleNumber);
Assert.Equal(scaleNumber, note.ScaleNumber);
Assert.Equal(lengthType, note.Length);
Assert.Equal(isDotted, note.IsDotted);
Assert.Equal(100, note.Volume);
}

[Fact(DisplayName = "例外のテスト")]
public void InitializeExceptionTest()
{
var isDotted = true;
var lengthType = LengthType.Whole;
// 例外のテスト
_ = Assert.Throws<ArgumentException>(() => new Note(Scale.G, 0, lengthType, isDotted));
_ = Assert.Throws<ArgumentException>(() => new Note(Scale.D, 8, lengthType, isDotted));
_ = Assert.Throws<ArgumentException>(() => new Note(Scale.G, 9, lengthType, isDotted));
_ = Assert.Throws<ArgumentException>(() => new Note(Scale.G, -1, lengthType, isDotted));
}

[Fact(DisplayName = "簡単なコンストラクタで初期化が正しく行えるかのテスト")]
public void EasinessInitializeTest()
{
Expand Down
Loading