Problems "playing" AudioSampleBuffer


Hi everybody… I’m Marcello and I want you to forgive me for my english
So, here is the problem:
I want to play audio from an AudioSampleBuffer, so I decided to write a MyAudioSource that inherits from PositionableAudioSource.
this is the code:

int MyAudioSource::getTotalLength() const
    return (int) reader->getNumSamples();

void MyAudioSource::getNextAudioBlock (const AudioSourceChannelInfo& info)
  long lung=info.numSamples;
        if ((start+info.numSamples)>reader->getNumSamples())
        for (int i=0; i<reader->getNumChannels(); i++)
        nextPlayPos += info.numSamples;


(reader is the audiosamplebuffer)

Yes, it play, but it always crash at the end of the playback.
If i try int MyAudioSource::getTotalLength() const { return (int) reader->getNumSamples()-40000; //just to test }
it play a few samples of the buffer, but with no problems.

What I miss or where i’m wrong???
And… there’s a finest way to play audio from an AudioBufferSource?


You’re got the right kind of idea, but your code’s just not correctly checking whether it’s reading beyond the end of the buffer. Remember it must be able to read from any position, even far beyond the start or end of the buffer.


thanks for the quick reply jules…
i wrote:

void MyAudioSource::getNextAudioBlock (const AudioSourceChannelInfo& info)
    if (info.numSamples > 0)
        const int start = nextPlayPos;
        if (start + info.numSamples <= reader->getNumSamples())
            for (int i=0; i<reader->getNumChannels(); i++)
            nextPlayPos += info.numSamples;

Now, it worked the first time (i heard just the sound cutted at the end), but it no more works.
So… what kind of controls am i suppost to do?
I don’t want you to code for me but an issue is appreciate…


There are a bunch of assertions in AudioSampleBuffer to warn you when you try to copy a dodgy area. Aren’t you running it in debug mode?


Problem solved.
It was a stupid error, dependent on the fact that the buffer didn’t exists anymore… (i hate pointers)
Thanks jules


whuuuat ? could start a flame war here :slight_smile:


Wait… I mean:
I always wrote java code… and it happens constantly to me that i forget one or two of them so…
I don’t want war… PEACE


just joking… :slight_smile: peace to you too !