Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Delay Between Record and Play  (Read 4804 times)

0 Members and 2 Guests are viewing this topic.

ClaudioVC

  • Newbie
  • *
  • Posts: 10
    • View Profile
Delay Between Record and Play
« on: February 17, 2017, 01:45:53 am »
Hi all!,
I was writing a little about it in General Section, but i think the main theme of the topic is not the same.

Well, i'm working in a Software for a Loop Pedal. I'm starting with the code, so i'm just trying to do one loop works. So, the idea is record the loop and when i stop record then play the sound recorded. i made this code:

Quote
                if(Event.key.code == sf::Keyboard::R){
                    recorder.start();
                    std::cout<<"> Recording Loop"<<std::endl;
                }
                else if(Event.key.code == sf::Keyboard::S){
                    recorder.stop();
                    clock.restart();
                    std::cout<<"> Playing Loop"<<std::endl;
                    buffer = recorder.getBuffer();
                    sound.setBuffer(buffer);
                    std::cout<<"> Delay Between Record and Play: "<<clock.getElapsedTime().asMicroseconds()<<std::endl;
                    sound.play();
                }

But i need those both actions start at the same time, i mean RECORD.STOP and SOUND.PLAY start together, because later i need to record another sound while im listening the first one and it doesnt have to exist delay. I print the delay between Record.stop and sound.play as MicroSeconds and i got this:



So i have 1570 microseconds between record.stop  and sound play. What can i do to get 0 second of Delay (or close)?.

I think if i put sound.play straight after record.stop it would works, but it couldnt be possible cause there are buffer = recorder.getbuffer() and sound.setbuffer() functions :/. Is there any way to avoid it?


Thanks to all!.
« Last Edit: February 17, 2017, 03:40:15 am by ClaudioVC »

Mario

  • SFML Team
  • Hero Member
  • *****
  • Posts: 879
    • View Profile
Re: Delay Between Record and Play
« Reply #1 on: February 17, 2017, 11:39:56 am »
What if you avoid copying the buffer and assign the recorder's buffer directly?

ClaudioVC

  • Newbie
  • *
  • Posts: 10
    • View Profile
Re: Delay Between Record and Play
« Reply #2 on: February 17, 2017, 03:21:19 pm »
What if you avoid copying the buffer and assign the recorder's buffer directly?

I edited this reply cause now i understand what you were trying to tell me jaja, im going to try and tell you if works!.

Thanks for help.
« Last Edit: February 17, 2017, 06:03:00 pm by ClaudioVC »

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11033
    • View Profile
    • development blog
    • Email
Delay Between Record and Play
« Reply #3 on: February 18, 2017, 03:16:39 pm »
Also 1.5ms is really no delay at all.

And you should keep in mind that SFML wasn't made for "high-performance" applications, so don't expect to be able to time everything to the last millisecond. ;)
« Last Edit: February 18, 2017, 03:22:45 pm by eXpl0it3r »
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Hapax

  • Hero Member
  • *****
  • Posts: 3379
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: Delay Between Record and Play
« Reply #4 on: February 18, 2017, 11:25:57 pm »
As I was involved in the previous thread about this topic, I understand the target of the application and why this delay is unacceptable but the thread was locked so I'll share my suggestion for a solution here.

Scenario:
You want to re-record a set amount of time and play back the previously recorded chunks of time while recording the new "chunk". The playback of such must begin immediately at the end of the recording chunk but there is a delay between stopping the recording and playing back that sound buffer.

Suggestion:
Use two sound buffers per "loop" (per channel). That is, record the first half of the chunk on one sound buffer and then the second half on the other sound buffer. As soon as the end of the chunk has ended, you can start the play back of the first half while stopping the second half.
The caveat here being that you need to make sure that the halves play back at the right time and you can't just allow the sound to loop - you must constantly switch between the two halves.
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*

Mario

  • SFML Team
  • Hero Member
  • *****
  • Posts: 879
    • View Profile
Re: Delay Between Record and Play
« Reply #5 on: February 19, 2017, 09:41:27 am »
Is the immediate playback just for reference? Or for mixing? If for the latter, I'd mix them in software rather than rerecording the playback (which will impact quality).