Question
Xamarin Forms Faster MonkeyTapWithSound It's basically a modification of this program at https://github.com/xamarin/xamarin-forms-book-samples/tree/master/Chapter09/MonkeyTapWithSound Modify the MonkeyTapWithSound program to initialize the sound buffers at launch. 1.
Xamarin Forms Faster MonkeyTapWithSound
It's basically a modification of this program at https://github.com/xamarin/xamarin-forms-book-samples/tree/master/Chapter09/MonkeyTapWithSound
Modify the MonkeyTapWithSound program to initialize the sound buffers at launch. 1. Create a new project called MTWSFast. Copy the files IPlatformSoundPlayer. and MonkeyTapWithSounPage.cs to the MTWSFast folder. Change the namespace to MTWSFast . Copy the 3 instances of PlatformSoundPlayer.cs to their respective Android, iOS and UWP folders. Change the namespace to MTWSFast.
I've modified the soundplayer.cs to look like this:
using System; using System.Collections.Generic; using System.Linq; using System.Text;
using Xamarin.Forms;
namespace MTWSFast { class SoundPlayer { const int samplingRate = 22050;
// Hard-coded for monaural, 16-bit-per-sample PCM public static byte[] MakeBuffer(double frequency = 400, int duration = 250) { short[] shortBuffer = new short[samplingRate * duration / 1000]; double angleIncrement = frequency / samplingRate; double angle = 0.0;
for (int i = 0; i
// 0 to 1 if (angle
// 1 to -1 else if (angle
// -1 to 0 else sample = 4 * (angle - 1);
shortBuffer[i] = (short)(32767 * sample); angle += angleIncrement;
while (angle > 1) angle -= 1; }
byte[] byteBuffer = new byte[2 * shortBuffer.Length]; Buffer.BlockCopy(shortBuffer, 0, byteBuffer, 0, byteBuffer.Length); return byteBuffer; } public static void PlayBufferSound(byte[] byteBuffer) { DependencyService.Get
But I've hit a wall on how I should finish the MonkeyTapPlayerWithSoundPage:
namespace MTWSFast { class MonkeyTapWithSoundPage : MonkeyTap.MonkeyTapPage { const int errorDuration = 500;
// Diminished 7th in 1st inversion: C, Eb, F#, A double[] frequencies = { 523.25, 622.25, 739.99, 880 }; double endFrequency = 65.4;
List
protected override void FlashBoxView(int index) { SoundPlayer.PlaySound(frequencies[index]); base.FlashBoxView(index); }
protected override void InitializeBoxView() { buffers = new List base.InitializeBoxView(); } protected override void EndGame() { SoundPlayer.PlaySound(65.4); base.EndGame(); } } } Any help would be appreciated.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started