[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [sc-users] Newb question - creating subclass for audio signals



I don't think there's any need for a subclass or hardcoded methods. A dictionary of functions would do.

~filters = (
filter1: { |input ... args|
LPF.ar(input, *args)
},
filter2: { |input ... args|
HPF.ar(input, *args)
},
...
);

SynthDef( "Filtering", {
    var signal1, signal2;

    signal1 = PlayBuf.ar( 2, bufNum );
    signal2 = PinkNoise.ar(1.0);    

    signal1 = ~filters[\filter1].value(signal1);
    signal2 = ~filters[\filter2].value(signal2);
} );


// or, for a slightly cleaner function-call syntax:

~filters = (
// see the Environment helpfile under "prototypes" for more about 'self'
filter1: { |self, input ... args|
LPF.ar(input, *args)
},
filter2: { |self, input ... args|
HPF.ar(input, *args)
},
...
);

SynthDef( "Filtering", {
    var signal1, signal2;

    signal1 = PlayBuf.ar( 2, bufNum );
    signal2 = PinkNoise.ar(1.0);    

    signal1 = ~filters.filter1(signal1);
    signal2 = ~filters.filter2(signal2);
} );

hjh


: H. James Harkins
.::!:.:.......:.::........:..!.::.::...:..:...:.:.:.:..:

"Come said the Muse,
Sing me a song no poet has yet chanted,
Sing me the universal."  -- Whitman