Support

If you have a problem or need to report a bug please email : support@dsprobotics.com

There are 3 sections to this support area:

DOWNLOADS: access to product manuals, support files and drivers

HELP & INFORMATION: tutorials and example files for learning or finding pre-made modules for your projects

USER FORUMS: meet with other users and exchange ideas, you can also get help and assistance here

NEW REGISTRATIONS - please contact us if you wish to register on the forum

Users are reminded of the forum rules they sign up to which prohibits any activity that violates any laws including posting material covered by copyright

Sine osc in ASM using fsin opcode?

DSP related issues, mathematics, processing and techniques

Sine osc in ASM using fsin opcode?

Postby TrojakEW » Thu Dec 27, 2012 3:03 pm

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

Re: Sine osc in ASM using fsin opcode?

Postby trogluddite » Thu Dec 27, 2012 6:50 pm

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

Re: Sine osc in ASM using fsin opcode?

Postby TrojakEW » Thu Dec 27, 2012 9:31 pm

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

Re: Sine osc in ASM using fsin opcode?

Postby MyCo » Fri Dec 28, 2012 2:25 am

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
MyCo
 
Posts: 718
Joined: Tue Jul 13, 2010 12:33 pm
Location: Germany

Re: Sine osc in ASM using fsin opcode?

Postby TrojakEW » Fri Dec 28, 2012 10:07 am

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

Re: Sine osc in ASM using fsin opcode?

Postby infuzion » Sat Dec 29, 2012 3:54 am

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.
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?

Postby TrojakEW » Sat Dec 29, 2012 10:45 am

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

Re: Sine osc in ASM using fsin opcode?

Postby trogluddite » Sat Dec 29, 2012 5:23 pm

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

Re: Sine osc in ASM using fsin opcode?

Postby MyCo » Sat Dec 29, 2012 6:53 pm

Yes, looks like a copy&paste mistake in the code. All 4 channels use the same table index.
User avatar
MyCo
 
Posts: 718
Joined: Tue Jul 13, 2010 12:33 pm
Location: Germany

Re: Sine osc in ASM using fsin opcode?

Postby infuzion » Sun Dec 30, 2012 5:58 am

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


Return to DSP

Who is online

Users browsing this forum: No registered users and 30 guests