Xamarin Urho IOS如何设置应用程序?

时间:2017-07-06 11:43:04

标签: c# ios xamarin

我正在关注这个例子,但它并没有那么有用: https://github.com/xamarin/urho-samples/tree/master/FeatureSamples/Core/29_SoundSynthesis

无论如何我得到一个运行时错误,说:该应用程序尚未配置。 但我做了一个应用程序对象。 错误发生在node = new Node(); 我错过了什么 这是我的班级:

using System;
using Urho.Audio;
using Urho;
using Urho.Resources;
using Urho.Gui;
using System.Diagnostics;
using System.Globalization;
namespace Brain_Entrainment
{
    public class IsochronicTones : Urho.Application
    {
        /// Scene node for the sound component.
        Node node;

        /// Sound stream that we update.
        BufferedSoundStream soundStream;
        public double Frequency { get; set; }
        public double Beat { get; set; }
        public double Amplitude { get; set; }
        public float Bufferlength { get; set; }
        const int numBuffers = 3;

        public IsochronicTones(ApplicationOptions AppOption) : base(AppOption)
        {
            Amplitude = 1;
            Frequency = 100;
            Beat = 0;
            Bufferlength = Int32.MaxValue;
        }

        public void play()
        {
            Start();


        }
        protected override void OnUpdate(float timeStep)
        {
            UpdateSound();
            base.OnUpdate(timeStep);
        }
        protected override void Start()
        {
            base.Start();
            CreateSound();
        }

        void CreateSound()
        {
            // Sound source needs a node so that it is considered enabled
            node = new Node();

            SoundSource source = node.CreateComponent();

            soundStream = new BufferedSoundStream();
            // Set format: 44100 Hz, sixteen bit, mono
            soundStream.SetFormat(44100, true, false);

            // Start playback. We don't have data in the stream yet, but the 
            //SoundSource will wait until there is data
            // as the stream is by default in the "don't stop at end" mode

            source.Play(soundStream);
        }

        void UpdateSound()
        {
            // Try to keep 1/10 seconds of sound in the buffer, to avoid both 
            //dropouts and unnecessary latency

            float targetLength = 1.0f / 10.0f;
            float requiredLength = targetLength -
            Bufferlength;//soundStream.BufferLength;
            float w = 0;

            if (requiredLength < 0.0f)
                return;
            uint numSamples = (uint)(soundStream.Frequency * requiredLength);
            if (numSamples == 0)
                return;
            // Allocate a new buffer and fill it with a simple two-oscillator 
            //algorithm.The sound is over - amplified
            // (distorted), clamped to the 16-bit range, and finally lowpass  -
            //filtered according to the coefficient
            var newData = new short[numSamples];
            for (int i = 0; i < numSamples; ++i)
            {
                float newValue = 0;
                if (Beat == 0)
                {
                    newValue = (float)(Amplitude * Math.Sin(Math.PI * Frequency * i / 44100D));
                }
                else
                {
                    w = (float)(1D * Math.Sin(i * Math.PI * Beat / 44100D));
                    if (w < 0)
                    {
                        w = 0;
                    }
                    newValue = (float)(Amplitude * Math.Sin(Math.PI * Frequency * i / 44100D));
                }
                //accumulator = MathHelper.Lerp(accumulator, newValue, filter);
                newData[i] = (short)newValue;
            }

            // Queue buffer to the stream for playback
            soundStream.AddData(newData, 0, newData.Length);
        }
    }
}

0 个答案:

没有答案