2011-01-11 02:55:51 +00:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
2013-11-14 19:33:13 +00:00
|
|
|
|
namespace BizHawk.Emulation.Common
|
2011-01-11 02:55:51 +00:00
|
|
|
|
{
|
2016-12-09 01:51:17 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// An interface that extends a sound provider to provide mixing capabilities through the SoundMixer class
|
|
|
|
|
/// </summary>
|
2016-12-09 16:24:43 +00:00
|
|
|
|
public interface IMixedSoundProvider : IAsyncSoundProvider
|
2016-12-09 01:51:17 +00:00
|
|
|
|
{
|
|
|
|
|
int MaxVolume { get; set; }
|
|
|
|
|
}
|
2013-11-04 01:39:19 +00:00
|
|
|
|
|
2016-12-09 01:51:17 +00:00
|
|
|
|
// This is a straightforward class to mix/chain multiple ISoundProvider sources.
|
2016-12-09 16:24:43 +00:00
|
|
|
|
public sealed class SoundMixer : IAsyncSoundProvider
|
2013-11-04 01:39:19 +00:00
|
|
|
|
{
|
2016-12-09 01:51:17 +00:00
|
|
|
|
private readonly List<IMixedSoundProvider> SoundProviders;
|
2013-11-04 01:39:19 +00:00
|
|
|
|
|
2016-12-09 01:51:17 +00:00
|
|
|
|
public SoundMixer(params IMixedSoundProvider[] soundProviders)
|
2013-11-04 01:39:19 +00:00
|
|
|
|
{
|
2016-12-09 01:51:17 +00:00
|
|
|
|
SoundProviders = new List<IMixedSoundProvider>(soundProviders);
|
2013-11-04 01:39:19 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-12-09 01:51:17 +00:00
|
|
|
|
public void AddSource(IMixedSoundProvider source)
|
2013-11-04 01:39:19 +00:00
|
|
|
|
{
|
|
|
|
|
SoundProviders.Add(source);
|
|
|
|
|
}
|
|
|
|
|
|
2016-12-09 01:51:17 +00:00
|
|
|
|
public void DisableSource(IMixedSoundProvider source)
|
2013-11-04 01:39:19 +00:00
|
|
|
|
{
|
|
|
|
|
SoundProviders.Remove(source);
|
|
|
|
|
}
|
2011-01-11 02:55:51 +00:00
|
|
|
|
|
2011-03-19 09:12:56 +00:00
|
|
|
|
public void DiscardSamples()
|
|
|
|
|
{
|
|
|
|
|
foreach (var soundSource in SoundProviders)
|
2016-12-11 17:14:42 +00:00
|
|
|
|
{
|
2011-03-19 09:12:56 +00:00
|
|
|
|
soundSource.DiscardSamples();
|
2016-12-11 17:14:42 +00:00
|
|
|
|
}
|
2011-03-19 09:12:56 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-11-04 01:39:19 +00:00
|
|
|
|
public void GetSamples(short[] samples)
|
|
|
|
|
{
|
|
|
|
|
foreach (var soundSource in SoundProviders)
|
2016-12-11 17:14:42 +00:00
|
|
|
|
{
|
2013-11-04 01:39:19 +00:00
|
|
|
|
soundSource.GetSamples(samples);
|
2016-12-11 17:14:42 +00:00
|
|
|
|
}
|
2013-11-04 01:39:19 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Splits the volume space equally between available sources.
|
|
|
|
|
public void EqualizeVolumes()
|
|
|
|
|
{
|
|
|
|
|
int eachVolume = short.MaxValue / SoundProviders.Count;
|
|
|
|
|
foreach (var source in SoundProviders)
|
2013-11-15 01:52:03 +00:00
|
|
|
|
{
|
2013-11-04 01:39:19 +00:00
|
|
|
|
source.MaxVolume = eachVolume;
|
2013-11-15 01:52:03 +00:00
|
|
|
|
}
|
2013-11-04 01:39:19 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2011-01-11 02:55:51 +00:00
|
|
|
|
}
|