Exemple #1
0
//////////////////////////////////////////
///\brief
///Append another buffer to this one
//////////////////////////////////////////
bool Buffer::Append(BufferPtr appendBuffer){
    if(this->SampleRate()==appendBuffer->SampleRate() && this->Channels()==appendBuffer->Channels()){
        long newBufferSize      = (this->Samples()+appendBuffer->Samples())*this->channels;

        if(newBufferSize>this->internalBufferSize){
            // Internal buffer too small. We need to make a new buffer
            // Create a new buffer
            float *newBuffer    = new float[newBufferSize];

            CopyFloat(newBuffer,this->buffer,this->sampleSize*this->channels);

            float *dst  = &newBuffer[this->sampleSize*this->channels];
            float *src  = appendBuffer->BufferPointer();
            long si     = appendBuffer->Samples()*this->channels;
            CopyFloat(dst,src,si);

            if(this->buffer){
                // Delete old buffer
                delete this->buffer;
            }
            // Set the new buffer
            this->buffer                = newBuffer;
            this->internalBufferSize    = newBufferSize;
        }else{
            // append the appendBuffer
            float *dst  = &this->buffer[this->sampleSize*this->channels];
            float *src  = appendBuffer->BufferPointer();
            long si     = appendBuffer->Samples()*this->channels;
//            CopyFloat( this->buffer + this->sampleSize*this->channels*sizeof(float),appendBuffer->BufferPointer(),appendBuffer->Samples()*this->channels);
            CopyFloat( dst,src,si);
        }

        this->sampleSize    = newBufferSize/this->channels;
        return true;

    }
    return false;
}
Exemple #2
0
BufferPtr Stream::GetNextDecoderBuffer(){
    // First get a buffer
    BufferPtr buffer = this->NewBuffer();

    // Get the buffer from the decoder
    if(!this->decoder->GetBuffer(buffer.get())){
        // Nothing to decode left, return a empty buffer
        return BufferPtr();
    }

    // We need to save the decoders samplerate to be able to calculate the current time-position
    if(!this->decoderSampleRate){
        this->decoderSampleRate = buffer->SampleRate();
    }

    // Calculate the current sample position
    this->decoderSamplePosition += buffer->Samples();

    // Save the position (seconds) in the buffer
    buffer->position    = ((double)this->decoderSamplePosition)/((double)this->decoderSampleRate);

    return buffer;

}
Exemple #3
0
//////////////////////////////////////////
///\brief
///Copies all the formats from one buffer to another
//////////////////////////////////////////
void Buffer::CopyFormat(BufferPtr fromBuffer){
    this->sampleSize    = fromBuffer->Samples();
    this->channels      = fromBuffer->Channels();
    this->sampleRate    = fromBuffer->SampleRate();
    this->ResizeBuffer();
}