p

D482's icon

Hi,

I am new to Max/MSP

hz37's icon
Max Patch
Copy patch and select New From Clipboard in Max.

If you simply want to achieve Haas effect delay in a stereo system, you could insert two [delay~] objects in a stereo signal and mess around with the the delay times (in samples):

If you need to dive deeper than that, look into MIAP:

There's a Max external for MIAP, too. Good luck!

D482's icon

Thanks for the help.

Roman Thilenius's icon

use [lcd] for mousetracking.

hz37's icon

The [lcd] object will let you do just this. In fact, I sort of made what I think you want to make because it was a nice experiment. Attached you can see how it looks (the [lcd] object is such that you need to lock the patcher to intercept mouse moves. The blue picture inside the [lcd] is on my OSX Desktop, so that's where the patch attempts to load it from.

There are several things you have to assume:

- Room size. I made an 8x8 meters room.

- Speaker position. I put them top left and top right.

- Ideal room and uniform propagation of sound from the speakers.

- The Haas delay is simple Pythagoras, because you delay based on the speed of sound in air (340 m/sec). So if your sample rate is 44 kHz, a distance of 340 meters would cause a 1 second delay, i.e. 44100 samples. In a square room of 8x8 meters, the longest distance from any speaker would be the square root of 8^2 + 8^2, approximately 11.3 meters. So your [delay~] objects would only need to hold about 1500 samples max.

- As for amplitude damping, that's a bit tricky. You can't say the speaker cone is at 0 meters and put a zero in 20 * log(p0 / p1) because you would try to take a logarithm of 0. So I have assumed a radius of 1 meters away from the speaker center at which position the relative amplitude is 0 dB. So if you move closer, say, at .5 meters from the speaker center, you would get a gain of 6.02 dB (20 * log(.5)). If you move away from the speaker, say, at 2 meters, you would get a loss of 6.02 dB. Also see:

You can make the thing even a bit more realistic by adding a reverb to it. But I don't know how to compute that, so that's a bit of a wild guess. I have a patch with a reverb if you want to play with it.

Max Patch
Copy patch and select New From Clipboard in Max.

Good luck! Here's the patch without reverb. It's complicated enough as it is.

Screen-Shot-2015-04-16-at-22.52.04.png
png
bg.jpg
jpg
Peter McCulloch's icon

There's an example of the Doppler effect in the Max examples in the spatialization section IIRC.

D482's icon

Oh wow thank you HZ37, really appreciate that.

hz37's icon

Ah, okay! Got it now! You are doing just the inverse of my patch. No need to go the IIR/FIR route I'd say. You can figure out how to do the inverse of my patch. I would go for a "standard" delay of both channels and compute how far away you are (Pythagoras) from any speaker and subtract that from the delay of a channel. Amplitude compensation is also just flipped from what I'm doing. In effect, my patch is a "room simulation" and yours a "sweet spot follower". You'll have to make the switch from scripted code to how Max does this. The room size is just a wild guess, and if you encounter an "8" in my patch, it's probably a room dimension I used. Like I said, you'll have to make some assumptions.

Let's see how far you can get by peeking at my patch. And the Kinect stuff I don't know too much about, so I hope you figure out a way to get the position from that device. Let me know if I can be of help! Good luck,

Hens

D482's icon

I have never used this Software before and I am struggling quite a lot to grasp it all, I have been researching and looking at a lot of examples and tutorials but it is hard to put it all together.

hz37's icon

Hi Catherine,

I have converted the upper part of your matlab code to Max. I'm not sure how you get the magic angles of 10 and 30 degrees at the start. Also, because you haven't specified how you get DL and DR, I have left that last bit out. See if you can make any sense of the Max code below. One thing to realise when you make things in Max is when inlets of an object actually cause any output. That's why you sometimes see objects like [t b], that "trigger a bang", which is then sent to another object's left inlet to cause an output. I would do the tutorials of Max. Maybe not all of them, but the Basic tutorials should get you a lot further. You can always skip stuff that's irrelevant for now.

So how are you doing on getting the Kinect input into Max? Seems like a kinda important part of your patch.

I would restrict your project to updating the delays of the signals and the amplitudes. Once you have the distances from the listener to both speakers, implementing the delay times will be quite trivial. It is impossible to specify fractional delays, because delays are quantised to samples. There is nothing between samples. Oh well, there is... it is called oversampling, but I wouldn't bother about that now.

Explain how you compute the thetas and we'll see if we get them to behave. If you can get a minimal patch with a moving virtual listener and listening angles/distances to work first, you are well on your way. Did you manage to get my previous thing (with the blue virtual room) to behave on your machine? You should be able to listen to the music being adjusted as you move the mouse over the blue room. Don't forget to lock the patch before you attempt to do that.

Good luck!

Max Patch
Copy patch and select New From Clipboard in Max.

Hens

hz37's icon
Max Patch
Copy patch and select New From Clipboard in Max.

Addendum: here's the earlier patch with angles computed.

bg1.jpg
jpg
D482's icon

I

Stereo.jpg
jpg
hz37's icon

I think you will get continuous update from the Kinect, so it will be a situation of reacting to notifications rather than polling for updates yourself. In my patch with the blue room you can hear how adjusting delays and amplitudes in Max is click free.

D482's icon

Thanks for the link!

I have been looking at this paper: http://archive.cnmat.berkeley.edu/ICMC2000/pdf/VBAP.pdf and the patches from the paper are attached as files. But unsure if i could implement any of it.

D482's icon
Max Patch
Copy patch and select New From Clipboard in Max.
D482's icon
Max Patch
Copy patch and select New From Clipboard in Max.
hz37's icon

Hi Catherine,

I'll attach a slightly updated version of my blue room thingie. You can adjust the blue boxes (click hold and drag) to move the sprite, and you will notice that the distances and angles are computed from that. The Kinect is going to give you X, Y and Z coordinates of a body part in 3D space. You will probably omit the Z coordinate and think of the whole thing happening in a flat plane. So that would mean interpreting the X and Y coordinates. I think the patch below could be a good starting point. I hope you do not want to draw too many animation stuff inside the LCD, because that gets overly complicated. So I would start with what I have: a box that represents the room and your mouse moves like a listener in that room. See if you can make sense of this and adapt parts so they are congruent with your ideas. You can toss out parts you don't need. Just be sure to save your in-between patches with different names so you can refer back to previous versions.

As for VBAP, it looks super interesting but also quite complicated and all happening in 3D space as well. I don't know what your deadline is, but I would start with a very much simplified version of what you want to accomplish. The way I read your request is that you want to input angles and draw a changing virtual source from that. If that's true, I would really ask myself if this is something you need to accomplish right now. Sure we can animate a sprite inside the LCD, based on angles, but isn't your aim in simple pseudo-code not simply this?:

Get position of listener
Compute distance of head to left speaker
Compute distance of head to right speaker
Compensate delay of signal for left channel based on distance
Compensate delay of signal for right channel based on distance
Compensate volume of signal for left channel based on distance
Compensate volume of signal for right channel based on distance

Good luck!

Max Patch
Copy patch and select New From Clipboard in Max.

Hens

D482's icon

ok thank you.

Roman Thilenius's icon

not IIR filters, no, you would use allpasses. (i think there is an object for it, if not, use 2 combs.)

D482's icon

Hi Hens,

I'v edited your patch quite a lot and got it kind of working for what I want but i was wanting to ask you one thing.

`

D482's icon

Oh actually it seems to have fixed itself when i started to play audio.

And sorry I didn't realise that the max code wouldn't compress there! =/

hz37's icon

Hi Catherine, that's awesome that you could use my example and work it into something new! By the way, you can edit your forum posts and replace the expanded code with the compressed code if so desired. Good luck!

Hens

D482's icon

Ah thanks, I didn't realise.

`

hz37's icon

Oh sure, that's just a conversion problem. I'm at work right now, so I can't open your patch but I can look at it tonight. What you can do already is answer these two questions:

1) Do you need to freely define where the speakers are in the room? If yes, we should make something that draws the speaker symbols in the room. And numeric input to define speaker positions (4 floats, I would guess).

2) What's the range of the x/y coordinates you get from the Kinect? As you can see, the sprite inside the "room" is just drawn by a list/tuple of numbers, so getting in Kinect coordinates and turning them into lcd pixel coordinates should be a breeze. But we need to know the range of the Kinect numbers to do that.

Mo' later!

D482's icon

Yeah they can be defined freely or just be kept in the lcd box as I adjusted the box to 2x2 so it is quite realistic as to where the speakers would be placed in the home now.

D482's icon

Oh it won't let me upload the screen shot.

hz37's icon
Max Patch
Copy patch and select New From Clipboard in Max.

Here's how you can easily scale the Kinect parameters to the LCD pixel parameters. If you can live with the speakers at a fixed position, I would go for that to not make things overly complicated. I would experiment with getting the X and Y readings as precise as possible. In this patch I'm guessing the minimal values are where you are standing in the top left corner and the maximum values where you are in the lower right corner, but there may be a constant value to take into account.

D482's icon

Ok thanks, how will I get it to scale in real time?

hz37's icon

Just connect the Kinect output to the [scale]. Max is all about doing things in real time.

D482's icon

Just want to say thank you HZ37! Got it all working in the end, couldn't have completed it without you help, thank you!