Why are no AudioSampleBuffer methods inline?

wouldn’t that make sence since they are used so often and are so simple?
getNumSamples, getNumChannels, getSampleData, etc…
maybe i miss something here…thanks :slight_smile:

edit: counts for simple MidiBuffer / MidiEvent …etc. methods too!

They’re not explicitly inline, but I’d be very surprised if any modern compiler failed to inline most of those methods!

maybe i did something wrong… but i analysed the assembly and i had to make them __forceinline to get them inlined…maybe its just my compiler settings…ah…wait! microsoft can’t inline because of the default parameter!
i just changed that and it inlines! i think that reduces overhead by a third, but i’m just counting assambler instructions…there may be more to it.
may be worth a change to your code…it just broke 6 lines in the rest of the JUCE source.

http://msdn.microsoft.com/en-us/library/z8y1yy88(VS.80).aspx

thanks man!

Are you saying that it failed to inline

int getNumChannels() const throw() { return numChannels; }

!?

Not sure about changing getSampleData though, because if you’re writing anything that’s even slightly performance-dependent you’d only call that to get a pointer, and then work directly with the pointer, right?

int getNumChannels() const throw() { return numChannels; }

should work, but

getNumSamples(int chan, int off = 0)

fails in vc++ because of the default parameter.
(according to the doc i posted & my own observations)
i call it once per callback (o course) and do my stuff with array/pointer acces, but still, the funcion call overerhead is much bigger than the actual operation, a simple dereferencing! so it should be inlined :).
i made some stuff inline over here and (almost) doubled performance ! i did not change mich in your code, just the getSampleData default parameter…also the stuff i made inline where funcion calls pers sample, wich should have been inline in the first place, as ther is no big difference in code size.

It’d be easy enough to remove the default param without breaking any code:

[code] /** Returns a pointer one of the buffer’s channels.

    For speed, this doesn't check whether the channel number is out of range, 
    so be careful when using it!
*/
float* getSampleData (const int channelNumber) const throw()
{
    jassert (((unsigned int) channelNumber) < (unsigned int) numChannels);
    return channels [channelNumber];
}

/** Returns a pointer to a sample in one of the buffer's channels.

    For speed, this doesn't check whether the channel and sample number
    are out-of-range, so be careful when using it!
*/
float* getSampleData (const int channelNumber,
                      const int sampleOffset) const throw()
{
    jassert (((unsigned int) channelNumber) < (unsigned int) numChannels);
    jassert (((unsigned int) sampleOffset) < (unsigned int) size);
    return channels [channelNumber] + sampleOffset;
}

[/code]

:!: yeah, of course…i often fail to see the obvious solutions :smiley:
did not break much anyways ;).
peace & thanks man!

Soo, uhm. How does this work for gcc? Does it inline allright, even in case of default args…?

  • A