Fix #17230: Dummy audio output class
This commit is contained in:
committed by
abcdefg30
parent
70b1df6ce7
commit
72eb4e1749
@@ -45,10 +45,12 @@ namespace OpenRA
|
|||||||
ISound video;
|
ISound video;
|
||||||
MusicInfo currentMusic;
|
MusicInfo currentMusic;
|
||||||
Dictionary<uint, ISound> currentSounds = new Dictionary<uint, ISound>();
|
Dictionary<uint, ISound> currentSounds = new Dictionary<uint, ISound>();
|
||||||
|
public bool DummyEngine { get; private set; }
|
||||||
|
|
||||||
public Sound(IPlatform platform, SoundSettings soundSettings)
|
public Sound(IPlatform platform, SoundSettings soundSettings)
|
||||||
{
|
{
|
||||||
soundEngine = platform.CreateSound(soundSettings.Device);
|
soundEngine = platform.CreateSound(soundSettings.Device);
|
||||||
|
DummyEngine = soundEngine.Dummy;
|
||||||
|
|
||||||
if (soundSettings.Mute)
|
if (soundSettings.Mute)
|
||||||
MuteAudio();
|
MuteAudio();
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ namespace OpenRA
|
|||||||
ISoundSource AddSoundSourceFromMemory(byte[] data, int channels, int sampleBits, int sampleRate);
|
ISoundSource AddSoundSourceFromMemory(byte[] data, int channels, int sampleBits, int sampleRate);
|
||||||
ISound Play2D(ISoundSource sound, bool loop, bool relative, WPos pos, float volume, bool attenuateVolume);
|
ISound Play2D(ISoundSource sound, bool loop, bool relative, WPos pos, float volume, bool attenuateVolume);
|
||||||
ISound Play2DStream(Stream stream, int channels, int sampleBits, int sampleRate, bool loop, bool relative, WPos pos, float volume);
|
ISound Play2DStream(Stream stream, int channels, int sampleBits, int sampleRate, bool loop, bool relative, WPos pos, float volume);
|
||||||
|
bool Dummy { get; }
|
||||||
float Volume { get; set; }
|
float Volume { get; set; }
|
||||||
void PauseSound(ISound sound, bool paused);
|
void PauseSound(ISound sound, bool paused);
|
||||||
void StopSound(ISound sound);
|
void StopSound(ISound sound);
|
||||||
|
|||||||
@@ -104,7 +104,7 @@ namespace OpenRA.Mods.Common.Widgets
|
|||||||
if (!stopped && !paused)
|
if (!stopped && !paused)
|
||||||
{
|
{
|
||||||
var nextFrame = 0;
|
var nextFrame = 0;
|
||||||
if (video.HasAudio)
|
if (video.HasAudio && !Game.Sound.DummyEngine)
|
||||||
nextFrame = (int)float2.Lerp(0, video.Frames, Game.Sound.VideoSeekPosition * invLength);
|
nextFrame = (int)float2.Lerp(0, video.Frames, Game.Sound.VideoSeekPosition * invLength);
|
||||||
else
|
else
|
||||||
nextFrame = video.CurrentFrame + 1;
|
nextFrame = video.CurrentFrame + 1;
|
||||||
|
|||||||
@@ -9,6 +9,7 @@
|
|||||||
*/
|
*/
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
using System;
|
||||||
using OpenRA.Primitives;
|
using OpenRA.Primitives;
|
||||||
|
|
||||||
namespace OpenRA.Platforms.Default
|
namespace OpenRA.Platforms.Default
|
||||||
@@ -21,9 +22,17 @@ namespace OpenRA.Platforms.Default
|
|||||||
}
|
}
|
||||||
|
|
||||||
public ISoundEngine CreateSound(string device)
|
public ISoundEngine CreateSound(string device)
|
||||||
|
{
|
||||||
|
try
|
||||||
{
|
{
|
||||||
return new OpenAlSoundEngine(device);
|
return new OpenAlSoundEngine(device);
|
||||||
}
|
}
|
||||||
|
catch (InvalidOperationException e)
|
||||||
|
{
|
||||||
|
Log.Write("sound", "Failed to initialize OpenAL device. Error was {0}", e);
|
||||||
|
return new DummySoundEngine(device);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public IFont CreateFont(byte[] data)
|
public IFont CreateFont(byte[] data)
|
||||||
{
|
{
|
||||||
|
|||||||
75
OpenRA.Platforms.Default/DummySoundEngine.cs
Normal file
75
OpenRA.Platforms.Default/DummySoundEngine.cs
Normal file
@@ -0,0 +1,75 @@
|
|||||||
|
#region Copyright & License Information
|
||||||
|
/*
|
||||||
|
* Copyright 2007-2019 The OpenRA Developers (see AUTHORS)
|
||||||
|
* This file is part of OpenRA, which is free software. It is made
|
||||||
|
* available to you under the terms of the GNU General Public License
|
||||||
|
* as published by the Free Software Foundation, either version 3 of
|
||||||
|
* the License, or (at your option) any later version. For more
|
||||||
|
* information, see COPYING.
|
||||||
|
*/
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
using System.IO;
|
||||||
|
|
||||||
|
namespace OpenRA.Platforms.Default
|
||||||
|
{
|
||||||
|
sealed class DummySoundEngine : ISoundEngine
|
||||||
|
{
|
||||||
|
public bool Dummy { get { return true; } }
|
||||||
|
|
||||||
|
public SoundDevice[] AvailableDevices()
|
||||||
|
{
|
||||||
|
var defaultDevices = new[]
|
||||||
|
{
|
||||||
|
new SoundDevice(null, "Default Output"),
|
||||||
|
};
|
||||||
|
|
||||||
|
return defaultDevices;
|
||||||
|
}
|
||||||
|
|
||||||
|
public DummySoundEngine(string deviceName) { }
|
||||||
|
|
||||||
|
public ISoundSource AddSoundSourceFromMemory(byte[] data, int channels, int sampleBits, int sampleRate)
|
||||||
|
{
|
||||||
|
return new NullSoundSource();
|
||||||
|
}
|
||||||
|
|
||||||
|
public ISound Play2D(ISoundSource soundSource, bool loop, bool relative, WPos pos, float volume, bool attenuateVolume)
|
||||||
|
{
|
||||||
|
return new NullSound();
|
||||||
|
}
|
||||||
|
|
||||||
|
public ISound Play2DStream(Stream stream, int channels, int sampleBits, int sampleRate, bool loop, bool relative, WPos pos, float volume)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public float Volume
|
||||||
|
{
|
||||||
|
get { return 0; }
|
||||||
|
set { }
|
||||||
|
}
|
||||||
|
|
||||||
|
public void PauseSound(ISound sound, bool paused) { }
|
||||||
|
public void SetAllSoundsPaused(bool paused) { }
|
||||||
|
public void SetSoundVolume(float volume, ISound music, ISound video) { }
|
||||||
|
public void StopSound(ISound sound) { }
|
||||||
|
public void StopAllSounds() { }
|
||||||
|
public void SetListenerPosition(WPos position) { }
|
||||||
|
public void Dispose() { }
|
||||||
|
}
|
||||||
|
|
||||||
|
class NullSoundSource : ISoundSource
|
||||||
|
{
|
||||||
|
public void Dispose() { }
|
||||||
|
}
|
||||||
|
|
||||||
|
class NullSound : ISound
|
||||||
|
{
|
||||||
|
public float Volume { get; set; }
|
||||||
|
public float SeekPosition { get { return 0; } }
|
||||||
|
public bool Complete { get { return false; } }
|
||||||
|
|
||||||
|
public void SetPosition(WPos position) { }
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -23,6 +23,8 @@ namespace OpenRA.Platforms.Default
|
|||||||
{
|
{
|
||||||
sealed class OpenAlSoundEngine : ISoundEngine
|
sealed class OpenAlSoundEngine : ISoundEngine
|
||||||
{
|
{
|
||||||
|
public bool Dummy { get { return false; } }
|
||||||
|
|
||||||
public SoundDevice[] AvailableDevices()
|
public SoundDevice[] AvailableDevices()
|
||||||
{
|
{
|
||||||
var defaultDevices = new[]
|
var defaultDevices = new[]
|
||||||
|
|||||||
Reference in New Issue
Block a user