Adding a delay

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Adding a delay

Shiv Jairam
Hello,

If I for example have alsa_pcm:capture_1 and alsa_pcm:playback_1 connected. And I have a mic plugged into my sound card. I can then hear the playback in real time.

But what are my options if I wanted to add a delay of anywhere between 20-800 msec so I don't hear playback in real time? Is there perhaps and easy way to modify in process() in your simple_client example?

Thank you.
--
Shiv Jairam
-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
Jackit-devel mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/jackit-devel
Reply | Threaded
Open this post in threaded view
|

Re: Adding a delay

Shiv Jairam
Hi Nicolas,

Thank you.

But I am still curious as to the coding techniques involved in such a delay algorithm. Any pointers?


Regards.

On Jan 22, 2008 6:58 PM, Nicolas Joyard < [hidden email]> wrote:
Hello,

I think the easiest way is to add a client with a delay effect, for example a LADSPA rack.

Greets,

Nicolas

2008/1/23, Shiv Jairam <[hidden email]>:
Hello,

If I for example have alsa_pcm:capture_1 and alsa_pcm:playback_1 connected. And I have a mic plugged into my sound card. I can then hear the playback in real time.

But what are my options if I wanted to add a delay of anywhere between 20-800 msec so I don't hear playback in real time? Is there perhaps and easy way to modify in process() in your simple_client example?

Thank you.
--
Shiv Jairam
-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
Jackit-devel mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/jackit-devel




--
Nicolas JOYARD



--
Shiv Jairam
-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
Jackit-devel mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/jackit-devel
Reply | Threaded
Open this post in threaded view
|

Re: Adding a delay

Fons Adriaensen-2
On Wed, Jan 23, 2008 at 09:16:40AM -0500, Shiv Jairam wrote:

> But I am still curious as to the coding techniques involved in such a delay
> algorithm. Any pointers?

You write the samples from the input port to a circular buffer,
and write for the buffer to the output port. The difference
between the read and write pointers is the delay in samples.

That's all. There a various tricks to optimise it, but that's
basic programming.

--
FA

Laboratorio di Acustica ed Elettroacustica
Parma, Italia

Lascia la spina, cogli la rosa.


-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
Jackit-devel mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/jackit-devel
Reply | Threaded
Open this post in threaded view
|

Re: Adding a delay

Pieter Palmers
In reply to this post by Shiv Jairam
Shiv Jairam wrote:
> Hi Nicolas,
>
> Thank you.
>
> But I am still curious as to the coding techniques involved in such a
> delay algorithm. Any pointers?
For your reference:

Pieter's fantastic ultra delay alorithm:

Init:
1) allocate a jack_ringbuffer of 2 * delay_in_secs/samplerate frames and
call it delay_buffer
2) write delay_in_secs/samplerate zero's to delay_buffer

  Process callback for capture port:
   process(in_buffer, nframes) {
    jack_ringbuffer_write(delay_buffer, in_buffer, nframes);
   }

  Process callback for playback port:
   process(out_buffer, nframes) {
    jack_ringbuffer_read(delay_buffer, out_buffer, nframes);
   }

Shutdown:
1) Deallocate buffer

(Note that this 'code' above won't compile since it was written in
'pseudo-code'. Pseudo-code is an informal description of an algorithm
that, although might resemble a specific programming language, is not
valid code.)

Please don't hesitate to contact the mailing list if you'd like us to
provide a fully implemented version of this. Most of us will also have
the time to explain how to install a C compiler in order to build this
algorithm. This due to the fact that all of us have a good friend
nicknamed 'google' that helps us with the complex tasks involved in
every day DSP programming (and every day life in general).

Aside from that, you might have more luck asking algorithm-related
questions on a music-dsp related mailing list. Be careful though when
doing so, since some people might not take your questions serious.

Greets,

Pieter

PS: you might want to reconsider your DSP programming career if you need
help to come up with a software delay line. The usual expression used
for a delay-line in DSP environments is 'no-brainer'.

>
>
> Regards.
>
> On Jan 22, 2008 6:58 PM, Nicolas Joyard < [hidden email]
> <mailto:[hidden email]>> wrote:
>
>     Hello,
>
>     I think the easiest way is to add a client with a delay effect, for
>     example a LADSPA rack.
>
>     Greets,
>
>     Nicolas
>
>     2008/1/23, Shiv Jairam < [hidden email]
>     <mailto:[hidden email]>>:
>
>         Hello,
>
>         If I for example have alsa_pcm:capture_1 and alsa_pcm:playback_1
>         connected. And I have a mic plugged into my sound card. I can
>         then hear the playback in real time.
>
>         But what are my options if I wanted to add a delay of anywhere
>         between 20-800 msec so I don't hear playback in real time? Is
>         there perhaps and easy way to modify in process() in your
>         simple_client example?
>
>         Thank you.
>         --
>         Shiv Jairam
>         -------------------------------------------------------------------------
>         This SF.net email is sponsored by: Microsoft
>         Defy all challenges. Microsoft(R) Visual Studio 2008.
>         http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
>         _______________________________________________
>         Jackit-devel mailing list
>         [hidden email]
>         <mailto:[hidden email]>
>         https://lists.sourceforge.net/lists/listinfo/jackit-devel
>         <https://lists.sourceforge.net/lists/listinfo/jackit-devel>
>
>
>
>
>     --
>     Nicolas JOYARD
>
>
>
>
> --
> Shiv Jairam
>
>
> ------------------------------------------------------------------------
>
> -------------------------------------------------------------------------
> This SF.net email is sponsored by: Microsoft
> Defy all challenges. Microsoft(R) Visual Studio 2008.
> http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
>
>
> ------------------------------------------------------------------------
>
> _______________________________________________
> Jackit-devel mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/jackit-devel


-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
Jackit-devel mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/jackit-devel
Reply | Threaded
Open this post in threaded view
|

Re: Adding a delay

Shiv Jairam
In reply to this post by Fons Adriaensen-2
Hello,

So in terms of JACK, I would need to do the following (assuming a ring buffer of appropriate size already exists):

Get pointers to the memory locations that correspond to input_port and output_port via jack_port_get_buffer().
Using something like jack_ringbuffer_write_space(), I could put this as the test condition in a while loop. In the body of the while loop I would have jack_ringbuffer_write() write data from input_port to the ringbuffer until its full, then jack_ringbuffer_write_space() will return zero and the while loop will exit.
This will then cause jack_ringbuffer_read() to write data from the ringbuffer to output_port and I should hear the audio playback. Then it makes sense to call jack_ringbuffer_reset() after this, and the entire process happens again.

Am I forgetting anything else?

Thanks.

On 1/23/08, Fons Adriaensen <[hidden email]> wrote:
On Wed, Jan 23, 2008 at 09:16:40AM -0500, Shiv Jairam wrote:

> But I am still curious as to the coding techniques involved in such a delay
> algorithm. Any pointers?

You write the samples from the input port to a circular buffer,
and write for the buffer to the output port. The difference
between the read and write pointers is the delay in samples.

That's all. There a various tricks to optimise it, but that's
basic programming.

--
FA

Laboratorio di Acustica ed Elettroacustica
Parma, Italia

Lascia la spina, cogli la rosa.


-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
Jackit-devel mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/jackit-devel



--
Shiv Jairam
-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
Jackit-devel mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/jackit-devel