/************************************************************************************/ /* 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 = ":Sounds: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 one records a sine wave to a file called test to disk. You can control the freq of ***/ /***** the sineosc by moving the mouse ************/ /***********SinOsc.ar(freq, phase, mul, add)*************/ /********record(ugenGraphFunc, duration, pathName, headerFormat, sampleFormat)******/ MouseX.kr(minval, maxval, warp, lagTime) Creates a Plug unit generator and a MouseAxis and installs the control source in the unit generator. minval - The minimum output value. maxval - The maximum output value. warp - a Symbol, either 'linear' or 'exponential' which determines the mapping of the range. The default is 'linear'. lagTime - a 60dB decay time for exponential smoothing of the control function. The default is 0.1 seconds. Synth.record(ugenGraphFunc, duration, pathName, headerFormat, sampleFormat) Generate audio to a file and play to output hardware simultaneously. ugenGraphFunc - a function that returns a graph of unit generators. duration - The amount of time in seconds to write to the file. pathName - a String giving the path to the file to save. headerFormat - the format for the SoundFile header. See the SoundFile documentation. sampleFormat - the format of the samples. See the SoundFile documentation. ( var fileName = ":Sounds:test"; var duration = 20, freq, amp; Synth.record({ freq = MouseX.kr(50.0, 20000.0, 'exponential', 0.5); amp = 0.025; SinOsc.ar(freq, amp)}, duration, fileName, 'AIFF', '16 big endian signed'); ) /***********************************/ /************************************/ /************** to read a snd file from disk and write back to disk with new name **************/ /*************** while filtering with the mouse ************************************/ /************* This works with that ending bug ***********************************/ RLPF.ar(in, freq, rq, mul, add) A resonant low pass filter. in - input signal to be processed freq - cutoff frequency. rq - the reciprocal of Q. bandwidth / cutoffFreq. DiskIn.ar(soundFile, loopFlag, startFrame, numFrames) DiskIn streams audio from a sound file. If the sound file has been preloaded then the audio will start instantly. Otherwise it will output some silence until the first buffer read has been completed. The output of DiskIn will be an Array of as many channels as there are in the file. soundFile - the SoundFile to read. loopFlag - a Boolean value. If true, then the file is looped. The loop points are the sustain loop points in the SoundFile. If these points are equal, then the entire file is looped. If false then the file is not looped. The default value is false. startFrame - the sample frame at which to start playback if the sound file has not been preloaded. If the sound file has been preloaded, this argument is ignored. The default value is zero. numFrames - the number of frames in the double buffer if the sound file has not been preloaded. If the sound file has been preloaded, this argument is ignored. The default value is 32768. ( var fileName = ":Sounds:test"; var file; file = SoundFile.new; if ( file.readHeader(":Sounds:cash.snd") // read the file's header and: { file.preloadData; }, // preload the data { Synth.record({ var rQ; rQ = MouseY.kr(0.01, 1, 'exponential'); // bandwidth ratio = 1/Q RLPF.ar( DiskIn.ar(file, false), MouseX.kr(100, 12000, 'exponential'), // mouse x controls cutoff freq rQ, 0.25) }, 40.0, fileName, 'AIFF', '16 big endian signed'); }) ) /***********************************/ /****************************************************************************/ BPF 2nd order Butterworth bandpass filter BPF.ar(in, kfreq, krq, mul, add) A second order low pass filter. in - input signal to be processed kfreq - cutoff frequency in Hertz. krq - the reciprocal of Q. bandwidth / cutoffFreq. This one does filtering and writes to disk. ( var fileName = ":Sounds:test3"; // write out to file test3, read from file cash.snd var file; var center_freq = 5000; // tweak on this to change the filter file = SoundFile.new; if ( file.readHeader(":Sounds:cash.snd") // read the file's header and: { file.preloadData; }, // preload the data { Synth.record({ BPF.ar( DiskIn.ar(file, false), center_freq, 1.0, 2.5) //boosting 30Hz to 100 Hz }, 40.0, fileName, 'AIFF', '16 big endian signed'); }) ) /**************************************************************************/ /**************************************/ /**************************/ /********** Moving filters controlled by a sine wave, this works and **************************/ /********** it writes to disk **************************/ This one will filter white noise. ( var fileName = ":Sounds:hipassmove.aiff"; // write out to this file Synth.record({LPF.ar(WhiteNoise.ar(0.5),FSinOsc.kr(XLine.kr(0.10,0.10,10),5000,5000))}, 15.0, fileName, 'AIFF', '16 big endian signed'); ) /**************************/ /********** Moving filters controlled by a saw wave, this works and it writes /********** to disk **************************/ ( var fileName = ":Sounds:hipasssaw.aiff"; // write out to file white.aiff Synth.record({LPF.ar(WhiteNoise.ar(0.5),LFSaw.kr(XLine.kr(0.10,0.10,20),5000,5000))}, 20.0, fileName, 'AIFF', '16 big endian signed'); ) /******************************************************/ /***************To read a snd file from disk and write back to disk with delay ***/ /************* This works ********************************************** *******************/ ( // preload, no loop var fileName = ":Sounds:test"; var file; var liveSound, delayedSignal; file = SoundFile.new; if ( file.readHeader(":Sounds:cash.snd") // read the file's header and: { file.preloadData; }, // preload the data { Synth.record({liveSound = DiskIn.ar(file); delayedSignal = DelayA.ar( in: liveSound, maxdelaytime: 1.0, delaytime: 0.5, mul: 0.8, add:liveSound) }, 30.0, fileName, 'AIFF', '16 big endian signed'); })) /**************************************************************************/ // fooling around with playback rate, using an orchestra to trigger a sample, rand amps and playback rates. // lp // PlayBuf.at(signal, sigSampleRate, playbackRate, offset, loopstart, loopend,mul,add) ( 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 Synth.play({ signal = sound.data.at(0); // points at header of wave OrcScore.ar( [{ arg spawn, i, synth, deltaTime, instrumentNum, amp, playbackRate; PlayBuf.ar(signal, sound.sampleRate, playbackRate + (playbackRate.rand2/5), signal.size-2, 0, signal.size-2, amp.rand ); }], // this is the score below #[ // deltaTime, instrumentNum, amp, playbackRate [3.0, 0, 0.3, 1.0] ], 1, nil, 40) }), { (filename ++ " not found.\n").post }); ) /***** This one has a more complex score and gets rid of the randomizer in the Playback rate **/ ( 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 Synth.play({ signal = sound.data.at(0); // points at header of wave OrcScore.ar( [{ arg spawn, i, synth, deltaTime, instrumentNum, amp, playbackRate; PlayBuf.ar(signal, sound.sampleRate, playbackRate, signal.size-2, 0, signal.size-2, amp.rand ); }], // this is the score below #[ // deltaTime, instrumentNum, amp, playbackRate [3.0, 0, 0.3, 1.0], [3.0, 0, 0.3, 0.5] ], 1, nil, 40) }), { (filename ++ " not found.\n").post }); ) /*** Take a look at the OrcScore help page ************/ /**************************/ /**************************************************************************/ // fooling around with playback rate, using an orchestra to trigger a sample, rand amps and playback rates. // This one writes to disk. // PlayBuf.at(signal, sigSampleRate, playbackRate, offset, loopstart, loopend,mul,add) ( var filename, sound, signal; var writeFile = ":Sounds:testfile"; // write to this file filename = ":Sounds:floating_1"; // specify read filename sound = SoundFile.new; // Creates a new SoundFile instance. if (sound.read(filename), // Check if file exists Synth.record({ signal = sound.data.at(0); // points at header of wave OrcScore.ar( [{ arg spawn, i, synth, deltaTime, instrumentNum, amp, playbackRate; PlayBuf.ar(signal, sound.sampleRate, playbackRate + (playbackRate.rand2/5), signal.size-2, 0, signal.size-2, amp.rand ); }], // this is the score below #[ // deltaTime, instrumentNum, ... [3.0, 0, 0.3, 1.0] ], 1, nil, 40) },30.0, writeFile, 'AIFF', '16 big endian signed'), { (filename ++ " not found.\n").post }); ) /*************************************/ /********** Moving filters controlled by a sine wave, filters an input file, this works *******************/ ( var fileName = ":Sounds:test3"; // write out to file test3, read from file cash.snd var file; file = SoundFile.new; if ( file.readHeader(":Sounds:cash.snd") // read the file's header and: { file.preloadData; }, // preload the data Synth.record({LPF.ar(DiskIn.ar(file, false),FSinOsc.kr(XLine.kr(0.10,0.5,5),5000,5000))}, 15.0, fileName, 'AIFF', '16 big endian signed'); )) /***************************/