void DrawnWaveform::
        updateMaxValue(Signal::pMonoBuffer b)
{
    float *p = b->waveform_data()->getCpuMemory();
    float maxValue=0;
    Signal::IntervalType N = b->number_of_samples();
    for(Signal::IntervalType i=0; i<N; ++i)
        maxValue = std::max(std::abs(p[i]), maxValue);
    maxValue *= 1.1;
    this->maxValue = std::max(this->maxValue, maxValue);
}
Exemple #2
0
pChunk DummyTransform::
        operator()( Signal::pMonoBuffer b )
{
    // This is the dummy part.
    DummyChunk*p;
    pChunk c(p = new DummyChunk);
    p->original = b;

    c->chunk_offset = b->sample_offset ();
    c->first_valid_sample = 0;
    c->n_valid_samples = (int)b->number_of_samples ();
    c->original_sample_rate = b->sample_rate ();
    c->sample_rate = b->sample_rate ();
    c->transform_data.reset (new Tfr::ChunkData(b->waveform_data ()->size ()));

    return c;
}
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;
}