- 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:
parent
3e65589f23
commit
61f12a03fa
@ -1,5 +1,4 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Runtime.InteropServices;
|
||||
using ANX.Framework.Audio;
|
||||
using ANX.Framework.NonXNA.Development;
|
||||
@ -40,33 +39,12 @@ namespace ANX.Framework.Content
|
||||
|
||||
int dataCount = input.ReadInt32();
|
||||
byte[] data = input.ReadBytes(dataCount);
|
||||
|
||||
int loopStart = input.ReadInt32();
|
||||
int loopLength = input.ReadInt32();
|
||||
|
||||
int duration = input.ReadInt32();
|
||||
|
||||
byte[] soundData;
|
||||
using (var mStream = new MemoryStream(20 + header.Length + 8 + data.Length))
|
||||
{
|
||||
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);
|
||||
return new SoundEffect(data, 0, data.Length, headerStruct.nSamplesPerSec, (AudioChannels)headerStruct.nChannels,
|
||||
loopStart, loopLength);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -25,69 +25,46 @@ namespace ANX.Framework.Media
|
||||
get { return Rating > 0; }
|
||||
}
|
||||
|
||||
public Artist Artist
|
||||
{
|
||||
get
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
public Artist Artist { get; internal set; }
|
||||
public Album Album { get; internal set; }
|
||||
public Genre Genre { get; internal set; }
|
||||
|
||||
public Album Album
|
||||
{
|
||||
get
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
|
||||
public Genre Genre
|
||||
{
|
||||
get
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
|
||||
public TimeSpan Duration
|
||||
public TimeSpan Duration
|
||||
{
|
||||
get { return NativeSong.Duration; }
|
||||
}
|
||||
|
||||
public int Rating
|
||||
{
|
||||
get
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
public int Rating
|
||||
{
|
||||
get { throw new NotImplementedException(); }
|
||||
}
|
||||
|
||||
public int PlayCount
|
||||
{
|
||||
get
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
public int PlayCount
|
||||
{
|
||||
get { throw new NotImplementedException(); }
|
||||
}
|
||||
|
||||
public int TrackNumber
|
||||
{
|
||||
get
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
public int TrackNumber
|
||||
{
|
||||
get { throw new NotImplementedException(); }
|
||||
}
|
||||
|
||||
public bool IsProtected
|
||||
{
|
||||
get
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
public bool IsProtected
|
||||
{
|
||||
get { throw new NotImplementedException(); }
|
||||
}
|
||||
#endregion
|
||||
|
||||
#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)
|
||||
{
|
||||
var creator = AddInSystemFactory.Instance.GetDefaultCreator<ISoundSystemCreator>();
|
||||
@ -115,7 +92,8 @@ namespace ANX.Framework.Media
|
||||
return new Song(name, uri);
|
||||
}
|
||||
|
||||
public bool Equals(Song other)
|
||||
#region Equals
|
||||
public bool Equals(Song other)
|
||||
{
|
||||
return other != null && Name == other.Name;
|
||||
}
|
||||
@ -127,8 +105,10 @@ namespace ANX.Framework.Media
|
||||
|
||||
return base.Equals(obj);
|
||||
}
|
||||
#endregion
|
||||
|
||||
public void Dispose()
|
||||
#region Dispose
|
||||
public void Dispose()
|
||||
{
|
||||
if (IsDisposed)
|
||||
return;
|
||||
@ -139,6 +119,7 @@ namespace ANX.Framework.Media
|
||||
NativeSong.Dispose();
|
||||
NativeSong = null;
|
||||
}
|
||||
#endregion
|
||||
|
||||
internal void Play()
|
||||
{
|
||||
|
@ -8,36 +8,25 @@ using System.Collections.Generic;
|
||||
|
||||
namespace ANX.Framework.Media
|
||||
{
|
||||
public sealed class SongCollection
|
||||
: IEnumerable<Song>, IEnumerable, IDisposable
|
||||
public sealed class SongCollection : IEnumerable<Song>, IEnumerable, IDisposable
|
||||
{
|
||||
private List<Song> songs;
|
||||
private readonly List<Song> songs;
|
||||
|
||||
public bool IsDisposed
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
public bool IsDisposed { get; private set; }
|
||||
|
||||
public int Count
|
||||
{
|
||||
get
|
||||
{
|
||||
return songs.Count;
|
||||
}
|
||||
}
|
||||
public int Count
|
||||
{
|
||||
get { return songs.Count; }
|
||||
}
|
||||
|
||||
public Song this[int index]
|
||||
{
|
||||
get
|
||||
{
|
||||
return songs[index];
|
||||
}
|
||||
}
|
||||
public Song this[int index]
|
||||
{
|
||||
get { return songs[index]; }
|
||||
}
|
||||
|
||||
internal SongCollection()
|
||||
internal SongCollection(IEnumerable<Song> allSongs)
|
||||
{
|
||||
songs = new List<Song>();
|
||||
songs = new List<Song>(allSongs);
|
||||
IsDisposed = false;
|
||||
}
|
||||
|
||||
|
@ -41,6 +41,7 @@
|
||||
<Compile Include="SupportedPlatformsImpl.cs" />
|
||||
<Compile Include="WindowsContentManager.cs" />
|
||||
<Compile Include="WindowsGameTimer.cs" />
|
||||
<Compile Include="WindowsMediaLibrary.cs" />
|
||||
<Compile Include="WindowsStorageContainer.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="WindowsGameHost.cs" />
|
||||
@ -55,6 +56,17 @@
|
||||
<Name>ANX.Framework</Name>
|
||||
</ProjectReference>
|
||||
</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" />
|
||||
<!-- 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.
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
@ -63,10 +63,10 @@ namespace ANX.PlatformSystem.Windows
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region CreateMediaPlayer (TODO)
|
||||
#region CreateMediaPlayer
|
||||
public INativeMediaLibrary CreateMediaLibrary()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
return new WindowsMediaLibrary();
|
||||
}
|
||||
#endregion
|
||||
|
||||
|
@ -3,6 +3,7 @@ using System.IO;
|
||||
using ANX.Framework.Audio;
|
||||
using ANX.Framework.NonXNA.Development;
|
||||
using ANX.Framework.NonXNA.SoundSystem;
|
||||
using SharpDX;
|
||||
using SharpDX.Multimedia;
|
||||
using SharpDX.XAudio2;
|
||||
|
||||
@ -37,9 +38,26 @@ namespace ANX.SoundSystem.Windows.XAudio
|
||||
|
||||
internal XAudioSoundEffect(byte[] buffer, int offset, int count, int sampleRate, AudioChannels channels,
|
||||
int loopStart, int loopLength)
|
||||
{
|
||||
// TODO: the buffer already contains the pcm data to be played!
|
||||
throw new NotImplementedException();
|
||||
{
|
||||
WaveFormat = new WaveFormat(sampleRate, (int)channels);
|
||||
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()
|
||||
|
Loading…
x
Reference in New Issue
Block a user