/************************************************************************************/
/* this is an example used for file reading/opening and writing to a different file                                           */
/* filename = ":DIRECTORY:SOUDNFILE_NAME";                                                                                   */
/*                                                                                                                                                                     */
/*************************************************************************************/
read and plot a sound file
the sample rate of the output file is the same as the input file

(

var rFilename, sound;
var wFilename, headerName;

rFilename = ":Sounds:floating_1";    // specify read filename
wFilename = "floating_3";    // specify write filename

 sound = SoundFile.new;      // Ceates a new SoundFile instance.

 if (sound.read(rFilename),     // Check if file exists
 {
  sound.plot;      // output to plot
  sound.write(wFilename);    // writes to wFilename
 },
  {(rFilename ++ " not found.\n").post });   // prompt error if rFilename not found
)
 

/************************************************************************************/
/* this is an example used for file reading/opening and playing the read file                                                  */
/* filename = ":DIRECTORY:SOUDNFILE_NAME";                                                                                  */
/*                                                                                                                                                                     */
/*************************************************************************************/
PlayBuf.at(signal, sigSampleRate, playbackRate, offset, loopstart, loopend,mul,add)
signal - a Signal buffer
sigSampleRate - the sample rate of the signal
playbackRate - 1.0 is normal, 2.0 is one octave up, 0.5 is one octave down
offset - sample offset. This can either be a static starting offset, or a modulateable offset.
loopstart - sample number of beginning of loop
loopend - sample number of end of loop

(
var filename, sound, signal;

filename = ":Sounds:floating_1";     // specify read filename
sound = SoundFile.new;      // Creates a new SoundFile instance.

 if (sound.read(filename),      // Check if file exists
 {
  signal = sound.data.at(0);    // points at header of wave
  // Synth.play( { PlayBuf.ar(signal, sound.sampleRate, 1, 0, 0, signal.size-2) } ); // size-2: header, sample format info
   // size-2: header, sample format info
   // the above will work, with all the parameters specified, but...
   Synth.play( { PlayBuf.ar(signal) } ); // this is a simple way to do it, have it use defaults

 },
  { (filename ++  " not found.\n").post });

)

/************************************************************************************/
/* this is an example used for altering the soundfile                                                                                       */
/* we'll run it through a delay                                                                                                                         */
/*                                                                                                                                                                    */
/************************************************************************************/
(
var filename, sound, signal, delayedSignal, z, delayTime;

filename = ":Sounds:floating_1";     // specify read filename
sound = SoundFile.new;      // Creates a new SoundFile instance.

 if (sound.read(filename),      // Check if file exists
 {
  signal = sound.data.at(0) ;    // points at header of wave
  // DelayA.ar(in, maxdelaytime, delaytime, mul, add)
  // first, describe a simple delay for the signal, which itself is a predefined block
  // note that PlayBuf.ar(signal) is the input signal, and we're delaying that
  // and mixing it back in with itself, via the add parameter of Delay
  // XLine.ar(start, end, dur, mul, add), using xline, we'll change the delay
  // time over time
  delayedSignal = { DelayA.ar(PlayBuf.ar(signal), 2, XLine.ar(0.005, 2.0, 15) ,1, PlayBuf.ar(signal))  } ;
  Synth.play(delayedSignal) ;

 },
  { (filename ++  " not found.\n").post });
)