Joystick audio control

May 2, 2007 at 9:00am

Joystick audio control

Hello! I’m wondering whether anyone can help me with a patch I’m trying to cobble together. I have been using the buttons on a USB joystick to trigger sounds using MIDI, but I dont know how to map the x, yand z axes to work as controller changes. What I’d really like to do is use the x and y axis to control the volume and panning of a live audio feed, but I don’t have a clue how to do this… Here’s the (rather limited) code I’ve got so far:

#P window setfont “Sans Serif” 9.;
#P number 616 329 35 9 0 0 0 139 0 0 0 221 221 221 222 222 222 0 0 0;
#P number 544 330 35 9 0 0 0 139 0 0 0 221 221 221 222 222 222 0 0 0;
#P user ezdac~ 795 505 839 538 0;
#P user ezadc~ 795 172 839 205 0;
#P window linecount 1;
#P newex 562 252 45 9109513 route 0 4;
#P newex 351 366 28 9109513 sel 0;
#P message 361 398 18 9109513 42;
#P number 363 344 35 9 0 0 0 139 0 0 0 221 221 221 222 222 222 0 0 0;
#P newex 354 451 30 9109513 pack;
#P newex 354 424 82 9109513 makenote 90 10;
#P newex 266 365 28 9109513 sel 0;
#P message 276 397 18 9109513 40;
#P number 278 343 35 9 0 0 0 139 0 0 0 221 221 221 222 222 222 0 0 0;
#P newex 269 450 30 9109513 pack;
#P newex 269 423 82 9109513 makenote 90 10;
#P newex 181 366 28 9109513 sel 0;
#P message 191 398 18 9109513 38;
#P number 193 344 35 9 0 0 0 139 0 0 0 221 221 221 222 222 222 0 0 0;
#P newex 184 451 30 9109513 pack;
#P newex 184 424 82 9109513 makenote 90 10;
#P newex 93 367 28 9109513 sel 0;
#P message 103 399 20 9109513 36;
#P number 105 345 35 9 0 0 0 139 0 0 0 221 221 221 222 222 222 0 0 0;
#P window linecount 3;
#P comment 63 93 100 9109513 These numbers are wht you should have in the “route” box;
#P number 165 93 35 9 0 0 0 139 0 0 0 221 221 221 222 222 222 0 0 0;
#P window linecount 1;
#P comment 290 85 100 9109513 updating rate = 1ms;
#P newex 165 33 31 9109513 dac~;
#P newex 138 625 43 9109513 midiout;
#P newex 285 22 48 9109513 loadbang;
#P window linecount 2;
#P comment 425 134 100 9109513 select your input device;
#P window linecount 3;
#P comment 46 670 100 9109513 Double click to select your midi output. From MAX/MSP;
#P window linecount 1;
#P newex 138 602 92 9109513 midiformat;
#P newex 96 452 30 9109513 pack;
#P newex 96 425 80 9109513 makenote 127 10;
#P newex 220 224 81 9109513 route 48 49 50 51;
#P message 245 83 35 9109513 poll 1;
#P user umenu 245 132 173 9109543 1 64 148 1;
#X add “SideWinder Joystick”;
#P message 245 60 32 9109513 menu;
#P newex 209 132 29 9109513 hi;
#P comment 692 257 100 9109513 What happens here?;
#P connect 17 0 19 0;
#P connect 18 0 6 0;
#P connect 6 0 7 0;
#P connect 19 1 18 0;
#P connect 5 0 17 0;
#P fasten 6 1 7 1 171 446 121 446;
#P connect 7 0 8 0;
#P connect 21 0 8 0;
#P connect 26 0 8 0;
#P connect 31 0 8 0;
#P connect 8 0 12 0;
#P fasten 1 0 15 0 214 154 202 154 202 90 170 90;
#P connect 22 0 24 0;
#P connect 23 0 20 0;
#P connect 20 0 21 0;
#P connect 24 1 23 0;
#P connect 5 1 22 0;
#P fasten 20 1 21 1 261 445 209 445;
#P fasten 3 1 1 0 413 150 421 150 421 127 214 127;
#P fasten 4 0 1 0 250 117 214 117;
#P fasten 2 0 1 0 250 81 214 81;
#P connect 1 0 5 0;
#P fasten 11 0 2 0 290 52 250 52;
#P fasten 11 0 4 0 290 80 250 80;
#P fasten 1 1 3 0 233 148 241 19 241 110 250 110;
#P connect 27 0 29 0;
#P connect 28 0 25 0;
#P connect 25 0 26 0;
#P connect 29 1 28 0;
#P connect 5 2 27 0;
#P fasten 25 1 26 1 346 444 294 444;
#P connect 32 0 34 0;
#P connect 33 0 30 0;
#P connect 30 0 31 0;
#P connect 34 1 33 0;
#P connect 5 3 32 0;
#P fasten 30 1 31 1 431 445 379 445;
#P connect 35 0 38 0;
#P connect 1 0 35 0;
#P connect 35 1 39 0;
#P connect 36 0 37 0;
#P connect 36 1 37 1;
#P window clipboard copycount 40;

If anyone can help, I’d be very grateful…

Ed

#31709
May 2, 2007 at 10:36am

Ed wrote:
> What I’d really like to
> do is use the x and y axis to control the volume and panning of a
> live audio feed, but I don’t have a clue how to do this… Here’s the
> (rather limited) code I’ve got so far:

Your patch doesn’t make sense to me for what you seem to want to do:

- There’s no MSP stuff for controlling gain or pan of some audio source.

- All that happens is that joystick input is reformatted as midi
messages (but not rescaled, which is probably bad) and sent out of a
midi output.

Is the volume / pan thing you want to control going to be in your patch,
or somewhere else?

If it’s going to be in your patch, first make something in msp that
controls the gain / pan of a signal, consulting the docs,
maxobjects.com, and list archives as needed. The rest will then be
considerably more apparent – the aim would be to rescale the joystick
input to a range that works with whatever your eventual volume / pan
controls expect. I don’t see that midi *needs* to come into it.


Owen

#103335
May 2, 2007 at 3:43pm

Thanks Owen, I was going through the max tutorials and not finding a lot about audio. Now I’ve found the MSP tutorials, things are better! Although this new patch I’ve written is giving me weird latency problems, but I’m fairly sure its my eccentric soundcard. I haven’t sussed out panning yet but I’ve made a simple volume control:

#P window setfont “Sans Serif” 9.;
#P number 503 333 35 9 0 0 0 139 0 0 0 221 221 221 222 222 222 0 0 0;
#P number 431 334 35 9 0 0 0 139 0 0 0 221 221 221 222 222 222 0 0 0;
#P window linecount 1;
#P newex 451 252 45 9109513 route 0 4;
#P window linecount 3;
#P comment 69 142 100 9109513 These numbers are wht you should have in the “route” box;
#P number 171 142 35 9 0 0 0 139 0 0 0 221 221 221 222 222 222 0 0 0;
#P window linecount 1;
#P comment 381 104 100 9109513 updating rate = 1ms;
#P newex 359 21 48 9109513 loadbang;
#P window linecount 2;
#P comment 446 209 100 9109513 select your input device;
#P window linecount 1;
#P message 334 108 35 9109513 poll 1;
#P user umenu 256 208 173 9109543 1 64 224 1;
#X add “SideWinder Joystick”;
#P message 334 85 32 9109513 menu;
#P newex 221 207 29 9109513 hi;
#P user ezadc~ 269 335 313 368 0;
#P window setfont “Proportional Serif” 10.;
#P comment 306 637 13 9175050 R;
#P comment 249 637 13 9175050 L;
#P comment 268 625 35 9175050 On/Off;
#P window linecount 2;
#P comment 467 496 72 9175050 Amplitude in dB;
#P window linecount 1;
#P comment 494 439 51 9175050 Amplitude;
#P window setfont “Fixedwidth Serif” 10.;
#P flonum 467 481 69 10 0 0 160 141 0 0 0 221 221 221 222 222 222 0 0 0;
#P newex 467 460 38 9240586 AtodB;
#P newex 425 417 56 9240586 / 65535.;
#P flonum 425 438 69 10 0. 1. 3 141 0 0 0 221 221 221 222 222 222 0 0 0;
#P newex 425 500 38 9240586 line~;
#P message 425 481 38 9240586 $1 50;
#P newex 326 613 27 9240586 *~;
#P newex 425 460 38 9240586 * 0.5;
#P newex 231 613 27 9240586 *~;
#P user ezdac~ 262 639 306 672 0;
#P fasten 16 0 23 0 226 203 208 203 208 139 176 139;
#P connect 16 0 25 0;
#P connect 16 1 18 0;
#P fasten 21 0 17 0 364 51 339 51;
#P fasten 21 0 19 0 364 79 339 79;
#P connect 25 1 27 0;
#P connect 25 0 26 0;
#P connect 8 0 9 0;
#P connect 6 0 2 0;
#P fasten 6 0 8 0 430 456 472 456;
#P connect 4 0 5 0;
#P connect 2 0 4 0;
#P connect 7 0 6 0;
#P connect 26 0 7 0;
#P fasten 5 0 1 1 430 578 319 578 319 606 253 606;
#P fasten 5 0 3 1 430 606 348 606;
#P connect 15 1 3 0;
#P fasten 3 0 0 1 331 635 301 635;
#P fasten 1 0 0 0 236 635 267 635;
#P connect 15 0 1 0;
#P fasten 17 0 16 0 339 156 226 156;
#P fasten 19 0 16 0 339 192 226 192;
#P fasten 18 1 16 0 424 225 442 225 442 202 226 202;
#P window clipboard copycount 28;

Thanks very much for your reply!

Ed

#103336
May 2, 2007 at 4:52pm

Ed wrote:
> Thanks Owen, I was going through the max tutorials and not finding a
> lot about audio. Now I’ve found the MSP tutorials, things are better!

Yeah, they’ll help :)

> Although this new patch I’ve written is giving me weird latency
> problems, but I’m fairly sure its my eccentric soundcard.

Check your buffer settings in the dsp status window. If you’re on
windows, make sure you’re using a proper ASIO driver, if available,

> I haven’t
> sussed out panning yet but I’ve made a simple volume control:

Good going – you’ll find that the linear mapping you’ve got at the
moment sounds uneven, I suspect. The [gain~] object may be helpful.

Panners are more involved, but the examples folder is your friend.


Owen

#103337
May 2, 2007 at 7:28pm

We did this a while back, using a sort of surround-sound installation approach; it was fun. If you are having wierd reactions, take a look at the polling frequency in the [hi] object. I set ours to 10ms, which was more than fast enough.

#103338
May 3, 2007 at 6:48pm

hi,
I made this some weeks ago to illustrate the tutorial of Andrew Benson about making connections between a Joystick and Max.

Hope it will give you some ideas …

http://vids.myspace.com/index.cfm?fuseaction=vids.individual&videoid=2015981911

#103339

You must be logged in to reply to this topic.