Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

FFTDisplay.qml 2.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. // tonalisa - software to look at overtone-structures
  2. // Copyright (C) 2016 Dominik Schmidt-Philipp
  3. //
  4. // This program is free software: you can redistribute it and/or modify
  5. // it under the terms of the GNU General Public License as published by
  6. // the Free Software Foundation, either version 3 of the License, or
  7. // (at your option) any later version.
  8. //
  9. // This program is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. // GNU General Public License for more details.
  13. //
  14. // You should have received a copy of the GNU General Public License
  15. // along with this program. If not, see <http://www.gnu.org/licenses/>.
  16. //
  17. import QtQuick 2.0
  18. Item {
  19. id:root
  20. width:512; height:300
  21. property string file: activeAudioFile.path
  22. property real sampleRate: activeAudioFile.sampleRate
  23. property int fftSize: activeAudioFile.npts
  24. property var fftData: activeAudioFile.spectrum
  25. property var grid: [[100,300,500,1000,2000,5000,10000]]
  26. property var pixelData: []
  27. property real leftHz: 0
  28. property real rightHz: 10000
  29. property real max:0
  30. property real min:0
  31. function binToHertz(bin) {
  32. return bin * sampleRate / fftSize
  33. }
  34. function hertzToBin(hertz) {
  35. return Math.floor(hertz * fftSize / sampleRate)
  36. }
  37. function binToX(bin) {
  38. return width * (binToHertz(bin)-leftHz)/(rightHz-leftHz)
  39. }
  40. onFftDataChanged: {
  41. display.requestPaint()
  42. }
  43. onLeftHzChanged: {
  44. display.requestPaint()
  45. }
  46. onRightHzChanged: {
  47. display.requestPaint()
  48. }
  49. Canvas {
  50. id: display
  51. anchors.fill: parent
  52. function scale(val){
  53. return -Math.log(val/sampleRate) * 8
  54. }
  55. onPaint: {
  56. var ctx = getContext("2d")
  57. ctx.fillStyle = Qt.rgba(255,255,255,1);
  58. ctx.fillRect(0,0,width,height);
  59. ctx.beginPath()
  60. var i = hertzToBin(leftHz)
  61. ctx.moveTo(binToX(i),scale(fftData[i]))
  62. while ( i<hertzToBin( rightHz )) {
  63. i++
  64. ctx.lineTo(binToX(i),scale(fftData[i]))
  65. }
  66. ctx.strokeStyle = "#000000";
  67. ctx.stroke()
  68. }
  69. MouseArea {
  70. anchors.fill: parent
  71. onPressed: {
  72. fftvalue.text = "val= " + fftData[mouse.x];
  73. }
  74. }
  75. }
  76. }