Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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. . Set App.xaml.cs MainPage to MonkeyTapWithSoundPage. At this point the game should run the same as the original MTWSound. Verify this on Android and UWP. 2. The following are suggestions. If you want to do this in another fashion, feel free. The goal is to NOT modify the original MonkeyTap.cs file, but to do the modifications by overriding its methods. 3. Add a list of byte buffers to the MonkeyTapWithSoundPage class: 4. image text in transcribed 5. Split PlaySound into a MakeBuffer method with parameters (frequency) that returns a sound buffer, and another method PlayBufferedSound with the parameter (). 6. Add a method to MonkeyTapWithSoundPage to initialize the buffers in SoundPlayer. A good choice is to override InitializeBoxView. This method should step through the 4 existing frequencies and add a 5th buffer for the error sound. Make a for loop to set up buffers 0, 1, 2 and 3 with the frequency and flashDuration, and one more call outside the loop with endFrequency and errorDuration Modify FlashBoxView to call PlayBufferedSound with buffers[index] and flashDuration, and EndGame to use PlayBufferedSound with endBuffer and endDuration.

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().PlaySound(samplingRate, byteBuffer); } } }

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 buffers; byte[] endBuffer;

protected override void FlashBoxView(int index) { SoundPlayer.PlaySound(frequencies[index]); base.FlashBoxView(index); }

protected override void InitializeBoxView() { buffers = new List(); for(int i = 0; i

base.InitializeBoxView(); }

protected override void EndGame() { SoundPlayer.PlaySound(65.4); base.EndGame(); } } }

Any help would be appreciated.

class MonkeyTapwithSoundPage MonkeyTap .MonkeyTapPage const int errorDuration500; // Diminished 7th in 1st inversion: C, Eb, F#, A double[] frequencies- 523.25, 622.25, 739.99, 880 J; double endFrequency65.4; List buffers; byte[] endBuffer; class MonkeyTapwithSoundPage MonkeyTap .MonkeyTapPage const int errorDuration500; // Diminished 7th in 1st inversion: C, Eb, F#, A double[] frequencies- 523.25, 622.25, 739.99, 880 J; double endFrequency65.4; List buffers; byte[] endBuffer

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

The Database Management Systems

Authors: Patricia Ward, George A Dafoulas

1st Edition

ISBN: 1844804526, 978-1844804528

More Books

Students also viewed these Databases questions

Question

5. If yes, then why?

Answered: 1 week ago

Question

6. How would you design your ideal position?

Answered: 1 week ago