Skip to content

Commit 8abdefa

Browse files
committed
Implemented the minimum functionality
1 parent 7236254 commit 8abdefa

File tree

7 files changed

+676
-0
lines changed

7 files changed

+676
-0
lines changed

WaveFileManager.sln

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio 15
4+
VisualStudioVersion = 15.0.27428.2043
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WaveFileManager", "WaveFileManager\WaveFileManager.csproj", "{73248112-9ED2-4305-9133-9259E3C78CB4}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|Any CPU = Debug|Any CPU
11+
Debug|x64 = Debug|x64
12+
Debug|x86 = Debug|x86
13+
Release|Any CPU = Release|Any CPU
14+
Release|x64 = Release|x64
15+
Release|x86 = Release|x86
16+
EndGlobalSection
17+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
18+
{73248112-9ED2-4305-9133-9259E3C78CB4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
19+
{73248112-9ED2-4305-9133-9259E3C78CB4}.Debug|Any CPU.Build.0 = Debug|Any CPU
20+
{73248112-9ED2-4305-9133-9259E3C78CB4}.Debug|x64.ActiveCfg = Debug|Any CPU
21+
{73248112-9ED2-4305-9133-9259E3C78CB4}.Debug|x64.Build.0 = Debug|Any CPU
22+
{73248112-9ED2-4305-9133-9259E3C78CB4}.Debug|x86.ActiveCfg = Debug|Any CPU
23+
{73248112-9ED2-4305-9133-9259E3C78CB4}.Debug|x86.Build.0 = Debug|Any CPU
24+
{73248112-9ED2-4305-9133-9259E3C78CB4}.Release|Any CPU.ActiveCfg = Release|Any CPU
25+
{73248112-9ED2-4305-9133-9259E3C78CB4}.Release|Any CPU.Build.0 = Release|Any CPU
26+
{73248112-9ED2-4305-9133-9259E3C78CB4}.Release|x64.ActiveCfg = Release|Any CPU
27+
{73248112-9ED2-4305-9133-9259E3C78CB4}.Release|x64.Build.0 = Release|Any CPU
28+
{73248112-9ED2-4305-9133-9259E3C78CB4}.Release|x86.ActiveCfg = Release|Any CPU
29+
{73248112-9ED2-4305-9133-9259E3C78CB4}.Release|x86.Build.0 = Release|Any CPU
30+
EndGlobalSection
31+
GlobalSection(SolutionProperties) = preSolution
32+
HideSolutionNode = FALSE
33+
EndGlobalSection
34+
GlobalSection(ExtensibilityGlobals) = postSolution
35+
SolutionGuid = {4F5D2530-6CB4-4F1F-85FE-20999B0ADB12}
36+
EndGlobalSection
37+
EndGlobal

WaveFileManager/AssistantFunc.cs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
using System.IO;
7+
8+
namespace WaveFileManager
9+
{
10+
public partial class WaveFileManager
11+
{
12+
public static short[] GenerateSoundMonaural16bits(double herth, int samplesPerSec = 44100)
13+
{
14+
List<short> list = new List<short>();
15+
for (int i = 0; i < samplesPerSec * 2; i++)
16+
{
17+
list.Add((short)(Math.Sin(i / (double)samplesPerSec * 2d * Math.PI * herth) * 30000));
18+
}
19+
return list.ToArray();
20+
}
21+
22+
public static void CreateWaveFile(string path, short[] data)
23+
=> CreateFile(path, GenerateMonaural16bits(data));
24+
25+
public static void CreateWaveFile(string path, byte[] data)
26+
=> CreateFile(path, GenerateMonaural8bits(data));
27+
}
28+
}

WaveFileManager/CreateInstance.cs

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
7+
namespace WaveFileManager
8+
{
9+
public partial class WaveFileManager
10+
{
11+
public static MusicPropertyMonaural16bit GenerateMonaural16bits(short[] data)
12+
{
13+
MusicPropertyMonaural16bit w = new MusicPropertyMonaural16bit();
14+
15+
w.m_FileSize = 36 + data.Length * 2;
16+
w.m_PCMWAVEFORMAT_Size = 16;
17+
w.m_WaveFormatEx = WAVEFORMATEX.Monaural16bitsDefault;
18+
var data16bit = new MusicDataMonaural16bit();
19+
data16bit.m_DataSize = data.Length * 2;
20+
data16bit.m_Data = data;
21+
w.m_MusicData = data16bit;
22+
23+
return w;
24+
}
25+
26+
public static MusicPropertyMonaural8bit GenerateMonaural8bits(byte[] data)
27+
{
28+
MusicPropertyMonaural8bit w = new MusicPropertyMonaural8bit();
29+
30+
w.m_FileSize = 36 + data.Length;
31+
w.m_PCMWAVEFORMAT_Size = 16;
32+
w.m_WaveFormatEx = WAVEFORMATEX.Monaural8bitsDefault;
33+
var data8bit = new MusicDataMonaural8bit();
34+
data8bit.m_DataSize = data.Length;
35+
data8bit.m_Data = data;
36+
w.m_MusicData = data8bit;
37+
38+
return w;
39+
}
40+
}
41+
}

WaveFileManager/DefineDataType.cs

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
7+
namespace WaveFileManager
8+
{
9+
public class MusicProperty
10+
{
11+
public Int32 m_FileSize;
12+
public Int32 m_PCMWAVEFORMAT_Size;
13+
public WAVEFORMATEX m_WaveFormatEx;
14+
}
15+
16+
public class MusicPropertyMonaural16bit : MusicProperty
17+
{
18+
public MusicDataMonaural16bit m_MusicData;
19+
}
20+
21+
public class MusicPropertyMonaural8bit : MusicProperty
22+
{
23+
public MusicDataMonaural8bit m_MusicData;
24+
}
25+
26+
public struct MusicDataMonaural16bit
27+
{
28+
public Int32 m_DataSize;
29+
public Int16[] m_Data;
30+
}
31+
32+
public struct MusicDataMonaural8bit
33+
{
34+
public Int32 m_DataSize;
35+
public byte[] m_Data;
36+
}
37+
38+
public class WAVEFORMATEX
39+
{
40+
public Int16 wFormatTag;
41+
public UInt16 nChannels;
42+
public UInt32 nSamplesPerSec;
43+
public UInt32 nAvgBytePerSec;
44+
public UInt16 nBlockAlign;
45+
public UInt16 wBitsPerSample;
46+
47+
/// <summary>
48+
/// Monaural 16bits 44100Hz
49+
/// </summary>
50+
public static WAVEFORMATEX Monaural16bitsDefault
51+
{
52+
get
53+
{
54+
WAVEFORMATEX format = new WAVEFORMATEX();
55+
format.wFormatTag = 1;
56+
format.nChannels = 1;
57+
format.nSamplesPerSec = 44100;
58+
format.nAvgBytePerSec = 88200;
59+
format.nBlockAlign = 2;
60+
format.wBitsPerSample = 16;
61+
return format;
62+
}
63+
}
64+
65+
/// <summary>
66+
/// Monaural 8bits 44100Hz
67+
/// </summary>
68+
public static WAVEFORMATEX Monaural8bitsDefault
69+
{
70+
get
71+
{
72+
WAVEFORMATEX format = new WAVEFORMATEX();
73+
format.wFormatTag = 1;
74+
format.nChannels = 1;
75+
format.nSamplesPerSec = 44100;
76+
format.nAvgBytePerSec = 44100;
77+
format.nBlockAlign = 1;
78+
format.wBitsPerSample = 8;
79+
return format;
80+
}
81+
}
82+
}
83+
}

0 commit comments

Comments
 (0)