mirror of
https://github.com/miek/inspectrum.git
synced 2026-03-06 08:24:29 +01:00
Index tiles by sample id and fft size
This commit is contained in:
@@ -69,11 +69,11 @@ void Spectrogram::paintEvent(QPaintEvent *event)
|
||||
|
||||
for (int y = 0; y < height; y++) {
|
||||
if (tileLine >= linesPerTile()) {
|
||||
int tileId = (rect.y() + y) / linesPerTile();
|
||||
off_t tileId = lineToSample(rect.y() + y);
|
||||
tile = getTile(tileId);
|
||||
|
||||
// Handle case where we want to draw from part-way through the first tile
|
||||
tileLine = (rect.y() + y) - (tileId * linesPerTile());
|
||||
tileLine = (rect.y() + y) - sampleToLine(tileId);
|
||||
}
|
||||
|
||||
float *line = &tile[tileLine * fftSize];
|
||||
@@ -98,19 +98,19 @@ void Spectrogram::paintEvent(QPaintEvent *event)
|
||||
|
||||
float* Spectrogram::getTile(off_t tile)
|
||||
{
|
||||
auto iter = fftCache.find(qMakePair(zoomLevel, tile));
|
||||
auto iter = fftCache.find(qMakePair(fftSize, tile));
|
||||
if (iter != fftCache.end())
|
||||
return iter.value();
|
||||
|
||||
float *dest = new float[tileSize];
|
||||
float *ptr = dest;
|
||||
off_t sample = tile * linesPerTile() * getStride();
|
||||
off_t sample = tile;
|
||||
while ((ptr - dest) < tileSize) {
|
||||
getLine(ptr, sample);
|
||||
sample += getStride();
|
||||
ptr += fftSize;
|
||||
}
|
||||
fftCache.insert(qMakePair(zoomLevel, tile), dest);
|
||||
fftCache.insert(qMakePair(fftSize, tile), dest);
|
||||
return dest;
|
||||
}
|
||||
|
||||
@@ -211,6 +211,10 @@ off_t Spectrogram::lineToSample(int line) {
|
||||
return line * getStride();
|
||||
}
|
||||
|
||||
int Spectrogram::sampleToLine(off_t sample) {
|
||||
return sample / getStride();
|
||||
}
|
||||
|
||||
QString Spectrogram::sampleToTime(off_t sample)
|
||||
{
|
||||
return QString::number((float)sample / sampleRate).append("s");
|
||||
|
||||
Reference in New Issue
Block a user