It is currently Fri Apr 10, 2020 9:44 am

All times are UTC + 1 hour




Post new topic Reply to topic  [ 9 posts ] 
Author Message
 Post subject: Sinc interpolating
PostPosted: Thu Sep 29, 2011 8:46 am 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Mon Jan 12, 2004 11:40 pm
Posts: 761
Location: Okazaki, JAPAN
Code:
Procedure SincInterpolation(*buffer_audio_ptr, *sinc_table_ptr, *out_buffer_ptr, *dummy)
  !XOR Ecx, Ecx
  !XOR Edx, Edx
  !MOV Ecx, [p.p_sinc_table_ptr]
  !MOV Edx, [p.p_buffer_audio_ptr]
  !SUB  Edx, 2048
  !PXOR xmm4, xmm4
  !PXOR xmm5, xmm5
  For i=0 To 256
    !PXOR xmm3, xmm3 ; R
    !PXOR xmm1, xmm1 ; L
    !PXOR xmm0, xmm0 ; sinc
    !MOVSD xmm0, [Ecx] ; sinc
    !ADD Ecx, 8 ; sinc double table
    !MOVSS xmm1, [Edx] ; L
    !ADD Edx,4
    !MOVSS xmm3, [Edx] ; R
    !ADD Edx,12 ; 
    !CVTSS2SD xmm1, xmm1
    !CVTSS2SD xmm3, xmm3
    !mulpd xmm1, xmm0 ; sinc x L
    !mulpd xmm3, xmm0 ; sinc x R
    !ADDPD xmm4, xmm1 ; pcmdata2 L ++
    !ADDPD xmm5, xmm3 ; pcmdata2 R ++
  Next i
  !CVTSD2SS xmm4, xmm4
  !CVTSD2SS xmm5, xmm5
  !XOR Edx, Edx
  !MOV Edx, [p.p_out_buffer_ptr]
  !MOVSS [Edx], xmm4
  !MOVSS [Edx+4], xmm5
  !XOR Ecx, Ecx
  !XOR Edx, Edx
EndProcedure

_________________
My homepage in Japan - Bug head Nontallion
My facebook page.


Last edited by oryaaaaa on Tue Aug 21, 2012 3:55 am, edited 2 times in total.

Top
 Profile  
Reply with quote  
 Post subject: Re: Sinc interpolating (All source code)
PostPosted: Thu Sep 29, 2011 9:35 am 
Offline
Addict
Addict
User avatar

Joined: Sat Aug 15, 2009 6:59 pm
Posts: 1252
You should replace for next with a asm loop. For next is very slow compared to a asm loop.


Top
 Profile  
Reply with quote  
 Post subject: Re: Sinc interpolating (All source code)
PostPosted: Thu Sep 29, 2011 10:20 am 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Mon Jan 12, 2004 11:40 pm
Posts: 761
Location: Okazaki, JAPAN
Because, Asm loop is crushed. then This loop used.
Could you teach me about asm loop?

Thanks

_________________
My homepage in Japan - Bug head Nontallion
My facebook page.


Top
 Profile  
Reply with quote  
 Post subject: Re: Sinc interpolating (All source code)
PostPosted: Thu Sep 29, 2011 11:00 am 
Offline
PureBasic Expert
PureBasic Expert

Joined: Sun Aug 08, 2004 5:21 am
Posts: 3606
Location: Netherlands
I don't understand what you mean by 'crushed'.
Your routine currently isn't doing anything with the EAX register so you could use that one as a counter.
Another option is to calculate the end value of ECX or EDX and store that in EAX and compare after each cycle if the end has been reached.

The last two lines of your function
!XOR Ecx, Ecx
!XOR Edx, Edx
aren't required by the way. There's no need to reset these registers to 0.


Top
 Profile  
Reply with quote  
 Post subject: Re: Sinc interpolating (All source code)
PostPosted: Thu Sep 29, 2011 11:09 am 
Offline
Addict
Addict
User avatar

Joined: Sat Aug 15, 2009 6:59 pm
Posts: 1252
That should do it, but untested.

Code:
Procedure SincInterpolation(*buffer_audio_ptr, *sinc_table_ptr, *out_buffer_ptr, *dummy)
  !XOR Ecx, Ecx
  !XOR Edx, Edx
  !MOV Ecx, [p.p_sinc_table_ptr]
  !MOV Edx, [p.p_buffer_audio_ptr]
  !SUB  Edx, 2048
  !PXOR xmm4, xmm4
  !PXOR xmm5, xmm5
 
  !mov eax, 257
  !align 4
  !SincInterLoop:
 
    !PXOR xmm3, xmm3 ; R
    !PXOR xmm1, xmm1 ; L
    !PXOR xmm0, xmm0 ; sinc
    !MOVSD xmm0, [Ecx] ; sinc
    !ADD Ecx, 8 ; sinc double table
    !MOVSS xmm1, [Edx] ; L
    !ADD Edx,4
    !MOVSS xmm3, [Edx] ; R
    !ADD Edx,12 ;
    !CVTSS2SD xmm1, xmm1
    !CVTSS2SD xmm3, xmm3
    !mulpd xmm1, xmm0 ; sinc x L
    !mulpd xmm3, xmm0 ; sinc x R
    !ADDPD xmm4, xmm1 ; pcmdata2 L ++
    !ADDPD xmm5, xmm3 ; pcmdata2 R ++
   
  !dec eax
  !jnz SincInterLoop
 
  !CVTSD2SS xmm4, xmm4
  !CVTSD2SS xmm5, xmm5
  !XOR Edx, Edx
  !MOV Edx, [p.p_out_buffer_ptr]
  !MOVSS [Edx], xmm4
  !MOVSS [Edx+4], xmm5
  !XOR Ecx, Ecx
  !XOR Edx, Edx
EndProcedure


Top
 Profile  
Reply with quote  
 Post subject: Re: Sinc interpolating (All source code)
PostPosted: Thu Sep 29, 2011 12:56 pm 
Offline
PureBasic Bullfrog
PureBasic Bullfrog
User avatar

Joined: Wed Jul 06, 2005 5:42 am
Posts: 8049
Location: Fort Nelson, BC, Canada
Quote:
I don't understand what you mean by 'crushed'.
He means when he tries it it crashes.

_________________
Veni, vidi, vici.


Top
 Profile  
Reply with quote  
 Post subject: Re: Sinc interpolating (All source code)
PostPosted: Fri Sep 30, 2011 6:40 am 
Offline
PureBasic Expert
PureBasic Expert

Joined: Sun Aug 08, 2004 5:21 am
Posts: 3606
Location: Netherlands
@Netmaestro, now I understand :wink:

@oryaaaaa, just like the code from Thorium it's untested but you should be able to handle the left and right samples at the same time since each SSE register can contain two double precision values.
Something like
Code:
Procedure SincInterpolation(*buffer_audio_ptr, *sinc_table_ptr, *out_buffer_ptr, *dummy)
  !mov ecx, [p.p_sinc_table_ptr]
  !mov edx, [p.p_buffer_audio_ptr]
  !sub edx, 2048
  !pxor xmm2, xmm2
 
  !mov eax, 257
  !align 4
  !SincInterLoop:
 
  !movq xmm0, [ecx] ; sinc
  !movlhps xmm0, xmm0
  !cvtps2pd xmm1, [edx] ; L + R
  !mulpd xmm1, xmm0
  !addpd xmm2, xmm1
  !add ecx, 8
  !add edx, 16
 
  !dec eax
  !jnz SincInterLoop
 
  !cvtpd2ps xmm2, xmm2
  !mov edx, [p.p_out_buffer_ptr]
  !movq [edx], xmm2
EndProcedure


Top
 Profile  
Reply with quote  
 Post subject: Re: Sinc interpolating (All source code)
PostPosted: Fri Sep 30, 2011 9:48 am 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Mon Jan 12, 2004 11:40 pm
Posts: 761
Location: Okazaki, JAPAN
Thank you

I understand use to 2 register SIMD programing.

_________________
My homepage in Japan - Bug head Nontallion
My facebook page.


Top
 Profile  
Reply with quote  
 Post subject: Re: Sinc interpolating (All source code)
PostPosted: Tue Apr 17, 2012 4:55 pm 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Mon Jan 12, 2004 11:40 pm
Posts: 761
Location: Okazaki, JAPAN
Is there a method of the suppression of LOAD of CPU and execution?

_________________
My homepage in Japan - Bug head Nontallion
My facebook page.


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 9 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye