Thermin + Analog Sensor controlling volume?

I've been playing with the theremin sketch found here.

/* Theremin

Plays tones based on a sensor reading

circuit: * photoresistor from +5V to analog in 0 * photoresistor from analog pin 0 to ground * 8-ohm speaker on digital pin 8

created 10 Sep 2009 modified 8 Feb 2009 by Tom Igoe */

void setup() { Serial.begin(9600); }

void loop() { // get a sensor reading: int sensorReading = analogRead(0); int volReading = analogRead(1); Serial.println(sensorReading); // map the results from the sensor reading's range // to the desired pitch range: int pitch = map(sensorReading, 0, 1024, 200, 8000); // change volume based on reading from 2nd distance sensor analogWrite(2, volReading); // change the pitch, play for 10 ms: tone(9, pitch, 10); }

I have a ultrasonic distance sensor mapping values for the pitch. But this does not provide all the functionality of a theremin, where a second axis would control amplitude (volume). I think I need to make a second analog device (in this case a second distance sensor) resist the output going to the speaker. How do I do this?

I can provide a circuit diagram, but basically I have two Ultrasonic Distance Sensors connected to a0 and a1. The Speaker is on Digital pin 9. The AnalogReading from pin0 is mapped to a tone played on the speaker (this works). The AnalogReading from pin1 is output on pin2. I then have this running to a line that goes to the speaker. The output coming from digital pin9 goes to a voltage divider on this same line (in between a2 and the Speaker). But I shouldn't be using a voltage divider, thats not right. What do I need to do? The output from the digital pin obviously needs to go to the speaker. I think the output from pin2 should resist the output from the digital pin, similar to a potentiometer dial would.

Is there a software method? Or can I somehow use the reading from the 2nd analogDevice to control the Amplitude of the square Wave produced by the tone object?

Thanks for helping! steve-o

P.S. I know there are ways to make a real theremin with the Arduino. I'm just looking for a simple method to adapt this program for now so I can have a mock-up for class.