Thanks for your input Colin, I think you understand correctly, but it doesn't look like pa_stream_get_time() is really going to do it for me. I did find a way to get something close to what I want, however. If it turn on PA_STREAM_AUTO_TIMING_UPDATE without PA_STREAM_INTERPOLATE_TIMING, then the time stamp returned by pa_stream_get_time() (or equivalently pa_stream_get_timing_info()) increases in a step-wise fashion. This is fine, because I can estimate the time for the in-between step callbacks using the number of bytes read, and pa_bytes_to_usec(). <div>
<br></div><div>In fact, it seems like this estimate is quite precise. Looking at the value of gettimeofday() on two separate clients when when the time stamp steps forward, they are nearly equal (within 500 usec), and I verified that the data recorded for that invocation of the callback is equal for both clients. This looks really promising to me, but with more than two clients, the time difference starts to add up, and I wind up with unacceptably differing time estimates. <div>
<br></div><div>It seems like I ought to be able to use pa_timing_info to refine my estimate, accounting for the varying per-client delay, but I can't seem to make sense of the other values in the pa_timing_info struct. The timestamp itself is not even close between clients (off by 1/3rd of a second or more and fluctuating), and pa_source_usec, though it fluctuates as well, doesn't account for the difference an any way that's more accurate than my gettimeofday() method. Transport_usec seems to always be around 100us regardless, so it doesn't account for the timing difference between clients either. Basically, I can't do better than calling gettimofday() when the "time stamp step" occurs. Can I count on this behavior?</div>
<div><br></div><div>The frustrating thing is that pulse seems to be capable of sub-millisecond timing (as evidenced by the close temporal proximity of callbacks in two separate clients), but nothing in the API can give me what I want. I really don't want to give up since pulse provides so many other fantastic features, and is supported in many distributions by default. I'm thinking that I might be interested in working on the back end code that involves record stream timing. Would you be able to point me to a starting place?</div>
<div><br></div><div>Thanks,</div><div>Matt<br>
<br><div class="gmail_quote">On Thu, Jun 2, 2011 at 10:51 AM, Colin Guthrie <span dir="ltr"><<a href="mailto:gmane@colin.guthr.ie" target="_blank">gmane@colin.guthr.ie</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
'Twas brillig, and Matt Robbins at 02/06/11 16:33 did gyre and gimble:<br>
<div><div></div><div>> Hello Pulseaudio community,<br>
><br>
> I'm playing around with pulse to assess suitability for my project, and<br>
> while it seems like I should be able to do what I want, I'm struggling<br>
> with the API. Essentially, I need to record audio data with precise<br>
> (~1ms) time stamps. I'm doing collaborative sound source localization<br>
> between several machines, all synced to gps time. Since I don't really<br>
> need sample-accurate time, I figured it would be acceptable to call<br>
> gettimeofday() on ALSA interrupts to get a pretty good idea of when the<br>
> samples were recorded. Since all of the machines will be using the same<br>
> hardware, I don't even care if there's some fixed latency involved.<br>
> While doing this in ALSA would be an interesting project, when combined<br>
> with some the other things I need to do (stream splitting, fixed-point<br>
> resampling, etc.), it feels like I'd be reinventing the wheel. I've<br>
> been using JACK to accomplish what I need, but there are stability and<br>
> support issues on the embedded systems I'm using, so I'm looking into<br>
> alternatives, especially since the recent headless ubuntu release, which<br>
> has a working pulse server by default :)<br>
><br>
> I've tried cobbling something together using the pacat.c source using<br>
> pa_stream_set_read_callback(). My callback gets called, but although I<br>
> call pa_stream_get_timing_info(), I can't see how to derive the<br>
> information I need from the pa_timing_info struct because I can't see<br>
> how the timestamp field is related to the current fragment.<br>
><br>
> I'm not even sure if I'm going about this the right way, so if anyone<br>
> who knows the system could give me a few pointers, I'd really appreciate it.<br>
<br>
</div></div>I suspect you want to use:<br>
pa_stream_get_time().<br>
<br>
This returns the usecs since the stream started... this is likely what<br>
you want (IIUC).<br>
<br>
Cheers<br>
<br>
Col<br>
<br>
<br>
--<br>
<br>
Colin Guthrie<br>
gmane(at)<a href="http://colin.guthr.ie" target="_blank">colin.guthr.ie</a><br>
<a href="http://colin.guthr.ie/" target="_blank">http://colin.guthr.ie/</a><br>
<br>
Day Job:<br>
Tribalogic Limited [<a href="http://www.tribalogic.net/" target="_blank">http://www.tribalogic.net/</a>]<br>
Open Source:<br>
Mageia Contributor [<a href="http://www.mageia.org/" target="_blank">http://www.mageia.org/</a>]<br>
PulseAudio Hacker [<a href="http://www.pulseaudio.org/" target="_blank">http://www.pulseaudio.org/</a>]<br>
Trac Hacker [<a href="http://trac.edgewall.org/" target="_blank">http://trac.edgewall.org/</a>]<br>
<br>
_______________________________________________<br>
pulseaudio-discuss mailing list<br>
<a href="mailto:pulseaudio-discuss@lists.freedesktop.org" target="_blank">pulseaudio-discuss@lists.freedesktop.org</a><br>
<a href="http://lists.freedesktop.org/mailman/listinfo/pulseaudio-discuss" target="_blank">http://lists.freedesktop.org/mailman/listinfo/pulseaudio-discuss</a><br>
</blockquote></div><br>
</div></div>