Page 1 of 1
Sine osc in ASM using fsin opcode?
Posted: Thu Dec 27, 2012 3:03 pm
by TrojakEW
There is bug in stock sine osc so I was trying to optimize basic sine code to asm using fsin opcode. While feeding with single note/freq it works fine but using two or more (simple chord) cause problem. I'm still trying to learn asm so I donn't know what I'm missing here. Here is asm code:
Code: Select all
streamin freq;streamin phase;streamout out;
float temp=0.0;float a=0;float F1=1;float F2=2;
float PI2=6.2831853;
movaps xmm0,a;addps xmm0,freq;
movaps a,xmm0;
movaps xmm2,xmm0;
cmpps xmm0,F1,6;andps xmm0,F2;
subps xmm2,xmm0;movaps a,xmm2;
addps xmm2,phase;mulps xmm2,PI2;
movaps temp,xmm2;
fld temp[0];
mov eax,temp[0];
fsin;
fstp temp[0];
movaps xmm0,temp;
movaps out,xmm0;
Re: Sine osc in ASM using fsin opcode?
Posted: Thu Dec 27, 2012 6:50 pm
by trogluddite
Hi Trojak,
The reason is that for poly and mono4 signals, each block of code is responsible for four voices, using the four parallel "channels" of the SSE commands.
The floating point unit commands can only work on one channel at a time (in your case only channel[0]) - that's fine for mono signals, as they only make use of channel[0]. But for poly/mono4 signals, you have to explicity process each channel in turn, otherwise three out of every four notes won't get processed.
You can fix this very simply, by cutting and pasting the FPU sine code until you have four of them, and then edit the channel numbers on the copies to add channels [1],[2] and [3].
Code: Select all
fld temp[0];
fsin;
fstp temp[0];
fld temp[1];
fsin;
fstp temp[1];
fld temp[2];
fsin;
fstp temp[2];
fld temp[3];
fsin;
fstp temp[3];
PS) The move to eax isn't needed AFAIK, the FPU only communicates via the stack.
Re: Sine osc in ASM using fsin opcode?
Posted: Thu Dec 27, 2012 9:31 pm
by TrojakEW
Thanks. It works but it's actually slower then original asm or code. I thought than using fsin can be faster but no luck. Is there any other faster way to use sin in asm? Like quick rounding or quick abs trick (thanks for that too I learned that from you

). It's not only question for use in this example but for overall use in asm.
Re: Sine osc in ASM using fsin opcode?
Posted: Fri Dec 28, 2012 2:25 am
by MyCo
It depends on the frequency range that you need. For LFO, there are quiet good hacks, like self oscillating filter or taylor series...
BTW: what is your problem with the stock sine osc? I did some decoding on this, before Malc made the optimizations in "SNOWFLAKE", and haven't discovered any odds.
Re: Sine osc in ASM using fsin opcode?
Posted: Fri Dec 28, 2012 10:07 am
by TrojakEW
Sine OSC in snowflake act similar to my first fsin atempt. It work good with single input but strange with multiple/chord. It also start at -1octave compared to previous or coded one.
Re: Sine osc in ASM using fsin opcode?
Posted: Sat Dec 29, 2012 3:54 am
by infuzion
TrojakEW wrote:Sine OSC in snowflake act similar to my first fsin atempt. It work good with single input but strange with multiple/chord. It also start at -1octave compared to previous or coded one.
Perhaps you should submit a bug report then, with specific examples & outputs please?
It is not uncommon for old bugs be swapped out with new ones, so I don't disbelieve you. The more narrow you can make your request, the better chance you will see it fixed.
Re: Sine osc in ASM using fsin opcode?
Posted: Sat Dec 29, 2012 10:45 am
by TrojakEW
Well there is no need for any specific example or schematic. For me problem occur always when stock sine osc is used. It doesn't matter what setup I use. If it is simple schematic just with one sine osc or example synth.
Well MAYBE it is matter of CPU type. I have athlon 64 x2 4200 and only that one so I can't test if the problem occur on other CPU.
Re: Sine osc in ASM using fsin opcode?
Posted: Sat Dec 29, 2012 5:23 pm
by trogluddite
TrojakEW wrote:Sine OSC in snowflake act similar to my first fsin atempt. It work good with single input but strange with multiple/chord.
Confirmed - There IS a bug in the new stock sine oscillator.Try playing chords on this simple example synth with the selector set to the sine oscillator...
...all four SSE channels are using the same frequency value as the first channel, so you just get repeats of the same note instead of multiple pitches.
Bug report sent to the dev's.
Re: Sine osc in ASM using fsin opcode?
Posted: Sat Dec 29, 2012 6:53 pm
by MyCo
Yes, looks like a copy&paste mistake in the code. All 4 channels use the same table index.
Re: Sine osc in ASM using fsin opcode?
Posted: Sun Dec 30, 2012 5:58 am
by infuzion
trogluddite wrote:TrojakEW wrote:Sine OSC in snowflake act similar to my first fsin atempt. It work good with single input but strange with multiple/chord.
Confirmed - There IS a bug in the new stock sine oscillator.Try playing chords on this simple example synth with the selector set to the sine oscillator...
Broken Sine Osc.fsm
...all four SSE channels are using the same frequency value as the first channel, so you just get repeats of the same note instead of multiple pitches. Bug report sent to the dev's.
Thanks for isolating this Troggie!
This is why I refuse to pay to beta-test for people anymore... It should be the other way around!