Skip to content

Commit

Permalink
-Added full XAudio2 support
Browse files Browse the repository at this point in the history
-Added more than 1000 xml comments
-Mediatypes are getting generated through a t4 template now
-Removed the FFTAggregator class.
-Fixed several bugs
-Marked some classes as obsolete
-Removed the obsolete CSCore.Visualization project
-Fixed a few mistakes like incorrect names, ...
  • Loading branch information
filoe committed Jul 2, 2014
1 parent 1857625 commit f46a1a5
Show file tree
Hide file tree
Showing 341 changed files with 12,870 additions and 12,214 deletions.
63 changes: 63 additions & 0 deletions .gitattributes
@@ -0,0 +1,63 @@
###############################################################################
# Set default behavior to automatically normalize line endings.
###############################################################################
* text=auto

###############################################################################
# Set default behavior for command prompt diff.
#
# This is need for earlier builds of msysgit that does not have it on by
# default for csharp files.
# Note: This is only used by command line
###############################################################################
#*.cs diff=csharp

###############################################################################
# Set the merge driver for project and solution files
#
# Merging from the command prompt will add diff markers to the files if there
# are conflicts (Merging from VS is not affected by the settings below, in VS
# the diff markers are never inserted). Diff markers may cause the following
# file extensions to fail to load in VS. An alternative would be to treat
# these files as binary and thus will always conflict and require user
# intervention with every merge. To do so, just uncomment the entries below
###############################################################################
#*.sln merge=binary
#*.csproj merge=binary
#*.vbproj merge=binary
#*.vcxproj merge=binary
#*.vcproj merge=binary
#*.dbproj merge=binary
#*.fsproj merge=binary
#*.lsproj merge=binary
#*.wixproj merge=binary
#*.modelproj merge=binary
#*.sqlproj merge=binary
#*.wwaproj merge=binary

###############################################################################
# behavior for image files
#
# image files are treated as binary by default.
###############################################################################
#*.jpg binary
#*.png binary
#*.gif binary

###############################################################################
# diff behavior for common document formats
#
# Convert binary document formats to text before diffing them. This feature
# is only available from the command line. Turn it on by uncommenting the
# entries below.
###############################################################################
#*.doc diff=astextplain
#*.DOC diff=astextplain
#*.docx diff=astextplain
#*.DOCX diff=astextplain
#*.dot diff=astextplain
#*.DOT diff=astextplain
#*.pdf diff=astextplain
#*.PDF diff=astextplain
#*.rtf diff=astextplain
#*.RTF diff=astextplain
2 changes: 2 additions & 0 deletions CSCore.Test/CSCore.Test.csproj
Expand Up @@ -199,6 +199,7 @@
<Compile Include="CoreAudioAPI\MMDevicesTests.cs" />
<Compile Include="DMO\DmoEffectsTests.cs" />
<Compile Include="DMO\DmoEnumeratorTests.cs" />
<Compile Include="GlobalTestConfig.cs" />
<Compile Include="MediaFoundation\BasicMediaFoundationTests.cs" />
<Compile Include="ACM\AcmDriverTests.cs" />
<Compile Include="MediaFoundation\MediafoundationEncoderTests.cs" />
Expand All @@ -215,6 +216,7 @@
<Compile Include="CoreAudioAPI\AudioClientTests.cs" />
<Compile Include="Utils\DisposableSource.cs" />
<Compile Include="WaveInOut\WaveInTests.cs" />
<Compile Include="XAudio2\XAudio2Tests.cs" />
<None Include="WaveInOut\WaveOutTests.cs" />
</ItemGroup>
<ItemGroup>
Expand Down
4 changes: 2 additions & 2 deletions CSCore.Test/CoreAudioAPI/AudioClientTests.cs
Expand Up @@ -188,7 +188,7 @@ public void CheckVariousFormatsForSupported_SharedMode()
foreach (var b in bps)
{
waveFormats.Add(new WaveFormat(s, b, c));
waveFormats.Add(new WaveFormatExtensible(s, b, c, b == 32 ? MediaTypes.MEDIATYPE_IeeeFloat : MediaTypes.MEDIATYPE_Pcm));
waveFormats.Add(new WaveFormatExtensible(s, b, c, b == 32 ? AudioSubTypes.IeeeFloat : AudioSubTypes.Pcm));
}
}
}
Expand Down Expand Up @@ -222,7 +222,7 @@ public void CheckVariousFormatsForSupported_ExclusiveMode()
foreach (var b in bps)
{
waveFormats.Add(new WaveFormat(s, b, c));
waveFormats.Add(new WaveFormatExtensible(s, b, c, b == 32 ? MediaTypes.MEDIATYPE_IeeeFloat : MediaTypes.MEDIATYPE_Pcm));
waveFormats.Add(new WaveFormatExtensible(s, b, c, b == 32 ? AudioSubTypes.IeeeFloat : AudioSubTypes.Pcm));
}
}
}
Expand Down
38 changes: 37 additions & 1 deletion CSCore.Test/CoreAudioAPI/AudioSessionTests.cs
@@ -1,4 +1,6 @@
using System;
using System.Linq;
using System.Threading;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using CSCore.CoreAudioAPI;
using System.Diagnostics;
Expand Down Expand Up @@ -36,7 +38,9 @@ public void CanRegisterSessionNotification()
using (var sessionManager = GetDefaultAudioSessionManager2(DataFlow.Render))
{
AudioSessionNotification notification = new AudioSessionNotification();
sessionManager.RegisterSessionNotification(notification);

RegisterSessionNotification(sessionManager, notification);

sessionManager.UnregisterSessionNotification(notification);
}
}
Expand Down Expand Up @@ -210,5 +214,37 @@ private AudioSessionManager2 GetDefaultAudioSessionManager2(DataFlow dataFlow)
}
}
}

private void RegisterSessionNotification(AudioSessionManager2 audioSessionManager2,
IAudioSessionNotification audioSessionNotification)
{
if (Thread.CurrentThread.GetApartmentState() == ApartmentState.MTA)
{
audioSessionManager2.RegisterSessionNotification(audioSessionNotification);
}
else
{
using (ManualResetEvent waitHandle = new ManualResetEvent(false))
{
ThreadPool.QueueUserWorkItem(
(o) =>
{
try
{
audioSessionManager2.RegisterSessionNotification(audioSessionNotification);
}
finally
{
// ReSharper disable once AccessToDisposedClosure
waitHandle.Set();
}
});
waitHandle.WaitOne();
}
}

// ReSharper disable once ReturnValueOfPureMethodIsNotUsed
audioSessionManager2.GetSessionEnumerator().ToArray(); //necessary to make it work
}
}
}
8 changes: 8 additions & 0 deletions CSCore.Test/CoreAudioAPI/Utils.cs
Expand Up @@ -40,6 +40,14 @@ public static MMDevice GetDefaultRenderDevice()
}
}

public static MMDevice GetDefaultCaptureDevice()
{
using (var enumerator = new MMDeviceEnumerator())
{
return enumerator.GetDefaultAudioEndpoint(DataFlow.Capture, Role.Console);
}
}

public static AudioClient CreateDefaultRenderClient()
{
using (var enumerator = new MMDeviceEnumerator())
Expand Down
12 changes: 12 additions & 0 deletions CSCore.Test/GlobalTestConfig.cs
@@ -0,0 +1,12 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace CSCore.Test
{
public static class GlobalTestConfig
{
public const string testMP3 = @"C:\Temp\test.mp3";
}
}
4 changes: 2 additions & 2 deletions CSCore.Test/MediaFoundation/BasicMediaFoundationTests.cs
Expand Up @@ -29,7 +29,7 @@ public void CanCreateByteStreamFromIOStream()
public void CanCreateSourceReaderFromUrl()
{
MediaFoundationCore.Startup();
using (var reader = MediaFoundationCore.CreateSourceReaderFromUrl(@"C:\Temp\test.mp3"))
using (var reader = MediaFoundationCore.CreateSourceReaderFromUrl(GlobalTestConfig.testMP3))
{
Assert.IsNotNull(reader);
}
Expand All @@ -41,7 +41,7 @@ public void CanCreateSourceReaderFromUrl()
public void CanCreateSourceReaderFromIOStream()
{
MediaFoundationCore.Startup();
var stream = File.OpenRead(@"C:\Temp\test.mp3");
var stream = File.OpenRead(GlobalTestConfig.testMP3);
using (var comstream = new ComStream(stream))
{
var byteStream = MediaFoundationCore.IStreamToByteStream(comstream);
Expand Down
10 changes: 8 additions & 2 deletions CSCore.Test/MediaFoundation/MediafoundationEncoderTests.cs
Expand Up @@ -9,7 +9,7 @@ namespace CSCore.Test.MediaFoundation
[TestClass]
public class MediafoundationEncoderTests
{
const string testfile = @"C:\Temp\test.mp3";
const string testfile = GlobalTestConfig.testMP3;

[TestMethod]
[TestCategory("MediaFoundation")]
Expand All @@ -27,6 +27,9 @@ public void CanEncodeToMP3()
//Thread.Sleep(5000);
}
}

//cleanup
File.Delete(targetfilename);
}

[TestMethod]
Expand All @@ -44,9 +47,12 @@ public void CanEncodeToAAC()
MediaFoundationEncoder.EncodeWholeSource(encoder, source);
}
}

//cleanup
File.Delete(targetfilename);
}

//TODO: Why does this work, but crashes test-executionengine??
//Bug: Why does this work, but crashes the test-executionengine??
//[TestMethod]
//[TestCategory("MediaFoundation")]
//public void CanEncodeToWMA()
Expand Down
14 changes: 7 additions & 7 deletions CSCore.Test/SoundOut/SoundOutBehaviourTest.cs
Expand Up @@ -69,8 +69,9 @@ public void VolumeResetTest()
{
SoundOutTests((soundOut, source) =>
{
VolumeResetTestInternal(soundOut, source);
});
for (int i = 0; i < basic_iteration_count; i++ )
VolumeResetTestInternal(soundOut, source);
}, true);
}

[TestMethod]
Expand Down Expand Up @@ -121,8 +122,8 @@ public void ThrowsInvalidCallerThread()
bool flag = true;
foreach (var soundOut in GetSoundOuts())
{
var source = new DSP.FFTAggregator(new SineGenerator().ToWaveSource(16));
source.FFTCalculated += (s, e) =>
var source = new CSCore.Streams.NotificationSource(new SineGenerator().ToWaveSource());
source.BlockRead += (s, e) =>
{
try
{
Expand All @@ -131,7 +132,7 @@ public void ThrowsInvalidCallerThread()
catch (InvalidOperationException)
{
Debug.WriteLine("Invalid behaviour in {0}.", soundOut.GetType().FullName);
flag &= false;
flag = false;
}
};
soundOut.Initialize(source);
Expand Down Expand Up @@ -370,8 +371,6 @@ private void PlayPauseResumeBehaviourTestInternal(ISoundOut soundOut, IWaveSourc

private void VolumeResetTestInternal(ISoundOut soundOut, IWaveSource source)
{
source = new CSCore.Streams.LoopStream(source);

soundOut.Initialize(source);
soundOut.Play();
soundOut.Volume = 0.5f;
Expand All @@ -381,6 +380,7 @@ private void VolumeResetTestInternal(ISoundOut soundOut, IWaveSource source)
soundOut.Initialize(source);
soundOut.Play();
Assert.AreEqual(1.0f, soundOut.Volume);
soundOut.Stop();
}

private void PlaybackStoppedEventTestInternal(ISoundOut soundOut, IWaveSource source)
Expand Down
2 changes: 1 addition & 1 deletion CSCore.Test/Streams/MonoToStereoSourceTest.cs
Expand Up @@ -10,7 +10,7 @@ namespace CSCore.Test.Streams
[TestClass]
public class MonoToStereoSourceTest
{
const string testfile = @"C:\Temp\test.mp3";
const string testfile = GlobalTestConfig.testMP3;

[TestMethod]
[TestCategory("Streams")]
Expand Down
4 changes: 2 additions & 2 deletions CSCore.Test/Streams/StereoToMonoSourceTest.cs
Expand Up @@ -10,7 +10,7 @@ namespace CSCore.Test.Streams
[TestClass]
public class StereoToMonoSourceTest
{
const string testfile = @"C:\Temp\test.mp3";
const string testfile = GlobalTestConfig.testMP3;

[TestMethod]
[TestCategory("Streams")]
Expand All @@ -33,7 +33,7 @@ public void CanPlayStereoToMonoSource()
soundOut.Initialize(monoSource.ToWaveSource(16));
soundOut.Play();

Thread.Sleep((int)Math.Min(source.GetMilliseconds(source.Length), 60000));
Thread.Sleep((int)Math.Min(source.GetMilliseconds(source.Length), 20000));

soundOut.Dispose();
}
Expand Down
4 changes: 4 additions & 0 deletions CSCore.Test/WaveInOut/WaveInTests.cs
Expand Up @@ -15,7 +15,9 @@ public class WaveInTests
[TestCategory("WaveIn")]
public void CanEnumerateWaveInDevices()
{
#pragma warning disable 612
foreach (var device in WaveIn.Devices)
#pragma warning restore 612
{
Debug.WriteLine("{0};{1};{2}", device.Name, device.Channels, device.DriverVersion);
}
Expand All @@ -25,7 +27,9 @@ public void CanEnumerateWaveInDevices()
[TestCategory("WaveIn")]
public void CanCreateWaveInDevice()
{
#pragma warning disable 612
using (WaveIn waveIn = new WaveIn())
#pragma warning restore 612
{
waveIn.Initialize();
waveIn.Start();
Expand Down

0 comments on commit f46a1a5

Please sign in to comment.