annotate base/HitCount.h @ 1520:954d0cf29ca7 import-audio-data

Switch the normalisation option in WritableWaveFileModel from normalising on read to normalising on write, so that the saved file is already normalised and therefore can be read again without having to remember to normalise it
author Chris Cannam
date Wed, 12 Sep 2018 13:56:56 +0100
parents 48e9f538e6e9
children 410819150cd3
rev   line source
Chris@1256 1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
Chris@1256 2
Chris@1256 3 /*
Chris@1256 4 Sonic Visualiser
Chris@1256 5 An audio file viewer and annotation editor.
Chris@1256 6 Centre for Digital Music, Queen Mary, University of London.
Chris@1256 7
Chris@1256 8 This program is free software; you can redistribute it and/or
Chris@1256 9 modify it under the terms of the GNU General Public License as
Chris@1256 10 published by the Free Software Foundation; either version 2 of the
Chris@1256 11 License, or (at your option) any later version. See the file
Chris@1256 12 COPYING included with this distribution for more information.
Chris@1256 13 */
Chris@1256 14
Chris@1256 15 #ifndef HIT_COUNT_H
Chris@1256 16 #define HIT_COUNT_H
Chris@1256 17
Chris@1256 18 #include <string>
Chris@1256 19 #include <iostream>
Chris@1256 20
Chris@1256 21 /**
Chris@1256 22 * Profile class for counting cache hits and the like.
Chris@1256 23 */
Chris@1256 24 class HitCount
Chris@1256 25 {
Chris@1256 26 public:
Chris@1256 27 HitCount(std::string name) :
Chris@1429 28 m_name(name),
Chris@1429 29 m_hit(0),
Chris@1429 30 m_partial(0),
Chris@1429 31 m_miss(0)
Chris@1256 32 { }
Chris@1256 33
Chris@1256 34 ~HitCount() {
Chris@1274 35 #ifndef NO_HIT_COUNTS
Chris@1429 36 using namespace std;
Chris@1429 37 int total = m_hit + m_partial + m_miss;
Chris@1429 38 cerr << "Hit count: " << m_name << ": ";
Chris@1429 39 if (m_partial > 0) {
Chris@1429 40 cerr << m_hit << " hits, " << m_partial << " partial, "
Chris@1429 41 << m_miss << " misses";
Chris@1429 42 } else {
Chris@1429 43 cerr << m_hit << " hits, " << m_miss << " misses";
Chris@1429 44 }
Chris@1429 45 if (total > 0) {
Chris@1429 46 if (m_partial > 0) {
Chris@1429 47 cerr << " (" << ((m_hit * 100.0) / total) << "%, "
Chris@1429 48 << ((m_partial * 100.0) / total) << "%, "
Chris@1429 49 << ((m_miss * 100.0) / total) << "%)";
Chris@1429 50 } else {
Chris@1429 51 cerr << " (" << ((m_hit * 100.0) / total) << "%, "
Chris@1429 52 << ((m_miss * 100.0) / total) << "%)";
Chris@1429 53 }
Chris@1429 54 }
Chris@1429 55 cerr << endl;
Chris@1274 56 #endif
Chris@1256 57 }
Chris@1256 58
Chris@1256 59 void hit() { ++m_hit; }
Chris@1256 60 void partial() { ++m_partial; }
Chris@1256 61 void miss() { ++m_miss; }
Chris@1256 62
Chris@1256 63 private:
Chris@1256 64 std::string m_name;
Chris@1256 65 int m_hit;
Chris@1256 66 int m_partial;
Chris@1256 67 int m_miss;
Chris@1256 68 };
Chris@1256 69
Chris@1256 70 #endif