On Sat, Sep 5, 2015, at 01:23 AM, robert bristow-johnson wrote: > same problem (if that *is* a problem) if you pass sampleRate alongside > the AudioSampleBuffer rather than inside of it.
I agree, that would be the worst of both worlds. (At least from this perspective -- there may be other reasons to make an API that way.) The most relevant point I think is that, because this is a class-based object oriented language, your filter function doesn't have to be just a function: it will generally be implemented as a class (with a processing function, but also a constructor) instead. And the class can be supplied the sample rate on construction. So you don't have to pass the sample rate in to the processing function at all, but by constructing different instances of the class you can still set up different versions of the function according to the sample rate in use. There is a middle ground between "a single fixed sample rate throughout the whole application" (or, worse, 44100 hardcoded) and "every process call gets the sample rate supplied to it". > now suppose the source of audio changed (like a different file or > different internal buffer is now gonna be sent out) and it's a different > sample rate attached to it. now the function sees that it's a different > input rate and the interpolation step-size must change and it's > recalculated. A function whose job is to convert between sample rates is something of a special case. > no, it's the opposite. i gotta filter method and you send me an > AudioSampleBuffer and some parameters for the filter such as type (LPF, > etc), Q, and cutoff frequency (in units of physical frequency). i > cannot do the job until i know what the sample rate is. the best thing > is if i look at the AudioSampleBuffer itself That's likely to be too late. When you get audio data, you may be already in a realtime processing context and you may not be able to do rate dependent initialisation any more. You want to know the sample rate before that, and often you aren't in a position to reinitialise on the fly if it changes. So it makes sense for a processing class to get it on construction. Chris _______________________________________________ dupswapdrop: music-dsp mailing list music-dsp@music.columbia.edu https://lists.columbia.edu/mailman/listinfo/music-dsp