Hi Everyone! Wath is wrong in this code? // Using SndBuf to play a sound file // by ChucK Programmer, December 2050 SndBuf mySound => dac; // get file path me.dir(C:\Program Files (x86)\ChucK\audio\123.wav) => string path; // sound file we want to play "/audio/123.wav" => string filename; // + sign connects strings together! path+filename => filename; // tell SndBuf to read this file filename => mySound.read; // set gain 0.5 => mySound.gain; // play sound from the beginning 0.1 => mySound.pos; // advance time so we can hear it second => now; //
Hi,
The relevant code is here:
```
me.dir(C:\Program Files (x86)\ChucK\audio\123.wav) => string path;
```
At this point, the string "path" is "C:\Program Files
(x86)\ChucK\audio\123.wav".
```
"/audio/123.wav" => string filename;
// + sign connects strings together!
path+filename => filename;
```
so when you concatenate it with the "filename" string, you end up with a
string with the contents "C:\Program Files
(x86)\ChucK\audio\123.wav/audio/123.wav", which is not the correct path.
The correct code might look like this:
```
// get file path
me.dir("C:\Program Files (x86)\ChucK\audio\") => string path;
// sound file we want to play
"123.wav" => string filename;
// + sign connects strings together!
path+filename => filename;
```
I haven't been able to test this, since I'm not at a Windows computer right
now, but if my understanding is correct, it should work.
Hope that helps!
Best,
Hugh
On Mon, 16 Dec 2019 at 13:41, maria p cruz
Hi Everyone! Wath is wrong in this code?
// Using SndBuf to play a sound file // by ChucK Programmer, December 2050 SndBuf mySound => dac; // get file path me.dir(C:\Program Files (x86)\ChucK\audio\123.wav) => string path; // sound file we want to play "/audio/123.wav" => string filename; // + sign connects strings together! path+filename => filename; // tell SndBuf to read this file filename => mySound.read; // set gain 0.5 => mySound.gain; // play sound from the beginning 0.1 => mySound.pos; // advance time so we can hear it second => now; // _______________________________________________ chuck-users mailing list chuck-users@lists.cs.princeton.edu https://lists.cs.princeton.edu/mailman/listinfo/chuck-users
Hi Maria,
me.dir() doesn't accept strings but integers (or no arguments at all) to
return the path, starting from the current folder (ie the folder where the
ChucK script/program resides).
Assuming your ChucK program is saved in a folder called:
"~/Users/Me/Documents/ChucKFiles" if you use me.dir() this will return the
path I just specified, if you use me.dir(1) it would be the parent folder
so: "~/Users/Me/Documents", me.dir(2) returns: "~/Users/Me" and so on.
Then SndBuf method 'pos' wants an integer as an argument, since the
argument represents the position (playhead starting point) expressed in
samples (hence why integers).
I would recommend to always check the errors reported on the console
monitor, even if sometimes they can be 'cryptic', most of the time will
help you debugging the issue.
Useful to report the errors you get on the console here on the mailing list
as well when asking for help :)
now you code could look something like the following:
//--------------------------------------------------------------------------------
// Using SndBuf to play a sound file
// by ChucK Programmer, December 2050
SndBuf mySound => dac;
// path + filename (assuming the 'audio' folder is in the same
// folder as the script itself)
me.dir() + "/audio/123.wav" => string filename;
// tell SndBuf to read this file
filename => mySound.read;
// set gain
0.5 => mySound.gain;
// play sound from the beginning
0 => mySound.pos;
// advance time so we can hear it
second => now;
//--------------------------------------------------------------------------------
Cheers,
Mario
On Mon, 16 Dec 2019 at 18:41, maria p cruz
Hi Everyone! Wath is wrong in this code?
// Using SndBuf to play a sound file // by ChucK Programmer, December 2050 SndBuf mySound => dac; // get file path me.dir(C:\Program Files (x86)\ChucK\audio\123.wav) => string path; // sound file we want to play "/audio/123.wav" => string filename; // + sign connects strings together! path+filename => filename; // tell SndBuf to read this file filename => mySound.read; // set gain 0.5 => mySound.gain; // play sound from the beginning 0.1 => mySound.pos; // advance time so we can hear it second => now; // _______________________________________________ chuck-users mailing list chuck-users@lists.cs.princeton.edu https://lists.cs.princeton.edu/mailman/listinfo/chuck-users
participants (3)
-
Hugh Rawlinson
-
maria p cruz
-
Mario Buoninfante