Пример #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;
}
Пример #2
0
BufferPtr Stream::GetNextBuffer(){
    // First get the next decoded buffer
    BufferPtr currentBuffer = this->GetNextDecoderBuffer();

    if(currentBuffer){
        /////////////////////////////////////////////
        // Lets check if the buffer is too small
        bool moreBuffers(true);
        while(currentBuffer->Samples()<this->preferedBufferSampleSize && moreBuffers){
            BufferPtr appendBuffer = this->GetNextDecoderBuffer();
            if(appendBuffer){
                currentBuffer->Append(appendBuffer);
                this->DeleteBuffer(appendBuffer);
            }else{
                moreBuffers = false;
            }
        }
        /////////////////////////////////////////////

        BufferPtr oldBuffer     = this->NewBuffer();

        // Now lets loop through all DSP plugins
        for(Dsps::iterator dsp=this->dsps.begin();dsp!=this->dsps.end();++dsp){
            oldBuffer->CopyFormat(currentBuffer);
            oldBuffer->position = currentBuffer->position;

            if( (*dsp)->ProcessBuffers(currentBuffer.get(),oldBuffer.get()) ){
                // Success in processing DSP, swap the buffers
                currentBuffer.swap(oldBuffer);
            }
        }

        this->DeleteBuffer(oldBuffer);

    }

    return currentBuffer;
}
Пример #3
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;

}
Пример #4
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();
}