annotate base/BaseTypes.h @ 1260:24c0d4c5356e 3.0-integration

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