forked from MoonsideGames/MoonWorks
set loop on play instead of construct
parent
b1b6b84809
commit
6a1fa004d6
|
@ -8,7 +8,7 @@ namespace MoonWorks.Audio
|
||||||
{
|
{
|
||||||
internal IntPtr Handle;
|
internal IntPtr Handle;
|
||||||
internal FAudio.FAudioWaveFormatEx Format;
|
internal FAudio.FAudioWaveFormatEx Format;
|
||||||
public bool Loop { get; }
|
public bool Loop { get; protected set; } = false;
|
||||||
|
|
||||||
protected FAudio.F3DAUDIO_DSP_SETTINGS dspSettings;
|
protected FAudio.F3DAUDIO_DSP_SETTINGS dspSettings;
|
||||||
|
|
||||||
|
@ -168,8 +168,7 @@ namespace MoonWorks.Audio
|
||||||
ushort blockAlign,
|
ushort blockAlign,
|
||||||
ushort channels,
|
ushort channels,
|
||||||
uint samplesPerSecond,
|
uint samplesPerSecond,
|
||||||
bool is3D,
|
bool is3D
|
||||||
bool loop
|
|
||||||
) : base(device)
|
) : base(device)
|
||||||
{
|
{
|
||||||
var format = new FAudio.FAudioWaveFormatEx
|
var format = new FAudio.FAudioWaveFormatEx
|
||||||
|
@ -212,7 +211,6 @@ namespace MoonWorks.Audio
|
||||||
);
|
);
|
||||||
*/
|
*/
|
||||||
|
|
||||||
Loop = loop;
|
|
||||||
State = SoundState.Stopped;
|
State = SoundState.Stopped;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -242,7 +240,7 @@ namespace MoonWorks.Audio
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public abstract void Play();
|
public abstract void Play(bool loop);
|
||||||
public abstract void Pause();
|
public abstract void Pause();
|
||||||
public abstract void Stop(bool immediate);
|
public abstract void Stop(bool immediate);
|
||||||
|
|
||||||
|
|
|
@ -271,11 +271,11 @@ namespace MoonWorks.Audio
|
||||||
/// Gets a sound instance from the pool.
|
/// Gets a sound instance from the pool.
|
||||||
/// NOTE: If you lose track of instances, you will create garbage collection pressure!
|
/// NOTE: If you lose track of instances, you will create garbage collection pressure!
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public StaticSoundInstance GetInstance(bool loop = false)
|
public StaticSoundInstance GetInstance()
|
||||||
{
|
{
|
||||||
if (Instances.Count == 0)
|
if (Instances.Count == 0)
|
||||||
{
|
{
|
||||||
Instances.Push(new StaticSoundInstance(Device, this, false, loop));
|
Instances.Push(new StaticSoundInstance(Device, this, false));
|
||||||
}
|
}
|
||||||
|
|
||||||
return Instances.Pop();
|
return Instances.Pop();
|
||||||
|
|
|
@ -33,20 +33,21 @@ namespace MoonWorks.Audio
|
||||||
internal StaticSoundInstance(
|
internal StaticSoundInstance(
|
||||||
AudioDevice device,
|
AudioDevice device,
|
||||||
StaticSound parent,
|
StaticSound parent,
|
||||||
bool is3D,
|
bool is3D
|
||||||
bool loop
|
) : base(device, parent.FormatTag, parent.BitsPerSample, parent.BlockAlign, parent.Channels, parent.SamplesPerSecond, is3D)
|
||||||
) : base(device, parent.FormatTag, parent.BitsPerSample, parent.BlockAlign, parent.Channels, parent.SamplesPerSecond, is3D, loop)
|
|
||||||
{
|
{
|
||||||
Parent = parent;
|
Parent = parent;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void Play()
|
public override void Play(bool loop = false)
|
||||||
{
|
{
|
||||||
if (State == SoundState.Playing)
|
if (State == SoundState.Playing)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loop = loop;
|
||||||
|
|
||||||
if (Loop)
|
if (Loop)
|
||||||
{
|
{
|
||||||
Parent.Handle.LoopCount = 255;
|
Parent.Handle.LoopCount = 255;
|
||||||
|
|
|
@ -23,18 +23,19 @@ namespace MoonWorks.Audio
|
||||||
ushort blockAlign,
|
ushort blockAlign,
|
||||||
ushort channels,
|
ushort channels,
|
||||||
uint samplesPerSecond,
|
uint samplesPerSecond,
|
||||||
bool is3D,
|
bool is3D
|
||||||
bool loop
|
) : base(device, formatTag, bitsPerSample, blockAlign, channels, samplesPerSecond, is3D) { }
|
||||||
) : base(device, formatTag, bitsPerSample, blockAlign, channels, samplesPerSecond, is3D, loop) { }
|
|
||||||
|
|
||||||
public override void Play()
|
public override void Play(bool loop = false)
|
||||||
{
|
{
|
||||||
if (State == SoundState.Playing)
|
if (State == SoundState.Playing)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loop = loop;
|
||||||
State = SoundState.Playing;
|
State = SoundState.Playing;
|
||||||
|
|
||||||
Update();
|
Update();
|
||||||
FAudio.FAudioSourceVoice_Start(Handle, 0, 0);
|
FAudio.FAudioSourceVoice_Start(Handle, 0, 0);
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,8 +18,7 @@ namespace MoonWorks.Audio
|
||||||
public static StreamingSoundOgg Load(
|
public static StreamingSoundOgg Load(
|
||||||
AudioDevice device,
|
AudioDevice device,
|
||||||
string filePath,
|
string filePath,
|
||||||
bool is3D = false,
|
bool is3D = false
|
||||||
bool loop = false
|
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
var fileHandle = FAudio.stb_vorbis_open_filename(filePath, out var error, IntPtr.Zero);
|
var fileHandle = FAudio.stb_vorbis_open_filename(filePath, out var error, IntPtr.Zero);
|
||||||
|
@ -35,8 +34,7 @@ namespace MoonWorks.Audio
|
||||||
device,
|
device,
|
||||||
fileHandle,
|
fileHandle,
|
||||||
info,
|
info,
|
||||||
is3D,
|
is3D
|
||||||
loop
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -44,8 +42,7 @@ namespace MoonWorks.Audio
|
||||||
AudioDevice device,
|
AudioDevice device,
|
||||||
IntPtr fileHandle,
|
IntPtr fileHandle,
|
||||||
FAudio.stb_vorbis_info info,
|
FAudio.stb_vorbis_info info,
|
||||||
bool is3D,
|
bool is3D
|
||||||
bool loop
|
|
||||||
) : base(
|
) : base(
|
||||||
device,
|
device,
|
||||||
3, /* float type */
|
3, /* float type */
|
||||||
|
@ -53,8 +50,7 @@ namespace MoonWorks.Audio
|
||||||
(ushort) (4 * info.channels),
|
(ushort) (4 * info.channels),
|
||||||
(ushort) info.channels,
|
(ushort) info.channels,
|
||||||
info.sample_rate,
|
info.sample_rate,
|
||||||
is3D,
|
is3D
|
||||||
loop
|
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
FileHandle = fileHandle;
|
FileHandle = fileHandle;
|
||||||
|
|
Loading…
Reference in New Issue