I've got this simple patch:
Now I connected a game controller to Pd where the keys give me 1 or 0 depending whether I press the button or not.
If I press my button I want the osc~ to "play" and if I release it it should stop.
BUT: I wasn't able to find a point where to attach a switch. I don't want to switch off the DSP as I want to play another sound at another key the same time.
It would be nice if anyone of you would have a solution
EDIT: Okay the below solution worked, If there is any need for the project I've done (using a game controller as an instrument) just contact me directly.
This is done with an audio multiply object [*~] and 0 or 1, as the previous answer stated.
Here's a simple example with a PureData toggle box (which outputs 0 or 1, same as your game pad buttons):
The object [line~] makes a smooth transition from 0 to 1 and back over the course of 100 milliseconds (the message box above replaces the token $1 with it's input), this provides a volume envelope and stop clicks, which can occur when the level of a tone change too abruptly. If you want this change to sound instant, still use a [line~] but change the 100 down to 10.
If it's any help to you, I also have a tutorial on using game pads in pure data