]> code.delx.au - pulseaudio/blob - polyp/sample.h
add CPU load limiter
[pulseaudio] / polyp / sample.h
1 #ifndef foosamplehfoo
2 #define foosamplehfoo
3
4 /* $Id$ */
5
6 /***
7 This file is part of polypaudio.
8
9 polypaudio is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published
11 by the Free Software Foundation; either version 2 of the License,
12 or (at your option) any later version.
13
14 polypaudio is distributed in the hope that it will be useful, but
15 WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 General Public License for more details.
18
19 You should have received a copy of the GNU General Public License
20 along with polypaudio; if not, write to the Free Software
21 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
22 USA.
23 ***/
24
25 #include <inttypes.h>
26 #include <sys/types.h>
27 #include <math.h>
28
29 #include "cdecl.h"
30
31 /** \file
32 * Constants and routines for sample type handling */
33
34 PA_C_DECL_BEGIN
35
36 /** Sample format */
37 enum pa_sample_format {
38 PA_SAMPLE_U8, /**< Unsigned 8 Bit PCM */
39 PA_SAMPLE_ALAW, /**< 8 Bit a-Law */
40 PA_SAMPLE_ULAW, /**< 8 Bit mu-Law */
41 PA_SAMPLE_S16LE, /**< Signed 16 Bit PCM, little endian (PC) */
42 PA_SAMPLE_S16BE, /**< Signed 16 Bit PCM, big endian */
43 PA_SAMPLE_FLOAT32LE, /**< 32 Bit IEEE floating point, little endian, range -1..1 */
44 PA_SAMPLE_FLOAT32BE, /**< 32 Bit IEEE floating point, big endian, range -1..1 */
45 PA_SAMPLE_MAX /**< Upper limit of valid sample types */
46 };
47
48 #ifdef WORDS_BIGENDIAN
49 /** Signed 16 Bit PCM, native endian */
50 #define PA_SAMPLE_S16NE PA_SAMPLE_S16BE
51 /** 32 Bit IEEE floating point, native endian */
52 #define PA_SAMPLE_FLOAT32NE PA_SAMPLE_FLOAT32BE
53 #else
54 /** Signed 16 Bit PCM, native endian */
55 #define PA_SAMPLE_S16NE PA_SAMPLE_S16LE
56 /** 32 Bit IEEE floating point, native endian */
57 #define PA_SAMPLE_FLOAT32NE PA_SAMPLE_FLOAT32LE
58 #endif
59
60 /** A Shortcut for PA_SAMPLE_FLOAT32NE */
61 #define PA_SAMPLE_FLOAT32 PA_SAMPLE_FLOAT32NE
62
63 /** A sample format and attribute specification */
64 struct pa_sample_spec {
65 enum pa_sample_format format; /**< The sample format */
66 uint32_t rate; /**< The sample rate. (e.g. 44100) */
67 uint8_t channels; /**< Audio channels. (1 for mono, 2 for stereo, ...) */
68 };
69
70 /** Type for usec specifications */
71 typedef uint32_t pa_usec_t;
72
73 /** Return the amount of bytes playback of a second of audio with the speicified sample type takes */
74 size_t pa_bytes_per_second(const struct pa_sample_spec *spec);
75
76 /** Return the size of a frame with the specific sample type */
77 size_t pa_frame_size(const struct pa_sample_spec *spec);
78
79 /** Calculate the time the specified bytes take to play with the specified sample type */
80 pa_usec_t pa_bytes_to_usec(size_t length, const struct pa_sample_spec *spec);
81
82 /** Return non-zero when the sample type specification is valid */
83 int pa_sample_spec_valid(const struct pa_sample_spec *spec);
84
85 /** Return non-zero when the two sample type specifications match */
86 int pa_sample_spec_equal(const struct pa_sample_spec*a, const struct pa_sample_spec*b);
87
88 /** Maximum required string length for pa_sample_spec_snprint() */
89 #define PA_SAMPLE_SNPRINT_MAX_LENGTH 32
90
91 /** Pretty print a sample type specification to a string */
92 void pa_sample_spec_snprint(char *s, size_t l, const struct pa_sample_spec *spec);
93
94 /** Volume specification: 0: silence; < 256: diminished volume; 256: normal volume; > 256 amplified volume */
95 typedef uint32_t pa_volume_t;
96
97 /** Normal volume (100%) */
98 #define PA_VOLUME_NORM (0x100)
99
100 /** Muted volume (0%) */
101 #define PA_VOLUME_MUTED (0)
102
103 /** Multiply two volumes specifications, return the result. This uses PA_VOLUME_NORM as neutral element of multiplication. */
104 pa_volume_t pa_volume_multiply(pa_volume_t a, pa_volume_t b);
105
106 /** Convert volume from decibel to linear level. \since 0.4 */
107 pa_volume_t pa_volume_from_dB(double f);
108
109 /** Convert volume from linear level to decibel. \since 0.4 */
110 double pa_volume_to_dB(pa_volume_t v);
111
112 #ifdef INFINITY
113 #define PA_DECIBEL_MININFTY (-INFINITY)
114 #else
115 /** This value is used as minus infinity when using pa_volume_{to,from}_dB(). \since 0.4 */
116 #define PA_DECIBEL_MININFTY (-200)
117 #endif
118
119 /** Pretty print a byte size value. (i.e. "2.5 MB") */
120 void pa_bytes_snprint(char *s, size_t l, off_t v);
121
122 PA_C_DECL_END
123
124 #endif