final Shape clipOrig = g2.getClip();
// float[] chanBuf;
long start = info.span.start;
long totalLength = info.getTotalLength();
Span chunkSpan;
long fullLen;
// long fullStop;
int chunkLen; // decimLen;
float scaleX, ampLog;
Rectangle r;
// final float scaleX = (float) (view.getWidth() * stepSize) / totalLength;
//final float pixScale = 1072 / (view.getAmpLogMax() - view.getAmpLogMin());
//final float pixOff = -view.getAmpLogMin();
final float pixScale = 10720 / (view.getAmpLogMax() - view.getAmpLogMin());
final float pixOff = -view.getAmpLogMin() / 10;
g2.setRenderingHint( RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR );
try {
drawBusyList.clear(); // "must be called in the event thread"
synchronized( bufSync ) {
createBuffers();
long screenOffX = 0;
while( totalLength > 0 ) {
fullLen = Math.min( maxLen, totalLength );
// chunkLen = (int) (fromPCM ? fullLen : decimHelps[ info.idx ].fullrateToSubsample( fullLen ));
chunkLen = (int) (decimHelps[ info.idx ].fullrateToSubsample( fullLen ));
// decimLen = chunkLen / info.inlineDecim;
// chunkLen = decimLen * info.inlineDecim;
fullLen = (long) chunkLen << info.shift;
// chunkLen = (int) (fullLen / stepSize);
// if( fromPCM ) {
// fullStop = fullScale.getSpan().stop;
// if( start + fullLen <= fullStop ) {
// chunkSpan = new Span( start, start + fullLen );
// fullScale.readFrames( tmpBuf, 0, chunkSpan );
// } else {
// chunkSpan = new Span( start, fullStop );
// fullScale.readFrames( tmpBuf, 0, chunkSpan );
// // duplicate last frames
//// for( int i = (int) chunkSpan.getLength(), j = i - 1; i < (int) fullLen; i++ ) {
//// for( int ch = 0; ch < fullChannels; ch++ ) {
//// sPeakP = tmpBuf[ ch ];
//// sPeakP[ i ] = sPeakP[ j ];
//// }
//// }
// }
// decimator.decimatePCM( tmpBuf, tmpBuf2, fftBuf, 0, decimLen, info.inlineDecim );
// } else {
//// chunkSpan = new Span( start, start + fullLen );
// chunkSpan = new Span( start, start + fullLen );
// readFrames( info.idx, tmpBuf2, 0, drawBusyList, chunkSpan, null);
// if( info.inlineDecim > 1 ) decimator.decimate( tmpBuf2, tmpBuf2, 0, decimLen, info.inlineDecim );
// }
chunkSpan = new Span( start, start + fullLen );
//System.out.println( "chunkSpan = " + chunkSpan + "; chunkLen = " + chunkLen + "; fullLen = " + fullLen + "; screenOffX " + screenOffX + "; subLength " + info.sublength + "; shift " + info.shift + "; totalLen " + info.getTotalLength() );
if( readFrames( info.idx, tmpBuf2, 0, drawBusyList, chunkSpan, null )) {
// if( tempFAsync == null || tempFAsync[0] == null ) break;
// tempFAsync[0].seekFrame( Math.min( start / stepSize, tempFAsync[0].getFrameNum() ));
// int gaga = (int) Math.min( fullLen, Math.min( tmpBufSize2, tempFAsync[0].getFrameNum() - tempFAsync[0].getFramePosition() ));
// tempFAsync[0].readFrames( tmpBuf2, 0, gaga);
for( int ch = 0, tmpChReset = 0; ch < fullChannels; ch++, tmpChReset += modelChannels ) {
r = view.rectForChannel( ch );
scaleX = (float) r.width / info.getTotalLength();
//System.out.println( " ... for ch = " + ch + "; scaleX = " + scaleX );
for( int x = 0, off = 0; x < chunkLen; x++ ) {
for( int y = 0, off2 = x + dataStartOff, tmpCh = tmpChReset; y < modelChannels; y++, tmpCh++, off2 -= imgW, off++ ) {
// ampLog = log10.calc( tmpBuf2[ tmpCh ][ x ]) * 20;
ampLog = log10.calc( Math.max( 1.0e-9f, tmpBuf2[ tmpCh ][ x ]));
data[ off2 ] = colors[ Math.max( 0, Math.min( 1072, (int) ((ampLog + pixOff) * pixScale) ))];
}
}
raster.setDataElements( 0, 0, imgW, modelChannels, data );
g2.drawImage( bufImg, r.x + (int) (screenOffX * scaleX + 0.5f), r.y, r.x + (int) ((screenOffX + fullLen) * scaleX + 0.5f), r.y + r.height, 0, 0, chunkLen, modelChannels, view );
}
}
start += fullLen; // chunkLen * stepSize;
totalLength -= fullLen; // chunkLen * stepSize;
screenOffX += fullLen;
// if( gaga == 0 ) totalLength = 0;
}
} // synchronized( bufSync )
// System.err.println( "busyList.size() = "+busyList.size() );
for( int ch = 0; ch < fullChannels; ch++ ) {
r = view.rectForChannel( ch );
g2.clipRect( r.x, r.y, r.width, r.height );
if( !drawBusyList.isEmpty() ) {
// g2.setColor( Color.red );
g2.setPaint( pntBusy );
for( int i = 0; i < drawBusyList.size(); i++ ) {
chunkSpan = (Span) drawBusyList.get( i );
scaleX = (float) r.width / info.getTotalLength();
g2.fillRect( (int) ((chunkSpan.start - info.span.start) * scaleX) + r.x, r.y,
(int) (chunkSpan.getLength() * scaleX), r.height );
}
}
// g2.setTransform(atOrig);
g2.setClip( clipOrig );
}