32 bit float Waveform code - how to speed up?

Guys, I’m just toying with the idea of creating a simple FEZ Panda synth using simple waveform creating code.

My first attempt was a simple sawtooth by adding rate to a variable and checking when its near overflowing. But .NET is very slow on doing this very simple task. So my question is, is there something I’m missing here?

Are there ways to speed things up with .NET or its just too slow for such idea?

Best Regards, WilliamK

Ah, forgot to mention, haven’t tried 16 bit for the waveform, will do that too. :wink:

Wk

Here’s a simple test code for a Sawtooth waveform. (or something close to that) This is so basic and silly that makes me wonder, why the heck it takes 2 seconds to generate 1 second of 44.1khz data?

using System;
using System.Threading;
using Microsoft.SPOT;
using Microsoft.SPOT.Hardware;
using GHIElectronics.NETMF.FEZ;

namespace FEZ_Panda_Application1
{
    public class Program
    {
        public static void Main()
        {
            short wave = -32768;
            int samplerate = 44100;
            int x = 0;
            OutputPort led = new OutputPort((Cpu.Pin)FEZ_Pin.Digital.LED, false);

            while (true)
            {
                for (x = 0; x < samplerate; x++)
                {
                    wave++;
                    if (wave == 32767) wave = -32768;
                }

                led.Write(true);
                Thread.Sleep(25);
                led.Write(false);
            }
        }
    }
}

so let me just reiterate: .Net Micro Framework is not a real-time, time-critical, time-predictable, environment.

Yes, I’m aware of that, but still, isn’t there any way I could speed up a simple waveform creating process? Any “hacks” or optimization schemes? :wink: Just trying to figure out why such simple task is taking so long.

Wk

Speed up = native code = no easy debugging = can be done using RLP = use fez cobra

why are you using float? all your values are integer.

Does the chip include a floating point processor? Check the manual. if not, then all the floating point math is done in software.

Thanks, but I also tried a simple int wave = 0 and wave++ code and the resulting time was nearly the same, so that’s not the problem.

In any event I need to think outside the box, and check what I could do for the FEZ community using my knowledge. :wink:

I already have a MIDI thing on the process, just waiting for the final PCB to arrive. Its Arduino compatible, just need to check if I can convert to .NET too. MIDI is much easier to handle, compared to Audio.

Wk

float vs integer you get better performance but this is not your problem here. The x1000 loops that are needed in C# is what is slowing it down. This is why, for example, we have native CRC libraries.