source: roaraudio/libroarpulse/volume.c @ 3847:c8ba27bb7e0d

Last change on this file since 3847:c8ba27bb7e0d was 3517:1a3218a3fc5b, checked in by phi, 14 years ago

updated license headers, FSF moved office

File size: 4.3 KB
Line 
1//volume.c:
2
3/*
4 *      Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2010
5 *  The code (may) include prototypes and comments (and maybe
6 *  other code fragements) from libpulse*. They are mostly copyrighted by:
7 *  Lennart Poettering <poettering@users.sourceforge.net> and
8 *  Pierre Ossman <drzeus@drzeus.cx>
9 *
10 *  This file is part of libroarpulse a part of RoarAudio,
11 *  a cross-platform sound system for both, home and professional use.
12 *  See README for details.
13 *
14 *  This file is free software; you can redistribute it and/or modify
15 *  it under the terms of the GNU General Public License version 3
16 *  as published by the Free Software Foundation.
17 *
18 *  RoarAudio is distributed in the hope that it will be useful,
19 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
20 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21 *  GNU General Public License for more details.
22 *
23 *  You should have received a copy of the GNU General Public License
24 *  along with this software; see the file COPYING.  If not, write to
25 *  the Free Software Foundation, 51 Franklin Street, Fifth Floor,
26 *  Boston, MA 02110-1301, USA.
27 *
28 *  NOTE for everyone want's to change something and send patches:
29 *  read README and HACKING! There a addition information on
30 *  the license of this document you need to read before you send
31 *  any patches.
32 *
33 *  NOTE for uses of non-GPL (LGPL,...) software using libesd, libartsc
34 *  or libpulse*:
35 *  The libs libroaresd, libroararts and libroarpulse link this libroar
36 *  and are therefore GPL. Because of this it may be illigal to use
37 *  them with any software that uses libesd, libartsc or libpulse*.
38 */
39
40#include <libroarpulse/libroarpulse.h>
41
42/** Return non-zero when *a == *b */
43int pa_cvolume_equal(const pa_cvolume *a, const pa_cvolume *b) {
44 int i;
45
46 if ( a == b )
47  return 1;
48
49 if ( a == NULL || b == NULL )
50  return 0;
51
52 if ( a->channels != b->channels )
53  return 0;
54
55 for (i = 0; i < a->channels; i++)
56  if ( a->values[i] != b->values[i] )
57   return 0;
58
59 return 1;
60}
61
62/** Set the volume of all channels to the specified parameter */
63pa_cvolume* pa_cvolume_set(pa_cvolume *a, unsigned channels, pa_volume_t v) {
64 int i;
65
66 if ( a == NULL )
67  return NULL;
68
69 if ( channels > PA_CHANNELS_MAX )
70  return NULL;
71
72 a->channels = channels;
73
74 for (i = 0; i < channels; i++) {
75  a->values[i] = v;
76 }
77
78 return a;
79}
80
81/** Pretty print a volume structure */
82char *pa_cvolume_snprint(char *s, size_t l, const pa_cvolume *c);
83
84/** Return the average volume of all channels */
85pa_volume_t pa_cvolume_avg(const pa_cvolume *a) {
86 int64_t sum = 0;
87 int i;
88
89#ifndef PA_VOLUME_INVALID
90#define PA_VOLUME_INVALID ((pa_volume_t) UINT32_MAX)
91#endif
92
93 if ( a == NULL )
94  return PA_VOLUME_INVALID;
95
96 for (i = 0; i < a->channels; i++)
97  sum += a->values[i];
98
99 return sum/a->channels;
100}
101
102/** Return TRUE when the passed cvolume structure is valid, FALSE otherwise */
103int pa_cvolume_valid(const pa_cvolume *v) {
104 if ( v == NULL )
105  return 0;
106
107 if ( v->channels <= 0 )
108  return 0;
109
110 if ( v->channels > PA_CHANNELS_MAX )
111  return 0;
112
113 return 1;
114}
115
116/** Return non-zero if the volume of all channels is equal to the specified value */
117int pa_cvolume_channels_equal_to(const pa_cvolume *a, pa_volume_t v) {
118 int i;
119
120 if ( a == NULL )
121  return 0;
122
123 for (i = 0; i < a->channels; i++)
124  if ( a->values[i] != v )
125   return 0;
126
127 return 1;
128}
129
130/** Multiply two volumes specifications, return the result. This uses PA_VOLUME_NORM as neutral element of multiplication. This is only valid for software volumes! */
131pa_volume_t pa_sw_volume_multiply(pa_volume_t a, pa_volume_t b);
132
133/** Multiply to per-channel volumes and return the result in *dest. This is only valid for software volumes! */
134pa_cvolume *pa_sw_cvolume_multiply(pa_cvolume *dest, const pa_cvolume *a, const pa_cvolume *b);
135
136/** Convert a decibel value to a volume. This is only valid for software volumes! \since 0.4 */
137pa_volume_t pa_sw_volume_from_dB(double f);
138
139/** Convert a volume to a decibel value. This is only valid for software volumes! \since 0.4 */
140double pa_sw_volume_to_dB(pa_volume_t v);
141
142/** Convert a linear factor to a volume. This is only valid for software volumes! \since 0.8 */
143pa_volume_t pa_sw_volume_from_linear(double v);
144
145/** Convert a volume to a linear factor. This is only valid for software volumes! \since 0.8 */
146double pa_sw_volume_to_linear(pa_volume_t v);
147
148//ll
Note: See TracBrowser for help on using the repository browser.