Skip to content

Commit

Permalink
Merge branch 'develop3d' of http://github.com/mono/MonoGame into andr…
Browse files Browse the repository at this point in the history
…oid_texture_reload_fix
  • Loading branch information
Aranda committed Nov 14, 2012
2 parents 6322d61 + 65cfd25 commit 2c69434
Show file tree
Hide file tree
Showing 64 changed files with 1,833 additions and 419 deletions.
26 changes: 26 additions & 0 deletions MonoGame.Framework.WindowsPhone.sln
@@ -0,0 +1,26 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 2012
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MonoGame.Framework.WindowsPhone", "MonoGame.Framework\MonoGame.Framework.WindowsPhone.csproj", "{BAA9A6E4-7690-4DE0-9531-DE0EAEEC9739}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|ARM = Debug|ARM
Debug|x86 = Debug|x86
Release|ARM = Release|ARM
Release|x86 = Release|x86
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{BAA9A6E4-7690-4DE0-9531-DE0EAEEC9739}.Debug|ARM.ActiveCfg = Debug|ARM
{BAA9A6E4-7690-4DE0-9531-DE0EAEEC9739}.Debug|ARM.Build.0 = Debug|ARM
{BAA9A6E4-7690-4DE0-9531-DE0EAEEC9739}.Debug|x86.ActiveCfg = Debug|x86
{BAA9A6E4-7690-4DE0-9531-DE0EAEEC9739}.Debug|x86.Build.0 = Debug|x86
{BAA9A6E4-7690-4DE0-9531-DE0EAEEC9739}.Release|ARM.ActiveCfg = Release|ARM
{BAA9A6E4-7690-4DE0-9531-DE0EAEEC9739}.Release|ARM.Build.0 = Release|ARM
{BAA9A6E4-7690-4DE0-9531-DE0EAEEC9739}.Release|x86.ActiveCfg = Release|x86
{BAA9A6E4-7690-4DE0-9531-DE0EAEEC9739}.Release|x86.Build.0 = Release|x86
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal
40 changes: 28 additions & 12 deletions MonoGame.Framework/Audio/SoundEffect.cs
Expand Up @@ -306,10 +306,12 @@ public string Name

public SoundEffectInstance CreateInstance()
{
var instance = new SoundEffectInstance();
#if WINRT
instance._effect = this;
instance._voice = new SourceVoice(SoundEffect.Device, _format, VoiceFlags.None, XAudio2.MaximumFrequencyRatio);
SourceVoice voice = null;
if (Device != null)
voice = new SourceVoice(Device, _format, VoiceFlags.None, XAudio2.MaximumFrequencyRatio);

var instance = new SoundEffectInstance(this, voice);
#else
instance.Sound = _sound;
#endif
Expand Down Expand Up @@ -391,8 +393,8 @@ public static float MasterVolume
}

#if WINRT
public static XAudio2 Device;
public static MasteringVoice MasterVoice;
internal static XAudio2 Device { get; private set; }
internal static MasteringVoice MasterVoice { get; private set; }

private static bool _device3DDirty = true;
private static Speakers _speakers = Speakers.Stereo;
Expand All @@ -417,7 +419,7 @@ public static Speakers Speakers

private static X3DAudio _device3D;

public static X3DAudio Device3D
internal static X3DAudio Device3D
{
get
{
Expand All @@ -433,15 +435,29 @@ public static X3DAudio Device3D

static SoundEffect()
{
// This cannot fail.
Device = new XAudio2();
Device.StartEngine();

// Let windows autodetect number of channels and sample rate.
MasterVoice = new MasteringVoice(Device, XAudio2.DefaultChannels, XAudio2.DefaultSampleRate);
MasterVoice.SetVolume(_masterVolume, 0);
try
{
Device.StartEngine();

// Let windows autodetect number of channels and sample rate.
MasterVoice = new MasteringVoice(Device, XAudio2.DefaultChannels, XAudio2.DefaultSampleRate);
MasterVoice.SetVolume(_masterVolume, 0);

// The autodetected value of MasterVoice.ChannelMask corresponds to the speaker layout.
Speakers = (Speakers)MasterVoice.ChannelMask;
}
catch
{
// Release the device and null it as
// we have no audio support.
Device.Dispose();
Device = null;
MasterVoice = null;
}

// The autodetected value of MasterVoice.ChannelMask corresponds to the speaker layout.
Speakers = (Speakers)MasterVoice.ChannelMask;
}

// Does someone actually need to call this if it only happens when the whole
Expand Down
106 changes: 70 additions & 36 deletions MonoGame.Framework/Audio/SoundEffectInstance.cs
Expand Up @@ -60,8 +60,8 @@ public sealed class SoundEffectInstance : IDisposable
#endif

#if WINRT
internal SourceVoice _voice { get; set; }
internal SoundEffect _effect { get; set; }
private SourceVoice _voice { get; set; }
private SoundEffect _effect { get; set; }

private bool _paused;
private bool _loop;
Expand All @@ -81,17 +81,24 @@ internal Sound Sound
}
#endif

internal SoundEffectInstance()
{
}

#if WINRT
internal SoundEffectInstance(SoundEffect effect, SourceVoice voice)
{
_effect = effect;
_voice = voice;
}
#endif

public void Dispose()
{
#if WINRT
_voice.DestroyVoice();
_voice.Dispose();
_voice = null;
_effect = null;
if (_voice != null)
{
_voice.DestroyVoice();
_voice.Dispose();
_voice = null;
}
_effect = null;
#elif ANDROID
if (_streamId >= 0)
_sound.Stop(_streamId);
Expand All @@ -105,7 +112,11 @@ public void Dispose()

public void Apply3D (AudioListener listener, AudioEmitter emitter)
{
#if WINRT
#if WINRT
// If we have no voice then nothing to do.
if (_voice == null)
return;

// Convert from XNA Emitter to a SharpDX Emitter
var e = emitter.ToEmitter();
e.CurveDistanceScaler = SoundEffect.DistanceScale;
Expand Down Expand Up @@ -141,8 +152,9 @@ public void Apply3D (AudioListener[] listeners,AudioEmitter emitter)

public void Pause ()
{
#if WINRT
_voice.Stop();
#if WINRT
if (_voice != null)
_voice.Stop();
_paused = true;
#else
if ( _sound != null )
Expand All @@ -159,20 +171,23 @@ public void Pause ()

public void Play ()
{
#if WINRT
// Choose the correct buffer depending on if we are looped.
var buffer = _loop ? _effect._loopedBuffer : _effect._buffer;

if (_voice.State.BuffersQueued > 0)
#if WINRT
if (_voice != null)
{
_voice.Stop();
_voice.FlushSourceBuffers();
}
// Choose the correct buffer depending on if we are looped.
var buffer = _loop ? _effect._loopedBuffer : _effect._buffer;

_voice.SubmitSourceBuffer(buffer, null);
_voice.Start();
if (_voice.State.BuffersQueued > 0)
{
_voice.Stop();
_voice.FlushSourceBuffers();
}

_paused = false;
_voice.SubmitSourceBuffer(buffer, null);
_voice.Start();
}

_paused = false;
#else
if ( _sound != null )
{
Expand All @@ -195,7 +210,8 @@ public void Play ()
public void Resume()
{
#if WINRT
_voice.Start();
if (_voice != null)
_voice.Start();
_paused = false;
#else
if ( _sound != null )
Expand All @@ -216,9 +232,13 @@ public void Resume()
public void Stop()
{
#if WINRT
_voice.Stop(0);
_voice.FlushSourceBuffers();
_paused = false;
if (_voice != null)
{
_voice.Stop(0);
_voice.FlushSourceBuffers();
}

_paused = false;
#else
if ( _sound != null )
{
Expand All @@ -236,7 +256,9 @@ public void Stop()
public void Stop(bool immediate)
{
#if WINRT
_voice.Stop( immediate ? 0 : (int)PlayFlags.Tails );
if (_voice != null)
_voice.Stop(immediate ? 0 : (int)PlayFlags.Tails);

_paused = false;
#else
if ( _sound != null )
Expand Down Expand Up @@ -319,10 +341,14 @@ public float Pan

set
{
#if WINRT
#if WINRT
// According to XNA documentation:
// "Panning, ranging from -1.0f (full left) to 1.0f (full right). 0.0f is centered."
_pan = MathHelper.Clamp(value, -1.0f, 1.0f);

// If we have no voice then nothing more to do.
if (_voice == null)
return;

var srcChannelCount = _effect._format.Channels;
var dstChannelCount = SoundEffect.MasterVoice.VoiceDetails.InputChannelCount;
Expand Down Expand Up @@ -420,6 +446,9 @@ public float Pitch
get
{
#if WINRT
if (_voice == null)
return 0.0f;

// NOTE: This is copy of what XAudio2.FrequencyRatioToSemitones() does
// which avoids the native call and is actually more accurate.
var pitch = 39.86313713864835 * Math.Log10(_voice.FrequencyRatio);
Expand All @@ -439,6 +468,9 @@ public float Pitch
set
{
#if WINRT
if (_voice == null)
return;

// NOTE: This is copy of what XAudio2.SemitonesToFrequencyRatio() does
// which avoids the native call and is actually more accurate.
var ratio = Math.Pow(2.0, value);
Expand All @@ -457,11 +489,9 @@ public SoundState State
get
{
#if WINRT
// If no buffers queued the sound is stopped.
if (_voice.State.BuffersQueued == 0)
{
// If no voice or no buffers queued the sound is stopped.
if (_voice == null || _voice.State.BuffersQueued == 0)
return SoundState.Stopped;
}

// Because XAudio2 does not actually provide if a SourceVoice is Started / Stopped
// we have to save the "paused" state ourself.
Expand Down Expand Up @@ -498,7 +528,10 @@ public float Volume
get
{
#if WINRT
return _voice.Volume;
if (_voice == null)
return 0.0f;
else
return _voice.Volume;
#else
if (_sound != null)
{
Expand All @@ -514,7 +547,8 @@ public float Volume
set
{
#if WINRT
_voice.SetVolume(value, XAudio2.CommitNow);
if (_voice != null)
_voice.SetVolume(value, XAudio2.CommitNow);
#else
if ( _sound != null )
{
Expand Down
Expand Up @@ -40,8 +40,11 @@ 1. Definitions

using System;
using System.Collections.Generic;

#if WINRT
using System.Reflection;
#endif
using Microsoft.Xna.Framework.Graphics;
using System.Diagnostics;

namespace Microsoft.Xna.Framework.Content
{
Expand All @@ -57,15 +60,17 @@ protected internal override EffectMaterial Read (ContentReader input, EffectMate
foreach (KeyValuePair<string, object> item in dict) {
var parameter = effectMaterial.Parameters [item.Key];
if (parameter != null) {
#if WINRT
if (typeof(Texture).GetTypeInfo().IsAssignableFrom(item.Value.GetType().GetTypeInfo())){
#else
if (typeof(Texture).IsAssignableFrom (item.Value.GetType ())) {
#endif
parameter.SetValue ((Texture)item.Value);
} else {
throw new NotImplementedException ();
}
} else {
#if DEBUG
Console.WriteLine ("No parameter " + item.Key);
#endif
Debug.WriteLine ("No parameter " + item.Key);
}
}

Expand Down
4 changes: 2 additions & 2 deletions MonoGame.Framework/Content/ContentReaders/Texture2DReader.cs
Expand Up @@ -99,7 +99,7 @@ protected internal override Texture2D Read(ContentReader reader, Texture2D exist
case SurfaceFormat.Dxt5:
convertedFormat = SurfaceFormat.RgbaPvrtc4Bpp;
break;
#elif ANDROID || PSS
#elif ANDROID || PSM
case SurfaceFormat.Dxt1:
case SurfaceFormat.Dxt3:
case SurfaceFormat.Dxt5:
Expand All @@ -125,7 +125,7 @@ protected internal override Texture2D Read(ContentReader reader, Texture2D exist
//Convert the image data if required
switch (surfaceFormat)
{
#if ANDROID || PSS
#if ANDROID || PSM
//no Dxt in OpenGL ES
case SurfaceFormat.Dxt1:
levelData = DxtUtil.DecompressDxt1(levelData, levelWidth, levelHeight);
Expand Down

0 comments on commit 2c69434

Please sign in to comment.