Ejemplo n.º 1
0
pChunk DrawnWaveform::
        operator()( Signal::pMonoBuffer b )
{
    float blobsize = blob(b->sample_rate());

    unsigned w = ((unsigned)(b->number_of_samples() / blobsize / drawWaveform_BLOCK_SIZE)) *drawWaveform_BLOCK_SIZE;

    if (0 == w)
        throw std::logic_error("DrawnWaveform::operator() Not enough data");

    size_t free = availableMemoryForSingleAllocation();

    free /= 2; // Don't even try to get close to use all memory
    // never use more than 64 MB
    if (free > 64<<20)
        free = 64<<20;

    unsigned wmax = free/(drawWaveform_YRESOLUTION*sizeof(Tfr::ChunkElement)*drawWaveform_BLOCK_SIZE ) * drawWaveform_BLOCK_SIZE;
    if (0==wmax)
        wmax = free/(drawWaveform_YRESOLUTION*sizeof(Tfr::ChunkElement));
    if (0==wmax)
        wmax = 1;
    if (wmax < w)
        w = wmax;

    updateMaxValue(b);

    pChunk c(new DrawnWaveformChunk(this->block_fs));
    c->transform_data.reset( new ChunkData(w, drawWaveform_YRESOLUTION, 1));

    unsigned readstop = b->number_of_samples();
    if (b->getInterval().last > signal_length)
    {
        if (b->getInterval().first > signal_length)
            readstop = 0;
        else
            readstop = signal_length - b->getInterval().first;
    }

    float writeposoffs = ((b->sample_offset() / blobsize) - floorf((b->sample_offset() / blobsize).asFloat())).asFloat();
    ::drawWaveform(
            b->waveform_data(),
            c->transform_data,
            blobsize,
            readstop,
            maxValue,
            writeposoffs);

    this->block_fs = 0;

    c->chunk_offset = b->sample_offset() / blobsize + writeposoffs;
    c->freqAxis = freqAxis( b->sample_rate() );

    c->first_valid_sample = 0;
    c->n_valid_samples = c->nSamples();

    c->original_sample_rate = b->sample_rate();
    c->sample_rate = b->sample_rate() / blobsize;

    return c;
}