• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #ifndef foosampleutilhfoo
2 #define foosampleutilhfoo
3 
4 /***
5   This file is part of PulseAudio.
6 
7   Copyright 2004-2006 Lennart Poettering
8   Copyright 2006 Pierre Ossman <ossman@cendio.se> for Cendio AB
9 
10   PulseAudio is free software; you can redistribute it and/or modify
11   it under the terms of the GNU Lesser General Public License as published
12   by the Free Software Foundation; either version 2.1 of the License,
13   or (at your option) any later version.
14 
15   PulseAudio is distributed in the hope that it will be useful, but
16   WITHOUT ANY WARRANTY; without even the implied warranty of
17   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18   General Public License for more details.
19 
20   You should have received a copy of the GNU Lesser General Public License
21   along with PulseAudio; if not, see <http://www.gnu.org/licenses/>.
22 ***/
23 
24 #include <inttypes.h>
25 #include <limits.h>
26 
27 #include <pulse/gccmacro.h>
28 #include <pulse/sample.h>
29 #include <pulse/volume.h>
30 #include <pulse/channelmap.h>
31 
32 #include <pulsecore/memblock.h>
33 #include <pulsecore/memchunk.h>
34 
35 typedef struct pa_silence_cache {
36     pa_memblock* blocks[PA_SAMPLE_MAX];
37 } pa_silence_cache;
38 
39 void pa_silence_cache_init(pa_silence_cache *cache);
40 void pa_silence_cache_done(pa_silence_cache *cache);
41 
42 void *pa_silence_memory(void *p, size_t length, const pa_sample_spec *spec);
43 pa_memchunk* pa_silence_memchunk(pa_memchunk *c, const pa_sample_spec *spec);
44 pa_memblock* pa_silence_memblock(pa_memblock *b, const pa_sample_spec *spec);
45 
46 pa_memchunk* pa_silence_memchunk_get(pa_silence_cache *cache, pa_mempool *pool, pa_memchunk* ret, const pa_sample_spec *spec, size_t length);
47 
48 size_t pa_frame_align(size_t l, const pa_sample_spec *ss) PA_GCC_PURE;
49 
50 bool pa_frame_aligned(size_t l, const pa_sample_spec *ss) PA_GCC_PURE;
51 
52 void pa_interleave(const void *src[], unsigned channels, void *dst, size_t ss, unsigned n);
53 void pa_deinterleave(const void *src, void *dst[], unsigned channels, size_t ss, unsigned n);
54 
55 void pa_sample_clamp(pa_sample_format_t format, void *dst, size_t dstr, const void *src, size_t sstr, unsigned n);
56 
pa_mult_s16_volume(int16_t v,int32_t cv)57 static inline int32_t pa_mult_s16_volume(int16_t v, int32_t cv) {
58 #ifdef HAVE_FAST_64BIT_OPERATIONS
59     /* Multiply with 64 bit integers on 64 bit platforms */
60     return (v * (int64_t) cv) >> 16;
61 #else
62     /* Multiplying the 32 bit volume factor with the
63      * 16 bit sample might result in an 48 bit value. We
64      * want to do without 64 bit integers and hence do
65      * the multiplication independently for the HI and
66      * LO part of the volume. */
67 
68     int32_t hi = cv >> 16;
69     int32_t lo = cv & 0xFFFF;
70     return ((v * lo) >> 16) + (v * hi);
71 #endif
72 }
73 
74 pa_usec_t pa_bytes_to_usec_round_up(uint64_t length, const pa_sample_spec *spec);
75 size_t pa_usec_to_bytes_round_up(pa_usec_t t, const pa_sample_spec *spec);
76 
77 void pa_memchunk_dump_to_file(pa_memchunk *c, const char *fn);
78 
79 void pa_memchunk_sine(pa_memchunk *c, pa_mempool *pool, unsigned rate, unsigned freq);
80 
81 typedef void (*pa_do_volume_func_t) (void *samples, const void *volumes, unsigned channels, unsigned length);
82 
83 pa_do_volume_func_t pa_get_volume_func(pa_sample_format_t f);
84 void pa_set_volume_func(pa_sample_format_t f, pa_do_volume_func_t func);
85 
86 size_t pa_convert_size(size_t size, const pa_sample_spec *from, const pa_sample_spec *to);
87 
88 #define PA_CHANNEL_POSITION_MASK_LEFT                                   \
89     (PA_CHANNEL_POSITION_MASK(PA_CHANNEL_POSITION_FRONT_LEFT)           \
90      | PA_CHANNEL_POSITION_MASK(PA_CHANNEL_POSITION_REAR_LEFT)          \
91      | PA_CHANNEL_POSITION_MASK(PA_CHANNEL_POSITION_FRONT_LEFT_OF_CENTER) \
92      | PA_CHANNEL_POSITION_MASK(PA_CHANNEL_POSITION_SIDE_LEFT)          \
93      | PA_CHANNEL_POSITION_MASK(PA_CHANNEL_POSITION_TOP_FRONT_LEFT)     \
94      | PA_CHANNEL_POSITION_MASK(PA_CHANNEL_POSITION_TOP_REAR_LEFT))     \
95 
96 #define PA_CHANNEL_POSITION_MASK_RIGHT                                  \
97     (PA_CHANNEL_POSITION_MASK(PA_CHANNEL_POSITION_FRONT_RIGHT)          \
98      | PA_CHANNEL_POSITION_MASK(PA_CHANNEL_POSITION_REAR_RIGHT)         \
99      | PA_CHANNEL_POSITION_MASK(PA_CHANNEL_POSITION_FRONT_RIGHT_OF_CENTER) \
100      | PA_CHANNEL_POSITION_MASK(PA_CHANNEL_POSITION_SIDE_RIGHT)         \
101      | PA_CHANNEL_POSITION_MASK(PA_CHANNEL_POSITION_TOP_FRONT_RIGHT)    \
102      | PA_CHANNEL_POSITION_MASK(PA_CHANNEL_POSITION_TOP_REAR_RIGHT))
103 
104 #define PA_CHANNEL_POSITION_MASK_CENTER                                 \
105     (PA_CHANNEL_POSITION_MASK(PA_CHANNEL_POSITION_FRONT_CENTER)         \
106      | PA_CHANNEL_POSITION_MASK(PA_CHANNEL_POSITION_REAR_CENTER)        \
107      | PA_CHANNEL_POSITION_MASK(PA_CHANNEL_POSITION_TOP_CENTER)         \
108      | PA_CHANNEL_POSITION_MASK(PA_CHANNEL_POSITION_TOP_FRONT_CENTER)   \
109      | PA_CHANNEL_POSITION_MASK(PA_CHANNEL_POSITION_TOP_REAR_CENTER))
110 
111 #define PA_CHANNEL_POSITION_MASK_FRONT                                  \
112     (PA_CHANNEL_POSITION_MASK(PA_CHANNEL_POSITION_FRONT_LEFT)           \
113      | PA_CHANNEL_POSITION_MASK(PA_CHANNEL_POSITION_FRONT_RIGHT)        \
114      | PA_CHANNEL_POSITION_MASK(PA_CHANNEL_POSITION_FRONT_CENTER)       \
115      | PA_CHANNEL_POSITION_MASK(PA_CHANNEL_POSITION_FRONT_LEFT_OF_CENTER) \
116      | PA_CHANNEL_POSITION_MASK(PA_CHANNEL_POSITION_FRONT_RIGHT_OF_CENTER) \
117      | PA_CHANNEL_POSITION_MASK(PA_CHANNEL_POSITION_TOP_FRONT_LEFT)     \
118      | PA_CHANNEL_POSITION_MASK(PA_CHANNEL_POSITION_TOP_FRONT_RIGHT)    \
119      | PA_CHANNEL_POSITION_MASK(PA_CHANNEL_POSITION_TOP_FRONT_CENTER))
120 
121 #define PA_CHANNEL_POSITION_MASK_REAR                                   \
122     (PA_CHANNEL_POSITION_MASK(PA_CHANNEL_POSITION_REAR_LEFT)            \
123      | PA_CHANNEL_POSITION_MASK(PA_CHANNEL_POSITION_REAR_RIGHT)         \
124      | PA_CHANNEL_POSITION_MASK(PA_CHANNEL_POSITION_REAR_CENTER)        \
125      | PA_CHANNEL_POSITION_MASK(PA_CHANNEL_POSITION_TOP_REAR_LEFT)      \
126      | PA_CHANNEL_POSITION_MASK(PA_CHANNEL_POSITION_TOP_REAR_RIGHT)     \
127      | PA_CHANNEL_POSITION_MASK(PA_CHANNEL_POSITION_TOP_REAR_CENTER))
128 
129 #define PA_CHANNEL_POSITION_MASK_LFE                                    \
130     PA_CHANNEL_POSITION_MASK(PA_CHANNEL_POSITION_LFE)
131 
132 #define PA_CHANNEL_POSITION_MASK_HFE                                    \
133     (PA_CHANNEL_POSITION_MASK_REAR | PA_CHANNEL_POSITION_MASK_FRONT     \
134      | PA_CHANNEL_POSITION_MASK_LEFT | PA_CHANNEL_POSITION_MASK_RIGHT   \
135      | PA_CHANNEL_POSITION_MASK_CENTER)
136 
137 #define PA_CHANNEL_POSITION_MASK_SIDE_OR_TOP_CENTER                     \
138     (PA_CHANNEL_POSITION_MASK(PA_CHANNEL_POSITION_SIDE_LEFT)            \
139      | PA_CHANNEL_POSITION_MASK(PA_CHANNEL_POSITION_SIDE_RIGHT)         \
140      | PA_CHANNEL_POSITION_MASK(PA_CHANNEL_POSITION_TOP_CENTER))
141 
142 #define PA_CHANNEL_POSITION_MASK_TOP                                    \
143     (PA_CHANNEL_POSITION_MASK(PA_CHANNEL_POSITION_TOP_CENTER)           \
144      | PA_CHANNEL_POSITION_MASK(PA_CHANNEL_POSITION_TOP_FRONT_LEFT)     \
145      | PA_CHANNEL_POSITION_MASK(PA_CHANNEL_POSITION_TOP_FRONT_RIGHT)    \
146      | PA_CHANNEL_POSITION_MASK(PA_CHANNEL_POSITION_TOP_FRONT_CENTER)   \
147      | PA_CHANNEL_POSITION_MASK(PA_CHANNEL_POSITION_TOP_REAR_LEFT)      \
148      | PA_CHANNEL_POSITION_MASK(PA_CHANNEL_POSITION_TOP_REAR_RIGHT)     \
149      | PA_CHANNEL_POSITION_MASK(PA_CHANNEL_POSITION_TOP_REAR_CENTER))
150 
151 #define PA_CHANNEL_POSITION_MASK_ALL            \
152     ((pa_channel_position_mask_t) (PA_CHANNEL_POSITION_MASK(PA_CHANNEL_POSITION_MAX)-1))
153 
154 #endif
155