Menu
support@nursinghomework.org
+1 714-215-3097

(Solved) : Xamarin Forms Faster Monkeytapwithsound S Basically Modification Program Https Githubcom X Q35612659

Xamarin Forms Faster MonkeyTapWithSound

It’s basically a modification of this program athttps://github.com/xamarin/xamarin-forms-book-samples/tree/master/Chapter09/MonkeyTapWithSound

Modify the MonkeyTapWithSound program to initialize the soundbuffers at launch.
1.   Create a new project called MTWSFast. Copy the filesIPlatformSoundPlayer. and MonkeyTapWithSounPage.cs to the MTWSFastfolder. Change the namespace to MTWSFast . Copy the 3 instances ofPlatformSoundPlayer.cs to their respective Android, iOS and UWPfolders. Change the namespace to MTWSFast.<platfoprm> . SetApp.xaml.cs MainPage to MonkeyTapWithSoundPage. At this point thegame should run the same as the original MTWSound. Verify this onAndroid and UWP.
2.   The following are suggestions. If you want to dothis in another fashion, feel free. The goal is to NOT modify theoriginal MonkeyTap.cs file, but to do the modifications byoverriding its methods.
3.   Add a list of byte buffers to theMonkeyTapWithSoundPage class:
4.   class MonkeyTapwithSoundPage MonkeyTap .MonkeyTapPage const int errorDuration500; // Diminished 7th in 1st inversion: C, Eb,
5.   Split PlaySound into a MakeBuffer method withparameters (frequency) that returns a sound buffer, and anothermethod PlayBufferedSound with the parameter (<buffer>).
6.   Add a method to MonkeyTapWithSoundPage to initializethe buffers in SoundPlayer. A good choice is to overrideInitializeBoxView. This method should step through the 4 existingfrequencies and add a 5th buffer for the error sound. Make a forloop to set up buffers 0, 1, 2 and 3 with the frequency andflashDuration, and one more call outside the loop with endFrequencyand errorDuration Modify FlashBoxView to call PlayBufferedSoundwith buffers[index] and flashDuration, and EndGame to usePlayBufferedSound 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, intduration = 250)
{
short[] shortBuffer = new short[samplingRate * duration /1000];
double angleIncrement = frequency / samplingRate;
double angle = 0.0;

for (int i = 0; i < shortBuffer.Length; i++)
{
// Define triangle wave
double sample;

// 0 to 1
if (angle < 0.25)
sample = 4 * angle;

// 1 to -1
else if (angle < 0.75)
sample = 4 * (0.5 – 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<IPlatformSoundPlayer>().PlaySound(samplingRate,byteBuffer);
}
}
}

But I’ve hit a wall on how I should finish theMonkeyTapPlayerWithSoundPage:

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

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

protected override void InitializeBoxView()
{
buffers = new List<byte[]>();
for(int i = 0; i<frequencies.Length; i++)
{ buffers.Add(SoundPlayer.MakeBuffer(frequencies[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<byte]> buffers; byte[] endBuffer; Show transcribed image text 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;

Leave a Reply

Your email address will not be published. Required fields are marked *