private void OnStreamingAudioPeriodicNotification(object sender, AudioTrack.PeriodicNotificationEventArgs args) { BeatStarted?.BeginInvoke(((nextBeat - 1) + totalBeats) % totalBeats, false, null, null); AppendStreamingAudio(MixBeat(GetNotes(nextBeat))); nextBeat = (nextBeat + 1) % totalBeats; }
private void OnStreamingAudioPeriodicNotification(object sender, BufferCompletedEventArgs args) #endif { //nextBeat refers to the next beat to generate - the current beat is the one before nextBeat int currentBeat = ((nextBeat - 1) + song.BeatCount) % song.BeatCount; //Call the BeatStarted callback on a separate thread BeatStarted?.BeginInvoke(currentBeat, false, null, null); //Mix the audio data for this beat short[] data = MixBeat(song.NotesAtBeat(nextBeat)); //Make sure the track isnt disposed of after we check if it's playing lock (trackDisposedOfSyncObject) { if (IsPlaying) { #if __ANDROID__ //Add the audio data to the track playingTrack.Write(data, 0, data.Length); #endif #if __IOS__ //Copy the audio data to the buffer passed in to this method unsafe { fixed(short *beatData = data) { args.UnsafeBuffer->CopyToAudioData((IntPtr)beatData, data.Length * 2); } } //Add the buffer to the audio queue audioQueue.EnqueueBuffer(args.IntPtrBuffer, data.Length * 2, null); #endif } } nextBeat = (nextBeat + 1) % song.BeatCount; }