Skip to content

Commit

Permalink
openal-soft implementation for Android
Browse files Browse the repository at this point in the history
Uses the same OpenAL code as most other supported MonoGame platforms.
Supports low latency sound on Android v4.2 and above.  Devices lower than v4.2 will have higher latency on sound playback.  Android v4.4 and higher no longer require double-buffered sound on the application side.  Tested on Nexus S with v4.1.2 and Nexus 5 with v4.4.4.
Target framework version raised to v4.2 (API Level 17) in Android and Ouya projects to allow testing for low latency sound support.  Application projects should have "Compile using Android version" set to API Level 17, "Minimum Android to target" set to API Level 14 and "Target Android version" set to "Use Compile using SDK version".  This allows use of the functions to test low latency sound support (available in v4.2), but apps can still be run on v4.0 devices.
GenerateProject.xslt extracted from Protobuild.exe to allow target framework version to be changed in Android and Ouya projects and to add support for EmbeddedNativeLibrary items.

Depends on MonoGame/MonoGame.Dependencies#19
  • Loading branch information
KonajuGames committed Jun 26, 2014
1 parent b37fad2 commit 459f21a
Show file tree
Hide file tree
Showing 8 changed files with 2,030 additions and 66 deletions.
1,790 changes: 1,790 additions & 0 deletions Build/GenerateProject.xslt

Large diffs are not rendered by default.

35 changes: 21 additions & 14 deletions Build/Projects/MonoGame.Framework.definition
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,12 @@
<PlatformSpecificOutputFolder>True</PlatformSpecificOutputFolder>

<CustomDefinitions>
<Platform Name="Android">TRACE;ANDROID;GLES;OPENGL</Platform>
<Platform Name="Android">TRACE;ANDROID;GLES;OPENGL;OPENAL</Platform>
<Platform Name="Angle">TRACE;ANGLE;GLES;OPENGL;OPENAL</Platform>
<Platform Name="iOS">IOS;GLES;OPENGL;OPENAL</Platform>
<Platform Name="Linux">TRACE;LINUX;OPENGL;OPENAL</Platform>
<Platform Name="MacOS">MONOMAC;OPENGL;OPENAL</Platform>
<Platform Name="Ouya">TRACE;ANDROID;GLES;OPENGL;OUYA</Platform>
<Platform Name="Ouya">TRACE;ANDROID;GLES;OPENGL;OUYA;OPENAL</Platform>
<Platform Name="PSMobile">PSM</Platform>
<Platform Name="Windows">TRACE;WINDOWS;DIRECTX;WINDOWS_MEDIA_SESSION</Platform>
<Platform Name="Windows8">TRACE;NETFX_CORE;WINRT;WINDOWS_STOREAPP;DIRECTX;DIRECTX11_1;WINDOWS_MEDIA_ENGINE</Platform>
Expand All @@ -64,6 +64,19 @@
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>

<EmbeddedNativeLibrary Include="..\ThirdParty\Dependencies\openal-soft\libs\armeabi-v7a\libopenal32.so">
<Platforms>Android,Ouya</Platforms>
<Link>libs\armeabi-v7a\libopenal32.so</Link>
</EmbeddedNativeLibrary>
<EmbeddedNativeLibrary Include="..\ThirdParty\Dependencies\openal-soft\libs\armeabi\libopenal32.so">
<Platforms>Android,Ouya</Platforms>
<Link>libs\armeabi\libopenal32.so</Link>
</EmbeddedNativeLibrary>
<EmbeddedNativeLibrary Include="..\ThirdParty\Dependencies\openal-soft\libs\x86\libopenal32.so">
<Platforms>Android,Ouya</Platforms>
<Link>libs\x86\libopenal32.so</Link>
</EmbeddedNativeLibrary>

<!-- Microsoft.Xna.Framework -->
<Compile Include="BoundingBox.cs" />
<Compile Include="BoundingFrustum.cs" />
Expand Down Expand Up @@ -138,31 +151,28 @@
<Compile Include="Audio\AudioEmitter.cs" />
<Compile Include="Audio\AudioListener.cs" />
<Compile Include="Audio\AudioLoader.cs">
<Platforms>Linux,WindowsGL,Angle</Platforms>
<Platforms>Linux,WindowsGL,Angle,Android,Ouya</Platforms>
</Compile>
<Compile Include="Audio\AudioUtil.cs">
<Platforms>Android,Ouya,PSMobile</Platforms>
<Platforms>PSMobile</Platforms>
</Compile>
<Compile Include="Audio\InstancePlayLimitException.cs" />
<Compile Include="Audio\MSADPCMToPCM.cs">
<Platforms>Android,Angle,iOS,Linux,MacOS,Ouya,PSMobile,WindowsGL,Web</Platforms>
</Compile>
<Compile Include="Audio\NoAudioHardwareException.cs" />
<Compile Include="Audio\OALSoundBuffer.cs">
<Platforms>Angle,iOS,Linux,MacOS,WindowsGL</Platforms>
<Platforms>Angle,iOS,Linux,MacOS,WindowsGL,Android,Ouya</Platforms>
</Compile>
<Compile Include="Audio\OpenALSoundController.cs">
<Platforms>Angle,iOS,Linux,MacOS,WindowsGL</Platforms>
<Platforms>Angle,iOS,Linux,MacOS,WindowsGL,Android,Ouya</Platforms>
</Compile>
<Compile Include="Audio\OpenALSupport.cs">
<Platforms>iOS,MacOS</Platforms>
</Compile>
<Compile Include="Audio\SoundEffect.cs" />
<Compile Include="Audio\SoundEffect.Android.cs">
<Platforms>Android,Ouya</Platforms>
</Compile>
<Compile Include="Audio\SoundEffect.OpenAL.cs">
<Platforms>Angle,iOS,Linux,WindowsGL,MacOS</Platforms>
<Platforms>Angle,iOS,Linux,WindowsGL,MacOS,Android,Ouya</Platforms>
</Compile>
<Compile Include="Audio\SoundEffect.PSM.cs">
<Platforms>PSMobile</Platforms>
Expand All @@ -174,11 +184,8 @@
<Platforms>Web</Platforms>
</Compile>
<Compile Include="Audio\SoundEffectInstance.cs" />
<Compile Include="Audio\SoundEffectInstance.Android.cs">
<Platforms>Android,Ouya</Platforms>
</Compile>
<Compile Include="Audio\SoundEffectInstance.OpenAL.cs">
<Platforms>Angle,iOS,Linux,WindowsGL,MacOS</Platforms>
<Platforms>Angle,iOS,Linux,WindowsGL,MacOS,Android,Ouya</Platforms>
</Compile>
<Compile Include="Audio\SoundEffectInstance.PSM.cs">
<Platforms>PSMobile</Platforms>
Expand Down
2 changes: 0 additions & 2 deletions MonoGame.Framework/Android/AndroidGamePlatform.cs
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,6 @@ void Activity_Resumed(object sender, EventArgs e)
{
IsActive = true;
_gameWindow.GameView.Resume();
SoundEffectInstance.SoundPool.AutoResume();
if(_MediaPlayer_PrevState == MediaState.Playing && Game.Activity.AutoPauseAndResumeMediaPlayer)
MediaPlayer.Resume();
if (!_gameWindow.GameView.IsFocused)
Expand All @@ -150,7 +149,6 @@ void Activity_Paused(object sender, EventArgs e)
_MediaPlayer_PrevState = MediaPlayer.State;
_gameWindow.GameView.Pause();
_gameWindow.GameView.ClearFocus();
SoundEffectInstance.SoundPool.AutoPause();
if(Game.Activity.AutoPauseAndResumeMediaPlayer)
MediaPlayer.Pause();
}
Expand Down
26 changes: 22 additions & 4 deletions MonoGame.Framework/Audio/OALSoundBuffer.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
// MonoGame - Copyright (C) The MonoGame Team
// This file is subject to the terms and conditions defined in
// file 'LICENSE.txt', which is part of this source code package.

using System;

#if IOS || WINDOWS || LINUX || ANGLE
using OpenTK.Audio.OpenAL;
#elif MONOMAC
#if MONOMAC
using MonoMac.OpenAL;
#else
using OpenTK.Audio.OpenAL;
#endif


namespace Microsoft.Xna.Framework.Audio
{
internal class OALSoundBuffer : IDisposable
Expand All @@ -17,6 +20,7 @@ internal class OALSoundBuffer : IDisposable
int sampleRate;
private int _sourceId;
bool _isDisposed;
internal int _pauseCount;

public OALSoundBuffer ()
{
Expand Down Expand Up @@ -87,6 +91,20 @@ public void BindDataBuffer(byte[] dataBuffer, ALFormat format, int size, int sam

}

public void Pause()
{
if (_pauseCount == 0)
AL.SourcePause(_sourceId);
++_pauseCount;
}

public void Resume()
{
--_pauseCount;
if (_pauseCount == 0)
AL.SourcePlay(_sourceId);
}

public void Dispose()
{
Dispose(true);
Expand Down

0 comments on commit 459f21a

Please sign in to comment.