kwave  18.07.70
Sample.h
Go to the documentation of this file.
1 /***************************************************************************
2  Sample.h - definition of the sample type
3  -------------------
4  begin : Feb 09 2001
5  copyright : (C) 2001 by Thomas Eschenbacher
6  email : Thomas Eschenbacher <thomas.eschenbacher@gmx.de>
7  ***************************************************************************/
8 
9 /***************************************************************************
10  * *
11  * This program is free software; you can redistribute it and/or modify *
12  * it under the terms of the GNU General Public License as published by *
13  * the Free Software Foundation; either version 2 of the License, or *
14  * (at your option) any later version. *
15  * *
16  ***************************************************************************/
17 
18 #ifndef SAMPLE_H
19 #define SAMPLE_H
20 
21 //***************************************************************************
22 
23 #include <QtGlobal>
24 #include <limits>
25 #include <sys/types.h>
26 
28 typedef quint64 sample_index_t;
29 
31 #define SAMPLE_INDEX_MAX ( std::numeric_limits<sample_index_t>::max() )
32 
37 typedef qint32 sample_t;
38 
40 typedef qint32 sample_storage_t;
41 
43 #define SAMPLE_BITS 24
44 
46 #define SAMPLE_STORAGE_BITS (sizeof(sample_storage_t) * 8)
47 
49 #define SAMPLE_MIN (-(1 << (SAMPLE_BITS - 1)) + 1)
50 
52 #define SAMPLE_MAX (+(1 << (SAMPLE_BITS - 1)) - 1)
53 
57 static inline sample_t float2sample(const float f) {
58  return static_cast<sample_t>(
59  f * static_cast<float>(1 << (SAMPLE_BITS - 1)));
60 }
61 
65 static inline float sample2float(const sample_t s) {
66  return static_cast<float>(
67  static_cast<float>(s) / static_cast<float>(1 << (SAMPLE_BITS - 1)));
68 }
69 
73 static inline double sample2double(const sample_t s) {
74  return static_cast<double>(
75  static_cast<double>(s) / static_cast<double>(1 << (SAMPLE_BITS - 1)));
76 }
77 
81 static inline sample_t double2sample(const double f) {
82  return static_cast<sample_t>(
83  f * static_cast<double>(1 << (SAMPLE_BITS - 1)));
84 }
85 
86 #endif /* SAMPLE_H */
87 
88 //***************************************************************************
89 //***************************************************************************
quint64 sample_index_t
Definition: Sample.h:28
qint32 sample_storage_t
Definition: Sample.h:40
static float sample2float(const sample_t s)
Definition: Sample.h:65
static double sample2double(const sample_t s)
Definition: Sample.h:73
static sample_t double2sample(const double f)
Definition: Sample.h:81
static sample_t float2sample(const float f)
Definition: Sample.h:57
#define SAMPLE_BITS
Definition: Sample.h:43
qint32 sample_t
Definition: Sample.h:37