From 9907232af78e80cea3a8352db39fed4b1ba4a5aa Mon Sep 17 00:00:00 2001 From: Alessandro Proto Date: Thu, 16 Feb 2023 19:12:50 +0100 Subject: [PATCH] Added back volume arg --- Capy64/Core/Audio.cs | 13 ++----------- Capy64/Runtime/Libraries/Audio.cs | 4 ++-- 2 files changed, 4 insertions(+), 13 deletions(-) diff --git a/Capy64/Core/Audio.cs b/Capy64/Core/Audio.cs index f9df6f2..436a75c 100644 --- a/Capy64/Core/Audio.cs +++ b/Capy64/Core/Audio.cs @@ -14,16 +14,7 @@ // limitations under the License. using Microsoft.Xna.Framework.Audio; -using Microsoft.Xna.Framework.Graphics; 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; @@ -54,7 +45,7 @@ public class Audio : IDisposable 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 buffer = new byte[size]; @@ -74,7 +65,7 @@ public class Audio : IDisposable }; 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) { buffer[i] = (byte)(sample >> 8); diff --git a/Capy64/Runtime/Libraries/Audio.cs b/Capy64/Runtime/Libraries/Audio.cs index 87c472a..ea28ba0 100644 --- a/Capy64/Runtime/Libraries/Audio.cs +++ b/Capy64/Runtime/Libraries/Audio.cs @@ -157,7 +157,7 @@ public class Audio : IComponent var freq = L.OptNumber(1, 440); 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); var timespan = TimeSpan.FromSeconds(time); @@ -172,7 +172,7 @@ public class Audio : IComponent null, }); - var buffer = _game.Audio.GenerateWave((Waveform)form, freq, timespan); + var buffer = _game.Audio.GenerateWave((Waveform)form, freq, timespan, volume); try {