- Fixed the SoundEffectReader to work the same as xna does

- Implemented the proper Constructor in XAudioSoundEffect for the SoundEffectReader
- Started implementing the native MediaLibrary class in the WindowsPlatformSystem
This commit is contained in:
SND\AstrorEnales_cp 2012-10-08 11:28:38 +00:00 committed by Konstantin Koch
parent 3e65589f23
commit 61f12a03fa
7 changed files with 173 additions and 106 deletions

View File

@ -1,5 +1,4 @@
using System; using System;
using System.IO;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using ANX.Framework.Audio; using ANX.Framework.Audio;
using ANX.Framework.NonXNA.Development; using ANX.Framework.NonXNA.Development;
@ -40,33 +39,12 @@ namespace ANX.Framework.Content
int dataCount = input.ReadInt32(); int dataCount = input.ReadInt32();
byte[] data = input.ReadBytes(dataCount); byte[] data = input.ReadBytes(dataCount);
int loopStart = input.ReadInt32(); int loopStart = input.ReadInt32();
int loopLength = input.ReadInt32(); int loopLength = input.ReadInt32();
int duration = input.ReadInt32(); int duration = input.ReadInt32();
byte[] soundData; return new SoundEffect(data, 0, data.Length, headerStruct.nSamplesPerSec, (AudioChannels)headerStruct.nChannels,
using (var mStream = new MemoryStream(20 + header.Length + 8 + data.Length)) loopStart, loopLength);
{
var writer = new BinaryWriter(mStream);
writer.Write("RIFF".ToCharArray());
writer.Write(20 + header.Length + data.Length);
writer.Write("WAVE".ToCharArray());
writer.Write("fmt ".ToCharArray());
writer.Write(header.Length);
writer.Write(header);
writer.Write("data".ToCharArray());
writer.Write(data.Length);
writer.Write(data);
soundData = mStream.ToArray();
}
return new SoundEffect(soundData, 0, soundData.Length, headerStruct.nSamplesPerSec,
(AudioChannels)headerStruct.nChannels, loopStart, loopLength);
} }
} }
} }

View File

@ -25,69 +25,46 @@ namespace ANX.Framework.Media
get { return Rating > 0; } get { return Rating > 0; }
} }
public Artist Artist public Artist Artist { get; internal set; }
{ public Album Album { get; internal set; }
get public Genre Genre { get; internal set; }
{
throw new NotImplementedException();
}
}
public Album Album public TimeSpan Duration
{
get
{
throw new NotImplementedException();
}
}
public Genre Genre
{
get
{
throw new NotImplementedException();
}
}
public TimeSpan Duration
{ {
get { return NativeSong.Duration; } get { return NativeSong.Duration; }
} }
public int Rating public int Rating
{ {
get get { throw new NotImplementedException(); }
{ }
throw new NotImplementedException();
}
}
public int PlayCount public int PlayCount
{ {
get get { throw new NotImplementedException(); }
{ }
throw new NotImplementedException();
}
}
public int TrackNumber public int TrackNumber
{ {
get get { throw new NotImplementedException(); }
{ }
throw new NotImplementedException();
}
}
public bool IsProtected public bool IsProtected
{ {
get get { throw new NotImplementedException(); }
{
throw new NotImplementedException();
}
} }
#endregion #endregion
#region Constructor #region Constructor
internal Song(string setName)
{
// TODO
var creator = AddInSystemFactory.Instance.GetDefaultCreator<ISoundSystemCreator>();
//NativeSong = creator.CreateSong(this, uri);
Name = setName;
IsDisposed = false;
}
internal Song(string setName, Uri uri) internal Song(string setName, Uri uri)
{ {
var creator = AddInSystemFactory.Instance.GetDefaultCreator<ISoundSystemCreator>(); var creator = AddInSystemFactory.Instance.GetDefaultCreator<ISoundSystemCreator>();
@ -115,7 +92,8 @@ namespace ANX.Framework.Media
return new Song(name, uri); return new Song(name, uri);
} }
public bool Equals(Song other) #region Equals
public bool Equals(Song other)
{ {
return other != null && Name == other.Name; return other != null && Name == other.Name;
} }
@ -127,8 +105,10 @@ namespace ANX.Framework.Media
return base.Equals(obj); return base.Equals(obj);
} }
#endregion
public void Dispose() #region Dispose
public void Dispose()
{ {
if (IsDisposed) if (IsDisposed)
return; return;
@ -139,6 +119,7 @@ namespace ANX.Framework.Media
NativeSong.Dispose(); NativeSong.Dispose();
NativeSong = null; NativeSong = null;
} }
#endregion
internal void Play() internal void Play()
{ {

View File

@ -8,36 +8,25 @@ using System.Collections.Generic;
namespace ANX.Framework.Media namespace ANX.Framework.Media
{ {
public sealed class SongCollection public sealed class SongCollection : IEnumerable<Song>, IEnumerable, IDisposable
: IEnumerable<Song>, IEnumerable, IDisposable
{ {
private List<Song> songs; private readonly List<Song> songs;
public bool IsDisposed public bool IsDisposed { get; private set; }
{
get;
private set;
}
public int Count public int Count
{ {
get get { return songs.Count; }
{ }
return songs.Count;
}
}
public Song this[int index] public Song this[int index]
{ {
get get { return songs[index]; }
{ }
return songs[index];
}
}
internal SongCollection() internal SongCollection(IEnumerable<Song> allSongs)
{ {
songs = new List<Song>(); songs = new List<Song>(allSongs);
IsDisposed = false; IsDisposed = false;
} }

View File

@ -41,6 +41,7 @@
<Compile Include="SupportedPlatformsImpl.cs" /> <Compile Include="SupportedPlatformsImpl.cs" />
<Compile Include="WindowsContentManager.cs" /> <Compile Include="WindowsContentManager.cs" />
<Compile Include="WindowsGameTimer.cs" /> <Compile Include="WindowsGameTimer.cs" />
<Compile Include="WindowsMediaLibrary.cs" />
<Compile Include="WindowsStorageContainer.cs" /> <Compile Include="WindowsStorageContainer.cs" />
<Compile Include="Properties\AssemblyInfo.cs" /> <Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="WindowsGameHost.cs" /> <Compile Include="WindowsGameHost.cs" />
@ -55,6 +56,17 @@
<Name>ANX.Framework</Name> <Name>ANX.Framework</Name>
</ProjectReference> </ProjectReference>
</ItemGroup> </ItemGroup>
<ItemGroup>
<COMReference Include="WMPLib">
<Guid>{6BF52A50-394A-11D3-B153-00C04F79FAA6}</Guid>
<VersionMajor>1</VersionMajor>
<VersionMinor>0</VersionMinor>
<Lcid>0</Lcid>
<WrapperTool>tlbimp</WrapperTool>
<Isolated>False</Isolated>
<EmbedInteropTypes>True</EmbedInteropTypes>
</COMReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it. <!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets. Other similar extension points exist, see Microsoft.Common.targets.

View File

@ -0,0 +1,89 @@
using System;
using System.IO;
using ANX.Framework.Media;
using ANX.Framework.NonXNA.PlatformSystem;
using WMPLib;
namespace ANX.PlatformSystem.Windows
{
class WindowsMediaLibrary : INativeMediaLibrary
{
private WindowsMediaPlayer nativePlayer;
public WindowsMediaLibrary()
{
nativePlayer = new WindowsMediaPlayer();
}
public Picture SavePicture(string file, Stream data)
{
throw new NotImplementedException();
}
public Picture SavePicture(string file, byte[] data)
{
throw new NotImplementedException();
}
public Picture GetPictureFromToken(string file)
{
throw new NotImplementedException();
}
public PictureCollection GetPictures()
{
throw new NotImplementedException();
}
public PictureAlbum GetRootPictureAlbum()
{
throw new NotImplementedException();
}
public PictureCollection GetSavedPictures()
{
throw new NotImplementedException();
}
public SongCollection GetSongs()
{
var collection = nativePlayer.mediaCollection;
var list = collection.getAll();
var songs = new Song[list.count];
// TODO: sort out songs!
for (int index = 0; index < songs.Length; index++)
{
var newSong = new Song(list.Item[index].name);
songs[index] = newSong;
}
return new SongCollection(songs);
}
public ArtistCollection GetArtists()
{
throw new NotImplementedException();
}
public AlbumCollection GetAlbums()
{
throw new NotImplementedException();
}
public PlaylistCollection GetPlaylists()
{
throw new NotImplementedException();
}
public GenreCollection GetGenres()
{
throw new NotImplementedException();
}
public void Dispose()
{
if (nativePlayer != null)
nativePlayer.close();
nativePlayer = null;
}
}
}

View File

@ -63,10 +63,10 @@ namespace ANX.PlatformSystem.Windows
} }
#endregion #endregion
#region CreateMediaPlayer (TODO) #region CreateMediaPlayer
public INativeMediaLibrary CreateMediaLibrary() public INativeMediaLibrary CreateMediaLibrary()
{ {
throw new NotImplementedException(); return new WindowsMediaLibrary();
} }
#endregion #endregion

View File

@ -3,6 +3,7 @@ using System.IO;
using ANX.Framework.Audio; using ANX.Framework.Audio;
using ANX.Framework.NonXNA.Development; using ANX.Framework.NonXNA.Development;
using ANX.Framework.NonXNA.SoundSystem; using ANX.Framework.NonXNA.SoundSystem;
using SharpDX;
using SharpDX.Multimedia; using SharpDX.Multimedia;
using SharpDX.XAudio2; using SharpDX.XAudio2;
@ -37,9 +38,26 @@ namespace ANX.SoundSystem.Windows.XAudio
internal XAudioSoundEffect(byte[] buffer, int offset, int count, int sampleRate, AudioChannels channels, internal XAudioSoundEffect(byte[] buffer, int offset, int count, int sampleRate, AudioChannels channels,
int loopStart, int loopLength) int loopStart, int loopLength)
{ {
// TODO: the buffer already contains the pcm data to be played! WaveFormat = new WaveFormat(sampleRate, (int)channels);
throw new NotImplementedException(); AudioBuffer = new AudioBuffer
{
LoopBegin = loopStart,
LoopLength = loopLength,
AudioBytes = count,
Flags = BufferFlags.EndOfStream
};
IntPtr handle;
unsafe
{
fixed (byte* ptr = &buffer[0])
handle = (IntPtr)(ptr + offset);
}
AudioBuffer.Stream = new DataStream(handle, count, false, false);
float sizeMulBlockAlign = (float)count / (WaveFormat.Channels * 2);
duration = TimeSpan.FromMilliseconds(sizeMulBlockAlign * 1000f / WaveFormat.SampleRate);
} }
~XAudioSoundEffect() ~XAudioSoundEffect()