Hey Guys,

I’m trying to write my own Sine-"Oscillator", which I can also manipulate in Phase, not only in Frequency. I need this for Synthesizing different sounds.

So therefore, I calculate a pure Sinewave and write it’s bytes to a Byte Array, from which the sound should then be created with system.createSound Method. But when I call this, I get a Error.

"File not Found". But I don’t have a file, only this Byte Array :)

Here is the Code:
byte[] buffer = new byte[SampleFrequency * SampleSize];
Channel c = new Channel();
public void setOSCFreq(,float frequency, float phase,float amplitude)
// Puffer für max 1 Sek
byte[] samplebuffer = new byte[SampleSize];

        for (int i = 0; i < SampleFrequency; i++)
            samplebuffer = BitConverter.GetBytes(Convert.ToInt16(Math.Round(amplitude*(Math.Sin(2 * Math.PI * frequency / SampleFrequency * i + phase)) * Int16.MaxValue)));
            Array.Copy(samplebuffer, 0, buffer, i * SampleSize, SampleSize);

        exinfo.cbsize = Marshal.SizeOf(exinfo);
        exinfo.length = (uint)buffer.Length;
        result = system.createSound(buffer, MODE.DEFAULT,ref exinfo, ref sound); 
        result = system.playSound(CHANNELINDEX.FREE, sound, false, ref c);


Whats wrong on this?

Two further questions:

1) Should I implement this by creating my own DSP?
2) If possible I would be happy about the "phase Option" for the existing FMOD OSC :)

Tanks for any help.

  • You must to post comments

Oooh 😳 Sorry I forgot to write the wave-header in the buffer.

result = system.createSound(buffer, MODE.DEFAULT,ref exinfo, ref sound);
I changed into this:
result = system.createSound(buffer,(MODE.HARDWARE | MODE.OPENMEMORY ),ref exinfo, ref sound);
Now it seems to work.

But the last two questions remain 😉

  • You must to post comments
Showing 1 result
Your Answer

Please first to submit.