how to set up an application

BrandonBooneBrandonBoone Brandon BooneUSMember ✭✭

I am following this example but it is not that useful:
https://github.com/xamarin/urho-samples/tree/master/FeatureSamples/Core/29_SoundSynthesis

anyhow I am getting an run time error that says: The application is not configured yet.
but I made an application object .
the error happen a node = new Node();
what am I missing
this is my class:

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;

//protected IsochronicTones(ApplicationOptions options = null) : base(options) {}

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);
}
}
}

Answers

  • BrandonBooneBrandonBoone Brandon Boone USMember ✭✭

    anyone ?

  • BrandonBooneBrandonBoone Brandon Boone USMember ✭✭

    ?

  • EgorBoEgorBo Egor Bogatov BYXamarin Team ✭✭✭
    edited July 28

    the "The application is not configured yet." usually means you are trying to initialize an Urho object and the app is not started yet. for example it may happen if you initialize field using "inline" syntax. I don't see any reason why this exception should be thrown in your case so if you could share the whole project - I'd try to reproduce. Or at least could you please paste the stack trace.

  • BrandonBooneBrandonBoone Brandon Boone USMember ✭✭
Sign In or Register to comment.