Skip to contentSkip to conversation

Repeatable exact I/O-delay

DISCUSSION Anders Torger 3 participants 7 messages Jul 27, 2002 – Jul 28, 2002

lore
Share & tools
lore
#0 lore raw

I have made a multi-channel convolution software (BruteFIR) which has some I/O-delay, typically 4096 samples.

The software works like this: it reads a block of 2048 samples, processes it during the coming 2048 samples, and then puts the processed samples to the output, thus a total of 4096 samples I/O-delay.

The problem here is that there is no mechanism I know of which can cause the output to start coming *exactly* 4096 samples after the first input sample is read. I have not measured, but probably the I/O-delay varies a few tens of samples each time the program is started.

I think repeatable exact I/O-delay is a very important feature, but I guess that hardware support is necessary to make it work reliably. So, why is this feature important?

This feature means that the computer could be sample-aligned with other hardware audio processors. In the recording studio, you could use audio processing software on a standard workstation as a low-cost alternative, and still let it collaborate with your existing hardware processors.

Low I/O-delay is good, but if it varies, you can't sample-align anyway. In many cases it is better to have exactly 4096 samples I/O-delay every time, than having an I/O-delay that varies between 100 - 150 samples. Even not all commercially available hardware audio processors have zero delay, some have delays up to tens of milliseconds, but they can be used anyway in most applications, since the delay is always the same and can be compensated for.

With repeatable exact I/O-delay, it would also be possible to build audio processing clusters, by duplicating the inputs (using for example ADAT duplicators) to several sample-aligned workstations. With my software I could build a synchronised convolution cluster, which could handle large-scale auralisation, wave field synthesis and other extremely demanding applications.

Does anyone have any comments on this? Is repeatable exact I/O-delay possible to achieve today with current hardware (and ALSA)?

/Anders Torger

-------------------------------------------------------
This sf.net email is sponsored by:ThinkGeek
Welcome to geek heaven.
http://thinkgeek.com/sf

#1 lore raw
Quoted 2 lines · Anders Torger

Does anyone have any comments on this? Is repeatable exact I/O-delay possible to achieve today with current hardware (and ALSA)?

It is the normal mode of operation for memory-mapped IO.

The only thing that could change the delay is your application taking too long to process the data to meet the deadline (xrun). In this case you'd probably enlarge the total delay by a factor two until a cycle is long enough to process or you exceed the maximum buffer size supported by the hardware.

If I'm not mistaken most cards support audio cycles of 2048 frames, for a software-through latency of 4096 frames. On the ice1712, this is the upper limit.

tim

-------------------------------------------------------
This sf.net email is sponsored by:ThinkGeek
Welcome to geek heaven.
http://thinkgeek.com/sf

#2 lore raw
Quoted 5 lines · you
Quoted 2 lines · Anders Torger

Does anyone have any comments on this? Is repeatable exact I/O-delay possible to achieve today with current hardware (and ALSA)?

It is the normal mode of operation for memory-mapped IO.

Is it really? How do I trigger play exactly X samples after I trigger capture? To copy samples exactly X samples into a buffer is simple, the problem is to tell the sound card to synchronise the playback ptr with the capture ptr, that is "start running the playback ptr exactly X samples after the capture ptr started". The window of X samples is then used by the software to do its magic.

/Anders Torger

-------------------------------------------------------
This sf.net email is sponsored by:ThinkGeek
Welcome to geek heaven.
http://thinkgeek.com/sf

#3 lore raw
Quoted 5 lines · Anders Torger
Quoted 4 lines · you
Quoted 2 lines · Anders Torger

Does anyone have any comments on this? Is repeatable exact I/O-delay possible to achieve today with current hardware (and ALSA)?

Quoted 8 lines
Quoted 1 line

It is the normal mode of operation for memory-mapped IO.

Is it really? How do I trigger play exactly X samples after I trigger capture? To copy samples exactly X samples into a buffer is simple, the problem is to tell the sound card to synchronise the playback ptr with the capture ptr, that is "start running the playback ptr exactly X samples after the capture ptr started". The window of X samples is then used by the software to do its magic.

The way you'd do this is to link the capture and playback streams of the device you use with snd_pcm_link(). They will start together and stay in sync (unless the hardware is broken by design). Instead of starting playback exactly 4096 frames later, you prime the playback stream with 4096 silent frames before starting it. At the first interrupt issued, there will be 2048 frames to be read from the capture stream and 2048 to write to playback. You'd read the input signal, write another 2048 silent frames, and from the next interrupt on you'll always have 2048 frames of processed signal to write, and 2048 input frames to feed to the FIR.

Implementing memory-mapped IO isn't exactly what you do in a day. jackit.sf.net or the shortly-to-be-released library I'm working on will do it for you. Just replace 'interrupt' above with a 'process' callback and you don't have to care about the exact workings of mmap'd ALSA at all.

tim

-------------------------------------------------------
This sf.net email is sponsored by:ThinkGeek
Welcome to geek heaven.
http://thinkgeek.com/sf

#4 lore raw
Quoted 2 lines

The way you'd do this is to link the capture and playback streams of the device you use with snd_pcm_link(). They will start together and

we still haven't established the timing for this. its possible that its not fast enough for the two streams to be started within <<1sample, particularly if and when 192kHz h/w appears. it might even be problematic with 96kHz operation. i would be suprised if this was true, but it needs to be measured and checked.

Quoted 1 line

Implementing memory-mapped IO isn't exactly what you do in a day.

:))

--p

-------------------------------------------------------
This sf.net email is sponsored by:ThinkGeek
Welcome to geek heaven.
http://thinkgeek.com/sf

#5 lore raw

Re: Starting playback/capture exactly the same time (was: Repeatable exact I/O-delay)

In reply to Tim Goetze
Quoted 16 lines · you
Quoted 6 lines · Anders Torger
Quoted 5 lines · you
Quoted 3 lines · Anders Torger

Does anyone have any comments on this? Is repeatable exact I/O-delay possible to achieve today with current hardware (and ALSA)?

Quoted 8 lines
Quoted 1 line

It is the normal mode of operation for memory-mapped IO.

Is it really? How do I trigger play exactly X samples after I trigger capture? To copy samples exactly X samples into a buffer is simple, the problem is to tell the sound card to synchronise the playback ptr with the capture ptr, that is "start running the playback ptr exactly X samples after the capture ptr started". The window of X samples is then used by the software to do its magic.

Quoted 10 lines

The way you'd do this is to link the capture and playback streams of the device you use with snd_pcm_link(). They will start together and stay in sync (unless the hardware is broken by design). Instead of starting playback exactly 4096 frames later, you prime the playback stream with 4096 silent frames before starting it. At the first interrupt issued, there will be 2048 frames to be read from the capture stream and 2048 to write to playback. You'd read the input signal, write another 2048 silent frames, and from the next interrupt on you'll always have 2048 frames of processed signal to write, and 2048 input frames to feed to the FIR.

Thanks. I'll try this. Not only the hardware can be broken, but also the driver I suppose. It seems like not all have support for snd_pcm_link(), for example my driver for RME96 (I have to do some maintenance work on that soon).

Quoted 5 lines

Implementing memory-mapped IO isn't exactly what you do in a day. jackit.sf.net or the shortly-to-be-released library I'm working on will do it for you. Just replace 'interrupt' above with a 'process' callback and you don't have to care about the exact workings of mmap'd ALSA at all.

This is great, but I don't see why this particular thing would require memory-mapped I/O. If one makes sure to write 4096 silent frames first start playback/capture using snd_pcm_link(), it should work with snd_pcm_read/write too, shouldn't it?

/Anders Torger

-------------------------------------------------------
This sf.net email is sponsored by:ThinkGeek
Welcome to geek heaven.
http://thinkgeek.com/sf

#6 lore raw

Re: Starting playback/capture exactly the same time (was: Repeatable exact I/O-delay)

Quoted 4 lines

Thanks. I'll try this. Not only the hardware can be broken, but also the driver I suppose. It seems like not all have support for snd_pcm_link(), for example my driver for RME96 (I have to do some maintenance work on that soon).

no code is needed to implement support for this. its handled by the ALSA mid-level layer. its possible that your driver has set or has not set some flag related to this, making the mid-level code think its not possible to do it.

Quoted 10 lines
Quoted 5 lines

Implementing memory-mapped IO isn't exactly what you do in a day. jackit.sf.net or the shortly-to-be-released library I'm working on will do it for you. Just replace 'interrupt' above with a 'process' callback and you don't have to care about the exact workings of mmap'd ALSA at all.

This is great, but I don't see why this particular thing would require memory-mapped I/O. If one makes sure to write 4096 silent frames first start playback/capture using snd_pcm_link(), it should work with snd_pcm_read/write too, shouldn't it?

yes, it should.

--p

-------------------------------------------------------
This sf.net email is sponsored by:ThinkGeek
Welcome to geek heaven.
http://thinkgeek.com/sf