Forums > MaxMSP

Greatest Possible Timing Precision

March 29, 2006 | 4:55 pm

This is related to my motion tracking using piezos post(below) but is really a new topic.

I am attempting to track where a ping pong ball hits a table during a game using an array of microphones.

I need to ask if it is possible with a standard audio interface (in my case m-audio firewire audiophile).

I know that sound travels at 340m/s and I am estimating that it travels at 600m/s through the table.

I think that to detect the position of impact within 5cm I need to be able to access data from the microphones to within 1/12 of a millisecond.

I understand that it is possible to sync Max to an external clock or to change the length of (what it thinks is a) millisecond to get at the timing data.

I understand that I can sample audio at a frequency of 44,100.

But…..and this is the question

Is it possible to analyse the signals accurately at these sub-millisecond levels?

Anyone any thoughts?

Gav


March 29, 2006 | 5:41 pm


March 29, 2006 | 5:53 pm

Hi Gavin,
My suspicion is that you are using max objects, when you actually need
the precision of MSP signal-based objects. I suggest using a signal
based timer, as demonstrated in the patch below. This will give you far
greater accuracy than using the timer object. Hope this helps get you
started.

Cheers,
Andrew B.

#P window setfont "Sans Serif" 9.;
#P window linecount 3;
#P comment 297 195 221 196617 this should theoretically work. I haven’t
tested myself. You will need to include some logic to define which is
the first event.;
#P window linecount 1;
#P comment 367 45 100 196617 audio in;
#P newex 348 87 31 196617 abs~;
#P newex 296 88 31 196617 abs~;
#P comment 43 48 154 196617 here is how you time in samples;
#P inlet 348 43 15 0;
#P inlet 296 42 15 0;
#P button 348 164 15 0;
#P newex 348 108 45 196617 >=~ 0.5;
#P newex 348 135 36 196617 edge~;
#P button 296 164 15 0;
#P newex 296 108 45 196617 >=~ 0.5;
#P newex 296 135 36 196617 edge~;
#P comment 97 217 116 196617 reports maximum value;
#P comment 82 66 14 196617 2.;
#P comment 44 65 14 196617 1.;
#P flonum 141 279 96 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P newex 85 258 66 196617 sampstoms~;
#P button 81 81 15 0;
#P newex 81 100 57 196617 t reset b b;
#P flonum 85 236 53 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P newex 43 212 53 196617 minmax~;
#P message 104 123 29 196617 stop;
#P user ezdac~ 205 47 249 80 0;
#P button 43 80 15 0;
#P newex 43 153 40 196617 count~;
#P comment 84 153 126 196617 counts number of samples;
#P comment 395 108 100 196617 get events like so;
#P connect 22 0 25 0;
#P connect 25 0 19 0;
#P connect 21 0 24 0;
#P connect 24 0 16 0;
#P connect 19 0 18 0;
#P connect 18 0 20 0;
#P connect 15 0 17 0;
#P connect 16 0 15 0;
#P connect 10 1 11 0;
#P connect 7 0 10 0;
#P connect 8 2 6 0;
#P connect 9 0 8 0;
#P connect 8 0 6 0;
#P connect 8 1 5 0;
#P connect 6 3 7 0;
#P connect 2 0 6 0;
#P connect 5 0 2 0;
#P connect 3 0 2 0;
#P window clipboard copycount 28;


April 1, 2006 | 10:46 pm

I’ve been experimenting with MSP and I’m getting there but could really use a hand!

I now have a patch which detects the incoming signal (at 96000 hz)and outputs the time if the level goes above a threshold value.

The main problem is that either the count~ or the snapshot~ objects are jumping in steps of 512 (or whatever value I set the hardware buffer to).

I need to detect where the amplitude rises to within a sample or 2. 512 is not precise enough.

I’ve been playing around with recording the input into a named buffer. I can see the wave forms in each channel, the information is there but I don’t know how to get it.

I have been trying to search through the buffer using count~ and index~ but getting a bit stuck.

Anyone know what I’m on about?

Gav

max v2;
#N vpatcher 0 0 952 668;
#P origin 0 21;
#P window setfont "Sans Serif" 9.;
#P flonum 308 401 143 9 0 0 0 139 0 0 0 221 221 221 222 222 222 0 0 0;
#P flonum 139 401 143 9 0 0 0 139 0 0 0 221 221 221 222 222 222 0 0 0;
#P newex 347 357 26 9109513 print;
#P newex 353 316 51 9109513 snapshot~;
#B color 5;
#P newex 285 315 51 9109513 snapshot~;
#B color 5;
#P newex 191 275 36 9109513 count~;
#B color 5;
#P message 474 341 18 9109513 50;
#P newex 441 398 27 9109513 *;
#P slider 558 381 15 128 0 1;
#P button 438 322 15 0;
#P button 403 233 15 0;
#P newex 356 259 45 9109513 onebang;
#P newex 296 260 45 9109513 onebang;
#P button 435 181 15 0;
#P button 174 96 15 0;
#P newex 124 50 50 9109513 metro 300;
#P newex 288 356 26 9109513 print;
#P button 466 270 15 0;
#P message 155 152 14 9109513 0;
#P button 122 103 15 0;
#P toggle 345 1 15 0;
#P newex 301 22 29 9109513 adc~;
#B color 5;
#P comment 367 24 100 9109513 audio in;
#P newex 348 66 31 9109513 abs~;
#P newex 296 67 31 9109513 abs~;
#P button 348 143 15 0;
#P newex 348 87 39 9109513 >=~ 0.2;
#P newex 348 114 36 9109513 edge~;
#P button 296 143 15 0;
#P newex 296 87 39 9109513 >=~ 0.2;
#P newex 296 114 36 9109513 edge~;
#P connect 15 0 11 0;
#P connect 10 0 15 0;
#P connect 26 0 29 0;
#P connect 11 0 12 0;
#P connect 15 0 16 0;
#P connect 11 0 25 0;
#P connect 25 0 26 0;
#P connect 18 0 26 0;
#P connect 26 0 14 0;
#P connect 9 0 6 0;
#P connect 6 0 1 0;
#P connect 1 0 0 0;
#P connect 0 0 2 0;
#P connect 2 0 18 0;
#P connect 10 0 9 0;
#P connect 27 0 30 0;
#P connect 20 0 18 1;
#P connect 27 0 28 0;
#P connect 9 1 7 0;
#P connect 7 0 4 0;
#P connect 4 0 3 0;
#P connect 3 0 5 0;
#P connect 25 0 27 0;
#P connect 19 0 27 0;
#P connect 5 0 19 0;
#P connect 20 0 19 1;
#P connect 15 0 20 0;
#P connect 5 0 17 0;
#P connect 19 0 21 0;
#P connect 24 0 23 1;
#P connect 15 0 24 0;
#P connect 23 0 22 0;
#P pop;


April 2, 2006 | 4:10 pm

On 2-Apr-2006, at 0:46, gavin wrote:

> The main problem is that either the count~ or the snapshot~ objects
> are jumping in steps of 512 (or whatever value I set the hardware
> buffer to).

Yeah. Max messages (ie, anything going through plain-vanilla patch
cords) are only triggered between signal vectors. You could set your
signal vector size to 2 samples (you can even set it to single-
samples by using a ;max message), but for what you want you would be
better off to do everything the MSP-domain.

Hope this gets you going in the right direction. Someone else may
feel inclined to try to amend your patch.

– Peter

————– http://www.bek.no/~pcastine/Litter/ ————-
Peter Castine +–> Litter Power & Litter Bundle for Jitter

iCE: Sequencing, Recording & |home | chez nous|
Interface Building for |bei uns | i nostri|
Max/MSP Extremely cool http://www.castine.de

http://www.dspaudio.com/


April 2, 2006 | 7:28 pm

> Is it possible to analyse the signals accurately at these sub-millisecond levels?

do the math … 1/12th milisecond at 44.100 Hz
is humh ..possible, yet its all but precise.

any chance to repeat the experiment with a bigger ball
in a bigger room ? :)


April 2, 2006 | 7:36 pm

Quote: gavspav wrote on Sat, 01 April 2006 15:46
—————————————————-
> I’ve been experimenting with MSP and I’m getting there but could really use a hand!
>
> I now have a patch which detects the incoming signal (at 96000 hz)and outputs the time if the level goes above a threshold value.
>
>
> The main problem is that either the count~ or the snapshot~ objects are jumping in steps of 512 (or whatever value I set the hardware buffer to).
>
> I need to detect where the amplitude rises to within a sample or 2. 512 is not precise enough.
>
> I’ve been playing around with recording the input into a named buffer. I can see the wave forms in each channel, the information is there but I don’t know how to get it.
>
> I have been trying to search through the buffer using count~ and index~ but getting a bit stuck.
>
> Anyone know what I’m on about?

havent been looking at the patch but maybe its simpler
than you thought.
there is, for example, the [>~] object to split signals
and so detect certain values.
or why not substract -0.9 from the input and then use
[zerox~] to find the most peaks of the ping pong sounds.

use signals only or you can forget it.

whats your aim, what do you want to do with the
"sequence" data?


April 3, 2006 | 11:27 am

Hello,

thanks for your suggestions.

Peter when you say Max messages are the ones with the plain/vanilla
patch cords do these signify messages from MSP to Max?

Also I am trying to keep it in the MSP domain but am I right in thinking that:

MSP threads running at signal rate operate once every time a chunk of sound is brought in which for me at the mo is 512 samples (My hardware buffer is set to 512 samples)

But within the objects there are operations going on at the sample rate i.e 96000 hz

If MSP processes the data in chunks, then how can I find out information relating to individual samples? The only way I have found to do it so far is by using an onject like peak~ which seems to force me to use max objects.

I wish to pinpoint when events happen to within a sample but it is not imperative that I process the data immediately. I am thinking that as long as I record the events I have a few ms to detect when they actually occur, so I could possibly use max objects as well.

Thanks,

Gavin


April 3, 2006 | 7:10 pm

Hi Gavin,

If you haven’t already, you may wish to investigate a network that
uses the sah~ object in conjunction with snapshot~ and edge~. Even
with these objects it can be problematic to isolate exactly the data
you want from a signal stream; some work has been done in this area
and a future version of Max may include a more precise tool to move
from the signal to event world.

Ben


April 3, 2006 | 8:39 pm

> some work has been done in this area
> and a future version of Max may include a more precise tool to move
> from the signal to event world.

One of the reasons I love cycling so frickin much is that you guys
are transparent. I don’t want to get off on a leftist rant here(take
that dennis miller), but when we ask you things, you respond
honestly and openly. It was a passing comment but its not to be
taken lightly. I don’t see this happening in many places. and its
worth an extra couple bucks and should be an example.

got that choir?!
-matt


April 3, 2006 | 8:43 pm

Hi Ben,

when you say some work has been done in this area, is there any links where I might be able to learn about this stuff.

I have experimented with sah~, edge~, snapshot~. I’m a bit in the dark though to be honest.

Gav


April 5, 2006 | 8:53 am

Ben Nevile wrote:
> a future version of Max may include a more precise tool to move
> from the signal to event world.

To measure sample accurate timing I’d use mxj~ to do the timing and then
pull the result out to the event world.

Thats probably the way to go. Counting samples in Java shouldn’t be too
hard even for a Java newbie. All the documentation and the examples are
there.

That means (as mostly) already the recent version of Max could do it…

Stefan

[][] [][][] [][] [][][]
[][][][][][][][][][][][][][][]

Stefan Tiedje
Klanggestalter
Electronic Composition
&
Improvisation

/~~~~~
\ /|() ()|
))))) )| | |( \
/// _/)/ )))))
___/ ///

————————-x—-
–_____———–|———–
–(_|_ —-|—–|—–()—-
– _|_)—-|—–()———–
———-()————x—–

14, Av. Pr. Franklin Roosevelt,
94320 Thiais, France
Phone at CCMIX +33-1-57 42 91 09


April 13, 2006 | 8:54 am

Thanks for the tip.

I’m back on the case now after a short break.
Looking at the Javascript documentation now.

Stefan wrote: Counting samples in Java shouldn’t be too
hard even for a Java newbie. All the documentation and the examples are there.

Stefan, are you referring to the javascript documentation within the MaxMSP folders or something else?

Gavin


April 13, 2006 | 1:14 pm

gavin wrote:
> Stefan wrote: Counting samples in Java shouldn’t be too hard even for
> a Java newbie. All the documentation and the examples are there.
>
> Stefan, are you referring to the javascript documentation within the
> MaxMSP folders or something else?

Don’t mix Javascript with Java, I am reffering to Java and the mxj~
object. You should get started with the mxj~ helpfile and the
WritingMaxExternalsInJava.pdf especially page 43, dealing with mxj~ and
audio.

Stefan

[][] [][][] [][] [][][]
[][][][][][][][][][][][][][][]

Stefan Tiedje
Klanggestalter
Electronic Composition
&
Improvisation

/~~~~~
\ /|() ()|
))))) )| | |( \
/// _/)/ )))))
___/ ///

————————-x—-
–_____———–|———–
–(_|_ —-|—–|—–()—-
– _|_)—-|—–()———–
———-()————x—–

14, Av. Pr. Franklin Roosevelt,
94320 Thiais, France
Phone at CCMIX +33-1-57 42 91 09


April 13, 2006 | 1:19 pm

Oops my mistake!
Ok thanks I’ll get stuck in,

Gav


Viewing 15 posts - 1 through 15 (of 15 total)