diff --git a/MPfm/MPfm.Android/Classes/Controls/OutputMeterView.cs b/MPfm/MPfm.Android/Classes/Controls/OutputMeterView.cs index 98a8dc0e..04973bf1 100644 --- a/MPfm/MPfm.Android/Classes/Controls/OutputMeterView.cs +++ b/MPfm/MPfm.Android/Classes/Controls/OutputMeterView.cs @@ -211,11 +211,7 @@ public override void Draw(global::Android.Graphics.Canvas canvas) // Get bar height -- If value = -100 then 0. If value = 0 then = 100. if value = 10 then = 110. //float barHeight = scaleMultiplier * (maxDB + 100); - //// Draw 0db line - //CoreGraphicsHelper.DrawLine(context, new List(){ - // new PointF(0, 4), - // new PointF(Bounds.Width, 4) - //}, _color0dBLine, 1, false, false); + // Draw 0db line var paintLine = new Paint { AntiAlias = true, Color = _color0dBLine @@ -307,25 +303,15 @@ public override void Draw(global::Android.Graphics.Canvas canvas) // Draw peak line float rightHeight = Height - (peakRightDB + 100); - canvas.DrawLine(barWidth, leftHeight, barWidth * 2, rightHeight, paintPeakLine); + canvas.DrawLine(barWidth, rightHeight, barWidth * 2, rightHeight, paintPeakLine); // Draw number of db strDB = peakRightDB.ToString("00.0").Replace(",", "."); if (maxRightDB == -100.0f) strDB = "-inf"; - //// Draw number of decibels (with font shadow to make it easier to read) - //sizeString = CoreGraphicsHelper.MeasureText(context, strDB, "HelveticaNeue-Bold", 10); - //newX = ((barWidth - sizeString.Width) / 2) + barWidth; - //// rectBackgroundText = new RectangleF(newX, Bounds.Height - sizeString.Height - 4, sizeString.Width, sizeString.Height); - //// rectBackgroundText.Inflate(new SizeF(2, 0)); - //// CoreGraphicsHelper.FillRect(context, rectBackgroundText, new CGColor(0.1f, 0.1f, 0.1f, 0.25f)); - //CoreGraphicsHelper.DrawTextAtPoint(context, new PointF(newX + 1, Bounds.Height - sizeString.Height - 4), strDB, "HelveticaNeue-CondensedBold", 10, new CGColor(0.1f, 0.1f, 0.1f, 0.2f)); - //CoreGraphicsHelper.DrawTextAtPoint(context, new PointF(newX, Bounds.Height - sizeString.Height - 4 - 1), strDB, "HelveticaNeue-CondensedBold", 10, new CGColor(1, 1, 1)); - rectText = new Rect(); paintText.GetTextBounds(strDB, 0, strDB.Length, rectText); - //int newX = (barWidth - rectText.Width()) / 2; newX = ((barWidth - rectText.Width()) / 2) + barWidth; canvas.DrawText(strDB, newX, Height - rectText.Height() - 4 - 1, paintText); } diff --git a/MPfm/MPfm.MVP/Presenters/EqualizerPresetsPresenter.cs b/MPfm/MPfm.MVP/Presenters/EqualizerPresetsPresenter.cs index 3568b056..72006a2c 100644 --- a/MPfm/MPfm.MVP/Presenters/EqualizerPresetsPresenter.cs +++ b/MPfm/MPfm.MVP/Presenters/EqualizerPresetsPresenter.cs @@ -136,8 +136,8 @@ private void HandleOutputMeterTimerElapsed(object sender, object eventArgs) for (int a = 0; a < data.Item1.Length; a++) { // The values are already negative to positive, it's just a matter of dividing the value by the max value to get it to -1/+1. - left[a] = (float)data.Item1[a] / (float)Int32.MaxValue; - right[a] = (float)data.Item2[a] / (float)Int32.MaxValue; + left[a] = (float)data.Item1[a] / (float)Int16.MaxValue; + right[a] = (float)data.Item2[a] / (float)Int16.MaxValue; //Console.WriteLine("EQPresetPresenter - a: {0} value: {1} newValue: {2}", a, data.Item1[a], left[a]); } diff --git a/MPfm/MPfm.MVP/Services/PlayerService.cs b/MPfm/MPfm.MVP/Services/PlayerService.cs index ad0e4ea1..77e7a403 100644 --- a/MPfm/MPfm.MVP/Services/PlayerService.cs +++ b/MPfm/MPfm.MVP/Services/PlayerService.cs @@ -151,29 +151,25 @@ public void PlayerCommandMessageReceived(PlayerCommandMessage m) int[] sampleData = new int[l4]; int length = _player.GetMixerData(lengthToFetch, sampleData); - // as less data might be returned by BASS_ChannelGetData as requested + // From BASS.NET API: Note: an int is 32-bit meaning if we expect to receive 16-bit data stereo a single int value will contain 2 x 16-bit, so a full stereo pair of data l4 = length / 4; int[] left = new int[l4 / 2]; int[] right = new int[l4 / 2]; for (int a = 0; a < l4; a++) { - int absLevel = Math.Abs(sampleData[a]); + int leftValue = Base.LowWord(sampleData[a]); + int rightValue = Base.HighWord(sampleData[a]); - // decide on L/R channel - if (a % 2 == 0) - { - // Left channel - left[a / 2] = sampleData[a]; - if (absLevel > maxL) - maxL = absLevel; - } - else - { - // Right channel - right[a / 2] = sampleData[a]; - if (absLevel > maxR) - maxR = absLevel; - } + int absLevelLeft = Math.Abs(leftValue); + int absLevelRight = Math.Abs(rightValue); + + left[a/2] = leftValue; + if (absLevelLeft > maxL) + maxL = absLevelLeft; + + right[a/2] = rightValue; + if (absLevelRight > maxR) + maxR = absLevelRight; } // // Get min max info from wave block diff --git a/MPfm/MPfm.Player/Player.cs b/MPfm/MPfm.Player/Player.cs index d37be8f9..6bbe9c8a 100644 --- a/MPfm/MPfm.Player/Player.cs +++ b/MPfm/MPfm.Player/Player.cs @@ -1342,6 +1342,7 @@ public long Seconds2Bytes(double value) /// Sample data public int GetMixerData(int length, int[] sampleData) { + // NOTE: Do *NOT* try to use the GetData/GetMixerData with short/Int16 array because it crashes under Xamarin.Android. int dataLength; if (Device.DriverType != DriverType.DirectSound) dataLength = _fxChannel.GetMixerData(sampleData, length); diff --git a/MPfm/MPfm.Sound/BassNetWrapper/Base.cs b/MPfm/MPfm.Sound/BassNetWrapper/Base.cs index d08d6197..b1ebd519 100644 --- a/MPfm/MPfm.Sound/BassNetWrapper/Base.cs +++ b/MPfm/MPfm.Sound/BassNetWrapper/Base.cs @@ -17,6 +17,7 @@ using System; using System.Collections.Generic; +using System.Security.Policy; using MPfm.Core; using Un4seen.Bass; using Un4seen.Bass.AddOn.Fx; @@ -368,6 +369,26 @@ public static Double LevelToDB_16Bit(double level) return Conversion.LevelToDB(level, 65535); } + /// + /// Extracts the low word (16-bit) out of a 32-bit integer. + /// + /// 32-bit integer + /// Low word (16-bit) + public static short LowWord(int dWord) + { + return Utils.LowWord(dWord); + } + + /// + /// Extracts the high word (16-bit) out of a 32-bit integer. + /// + /// 32-bit integer + /// High word (16-bit) + public static short HighWord(int dWord) + { + return Utils.HighWord(dWord); + } + #endregion #region Error Management @@ -390,5 +411,6 @@ public static void CheckForError() } #endregion + } }