├── .gitattributes ├── .gitignore ├── LICENSE ├── README.md ├── Screenshot1.png ├── Screenshot2.png ├── SuperSpectrogram.cpp ├── SuperSpectrogram.h ├── SuperSpectrogram.pro ├── colormap.h ├── fftw3.h ├── libfftw3f-3.lib ├── libfftw3f.a ├── main.cpp ├── mainwindow.cpp ├── mainwindow.h ├── palette.cpp ├── palette.h ├── spectrumanalyser.cpp └── spectrumanalyser.h /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | 4 | # Custom for Visual Studio 5 | *.cs diff=csharp 6 | 7 | # Standard to msysgit 8 | *.doc diff=astextplain 9 | *.DOC diff=astextplain 10 | *.docx diff=astextplain 11 | *.DOCX diff=astextplain 12 | *.dot diff=astextplain 13 | *.DOT diff=astextplain 14 | *.pdf diff=astextplain 15 | *.PDF diff=astextplain 16 | *.rtf diff=astextplain 17 | *.RTF diff=astextplain 18 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Windows image file caches 2 | Thumbs.db 3 | ehthumbs.db 4 | 5 | # Folder config file 6 | Desktop.ini 7 | 8 | # Recycle Bin used on file shares 9 | $RECYCLE.BIN/ 10 | 11 | # Windows Installer files 12 | *.cab 13 | *.msi 14 | *.msm 15 | *.msp 16 | 17 | # Windows shortcuts 18 | *.lnk 19 | 20 | # ========================= 21 | # Operating System Files 22 | # ========================= 23 | 24 | # OSX 25 | # ========================= 26 | 27 | .DS_Store 28 | .AppleDouble 29 | .LSOverride 30 | 31 | # Thumbnails 32 | ._* 33 | 34 | # Files that might appear in the root of a volume 35 | .DocumentRevisions-V100 36 | .fseventsd 37 | .Spotlight-V100 38 | .TemporaryItems 39 | .Trashes 40 | .VolumeIcon.icns 41 | 42 | # Directories potentially created on remote AFP share 43 | .AppleDB 44 | .AppleDesktop 45 | Network Trash Folder 46 | Temporary Items 47 | .apdisk 48 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 2, June 1991 3 | 4 | Copyright (C) 1989, 1991 Free Software Foundation, Inc., 5 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 6 | Everyone is permitted to copy and distribute verbatim copies 7 | of this license document, but changing it is not allowed. 8 | 9 | Preamble 10 | 11 | The licenses for most software are designed to take away your 12 | freedom to share and change it. By contrast, the GNU General Public 13 | License is intended to guarantee your freedom to share and change free 14 | software--to make sure the software is free for all its users. This 15 | General Public License applies to most of the Free Software 16 | Foundation's software and to any other program whose authors commit to 17 | using it. (Some other Free Software Foundation software is covered by 18 | the GNU Lesser General Public License instead.) You can apply it to 19 | your programs, too. 20 | 21 | When we speak of free software, we are referring to freedom, not 22 | price. Our General Public Licenses are designed to make sure that you 23 | have the freedom to distribute copies of free software (and charge for 24 | this service if you wish), that you receive source code or can get it 25 | if you want it, that you can change the software or use pieces of it 26 | in new free programs; and that you know you can do these things. 27 | 28 | To protect your rights, we need to make restrictions that forbid 29 | anyone to deny you these rights or to ask you to surrender the rights. 30 | These restrictions translate to certain responsibilities for you if you 31 | distribute copies of the software, or if you modify it. 32 | 33 | For example, if you distribute copies of such a program, whether 34 | gratis or for a fee, you must give the recipients all the rights that 35 | you have. You must make sure that they, too, receive or can get the 36 | source code. And you must show them these terms so they know their 37 | rights. 38 | 39 | We protect your rights with two steps: (1) copyright the software, and 40 | (2) offer you this license which gives you legal permission to copy, 41 | distribute and/or modify the software. 42 | 43 | Also, for each author's protection and ours, we want to make certain 44 | that everyone understands that there is no warranty for this free 45 | software. If the software is modified by someone else and passed on, we 46 | want its recipients to know that what they have is not the original, so 47 | that any problems introduced by others will not reflect on the original 48 | authors' reputations. 49 | 50 | Finally, any free program is threatened constantly by software 51 | patents. We wish to avoid the danger that redistributors of a free 52 | program will individually obtain patent licenses, in effect making the 53 | program proprietary. To prevent this, we have made it clear that any 54 | patent must be licensed for everyone's free use or not licensed at all. 55 | 56 | The precise terms and conditions for copying, distribution and 57 | modification follow. 58 | 59 | GNU GENERAL PUBLIC LICENSE 60 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 61 | 62 | 0. This License applies to any program or other work which contains 63 | a notice placed by the copyright holder saying it may be distributed 64 | under the terms of this General Public License. The "Program", below, 65 | refers to any such program or work, and a "work based on the Program" 66 | means either the Program or any derivative work under copyright law: 67 | that is to say, a work containing the Program or a portion of it, 68 | either verbatim or with modifications and/or translated into another 69 | language. (Hereinafter, translation is included without limitation in 70 | the term "modification".) Each licensee is addressed as "you". 71 | 72 | Activities other than copying, distribution and modification are not 73 | covered by this License; they are outside its scope. The act of 74 | running the Program is not restricted, and the output from the Program 75 | is covered only if its contents constitute a work based on the 76 | Program (independent of having been made by running the Program). 77 | Whether that is true depends on what the Program does. 78 | 79 | 1. You may copy and distribute verbatim copies of the Program's 80 | source code as you receive it, in any medium, provided that you 81 | conspicuously and appropriately publish on each copy an appropriate 82 | copyright notice and disclaimer of warranty; keep intact all the 83 | notices that refer to this License and to the absence of any warranty; 84 | and give any other recipients of the Program a copy of this License 85 | along with the Program. 86 | 87 | You may charge a fee for the physical act of transferring a copy, and 88 | you may at your option offer warranty protection in exchange for a fee. 89 | 90 | 2. You may modify your copy or copies of the Program or any portion 91 | of it, thus forming a work based on the Program, and copy and 92 | distribute such modifications or work under the terms of Section 1 93 | above, provided that you also meet all of these conditions: 94 | 95 | a) You must cause the modified files to carry prominent notices 96 | stating that you changed the files and the date of any change. 97 | 98 | b) You must cause any work that you distribute or publish, that in 99 | whole or in part contains or is derived from the Program or any 100 | part thereof, to be licensed as a whole at no charge to all third 101 | parties under the terms of this License. 102 | 103 | c) If the modified program normally reads commands interactively 104 | when run, you must cause it, when started running for such 105 | interactive use in the most ordinary way, to print or display an 106 | announcement including an appropriate copyright notice and a 107 | notice that there is no warranty (or else, saying that you provide 108 | a warranty) and that users may redistribute the program under 109 | these conditions, and telling the user how to view a copy of this 110 | License. (Exception: if the Program itself is interactive but 111 | does not normally print such an announcement, your work based on 112 | the Program is not required to print an announcement.) 113 | 114 | These requirements apply to the modified work as a whole. If 115 | identifiable sections of that work are not derived from the Program, 116 | and can be reasonably considered independent and separate works in 117 | themselves, then this License, and its terms, do not apply to those 118 | sections when you distribute them as separate works. But when you 119 | distribute the same sections as part of a whole which is a work based 120 | on the Program, the distribution of the whole must be on the terms of 121 | this License, whose permissions for other licensees extend to the 122 | entire whole, and thus to each and every part regardless of who wrote it. 123 | 124 | Thus, it is not the intent of this section to claim rights or contest 125 | your rights to work written entirely by you; rather, the intent is to 126 | exercise the right to control the distribution of derivative or 127 | collective works based on the Program. 128 | 129 | In addition, mere aggregation of another work not based on the Program 130 | with the Program (or with a work based on the Program) on a volume of 131 | a storage or distribution medium does not bring the other work under 132 | the scope of this License. 133 | 134 | 3. You may copy and distribute the Program (or a work based on it, 135 | under Section 2) in object code or executable form under the terms of 136 | Sections 1 and 2 above provided that you also do one of the following: 137 | 138 | a) Accompany it with the complete corresponding machine-readable 139 | source code, which must be distributed under the terms of Sections 140 | 1 and 2 above on a medium customarily used for software interchange; or, 141 | 142 | b) Accompany it with a written offer, valid for at least three 143 | years, to give any third party, for a charge no more than your 144 | cost of physically performing source distribution, a complete 145 | machine-readable copy of the corresponding source code, to be 146 | distributed under the terms of Sections 1 and 2 above on a medium 147 | customarily used for software interchange; or, 148 | 149 | c) Accompany it with the information you received as to the offer 150 | to distribute corresponding source code. (This alternative is 151 | allowed only for noncommercial distribution and only if you 152 | received the program in object code or executable form with such 153 | an offer, in accord with Subsection b above.) 154 | 155 | The source code for a work means the preferred form of the work for 156 | making modifications to it. For an executable work, complete source 157 | code means all the source code for all modules it contains, plus any 158 | associated interface definition files, plus the scripts used to 159 | control compilation and installation of the executable. However, as a 160 | special exception, the source code distributed need not include 161 | anything that is normally distributed (in either source or binary 162 | form) with the major components (compiler, kernel, and so on) of the 163 | operating system on which the executable runs, unless that component 164 | itself accompanies the executable. 165 | 166 | If distribution of executable or object code is made by offering 167 | access to copy from a designated place, then offering equivalent 168 | access to copy the source code from the same place counts as 169 | distribution of the source code, even though third parties are not 170 | compelled to copy the source along with the object code. 171 | 172 | 4. You may not copy, modify, sublicense, or distribute the Program 173 | except as expressly provided under this License. Any attempt 174 | otherwise to copy, modify, sublicense or distribute the Program is 175 | void, and will automatically terminate your rights under this License. 176 | However, parties who have received copies, or rights, from you under 177 | this License will not have their licenses terminated so long as such 178 | parties remain in full compliance. 179 | 180 | 5. You are not required to accept this License, since you have not 181 | signed it. However, nothing else grants you permission to modify or 182 | distribute the Program or its derivative works. These actions are 183 | prohibited by law if you do not accept this License. Therefore, by 184 | modifying or distributing the Program (or any work based on the 185 | Program), you indicate your acceptance of this License to do so, and 186 | all its terms and conditions for copying, distributing or modifying 187 | the Program or works based on it. 188 | 189 | 6. Each time you redistribute the Program (or any work based on the 190 | Program), the recipient automatically receives a license from the 191 | original licensor to copy, distribute or modify the Program subject to 192 | these terms and conditions. You may not impose any further 193 | restrictions on the recipients' exercise of the rights granted herein. 194 | You are not responsible for enforcing compliance by third parties to 195 | this License. 196 | 197 | 7. If, as a consequence of a court judgment or allegation of patent 198 | infringement or for any other reason (not limited to patent issues), 199 | conditions are imposed on you (whether by court order, agreement or 200 | otherwise) that contradict the conditions of this License, they do not 201 | excuse you from the conditions of this License. If you cannot 202 | distribute so as to satisfy simultaneously your obligations under this 203 | License and any other pertinent obligations, then as a consequence you 204 | may not distribute the Program at all. For example, if a patent 205 | license would not permit royalty-free redistribution of the Program by 206 | all those who receive copies directly or indirectly through you, then 207 | the only way you could satisfy both it and this License would be to 208 | refrain entirely from distribution of the Program. 209 | 210 | If any portion of this section is held invalid or unenforceable under 211 | any particular circumstance, the balance of the section is intended to 212 | apply and the section as a whole is intended to apply in other 213 | circumstances. 214 | 215 | It is not the purpose of this section to induce you to infringe any 216 | patents or other property right claims or to contest validity of any 217 | such claims; this section has the sole purpose of protecting the 218 | integrity of the free software distribution system, which is 219 | implemented by public license practices. Many people have made 220 | generous contributions to the wide range of software distributed 221 | through that system in reliance on consistent application of that 222 | system; it is up to the author/donor to decide if he or she is willing 223 | to distribute software through any other system and a licensee cannot 224 | impose that choice. 225 | 226 | This section is intended to make thoroughly clear what is believed to 227 | be a consequence of the rest of this License. 228 | 229 | 8. If the distribution and/or use of the Program is restricted in 230 | certain countries either by patents or by copyrighted interfaces, the 231 | original copyright holder who places the Program under this License 232 | may add an explicit geographical distribution limitation excluding 233 | those countries, so that distribution is permitted only in or among 234 | countries not thus excluded. In such case, this License incorporates 235 | the limitation as if written in the body of this License. 236 | 237 | 9. The Free Software Foundation may publish revised and/or new versions 238 | of the General Public License from time to time. Such new versions will 239 | be similar in spirit to the present version, but may differ in detail to 240 | address new problems or concerns. 241 | 242 | Each version is given a distinguishing version number. If the Program 243 | specifies a version number of this License which applies to it and "any 244 | later version", you have the option of following the terms and conditions 245 | either of that version or of any later version published by the Free 246 | Software Foundation. If the Program does not specify a version number of 247 | this License, you may choose any version ever published by the Free Software 248 | Foundation. 249 | 250 | 10. If you wish to incorporate parts of the Program into other free 251 | programs whose distribution conditions are different, write to the author 252 | to ask for permission. For software which is copyrighted by the Free 253 | Software Foundation, write to the Free Software Foundation; we sometimes 254 | make exceptions for this. Our decision will be guided by the two goals 255 | of preserving the free status of all derivatives of our free software and 256 | of promoting the sharing and reuse of software generally. 257 | 258 | NO WARRANTY 259 | 260 | 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY 261 | FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN 262 | OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES 263 | PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED 264 | OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 265 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS 266 | TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE 267 | PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, 268 | REPAIR OR CORRECTION. 269 | 270 | 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 271 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR 272 | REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, 273 | INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING 274 | OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED 275 | TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY 276 | YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER 277 | PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE 278 | POSSIBILITY OF SUCH DAMAGES. 279 | 280 | END OF TERMS AND CONDITIONS 281 | 282 | How to Apply These Terms to Your New Programs 283 | 284 | If you develop a new program, and you want it to be of the greatest 285 | possible use to the public, the best way to achieve this is to make it 286 | free software which everyone can redistribute and change under these terms. 287 | 288 | To do so, attach the following notices to the program. It is safest 289 | to attach them to the start of each source file to most effectively 290 | convey the exclusion of warranty; and each file should have at least 291 | the "copyright" line and a pointer to where the full notice is found. 292 | 293 | 294 | Copyright (C) 295 | 296 | This program is free software; you can redistribute it and/or modify 297 | it under the terms of the GNU General Public License as published by 298 | the Free Software Foundation; either version 2 of the License, or 299 | (at your option) any later version. 300 | 301 | This program is distributed in the hope that it will be useful, 302 | but WITHOUT ANY WARRANTY; without even the implied warranty of 303 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 304 | GNU General Public License for more details. 305 | 306 | You should have received a copy of the GNU General Public License along 307 | with this program; if not, write to the Free Software Foundation, Inc., 308 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 309 | 310 | Also add information on how to contact you by electronic and paper mail. 311 | 312 | If the program is interactive, make it output a short notice like this 313 | when it starts in an interactive mode: 314 | 315 | Gnomovision version 69, Copyright (C) year name of author 316 | Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 317 | This is free software, and you are welcome to redistribute it 318 | under certain conditions; type `show c' for details. 319 | 320 | The hypothetical commands `show w' and `show c' should show the appropriate 321 | parts of the General Public License. Of course, the commands you use may 322 | be called something other than `show w' and `show c'; they could even be 323 | mouse-clicks or menu items--whatever suits your program. 324 | 325 | You should also get your employer (if you work as a programmer) or your 326 | school, if any, to sign a "copyright disclaimer" for the program, if 327 | necessary. Here is a sample; alter the names: 328 | 329 | Yoyodyne, Inc., hereby disclaims all copyright interest in the program 330 | `Gnomovision' (which makes passes at compilers) written by James Hacker. 331 | 332 | , 1 April 1989 333 | Ty Coon, President of Vice 334 | 335 | This General Public License does not permit incorporating your program into 336 | proprietary programs. If your program is a subroutine library, you may 337 | consider it more useful to permit linking proprietary applications with the 338 | library. If this is what you want to do, use the GNU Lesser General 339 | Public License instead of this License. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # SuperSpectrogram 2 | Super spectrogram powered by Qt cross platform! 3 | 4 | # Frequency plotting style 5 | 1. Log(Default) 6 | 2. Linear 7 | 8 | You might want to switch between this two kind of plot by clicking(Or tap screen on Android) the application screen area. 9 | 10 | # Colormap and colormap license 11 | 9 colormap built-in, double click(Or double tap screen on Android) the application screen area to switch 9 colormap display. 12 | 13 | Colormap itself is converted from csv to c header file. And do not restricted by GPL v2. 14 | 15 | They are downloaded from http://www.kennethmoreland.com/color-advice/ generated by __**Kenneth Moreland**__ 16 | 17 | # Screenshots 18 | ![Screenshot1](https://rawgit.com/james34602/SuperSpectrogram/master/Screenshot1.png "Vibrato!") 19 | ![Screenshot2](https://rawgit.com/james34602/SuperSpectrogram/master/Screenshot2.png "Vibrato!") 20 | 21 | # Android user 22 | You need a powerful device to run this app, because the computation may not be ARM-friendly. 23 | 24 | # Non-Windows user 25 | Default buffer size for 44.1kHz or 48kHz sampling rate should be approximately divided by 10, should be enough for displaying low frequency, but don't expect you can distinguish frequency within 10Hz. 26 | 27 | # More... 28 | Remove # in .pro file for enabling title bar text peak display. -------------------------------------------------------------------------------- /Screenshot1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/james34602/SuperSpectrogram/4a81fcd176d821b3043ae166ca3d675a0cfb0ce7/Screenshot1.png -------------------------------------------------------------------------------- /Screenshot2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/james34602/SuperSpectrogram/4a81fcd176d821b3043ae166ca3d675a0cfb0ce7/Screenshot2.png -------------------------------------------------------------------------------- /SuperSpectrogram.cpp: -------------------------------------------------------------------------------- 1 | #include "SuperSpectrogram.h" 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include "colormap.h" 7 | Spectrogram::Spectrogram(SpectrumAnalyser *analyser, QWidget *parent) : 8 | paletteCount(0), QWidget(parent), m_analyser(analyser) 9 | { 10 | connect(m_analyser, SIGNAL(spectrumReady()), SLOT(moreSpectrumLog())); 11 | isLog = true; 12 | m_min = std::numeric_limits::max(); 13 | m_max = std::numeric_limits::min(); 14 | ColormapChange(paletteCount); 15 | } 16 | void Spectrogram::moreSpectrumLinear() 17 | { 18 | int w = width(); 19 | int h = m_analyser->spectrum().size(); 20 | QSize size(h, w); // rotate 90 degrees 21 | if (size == m_image.size()) { 22 | std::copy(m_image.bits() + m_image.bytesPerLine(), m_image.bits() + m_image.byteCount(), m_image.bits()); 23 | /* void* dest = m_image.bits(); 24 | for (int x = 1; x < w; ++x) { 25 | void* source = m_image.bits() + x * m_image.bytesPerLine(); 26 | memcpy(dest, source, m_image.bytesPerLine()); 27 | dest = source; 28 | }*/ 29 | } else { 30 | m_image = QImage(size, QImage::Format_RGB32); 31 | } 32 | for (int y = 0; y < h; ++y) { 33 | m_image.setPixel(h-y-1, w-1, gradiantAt(m_analyser->spectrum()[y])); 34 | } 35 | update(); 36 | } 37 | 38 | void Spectrogram::moreSpectrumLog() 39 | { 40 | int w = width(); 41 | int h = m_analyser->spectrum().size(); 42 | float yscale = log(h) / h; 43 | QSize size(h, w); // rotate 90 degrees 44 | if (size == m_image.size()) { 45 | std::copy(m_image.bits() + m_image.bytesPerLine(), m_image.bits() + m_image.byteCount(), m_image.bits()); 46 | /* void* dest = m_image.bits(); 47 | for (int x = 1; x < w; ++x) { 48 | void* source = m_image.bits() + x * m_image.bytesPerLine(); 49 | memcpy(dest, source, m_image.bytesPerLine()); 50 | dest = source; 51 | }*/ 52 | } else { 53 | m_image = QImage(size, QImage::Format_RGB32); 54 | } 55 | for (int y = 0; y < h; ++y) { 56 | float amp; 57 | int index = pow(2.7182818284590452354, y*yscale); 58 | amp = m_analyser->spectrum()[index]; 59 | m_image.setPixel(h-y-1, w-1, gradiantAt(amp)); 60 | } 61 | update(); 62 | } 63 | void Spectrogram::paintEvent(QPaintEvent *) 64 | { 65 | QPainter painter(this); 66 | painter.rotate(90.0); 67 | painter.scale(1, -1); 68 | painter.drawImage(QRect(0, 0, height(), width()), m_image); 69 | } 70 | void Spectrogram::mouseReleaseEvent (QMouseEvent *event) 71 | { 72 | if (event->button() == Qt::LeftButton) 73 | { 74 | isLog = !isLog; 75 | ColormapChange(paletteCount); 76 | if(isLog == false) { 77 | QObject::disconnect(m_analyser, SIGNAL(spectrumReady()), 0,0); 78 | connect(m_analyser, SIGNAL(spectrumReady()), SLOT(moreSpectrumLinear())); 79 | } else if (isLog == true) { 80 | QObject::disconnect(m_analyser, SIGNAL(spectrumReady()), 0,0); 81 | connect(m_analyser, SIGNAL(spectrumReady()), SLOT(moreSpectrumLog())); 82 | } 83 | } 84 | } 85 | void Spectrogram::mouseDoubleClickEvent (QMouseEvent *event) 86 | { 87 | if (event->button() == Qt::LeftButton) 88 | { 89 | paletteCount++; 90 | if(paletteCount > 8) 91 | paletteCount = 0; 92 | ColormapChange(paletteCount); 93 | } 94 | } 95 | void Spectrogram::ColormapChange(int count) 96 | { 97 | m_palette.deleteMap(); 98 | if (count == 0) { 99 | for(int i = 0; i < 32; i++) 100 | m_palette.setColorAt(scalar32[i], qRgb(redDawn32[i],greenDawn32[i],blueDawn32[i])); 101 | } 102 | else if(count == 1) { 103 | for(int i = 0; i < 32; i++) 104 | m_palette.setColorAt(scalar32[i], qRgb(redKindlmann32[i],greenKindlmann32[i],blueKindlmann32[i])); 105 | } 106 | else if (count == 2) { 107 | for(int i = 0; i < 32; i++) 108 | m_palette.setColorAt(scalar32[i], qRgb(redExtendedKindlmann32[i],greenExtendedKindlmann32[i],blueExtendedKindlmann32[i])); 109 | } 110 | else if (count == 3) { 111 | for(int i = 0; i < 32; i++) 112 | m_palette.setColorAt(scalar32[i], qRgb(redBlackBody32[i],greenBlackBody32[i],blueBlackBody32[i])); 113 | } 114 | else if (count == 4) { 115 | for(int i = 0; i < 32; i++) 116 | m_palette.setColorAt(scalar32[i], qRgb(redExtendedBlackBody32[i],greenExtendedBlackBody32[i],blueExtendedBlackBody32[i])); 117 | } 118 | else if (count == 5) { 119 | for(int i = 0; i < 32; i++) 120 | m_palette.setColorAt(scalar32[i], qRgb(redSmoothCoolWarm32[i],greenSmoothCoolWarm32[i],blueSmoothCoolWarm32[i])); 121 | } 122 | else if (count == 6) { 123 | for(int i = 0; i < 32; i++) 124 | m_palette.setColorAt(scalar32[i], qRgb(redBentCoolWarm32[i],greenBentCoolWarm32[i],blueBentCoolWarm32[i])); 125 | } 126 | else if (count == 7) { 127 | for(int i = 0; i < 32; i++) 128 | m_palette.setColorAt(scalar32[i], qRgb(redParula32[i],greenParula32[i],blueParula32[i])); 129 | } 130 | else if (count == 8) { 131 | for(int i = 0; i < 32; i++) 132 | m_palette.setColorAt(scalar32[i], qRgb(redJet32[i],greenJet32[i],blueJet32[i])); 133 | } 134 | else { 135 | for(int i = 0; i < 32; i++) 136 | m_palette.setColorAt(scalar32[i], qRgb(redKindlmann32[i],greenKindlmann32[i],blueKindlmann32[i])); 137 | } 138 | } 139 | QRgb Spectrogram::gradiantAt(float amp) //! a optimiser 140 | { 141 | if (amp <= 0.0) 142 | amp = m_min; 143 | else 144 | amp = std::log10(amp); 145 | if (amp < m_min) { 146 | m_min = amp; 147 | } 148 | if (amp > m_max) { 149 | m_max = amp; 150 | } 151 | amp = (amp - m_min) / (m_max - m_min); 152 | return m_palette.getColorAt(amp); 153 | } 154 | -------------------------------------------------------------------------------- /SuperSpectrogram.h: -------------------------------------------------------------------------------- 1 | #ifndef SPECTROGRAM_H 2 | #define SPECTROGRAM_H 3 | 4 | #include 5 | #include 6 | #include "palette.h" 7 | #include "spectrumanalyser.h" 8 | 9 | class Spectrogram : public QWidget 10 | { 11 | Q_OBJECT 12 | public: 13 | explicit Spectrogram(SpectrumAnalyser* analyser, QWidget *parent = 0); 14 | 15 | private slots: 16 | void moreSpectrumLinear(); 17 | void moreSpectrumLog(); 18 | 19 | private: 20 | bool isLog; 21 | void paintEvent(QPaintEvent *); 22 | QRgb gradiantAt(float amp); 23 | void mouseReleaseEvent (QMouseEvent *event); 24 | void mouseDoubleClickEvent (QMouseEvent *event); 25 | int paletteCount; 26 | void ColormapChange(int count); 27 | SpectrumAnalyser* m_analyser; 28 | Palette m_palette; 29 | float amp; 30 | QImage m_image; 31 | 32 | float m_min, m_max; 33 | }; 34 | 35 | #endif // SPECTROGRAM_H 36 | -------------------------------------------------------------------------------- /SuperSpectrogram.pro: -------------------------------------------------------------------------------- 1 | QT += core gui multimedia widgets 2 | 3 | TARGET = SuperSpectrogram 4 | TEMPLATE = app 5 | 6 | SOURCES += main.cpp\ 7 | mainwindow.cpp \ 8 | spectrumanalyser.cpp \ 9 | palette.cpp \ 10 | SuperSpectrogram.cpp 11 | 12 | HEADERS += mainwindow.h \ 13 | spectrumanalyser.h \ 14 | palette.h \ 15 | colormap.h \ 16 | SuperSpectrogram.h 17 | DEFINES += TITLEBAR 18 | win32 { 19 | message("* Windows 32 build") 20 | LIBS += ../SuperSpectrogram/libfftw3f-3.lib 21 | QMAKE_CXXFLAGS -= -O 22 | QMAKE_CXXFLAGS -= -O1 23 | QMAKE_CXXFLAGS += -O2# -fp:fast 24 | } 25 | android { 26 | message("* Android build") 27 | LIBS += ../SuperSpectrogram/libfftw3f.a 28 | QMAKE_CXXFLAGS_RELEASE *= -DNDEBUG -ffunction-sections -fdata-sections -Ofast -ftree-vectorize 29 | } 30 | -------------------------------------------------------------------------------- /colormap.h: -------------------------------------------------------------------------------- 1 | const double scalar32[32] = {0,0.032258065,0.064516129,0.096774194,0.129032258,0.161290323,0.193548387,0.225806452,0.258064516,0.290322581,0.322580645,0.35483871,0.387096774,0.419354839,0.451612903,0.483870968,0.516129032,0.548387097,0.580645161,0.612903226,0.64516129,0.677419355,0.709677419,0.741935484,0.774193548,0.806451613,0.838709677,0.870967742,0.903225806,0.935483871,0.967741935,1}; 2 | const int redDawn32[32] = {0,0,1,1,1,1,2,2,2,3,3,3,4,4,4,4,5,5,63,125,186,248,255,255,255,255,255,255,255,255,255,255}; 3 | const int greenDawn32[32] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,15,98,181,255,255,255,255}; 4 | const int blueDawn32[32] = {0,11,23,35,46,58,69,81,93,104,116,128,139,151,162,174,185,197,211,225,239,254,193,124,56,1,7,12,23,100,178,255}; 5 | const int redKindlmann32[32] = {0,28,39,45,50,55,62,63,10,8,7,6,5,5,6,6,7,7,8,8,11,58,96,132,168,203,243,250,252,253,254,255}; 6 | const int greenKindlmann32[32] = {0,1,3,4,5,6,7,8,26,60,78,91,102,112,122,132,142,152,162,172,182,189,196,201,205,207,205,211,221,232,243,255}; 7 | const int blueKindlmann32[32] = {0,29,53,74,97,120,141,169,209,174,145,124,110,100,89,76,61,45,31,25,9,9,9,10,10,10,12,161,200,223,240,255}; 8 | const int redExtendedKindlmann32[32] = {0,27,35,39,44,7,5,4,3,4,4,5,5,29,65,100,136,182,237,246,248,249,249,250,240,229,227,231,235,235,239,255}; 9 | const int greenExtendedKindlmann32[32] = {0,1,3,4,5,15,46,60,70,79,88,98,106,115,120,123,124,115,89,98,113,125,136,147,165,185,199,210,222,235,247,255}; 10 | const int blueExtendedKindlmann32[32] = {0,30,60,85,106,146,104,78,64,51,36,19,12,6,6,6,7,9,11,65,99,150,196,233,251,252,252,253,253,254,254,255}; 11 | const int redBlackBody32[32] = {0,22,34,46,59,72,85,99,113,128,143,158,173,182,190,197,205,213,221,224,225,227,228,229,229,229,229,237,244,249,253,255}; 12 | const int greenBlackBody32[32] = {0,8,15,19,21,24,26,28,30,31,32,33,33,46,59,71,83,93,104,118,132,146,159,172,185,198,210,219,228,237,246,255}; 13 | const int blueBlackBody32[32] = {0,4,9,13,17,19,21,24,26,28,30,33,35,33,31,28,23,17,7,4,4,3,3,3,4,5,6,81,128,171,213,255}; 14 | const int redExtendedBlackBody32[32] = {0,19,27,34,41,47,52,60,78,95,112,137,170,192,209,219,225,231,237,243,249,248,246,242,239,234,229,237,244,249,253,255}; 15 | const int greenExtendedBlackBody32[32] = {0,7,13,15,15,14,12,7,0,0,0,0,0,0,0,32,55,72,87,101,115,132,149,165,181,196,210,219,228,237,246,255}; 16 | const int blueExtendedBlackBody32[32] = {0,29,50,73,97,122,148,172,187,202,218,215,171,128,86,61,61,60,59,58,57,53,49,44,37,27,8,81,128,171,213,255}; 17 | const int redSmoothCoolWarm32[32] = {85,94,103,112,121,130,139,149,158,167,176,185,194,202,210,217,225,231,236,240,242,243,243,241,237,232,226,219,210,200,189,177}; 18 | const int greenSmoothCoolWarm32[32] = {72,87,101,115,129,142,154,166,177,186,195,203,209,214,218,220,219,214,207,200,191,181,170,157,144,130,115,99,81,62,40,1}; 19 | const int blueSmoothCoolWarm32[32] = {193,205,217,227,236,243,248,252,255,255,254,252,248,242,234,226,215,203,190,178,165,152,139,126,114,101,90,78,68,58,48,39}; 20 | const int redBentCoolWarm32[32] = {85,91,98,105,113,121,130,139,149,160,171,182,195,208,221,235,240,237,234,230,226,223,219,215,211,207,202,198,193,188,183,177}; 21 | const int greenBentCoolWarm32[32] = {72,84,96,107,118,130,141,152,163,174,184,195,206,216,227,237,236,224,211,199,186,173,161,148,134,121,107,93,77,60,40,1}; 22 | const int blueBentCoolWarm32[32] = {193,198,203,208,212,216,219,222,225,228,231,233,235,237,239,241,233,215,198,182,166,151,136,122,109,97,85,74,64,55,47,39}; 23 | const int redParula32[32] = {0,15,31,46,45,30,15,2,6,11,15,16,16,15,20,45,70,95,121,148,174,198,216,235,253,253,252,250,250,251,253,255}; 24 | const int greenParula32[32] = {0,12,24,37,52,70,88,105,116,127,138,148,157,167,175,180,184,189,190,189,188,189,191,193,195,209,226,242,251,253,254,255}; 25 | const int blueParula32[32] = {0,38,78,117,149,175,201,225,220,216,212,205,198,191,182,167,152,138,126,114,104,92,80,68,57,45,33,21,44,114,185,255}; 26 | const int redJet32[32] = {0,0,0,0,0,0,6,25,42,41,23,5,0,0,0,0,0,1,20,38,64,118,173,211,229,248,241,218,197,209,230,251}; 27 | const int greenJet32[32] = {0,0,0,2,13,25,28,17,5,19,56,92,140,194,248,254,255,255,255,255,255,255,255,239,203,166,119,65,12,1,1,1}; 28 | const int blueJet32[32] = {145,178,212,240,246,251,255,255,255,255,255,255,255,255,255,206,153,99,63,27,1,1,0,0,0,0,0,0,0,7,15,24}; -------------------------------------------------------------------------------- /fftw3.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2003, 2007-14 Matteo Frigo 3 | * Copyright (c) 2003, 2007-14 Massachusetts Institute of Technology 4 | * 5 | * The following statement of license applies *only* to this header file, 6 | * and *not* to the other files distributed with FFTW or derived therefrom: 7 | * 8 | * Redistribution and use in source and binary forms, with or without 9 | * modification, are permitted provided that the following conditions 10 | * are met: 11 | * 12 | * 1. Redistributions of source code must retain the above copyright 13 | * notice, this list of conditions and the following disclaimer. 14 | * 15 | * 2. Redistributions in binary form must reproduce the above copyright 16 | * notice, this list of conditions and the following disclaimer in the 17 | * documentation and/or other materials provided with the distribution. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS 20 | * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 21 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY 23 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 24 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE 25 | * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 27 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 28 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 29 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | */ 31 | 32 | /***************************** NOTE TO USERS ********************************* 33 | * 34 | * THIS IS A HEADER FILE, NOT A MANUAL 35 | * 36 | * If you want to know how to use FFTW, please read the manual, 37 | * online at http://www.fftw.org/doc/ and also included with FFTW. 38 | * For a quick start, see the manual's tutorial section. 39 | * 40 | * (Reading header files to learn how to use a library is a habit 41 | * stemming from code lacking a proper manual. Arguably, it's a 42 | * *bad* habit in most cases, because header files can contain 43 | * interfaces that are not part of the public, stable API.) 44 | * 45 | ****************************************************************************/ 46 | 47 | #ifndef FFTW3_H 48 | #define FFTW3_H 49 | 50 | #include 51 | 52 | #ifdef __cplusplus 53 | extern "C" 54 | { 55 | #endif /* __cplusplus */ 56 | 57 | /* If is included, use the C99 complex type. Otherwise 58 | define a type bit-compatible with C99 complex */ 59 | #if !defined(FFTW_NO_Complex) && defined(_Complex_I) && defined(complex) && defined(I) 60 | # define FFTW_DEFINE_COMPLEX(R, C) typedef R _Complex C 61 | #else 62 | # define FFTW_DEFINE_COMPLEX(R, C) typedef R C[2] 63 | #endif 64 | 65 | #define FFTW_CONCAT(prefix, name) prefix ## name 66 | #define FFTW_MANGLE_DOUBLE(name) FFTW_CONCAT(fftw_, name) 67 | #define FFTW_MANGLE_FLOAT(name) FFTW_CONCAT(fftwf_, name) 68 | #define FFTW_MANGLE_LONG_DOUBLE(name) FFTW_CONCAT(fftwl_, name) 69 | #define FFTW_MANGLE_QUAD(name) FFTW_CONCAT(fftwq_, name) 70 | 71 | /* IMPORTANT: for Windows compilers, you should add a line 72 | #define FFTW_DLL 73 | here and in kernel/ifftw.h if you are compiling/using FFTW as a 74 | DLL, in order to do the proper importing/exporting, or 75 | alternatively compile with -DFFTW_DLL or the equivalent 76 | command-line flag. This is not necessary under MinGW/Cygwin, where 77 | libtool does the imports/exports automatically. */ 78 | #if defined(FFTW_DLL) && (defined(_WIN32) || defined(__WIN32__)) 79 | /* annoying Windows syntax for shared-library declarations */ 80 | # if defined(COMPILING_FFTW) /* defined in api.h when compiling FFTW */ 81 | # define FFTW_EXTERN extern __declspec(dllexport) 82 | # else /* user is calling FFTW; import symbol */ 83 | # define FFTW_EXTERN extern __declspec(dllimport) 84 | # endif 85 | #else 86 | # define FFTW_EXTERN extern 87 | #endif 88 | 89 | enum fftw_r2r_kind_do_not_use_me { 90 | FFTW_R2HC=0, FFTW_HC2R=1, FFTW_DHT=2, 91 | FFTW_REDFT00=3, FFTW_REDFT01=4, FFTW_REDFT10=5, FFTW_REDFT11=6, 92 | FFTW_RODFT00=7, FFTW_RODFT01=8, FFTW_RODFT10=9, FFTW_RODFT11=10 93 | }; 94 | 95 | struct fftw_iodim_do_not_use_me { 96 | int n; /* dimension size */ 97 | int is; /* input stride */ 98 | int os; /* output stride */ 99 | }; 100 | 101 | #include /* for ptrdiff_t */ 102 | struct fftw_iodim64_do_not_use_me { 103 | ptrdiff_t n; /* dimension size */ 104 | ptrdiff_t is; /* input stride */ 105 | ptrdiff_t os; /* output stride */ 106 | }; 107 | 108 | typedef void (*fftw_write_char_func_do_not_use_me)(char c, void *); 109 | typedef int (*fftw_read_char_func_do_not_use_me)(void *); 110 | 111 | /* 112 | huge second-order macro that defines prototypes for all API 113 | functions. We expand this macro for each supported precision 114 | 115 | X: name-mangling macro 116 | R: real data type 117 | C: complex data type 118 | */ 119 | 120 | #define FFTW_DEFINE_API(X, R, C) \ 121 | \ 122 | FFTW_DEFINE_COMPLEX(R, C); \ 123 | \ 124 | typedef struct X(plan_s) *X(plan); \ 125 | \ 126 | typedef struct fftw_iodim_do_not_use_me X(iodim); \ 127 | typedef struct fftw_iodim64_do_not_use_me X(iodim64); \ 128 | \ 129 | typedef enum fftw_r2r_kind_do_not_use_me X(r2r_kind); \ 130 | \ 131 | typedef fftw_write_char_func_do_not_use_me X(write_char_func); \ 132 | typedef fftw_read_char_func_do_not_use_me X(read_char_func); \ 133 | \ 134 | FFTW_EXTERN void X(execute)(const X(plan) p); \ 135 | \ 136 | FFTW_EXTERN X(plan) X(plan_dft)(int rank, const int *n, \ 137 | C *in, C *out, int sign, unsigned flags); \ 138 | \ 139 | FFTW_EXTERN X(plan) X(plan_dft_1d)(int n, C *in, C *out, int sign, \ 140 | unsigned flags); \ 141 | FFTW_EXTERN X(plan) X(plan_dft_2d)(int n0, int n1, \ 142 | C *in, C *out, int sign, unsigned flags); \ 143 | FFTW_EXTERN X(plan) X(plan_dft_3d)(int n0, int n1, int n2, \ 144 | C *in, C *out, int sign, unsigned flags); \ 145 | \ 146 | FFTW_EXTERN X(plan) X(plan_many_dft)(int rank, const int *n, \ 147 | int howmany, \ 148 | C *in, const int *inembed, \ 149 | int istride, int idist, \ 150 | C *out, const int *onembed, \ 151 | int ostride, int odist, \ 152 | int sign, unsigned flags); \ 153 | \ 154 | FFTW_EXTERN X(plan) X(plan_guru_dft)(int rank, const X(iodim) *dims, \ 155 | int howmany_rank, \ 156 | const X(iodim) *howmany_dims, \ 157 | C *in, C *out, \ 158 | int sign, unsigned flags); \ 159 | FFTW_EXTERN X(plan) X(plan_guru_split_dft)(int rank, const X(iodim) *dims, \ 160 | int howmany_rank, \ 161 | const X(iodim) *howmany_dims, \ 162 | R *ri, R *ii, R *ro, R *io, \ 163 | unsigned flags); \ 164 | \ 165 | FFTW_EXTERN X(plan) X(plan_guru64_dft)(int rank, \ 166 | const X(iodim64) *dims, \ 167 | int howmany_rank, \ 168 | const X(iodim64) *howmany_dims, \ 169 | C *in, C *out, \ 170 | int sign, unsigned flags); \ 171 | FFTW_EXTERN X(plan) X(plan_guru64_split_dft)(int rank, \ 172 | const X(iodim64) *dims, \ 173 | int howmany_rank, \ 174 | const X(iodim64) *howmany_dims, \ 175 | R *ri, R *ii, R *ro, R *io, \ 176 | unsigned flags); \ 177 | \ 178 | FFTW_EXTERN void X(execute_dft)(const X(plan) p, C *in, C *out); \ 179 | FFTW_EXTERN void X(execute_split_dft)(const X(plan) p, R *ri, R *ii, \ 180 | R *ro, R *io); \ 181 | \ 182 | FFTW_EXTERN X(plan) X(plan_many_dft_r2c)(int rank, const int *n, \ 183 | int howmany, \ 184 | R *in, const int *inembed, \ 185 | int istride, int idist, \ 186 | C *out, const int *onembed, \ 187 | int ostride, int odist, \ 188 | unsigned flags); \ 189 | \ 190 | FFTW_EXTERN X(plan) X(plan_dft_r2c)(int rank, const int *n, \ 191 | R *in, C *out, unsigned flags); \ 192 | \ 193 | FFTW_EXTERN X(plan) X(plan_dft_r2c_1d)(int n,R *in,C *out,unsigned flags); \ 194 | FFTW_EXTERN X(plan) X(plan_dft_r2c_2d)(int n0, int n1, \ 195 | R *in, C *out, unsigned flags); \ 196 | FFTW_EXTERN X(plan) X(plan_dft_r2c_3d)(int n0, int n1, \ 197 | int n2, \ 198 | R *in, C *out, unsigned flags); \ 199 | \ 200 | \ 201 | FFTW_EXTERN X(plan) X(plan_many_dft_c2r)(int rank, const int *n, \ 202 | int howmany, \ 203 | C *in, const int *inembed, \ 204 | int istride, int idist, \ 205 | R *out, const int *onembed, \ 206 | int ostride, int odist, \ 207 | unsigned flags); \ 208 | \ 209 | FFTW_EXTERN X(plan) X(plan_dft_c2r)(int rank, const int *n, \ 210 | C *in, R *out, unsigned flags); \ 211 | \ 212 | FFTW_EXTERN X(plan) X(plan_dft_c2r_1d)(int n,C *in,R *out,unsigned flags); \ 213 | FFTW_EXTERN X(plan) X(plan_dft_c2r_2d)(int n0, int n1, \ 214 | C *in, R *out, unsigned flags); \ 215 | FFTW_EXTERN X(plan) X(plan_dft_c2r_3d)(int n0, int n1, \ 216 | int n2, \ 217 | C *in, R *out, unsigned flags); \ 218 | \ 219 | FFTW_EXTERN X(plan) X(plan_guru_dft_r2c)(int rank, const X(iodim) *dims, \ 220 | int howmany_rank, \ 221 | const X(iodim) *howmany_dims, \ 222 | R *in, C *out, \ 223 | unsigned flags); \ 224 | FFTW_EXTERN X(plan) X(plan_guru_dft_c2r)(int rank, const X(iodim) *dims, \ 225 | int howmany_rank, \ 226 | const X(iodim) *howmany_dims, \ 227 | C *in, R *out, \ 228 | unsigned flags); \ 229 | \ 230 | FFTW_EXTERN X(plan) X(plan_guru_split_dft_r2c)( \ 231 | int rank, const X(iodim) *dims, \ 232 | int howmany_rank, \ 233 | const X(iodim) *howmany_dims, \ 234 | R *in, R *ro, R *io, \ 235 | unsigned flags); \ 236 | FFTW_EXTERN X(plan) X(plan_guru_split_dft_c2r)( \ 237 | int rank, const X(iodim) *dims, \ 238 | int howmany_rank, \ 239 | const X(iodim) *howmany_dims, \ 240 | R *ri, R *ii, R *out, \ 241 | unsigned flags); \ 242 | \ 243 | FFTW_EXTERN X(plan) X(plan_guru64_dft_r2c)(int rank, \ 244 | const X(iodim64) *dims, \ 245 | int howmany_rank, \ 246 | const X(iodim64) *howmany_dims, \ 247 | R *in, C *out, \ 248 | unsigned flags); \ 249 | FFTW_EXTERN X(plan) X(plan_guru64_dft_c2r)(int rank, \ 250 | const X(iodim64) *dims, \ 251 | int howmany_rank, \ 252 | const X(iodim64) *howmany_dims, \ 253 | C *in, R *out, \ 254 | unsigned flags); \ 255 | \ 256 | FFTW_EXTERN X(plan) X(plan_guru64_split_dft_r2c)( \ 257 | int rank, const X(iodim64) *dims, \ 258 | int howmany_rank, \ 259 | const X(iodim64) *howmany_dims, \ 260 | R *in, R *ro, R *io, \ 261 | unsigned flags); \ 262 | FFTW_EXTERN X(plan) X(plan_guru64_split_dft_c2r)( \ 263 | int rank, const X(iodim64) *dims, \ 264 | int howmany_rank, \ 265 | const X(iodim64) *howmany_dims, \ 266 | R *ri, R *ii, R *out, \ 267 | unsigned flags); \ 268 | \ 269 | FFTW_EXTERN void X(execute_dft_r2c)(const X(plan) p, R *in, C *out); \ 270 | FFTW_EXTERN void X(execute_dft_c2r)(const X(plan) p, C *in, R *out); \ 271 | \ 272 | FFTW_EXTERN void X(execute_split_dft_r2c)(const X(plan) p, \ 273 | R *in, R *ro, R *io); \ 274 | FFTW_EXTERN void X(execute_split_dft_c2r)(const X(plan) p, \ 275 | R *ri, R *ii, R *out); \ 276 | \ 277 | FFTW_EXTERN X(plan) X(plan_many_r2r)(int rank, const int *n, \ 278 | int howmany, \ 279 | R *in, const int *inembed, \ 280 | int istride, int idist, \ 281 | R *out, const int *onembed, \ 282 | int ostride, int odist, \ 283 | const X(r2r_kind) *kind, unsigned flags); \ 284 | \ 285 | FFTW_EXTERN X(plan) X(plan_r2r)(int rank, const int *n, R *in, R *out, \ 286 | const X(r2r_kind) *kind, unsigned flags); \ 287 | \ 288 | FFTW_EXTERN X(plan) X(plan_r2r_1d)(int n, R *in, R *out, \ 289 | X(r2r_kind) kind, unsigned flags); \ 290 | FFTW_EXTERN X(plan) X(plan_r2r_2d)(int n0, int n1, R *in, R *out, \ 291 | X(r2r_kind) kind0, X(r2r_kind) kind1, \ 292 | unsigned flags); \ 293 | FFTW_EXTERN X(plan) X(plan_r2r_3d)(int n0, int n1, int n2, \ 294 | R *in, R *out, X(r2r_kind) kind0, \ 295 | X(r2r_kind) kind1, X(r2r_kind) kind2, \ 296 | unsigned flags); \ 297 | \ 298 | FFTW_EXTERN X(plan) X(plan_guru_r2r)(int rank, const X(iodim) *dims, \ 299 | int howmany_rank, \ 300 | const X(iodim) *howmany_dims, \ 301 | R *in, R *out, \ 302 | const X(r2r_kind) *kind, unsigned flags); \ 303 | \ 304 | FFTW_EXTERN X(plan) X(plan_guru64_r2r)(int rank, const X(iodim64) *dims, \ 305 | int howmany_rank, \ 306 | const X(iodim64) *howmany_dims, \ 307 | R *in, R *out, \ 308 | const X(r2r_kind) *kind, unsigned flags); \ 309 | \ 310 | FFTW_EXTERN void X(execute_r2r)(const X(plan) p, R *in, R *out); \ 311 | \ 312 | FFTW_EXTERN void X(destroy_plan)(X(plan) p); \ 313 | FFTW_EXTERN void X(forget_wisdom)(void); \ 314 | FFTW_EXTERN void X(cleanup)(void); \ 315 | \ 316 | FFTW_EXTERN void X(set_timelimit)(double t); \ 317 | \ 318 | FFTW_EXTERN void X(plan_with_nthreads)(int nthreads); \ 319 | FFTW_EXTERN int X(init_threads)(void); \ 320 | FFTW_EXTERN void X(cleanup_threads)(void); \ 321 | FFTW_EXTERN void X(make_planner_thread_safe)(void); \ 322 | \ 323 | FFTW_EXTERN int X(export_wisdom_to_filename)(const char *filename); \ 324 | FFTW_EXTERN void X(export_wisdom_to_file)(FILE *output_file); \ 325 | FFTW_EXTERN char *X(export_wisdom_to_string)(void); \ 326 | FFTW_EXTERN void X(export_wisdom)(X(write_char_func) write_char, \ 327 | void *data); \ 328 | FFTW_EXTERN int X(import_system_wisdom)(void); \ 329 | FFTW_EXTERN int X(import_wisdom_from_filename)(const char *filename); \ 330 | FFTW_EXTERN int X(import_wisdom_from_file)(FILE *input_file); \ 331 | FFTW_EXTERN int X(import_wisdom_from_string)(const char *input_string); \ 332 | FFTW_EXTERN int X(import_wisdom)(X(read_char_func) read_char, void *data); \ 333 | \ 334 | FFTW_EXTERN void X(fprint_plan)(const X(plan) p, FILE *output_file); \ 335 | FFTW_EXTERN void X(print_plan)(const X(plan) p); \ 336 | FFTW_EXTERN char *X(sprint_plan)(const X(plan) p); \ 337 | \ 338 | FFTW_EXTERN void *X(malloc)(size_t n); \ 339 | FFTW_EXTERN R *X(alloc_real)(size_t n); \ 340 | FFTW_EXTERN C *X(alloc_complex)(size_t n); \ 341 | FFTW_EXTERN void X(free)(void *p); \ 342 | \ 343 | FFTW_EXTERN void X(flops)(const X(plan) p, \ 344 | double *add, double *mul, double *fmas); \ 345 | FFTW_EXTERN double X(estimate_cost)(const X(plan) p); \ 346 | FFTW_EXTERN double X(cost)(const X(plan) p); \ 347 | \ 348 | FFTW_EXTERN int X(alignment_of)(R *p); \ 349 | FFTW_EXTERN const char X(version)[]; \ 350 | FFTW_EXTERN const char X(cc)[]; \ 351 | FFTW_EXTERN const char X(codelet_optim)[]; 352 | 353 | 354 | /* end of FFTW_DEFINE_API macro */ 355 | 356 | FFTW_DEFINE_API(FFTW_MANGLE_DOUBLE, double, fftw_complex) 357 | FFTW_DEFINE_API(FFTW_MANGLE_FLOAT, float, fftwf_complex) 358 | FFTW_DEFINE_API(FFTW_MANGLE_LONG_DOUBLE, long double, fftwl_complex) 359 | 360 | /* __float128 (quad precision) is a gcc extension on i386, x86_64, and ia64 361 | for gcc >= 4.6 (compiled in FFTW with --enable-quad-precision) */ 362 | #if (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)) \ 363 | && !(defined(__ICC) || defined(__INTEL_COMPILER) || defined(__CUDACC__) || defined(__PGI)) \ 364 | && (defined(__i386__) || defined(__x86_64__) || defined(__ia64__)) 365 | # if !defined(FFTW_NO_Complex) && defined(_Complex_I) && defined(complex) && defined(I) 366 | /* note: __float128 is a typedef, which is not supported with the _Complex 367 | keyword in gcc, so instead we use this ugly __attribute__ version. 368 | However, we can't simply pass the __attribute__ version to 369 | FFTW_DEFINE_API because the __attribute__ confuses gcc in pointer 370 | types. Hence redefining FFTW_DEFINE_COMPLEX. Ugh. */ 371 | # undef FFTW_DEFINE_COMPLEX 372 | # define FFTW_DEFINE_COMPLEX(R, C) typedef _Complex float __attribute__((mode(TC))) C 373 | # endif 374 | FFTW_DEFINE_API(FFTW_MANGLE_QUAD, __float128, fftwq_complex) 375 | #endif 376 | 377 | #define FFTW_FORWARD (-1) 378 | #define FFTW_BACKWARD (+1) 379 | 380 | #define FFTW_NO_TIMELIMIT (-1.0) 381 | 382 | /* documented flags */ 383 | #define FFTW_MEASURE (0U) 384 | #define FFTW_DESTROY_INPUT (1U << 0) 385 | #define FFTW_UNALIGNED (1U << 1) 386 | #define FFTW_CONSERVE_MEMORY (1U << 2) 387 | #define FFTW_EXHAUSTIVE (1U << 3) /* NO_EXHAUSTIVE is default */ 388 | #define FFTW_PRESERVE_INPUT (1U << 4) /* cancels FFTW_DESTROY_INPUT */ 389 | #define FFTW_PATIENT (1U << 5) /* IMPATIENT is default */ 390 | #define FFTW_ESTIMATE (1U << 6) 391 | #define FFTW_WISDOM_ONLY (1U << 21) 392 | 393 | /* undocumented beyond-guru flags */ 394 | #define FFTW_ESTIMATE_PATIENT (1U << 7) 395 | #define FFTW_BELIEVE_PCOST (1U << 8) 396 | #define FFTW_NO_DFT_R2HC (1U << 9) 397 | #define FFTW_NO_NONTHREADED (1U << 10) 398 | #define FFTW_NO_BUFFERING (1U << 11) 399 | #define FFTW_NO_INDIRECT_OP (1U << 12) 400 | #define FFTW_ALLOW_LARGE_GENERIC (1U << 13) /* NO_LARGE_GENERIC is default */ 401 | #define FFTW_NO_RANK_SPLITS (1U << 14) 402 | #define FFTW_NO_VRANK_SPLITS (1U << 15) 403 | #define FFTW_NO_VRECURSE (1U << 16) 404 | #define FFTW_NO_SIMD (1U << 17) 405 | #define FFTW_NO_SLOW (1U << 18) 406 | #define FFTW_NO_FIXED_RADIX_LARGE_N (1U << 19) 407 | #define FFTW_ALLOW_PRUNING (1U << 20) 408 | 409 | #ifdef __cplusplus 410 | } /* extern "C" */ 411 | #endif /* __cplusplus */ 412 | 413 | #endif /* FFTW3_H */ 414 | -------------------------------------------------------------------------------- /libfftw3f-3.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/james34602/SuperSpectrogram/4a81fcd176d821b3043ae166ca3d675a0cfb0ce7/libfftw3f-3.lib -------------------------------------------------------------------------------- /libfftw3f.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/james34602/SuperSpectrogram/4a81fcd176d821b3043ae166ca3d675a0cfb0ce7/libfftw3f.a -------------------------------------------------------------------------------- /main.cpp: -------------------------------------------------------------------------------- 1 | #include "mainwindow.h" 2 | #include 3 | #include 4 | int SamplingRate, OverlapSample, SamplLength; 5 | int main(int argc, char *argv[]) 6 | { 7 | QApplication a(argc, argv); 8 | QMessageBox msgBox; 9 | if(argc < 3 || argc > 3) 10 | { 11 | msgBox.setText("Argument less then 2 or more then 2\nUse default config!\nCommand line example:SuperSpectrum [44100/48000] [Overlap]"); 12 | msgBox.exec(); 13 | SamplingRate = 48000; 14 | #ifdef __ANDROID__ 15 | OverlapSample = 750; 16 | #else 17 | OverlapSample = 1000; 18 | msgBox.setText("FFTW pre-optimization stage..."); 19 | msgBox.exec(); 20 | #endif 21 | SamplLength = 4800; 22 | } 23 | else 24 | { 25 | SamplingRate = atoi(argv[1]); 26 | if(SamplingRate > 48000 || SamplingRate < 44100) 27 | SamplingRate = 48000; 28 | OverlapSample = atoi(argv[2]); 29 | SamplLength = SamplingRate/9; 30 | } 31 | MainWindow w; 32 | w.show(); 33 | return a.exec(); 34 | } 35 | -------------------------------------------------------------------------------- /mainwindow.cpp: -------------------------------------------------------------------------------- 1 | #include "mainwindow.h" 2 | #include 3 | #include 4 | extern int SamplingRate; 5 | extern int OverlapSample; 6 | extern int SamplLength; 7 | MainWindow::MainWindow(QWidget *parent) 8 | : QMainWindow(parent) 9 | { 10 | QAudioDeviceInfo audioDevice = QAudioDeviceInfo::defaultInputDevice(); 11 | m_format = audioDevice.preferredFormat(); 12 | m_format.setByteOrder((QAudioFormat::Endian)QSysInfo::ByteOrder); 13 | m_format.setSampleType(QAudioFormat::SignedInt); 14 | m_format.setSampleSize(16); 15 | m_format.setChannelCount(1); 16 | m_format.setSampleRate(SamplingRate); 17 | qDebug() << m_format; 18 | if (!audioDevice.isFormatSupported(m_format)) { 19 | qDebug("Format not supported"); 20 | } 21 | m_audioinput = new QAudioInput(audioDevice, m_format, this); 22 | m_spectrumanalyser = new SpectrumAnalyser(this); 23 | m_spectrumanalyser->setAudioFormat(m_format); 24 | // m_spectrumanalyser->setParameters(SamplLength, m_format.sampleRate() / 40); 25 | m_spectrumanalyser->setParameters(SamplLength, OverlapSample); 26 | m_spectrumanalyser->open(QIODevice::WriteOnly); 27 | m_audioinput->start(m_spectrumanalyser); 28 | m_spectrogram = new Spectrogram(m_spectrumanalyser, this); 29 | setCentralWidget(m_spectrogram); 30 | #ifdef TITLEBAR 31 | QObject::connect(m_spectrumanalyser, SIGNAL(titleBarUpdate(QString)), this, SLOT(titleBarUpdate(QString))); 32 | #endif 33 | } 34 | 35 | MainWindow::~MainWindow() 36 | { 37 | } 38 | #ifdef TITLEBAR 39 | void MainWindow::titleBarUpdate(QString text) 40 | { 41 | this->setWindowTitle(text); 42 | } 43 | #endif 44 | -------------------------------------------------------------------------------- /mainwindow.h: -------------------------------------------------------------------------------- 1 | #ifndef MAINWINDOW_H 2 | #define MAINWINDOW_H 3 | 4 | #include 5 | #include 6 | #include "SuperSpectrogram.h" 7 | #include "spectrumanalyser.h" 8 | 9 | class MainWindow : public QMainWindow 10 | { 11 | Q_OBJECT 12 | 13 | public: 14 | MainWindow(QWidget *parent = 0); 15 | ~MainWindow(); 16 | private slots: 17 | #ifdef TITLEBAR 18 | void titleBarUpdate(QString text); 19 | #endif 20 | private: 21 | QAudioFormat m_format; 22 | QAudioInput* m_audioinput; 23 | SpectrumAnalyser* m_spectrumanalyser; 24 | int desiredBuffer; 25 | Spectrogram* m_spectrogram; 26 | }; 27 | 28 | #endif // MAINWINDOW_H 29 | -------------------------------------------------------------------------------- /palette.cpp: -------------------------------------------------------------------------------- 1 | #include "palette.h" 2 | #include 3 | 4 | Palette::Palette() 5 | { 6 | } 7 | 8 | void Palette::deleteMap() 9 | { 10 | m_table.clear(); 11 | } 12 | 13 | void Palette::setVectorAt(double pos, QVector3D color) 14 | { 15 | m_table.insert(pos, color); 16 | } 17 | 18 | void Palette::setColorAt(double pos, QColor color) 19 | { 20 | m_table.insert(pos, QVector3D(color.redF(), color.greenF(), color.blueF())); 21 | } 22 | 23 | QVector3D Palette::getVectorAt(double pos) const 24 | { 25 | QMap::const_iterator i = m_table.constBegin(); 26 | double lastKey = i.key(); 27 | QVector3D lastValue = i.value(); 28 | if (pos < lastKey) 29 | return lastValue; 30 | while (i != m_table.constEnd()) { 31 | if (pos <= i.key()) { 32 | double coeff = (pos - lastKey) / (i.key() - lastKey); 33 | return coeff * i.value() + (1.0 - coeff) * lastValue; 34 | } 35 | lastKey = i.key(); 36 | lastValue = i.value(); 37 | ++i; 38 | } 39 | return lastValue; 40 | } 41 | 42 | QRgb Palette::getColorAt(double pos) const 43 | { 44 | QVector3D vec = getVectorAt(pos); 45 | QColor col; 46 | col.setRedF(vec.x()); 47 | col.setGreenF(vec.y()); 48 | col.setBlueF(vec.z()); 49 | return col.rgb(); 50 | } 51 | -------------------------------------------------------------------------------- /palette.h: -------------------------------------------------------------------------------- 1 | #ifndef PALETTE_H 2 | #define PALETTE_H 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | class Palette 9 | { 10 | public: 11 | Palette(); 12 | void deleteMap(); 13 | void setVectorAt(double pos, QVector3D color); 14 | void setColorAt(double pos, QColor color); 15 | QVector3D getVectorAt(double pos) const; 16 | QRgb getColorAt(double pos) const; 17 | 18 | private: 19 | QMap m_table; 20 | }; 21 | 22 | #endif // PALETTE_H 23 | -------------------------------------------------------------------------------- /spectrumanalyser.cpp: -------------------------------------------------------------------------------- 1 | #include "spectrumanalyser.h" 2 | SpectrumAnalyser::SpectrumAnalyser(QObject *parent) : 3 | QIODevice(parent) 4 | { 5 | m_plan = NULL; 6 | } 7 | 8 | SpectrumAnalyser::~SpectrumAnalyser() 9 | { 10 | fftwf_destroy_plan(m_plan); 11 | } 12 | 13 | qint64 SpectrumAnalyser::readData(char *data, qint64 maxlen) 14 | { 15 | return 0; 16 | } 17 | 18 | qint64 SpectrumAnalyser::writeData(const char *data, qint64 len) 19 | { 20 | int samplesReady = len >> 1; // 16bit = 2bytes (len / 2) 21 | const qint16* ptr = reinterpret_cast(data); 22 | while (samplesReady > 0) { 23 | m_fftin[m_nFFT - m_needed] = *ptr * 0.0001; 24 | --m_needed; 25 | --samplesReady; 26 | ++ptr; 27 | if (m_needed == 0) { 28 | runFFT(); 29 | m_needed = m_overlap; 30 | std::copy(m_fftin.begin() + m_overlap, m_fftin.end(), m_fftin.begin()); 31 | } 32 | } 33 | return len - samplesReady; 34 | } 35 | void SpectrumAnalyser::runFFT() 36 | { 37 | fftwf_execute(m_plan); 38 | #ifdef TITLEBAR 39 | float peakFrec = 0.0; 40 | float peakAmplitude = 0.0; 41 | for (int i = 0; i < m_fftout.size(); ++i) { 42 | m_spectrum[i] = std::norm(m_fftout[i] / float(m_nFFT)); // The norm value of a complex number is the squared magnitude 43 | if (m_spectrum[i] > peakAmplitude) { 44 | peakFrec = m_frequenceUnit * i; 45 | peakAmplitude = m_spectrum[i]; 46 | } 47 | } 48 | QString str = QString("SuperSpectrogram::Peak:%1Hz dB:%3").arg(peakFrec).arg(log10(peakAmplitude)*20.0); 49 | changeTitle(str); 50 | #else 51 | for (int i = 0; i < m_fftout.size(); ++i) 52 | m_spectrum[i] = std::norm(m_fftout[i] / float(m_nFFT)); // The norm value of a complex number is the squared magnitude 53 | #endif 54 | emit spectrumReady(); 55 | } 56 | #ifdef TITLEBAR 57 | void SpectrumAnalyser::changeTitle(QString text) 58 | { 59 | emit titleBarUpdate(text); 60 | } 61 | #endif 62 | QAudioFormat SpectrumAnalyser::audioFormat() const 63 | { 64 | return m_audioFormat; 65 | } 66 | void SpectrumAnalyser::setAudioFormat(const QAudioFormat &audioFormat) 67 | { 68 | m_audioFormat = audioFormat; 69 | } 70 | 71 | void SpectrumAnalyser::setParameters(int nfft, int overlap) 72 | { 73 | m_nFFT = nfft; 74 | m_overlap = overlap; 75 | m_fftin.fill(0.0, m_nFFT); 76 | m_needed = overlap; 77 | m_fftout.resize(m_nFFT / 2 + 1); 78 | m_spectrum.resize(m_fftout.size()); 79 | #ifdef __ANDROID__ 80 | m_plan = fftwf_plan_dft_r2c_1d(m_nFFT, m_fftin.data(), reinterpret_cast(m_fftout.data()), FFTW_ESTIMATE); 81 | #else 82 | m_plan = fftwf_plan_dft_r2c_1d(m_nFFT, m_fftin.data(), reinterpret_cast(m_fftout.data()), FFTW_PATIENT); 83 | #endif 84 | m_frequenceUnit = m_audioFormat.sampleRate() / m_nFFT; 85 | } 86 | const QVector &SpectrumAnalyser::spectrum() const 87 | { 88 | return m_spectrum; 89 | } 90 | float SpectrumAnalyser::frequenceUnit() const 91 | { 92 | return m_frequenceUnit; 93 | } 94 | -------------------------------------------------------------------------------- /spectrumanalyser.h: -------------------------------------------------------------------------------- 1 | #ifndef SPECTROGRAMANALYSER_H 2 | #define SPECTROGRAMANALYSER_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include "fftw3.h" 8 | #include 9 | 10 | class SpectrumAnalyser : public QIODevice 11 | { 12 | Q_OBJECT 13 | public: 14 | explicit SpectrumAnalyser(QObject *parent = 0); 15 | ~SpectrumAnalyser(); 16 | 17 | QAudioFormat audioFormat() const; 18 | void setAudioFormat(const QAudioFormat &audioFormat); 19 | 20 | void setParameters(int nfft, int overlap); 21 | 22 | const QVector& spectrum() const; 23 | 24 | float frequenceUnit() const; 25 | 26 | signals: 27 | void spectrumReady(); 28 | #ifdef TITLEBAR 29 | void titleBarUpdate(QString text); 30 | #endif 31 | private: 32 | qint64 readData(char *data, qint64 maxlen); 33 | qint64 writeData(const char *data, qint64 len); 34 | #ifdef TITLEBAR 35 | void changeTitle(QString text); 36 | #endif 37 | void runFFT(); 38 | 39 | int m_nFFT; 40 | int m_overlap; 41 | int m_needed; 42 | 43 | QAudioFormat m_audioFormat; 44 | QVector m_fftin; 45 | 46 | fftwf_plan m_plan; 47 | QVector > m_fftout; 48 | 49 | QVector m_spectrum; 50 | float m_frequenceUnit; 51 | }; 52 | 53 | #endif // SPECTROGRAMANALYSER_H 54 | --------------------------------------------------------------------------------