began working on audio system; added Naudio;

This commit is contained in:
Harrison Deng 2018-11-18 19:09:28 -06:00
parent a4bedd34af
commit 6086c6491b
6 changed files with 143 additions and 7 deletions

View File

@ -47,6 +47,9 @@
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects> <AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<Compile Include="Zer01HD\Audio\MusicController.cs" />
<Compile Include="Zer01HD\Audio\MusicList.cs" />
<Compile Include="Zer01HD\Audio\SupportedFormats.cs" />
<Compile Include="Zer01HD\Screens\MainMenu\MainPage.cs" /> <Compile Include="Zer01HD\Screens\MainMenu\MainPage.cs" />
<Compile Include="Zer01HD\Screens\Transitions\FadeAwayTransition.cs" /> <Compile Include="Zer01HD\Screens\Transitions\FadeAwayTransition.cs" />
<Compile Include="Zer01HD\Utilities\Camera\Camera2D.cs" /> <Compile Include="Zer01HD\Utilities\Camera\Camera2D.cs" />
@ -85,12 +88,12 @@
<Reference Include="BulletSharp, Version=0.11.0.0, Culture=neutral, processorArchitecture=MSIL"> <Reference Include="BulletSharp, Version=0.11.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\BulletSharp.0.11.1\lib\net40-client\BulletSharp.dll</HintPath> <HintPath>..\packages\BulletSharp.0.11.1\lib\net40-client\BulletSharp.dll</HintPath>
</Reference> </Reference>
<Reference Include="DSP, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\DSP.1.0.0\lib\DSP.dll</HintPath>
</Reference>
<Reference Include="MonoGame.Framework"> <Reference Include="MonoGame.Framework">
<HintPath>$(MonoGameInstallDirectory)\MonoGame\v3.0\Assemblies\DesktopGL\MonoGame.Framework.dll</HintPath> <HintPath>$(MonoGameInstallDirectory)\MonoGame\v3.0\Assemblies\DesktopGL\MonoGame.Framework.dll</HintPath>
</Reference> </Reference>
<Reference Include="NAudio, Version=1.8.5.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\NAudio.1.8.5\lib\net35\NAudio.dll</HintPath>
</Reference>
<Reference Include="System" /> <Reference Include="System" />
<Reference Include="System.Xml" /> <Reference Include="System.Xml" />
</ItemGroup> </ItemGroup>
@ -147,7 +150,9 @@
<None Include="app.manifest" /> <None Include="app.manifest" />
<None Include="packages.config" /> <None Include="packages.config" />
</ItemGroup> </ItemGroup>
<ItemGroup /> <ItemGroup>
<Folder Include="Zer01HD\Audio\Visualizer\" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Import Project="$(MSBuildExtensionsPath)\MonoGame\v3.0\MonoGame.Content.Builder.targets" /> <Import Project="$(MSBuildExtensionsPath)\MonoGame\v3.0\MonoGame.Content.Builder.targets" />
<Import Project="..\packages\BulletSharp.0.11.1\build\net40-client\BulletSharp.targets" Condition="Exists('..\packages\BulletSharp.0.11.1\build\net40-client\BulletSharp.targets')" /> <Import Project="..\packages\BulletSharp.0.11.1\build\net40-client\BulletSharp.targets" Condition="Exists('..\packages\BulletSharp.0.11.1\build\net40-client\BulletSharp.targets')" />

View File

@ -0,0 +1,26 @@
using Microsoft.Xna.Framework.Media;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace RhythmBullet.Zer01HD.Audio
{
internal class MusicController
{
MusicList musicList;
public MusicController(MusicList musicList)
{
this.musicList = musicList;
}
public void LoadMusic(string path)
{
}
}
}

View File

@ -0,0 +1,93 @@
using Microsoft.Xna.Framework.Media;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace RhythmBullet.Zer01HD.Audio
{
internal class MusicList
{
private volatile bool work;
private List<string> list = new List<string>();
public List<string> List
{
get
{
if (!thread.IsAlive)
{
lock (list)
{
return list;
}
}
else
{
return null;
}
}
}
private string path;
private Thread thread;
public MusicList()
{
}
public void Start()
{
if (thread == null || !thread.IsAlive)
{
work = true;
thread = new Thread(Search);
thread.Name = "Music Search Thread";
thread.Start();
}
}
public void Stop()
{
work = false;
}
private void Search()
{
lock (list)
{
list.AddRange(recursiveMusicSearch(path));
}
}
private List<string> recursiveMusicSearch(string path)
{
List<string> musicFiles = new List<string>();
string[] files = Directory.GetFiles(path);
for (int i = 0; i < files.Length && work; i++)
{
if (Directory.Exists(files[i]))
{
musicFiles.AddRange(recursiveMusicSearch(files[i]));
}
else
{
try
{
SupportedFormats format;
Enum.TryParse<SupportedFormats>(Path.GetExtension(files[i]).ToUpper(), out format);
musicFiles.Add(files[i]);
}
catch (ArgumentException e)
{
Console.WriteLine("MusicList", "Unsupported file format: " + Path.GetFileName(files[i]));
Console.WriteLine(e);
}
}
}
return musicFiles;
}
}
}

View File

@ -0,0 +1,13 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace RhythmBullet.Zer01HD.Audio
{
public enum SupportedFormats
{
WAV, MP3
}
}

View File

@ -74,8 +74,7 @@ namespace RhythmBullet.Zer01HD.Utilities.ContentSystem
{ {
if (queue.Count > 0 && (thread == null || !thread.IsAlive)) if (queue.Count > 0 && (thread == null || !thread.IsAlive))
{ {
ThreadStart threadStart = new ThreadStart(LoadBatch); thread = new Thread(LoadBatch);
thread = new Thread(threadStart);
thread.Start(); thread.Start();
} }
} }

View File

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<packages> <packages>
<package id="BulletSharp" version="0.11.1" targetFramework="net45" /> <package id="BulletSharp" version="0.11.1" targetFramework="net45" />
<package id="DSP" version="1.0.0" targetFramework="net45" /> <package id="NAudio" version="1.8.5" targetFramework="net45" />
</packages> </packages>