Sine osc in ASM using fsin opcode?

DSP related issues, mathematics, processing and techniques
Post Reply
User avatar
TrojakEW
Posts: 111
Joined: Sat Dec 25, 2010 10:12 am
Location: Slovakia

Sine osc in ASM using fsin opcode?

Post 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;
User avatar
trogluddite
Posts: 1730
Joined: Fri Oct 22, 2010 12:46 am
Location: Yorkshire, UK

Re: Sine osc in ASM using fsin opcode?

Post 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.
All schematics/modules I post are free for all to use - but a credit is always polite!
Don't stagnate, mutate to create!
User avatar
TrojakEW
Posts: 111
Joined: Sat Dec 25, 2010 10:12 am
Location: Slovakia

Re: Sine osc in ASM using fsin opcode?

Post 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 :D ). It's not only question for use in this example but for overall use in asm.
User avatar
MyCo
Posts: 718
Joined: Tue Jul 13, 2010 12:33 pm
Location: Germany
Contact:

Re: Sine osc in ASM using fsin opcode?

Post 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.
User avatar
TrojakEW
Posts: 111
Joined: Sat Dec 25, 2010 10:12 am
Location: Slovakia

Re: Sine osc in ASM using fsin opcode?

Post 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.
infuzion
Posts: 109
Joined: Tue Jul 13, 2010 11:55 am
Location: Kansas City, USA, Earth, Sol

Re: Sine osc in ASM using fsin opcode?

Post 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.
User avatar
TrojakEW
Posts: 111
Joined: Sat Dec 25, 2010 10:12 am
Location: Slovakia

Re: Sine osc in ASM using fsin opcode?

Post 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.
User avatar
trogluddite
Posts: 1730
Joined: Fri Oct 22, 2010 12:46 am
Location: Yorkshire, UK

Re: Sine osc in ASM using fsin opcode?

Post 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...
Broken Sine Osc.fsm
(16.87 KiB) Downloaded 1796 times

...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.
All schematics/modules I post are free for all to use - but a credit is always polite!
Don't stagnate, mutate to create!
User avatar
MyCo
Posts: 718
Joined: Tue Jul 13, 2010 12:33 pm
Location: Germany
Contact:

Re: Sine osc in ASM using fsin opcode?

Post by MyCo »

Yes, looks like a copy&paste mistake in the code. All 4 channels use the same table index.
infuzion
Posts: 109
Joined: Tue Jul 13, 2010 11:55 am
Location: Kansas City, USA, Earth, Sol

Re: Sine osc in ASM using fsin opcode?

Post 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!
Post Reply