mirror of
https://github.com/Ale32bit/Capy64.git
synced 2025-01-18 18:46:43 +00:00
Added back volume arg
This commit is contained in:
parent
9dd01041d0
commit
9907232af7
2 changed files with 4 additions and 13 deletions
|
@ -14,16 +14,7 @@
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
using Microsoft.Xna.Framework.Audio;
|
using Microsoft.Xna.Framework.Audio;
|
||||||
using Microsoft.Xna.Framework.Graphics;
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Concurrent;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Reflection;
|
|
||||||
using System.Runtime.CompilerServices;
|
|
||||||
using System.Security.Cryptography;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace Capy64.Core;
|
namespace Capy64.Core;
|
||||||
|
|
||||||
|
@ -54,7 +45,7 @@ public class Audio : IDisposable
|
||||||
return Sound.GetSampleDuration(buffer.Length);
|
return Sound.GetSampleDuration(buffer.Length);
|
||||||
}
|
}
|
||||||
|
|
||||||
public byte[] GenerateWave(Waveform form, double frequency, TimeSpan time)
|
public byte[] GenerateWave(Waveform form, double frequency, TimeSpan time, float volume = 1f)
|
||||||
{
|
{
|
||||||
var size = Sound.GetSampleSizeInBytes(time);
|
var size = Sound.GetSampleSizeInBytes(time);
|
||||||
var buffer = new byte[size];
|
var buffer = new byte[size];
|
||||||
|
@ -74,7 +65,7 @@ public class Audio : IDisposable
|
||||||
};
|
};
|
||||||
|
|
||||||
value = Math.Clamp(value, -1, 1);
|
value = Math.Clamp(value, -1, 1);
|
||||||
var sample = (short)(value >= 0.0f ? value * short.MaxValue : value * short.MinValue * -1);
|
var sample = (short)((value >= 0.0f ? value * short.MaxValue : value * short.MinValue * -1) * volume);
|
||||||
if (!BitConverter.IsLittleEndian)
|
if (!BitConverter.IsLittleEndian)
|
||||||
{
|
{
|
||||||
buffer[i] = (byte)(sample >> 8);
|
buffer[i] = (byte)(sample >> 8);
|
||||||
|
|
|
@ -157,7 +157,7 @@ public class Audio : IComponent
|
||||||
|
|
||||||
var freq = L.OptNumber(1, 440);
|
var freq = L.OptNumber(1, 440);
|
||||||
var time = L.OptNumber(2, 1);
|
var time = L.OptNumber(2, 1);
|
||||||
var volume = L.OptNumber(3, 1);
|
var volume = (float)L.OptNumber(3, 1);
|
||||||
volume = Math.Clamp(volume, 0, 1);
|
volume = Math.Clamp(volume, 0, 1);
|
||||||
|
|
||||||
var timespan = TimeSpan.FromSeconds(time);
|
var timespan = TimeSpan.FromSeconds(time);
|
||||||
|
@ -172,7 +172,7 @@ public class Audio : IComponent
|
||||||
null,
|
null,
|
||||||
});
|
});
|
||||||
|
|
||||||
var buffer = _game.Audio.GenerateWave((Waveform)form, freq, timespan);
|
var buffer = _game.Audio.GenerateWave((Waveform)form, freq, timespan, volume);
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue