Hi to all,
I'm trying to write an audio editor with waveform visualizer.
The number of audio samples I have to draw is ~10E6 or more. This is the code where I draw them:
Qt Code:
  1. void WaveWidget::updateWave()
  2. {
  3. int h = height();
  4. int w = width();
  5. // I need width and height here.
  6. // Also, I clear the cache at resize events
  7. QPixmap temp = QPixmap( w, h );
  8.  
  9. QPainter p( &temp );
  10. p.setRenderHint( QPainter::Antialiasing );
  11. p.fillRect( temp.rect(), Qt::white );
  12.  
  13. QPen pen( Qt::blue, 1 ); // blue solid line, 1 pixels wide
  14. p.setPen( pen );
  15. short* audio = reinterpret_cast<short*>(soundStream);
  16. for( unsigned int i = 0; i < numSamples; i++ )// numSamples very big (~10e6 or more)
  17. {
  18. int startY = maxHeight;
  19. for( int k = 0; k < channels; k++ )
  20. {
  21. short* value1 = audio + k;
  22. int x = i / ( numSamples / w);
  23. int y = *value1 * maxHeight / 0x0000FFFF * 2;
  24. QLine line( x, startY, x, startY + y );
  25. p.drawLine(line);
  26. startY += increment;
  27. }
  28. audio += sampleSize;
  29. }
  30. m_waveCachePixmap = temp;
  31. }
To copy to clipboard, switch view to plain text mode 

and the paintEvent
Qt Code:
  1. void WaveWidget::paintEvent( QPaintEvent* pe )
  2. {
  3. // call updateWave only if necesary, if not I draw what is in cache
  4. if( m_waveCachePixmap.isNull() )
  5. {
  6. updateWave();
  7. }
  8.  
  9. QPainter p( this );
  10. p.setRenderHint( QPainter::Antialiasing );
  11. p.drawPixmap( 0, 0, m_waveCachePixmap );
  12. }
To copy to clipboard, switch view to plain text mode 

where waveWidget inherits from QWidget.
The problem is that the draw process is very slow as I have to draw more that 10 millions of lines. Is not a fast way do draw something? For example the same audio file in audacity is displayed very fast.

Best Regards