comparison base/BaseTypes.h @ 1051:cafd65fc411b cxx11

Comments etc
author Chris Cannam
date Wed, 11 Mar 2015 09:29:44 +0000
parents 10055a284716
children d4a28d1479a8 54af1e21705c
comparison
equal deleted inserted replaced
1050:5ad98be7f635 1051:cafd65fc411b
1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
2
3 /*
4 Sonic Visualiser
5 An audio file viewer and annotation editor.
6 Centre for Digital Music, Queen Mary, University of London.
7
8 This program is free software; you can redistribute it and/or
9 modify it under the terms of the GNU General Public License as
10 published by the Free Software Foundation; either version 2 of the
11 License, or (at your option) any later version. See the file
12 COPYING included with this distribution for more information.
13 */
1 14
2 #ifndef BASE_TYPES_H 15 #ifndef BASE_TYPES_H
3 #define BASE_TYPES_H 16 #define BASE_TYPES_H
4 17
5 #include <cstdint> 18 #include <cstdint>
6 19
20 /** Frame index, the unit of our time axis. This is signed because the
21 axis conceptually extends below zero: zero represents the start of
22 the main loaded audio model, not the start of time; a windowed
23 transform could legitimately produce results before then. We also
24 use this for frame counts, simply to avoid error-prone arithmetic
25 between signed and unsigned types.
26 */
7 typedef int64_t sv_frame_t; 27 typedef int64_t sv_frame_t;
8 typedef double sv_samplerate_t;
9 28
29 /** Check whether an integer index is in range for a container,
30 avoiding overflows and signed/unsigned comparison warnings.
31 */
10 template<typename T, typename C> 32 template<typename T, typename C>
11 bool in_range_for(const C &container, T i) 33 bool in_range_for(const C &container, T i)
12 { 34 {
13 if (i < 0) return false; 35 if (i < 0) return false;
14 if (sizeof(T) > sizeof(typename C::size_type)) { 36 if (sizeof(T) > sizeof(typename C::size_type)) {
16 } else { 38 } else {
17 return static_cast<typename C::size_type>(i) < container.size(); 39 return static_cast<typename C::size_type>(i) < container.size();
18 } 40 }
19 } 41 }
20 42
43 /** Sample rate. We have to deal with sample rates provided as float
44 or (unsigned) int types, so we might as well have a type that can
45 represent both. Storage size isn't an issue anyway.
46 */
47 typedef double sv_samplerate_t;
48
21 #endif 49 #endif
50