flat assembler
Message board for the users of flat assembler.

Index > Windows > How implement ring buffer on fasm ?

Author
Thread Post new topic Reply to topic
Roman



Joined: 21 Apr 2012
Posts: 1320
Roman 16 Oct 2022, 14:39
I work with sound and want apply echo.
Program give me small portions sound.
Lets say 120 float values(120*4=480 bytes) for one portion.
All ring buffer size 480*5 = 2400 bytes.
Code:
=====
@   #

@ this mean pointer read from buffer.
# this mean pointer write to buffer
= this mean one portion ring buffer
    


I want save this five portions then read and apply to new portions sound.
Then I get echo effect.
Post 16 Oct 2022, 14:39
View user's profile Send private message Reply with quote
bitRAKE



Joined: 21 Jul 2003
Posts: 3557
Location: vpcmipstrm
bitRAKE 16 Oct 2022, 16:36
It's possible to create a circular mapping of memory.

This should greatly simplify algorithms to avoid boundary logic.

If the buffer is to be used by external libraries, this method also make the least assumption of them.

_________________
¯\(°_o)/¯ unlicense.org
Post 16 Oct 2022, 16:36
View user's profile Send private message Visit poster's website Reply with quote
Roman



Joined: 21 Apr 2012
Posts: 1320
Roman 16 Oct 2022, 19:59
My variant:
Code:
macro RingApply v,b { local .a,.b,.up
      mov eax,v
      movd xmm1,eax
      mov rax,RingBuffer
      mov r14,rax
      add eax,[Ring_w]

      mov r13,[rdx]  ;input float data
      xor r11,r11
.up:  movss xmm0,[r13+r11*4]
      mulss xmm0,xmm1
      movss [rax+r11*4],xmm0
      inc r11
      cmp r11d,200
      jb  .up

      add [Ring_w],256*4
      cmp [Ring_w],256*4*b
      jb  .a
      mov [Ring_w],0
.a:   add r14d,[Ring_r]
      add [Ring_r],256*4
      cmp [Ring_r],256*4*b
      jb  .b
      mov [Ring_r],0
.b:

      }                   
    Ring_start = 60;1 to Ring_Max-2
    Ring_Max   = 62
    RingApply 0.94,Ring_Max-2 
;data    
    RingBuffer dd 256*Ring_Max dup(0)
    Ring_r dd 0
    Ring_w dd 256*4*Ring_start 
    
Post 16 Oct 2022, 19:59
View user's profile Send private message Reply with quote
Furs



Joined: 04 Mar 2016
Posts: 2023
Furs 17 Oct 2022, 13:29
bitRAKE wrote:
It's possible to create a circular mapping of memory.

This should greatly simplify algorithms to avoid boundary logic.

If the buffer is to be used by external libraries, this method also make the least assumption of them.
That placeholder thing looks very useful. Didn't know it existed, too bad it seems it's Win10+ API only.

To be fair you can create ring buffer without it as well. The only issue is that you'll have a race so it's possible for the second alloc to fail, and you'll have to retry (possibly infinitely). I guess not a big problem if you suspend all threads or something, but not doable if not (or if you use it in a library).
Post 17 Oct 2022, 13:29
View user's profile Send private message Reply with quote
bitRAKE



Joined: 21 Jul 2003
Posts: 3557
Location: vpcmipstrm
bitRAKE 17 Oct 2022, 22:49
Allocating under 4GB addresses is the same way - could have been done before - just more reliable on Win10+ with VirtualAlloc2.

_________________
¯\(°_o)/¯ unlicense.org
Post 17 Oct 2022, 22:49
View user's profile Send private message Visit poster's website Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
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
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2023, Tomasz Grysztar. Also on GitHub, YouTube, Twitter.

Website powered by rwasa.