| 1 |
// Listing 4.7 Stereo panning with stereo sound files using SndBuf2 |
| 2 |
|
| 3 |
// Loading and panning stereo sound files |
| 4 |
// by ChucK Programmer, October, 2023 |
| 5 |
|
| 6 |
// declare and load up a stereo file |
| 7 |
// Make a stereo SndBuf2 and |
| 8 |
SndBuf2 myStereoSound; |
| 9 |
me.dir()+"/audio/stereo_fx_03.wav" => myStereoSound.read; // load a stereo sound file. |
| 10 |
|
| 11 |
// We'll use these for Stereo Panning |
| 12 |
Gain bal[2]; // (2) Makes a Gain UGen array for stereo volume control. |
| 13 |
|
| 14 |
// connect everything up in stereo |
| 15 |
myStereoSound.chan(0) => bal[0] => dac.left; // (3) Connects left to left, |
| 16 |
myStereoSound.chan(1) => bal[1] => dac.right; // right to right. |
| 17 |
|
| 18 |
// set our soundfile to repeat forever |
| 19 |
1 => myStereoSound.loop; // (4) Repeats automatically. |
| 20 |
|
| 21 |
while (true) { |
| 22 |
// pick a random playback rate and a random panning |
| 23 |
Math.random2f(0.2,1.8) => myStereoSound.rate; // (5) Sets a random rate (pitch and time). |
| 24 |
|
| 25 |
Math.random2f(-1.0,1.0) => float balance; // (6) Sets a random balance (pan). |
| 26 |
|
| 27 |
// turn balance into left/right gain between 0 and 1.0 |
| 28 |
(balance+1)/2.0 => float rightGain; // (7) Implements the stereo balance control. |
| 29 |
1.0 - rightGain => float leftGain; |
| 30 |
leftGain => bal[0].gain; |
| 31 |
rightGain => bal[1].gain; |
| 32 |
|
| 33 |
0.3 :: second => now; |
| 34 |
} |