UltraGrid
UltraGrid Low-Latency High-Resolution Transmission System
Loading...
Searching...
No Matches
utils.h
Go to the documentation of this file.
1
6/*
7 * Copyright (c) 2011-2021 CESNET, z. s. p. o.
8 * All rights reserved.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, is permitted provided that the following conditions
12 * are met:
13 *
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions and the following disclaimer.
16 *
17 * 2. Redistributions in binary form must reproduce the above copyright
18 * notice, this list of conditions and the following disclaimer in the
19 * documentation and/or other materials provided with the distribution.
20 *
21 * 3. Neither the name of CESNET nor the names of its contributors may be
22 * used to endorse or promote products derived from this software without
23 * specific prior written permission.
24 *
25 * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS
26 * "AS IS" AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING,
27 * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
28 * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
29 * EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
30 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
31 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
32 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
33 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
35 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
36 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37 */
38
39#ifndef _AUDIO_UTILS_H_
40#define _AUDIO_UTILS_H_
41
42#ifdef __cplusplus
43#include <cstdint>
44#include <cstddef>
45#else
46#include <stdbool.h>
47#include <stddef.h>
48#include <stdint.h>
49#endif
50
51#include "audio/types.h"
52
53#ifdef __cplusplus
54double calculate_rms(audio_frame2 *frame, int channel, double *peak);
55double calculate_rms(audio_frame *frame, int channel, double *peak);
57#endif
58
59#ifdef __cplusplus
60extern "C" {
61#endif
62
63bool audio_desc_eq(struct audio_desc, struct audio_desc);
66
72void change_bps(char *out, int out_bps, const char *in, int in_bps, int in_len /* bytes */);
74void change_bps2(char *out, int out_bps, const char *in, int in_bps, int in_len /* bytes */, bool dither);
75
87int32_t downshift_with_dither(int32_t val, int shift);
88
92void audio_frame_multiply_channel(struct audio_frame *frame, int new_channel_count);
93
94/*
95 * Extracts out_channel_count of channels from interleaved stream, starting with first_chan
96 */
97void copy_channel(char *out, const char *in, int bps, int in_len /* bytes */, int out_channel_count);
98
99/*
100 * Multiplexes channel into interleaved stream
101 */
102void mux_channel(char *out, const char *in, int bps, int in_len, int out_stream_channels, int chan_pos_stream, double scale);
103void demux_channel(char *out, char *in, int bps, int in_len, int in_stream_channels, int pos_in_stream);
104void remux_channel(char *out, const char *in, int bps, int in_len, int in_stream_channels, int out_stream_channels, int pos_in_stream, int pos_out_stream);
105
106void interleaved2noninterleaved(char *out, const char *in, int bps, int in_len /* bytes */, int channel_count);
107void interleaved2noninterleaved2(char **out, const char *in, int bps,
108 int in_len /* bytes */, int channel_count);
109void interleaved2noninterleaved_float(char **out, const char *in, int in_bps,
110 int in_len /* bytes */, int channel_count);
111
112/*
113 * Additional function that allosw mixing channels
114 *
115 * @return avareage volume
116 */
117void mux_and_mix_channel(char *out, const char *in, int bps, int in_len, int out_stream_channels, int chan_pos_stream, double scale);
118void remux_and_mix_channel(char *out, const char *in, int bps, int frames, int in_stream_channels, int out_stream_channels, int in_channel, int out_channel, double scale);
119double get_avg_volume(char *data, int bps, int in_len, int stream_channels, int chan_pos_stream);
120
127void float2int(char *out, const char *in, int len);
134void int2float(char *out, const char *in, int len);
135
136void signed2unsigned(char *out, const char *in, int in_len);
137
139const char *audio_desc_to_cstring(struct audio_desc desc);
140
142#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
143#define STORE_I32_SAMPLE(ptr, val, out_bps) \
144 memcpy((ptr), ((const char *) &(val)) + 4 - (out_bps), (out_bps))
145#else
146#define STORE_I32_SAMPLE(ptr, val, out_bps) memcpy((ptr), &(val), (out_bps))
147#endif
148
154bool append_audio_frame(struct audio_frame *frame, char *data, size_t data_len);
155
162struct audio_frame *audio_frame_copy(const struct audio_frame *src, bool keep_size);
163
164int parse_audio_format(const char *str, struct audio_desc *ret);
165
166#ifdef __cplusplus
168 ~channel_map();
169
170 int **map = nullptr; // index is source channel, content is output channels
171 int *sizes = nullptr;
172 int *contributors = nullptr; // count of contributing channels to output
173 int size = 0;
174 int max_output = -1;
175
176 bool validate();
178};
179
180bool parse_channel_map_cfg(struct channel_map *channel_map, const char *cfg);
181
182void format_audio_channel_volume(int chan_idx, double rms, double peak,
183 const char *format_color, char **volume_start,
184 char *volume_end);
185
186#endif
187
188#ifdef __cplusplus
189}
190#endif
191
192#endif
int void * val
struct video_desc desc
struct video_frame * frame
int void size_t * len
This file contains definition of some common audio types.
void interleaved2noninterleaved2(char **out, const char *in, int bps, int in_len, int channel_count)
Definition utils.cpp:566
void copy_channel(char *out, const char *in, int bps, int in_len, int out_channel_count)
Definition utils.cpp:306
void audio_channel_demux(const audio_frame2 *, int, audio_channel *)
Definition utils.cpp:528
struct audio_desc audio_desc_from_frame(const struct audio_frame *frame)
Definition utils.cpp:196
void remux_and_mix_channel(char *out, const char *in, int bps, int frames, int in_stream_channels, int out_stream_channels, int in_channel, int out_channel, double scale)
Definition utils.cpp:423
bool parse_channel_map_cfg(struct channel_map *channel_map, const char *cfg)
Definition utils.cpp:716
void signed2unsigned(char *out, const char *in, int in_len)
Definition utils.cpp:515
void float2int(char *out, const char *in, int len)
Definition utils.cpp:482
void audio_frame_write_desc(struct audio_frame *f, struct audio_desc desc)
Definition utils.cpp:220
bool append_audio_frame(struct audio_frame *frame, char *data, size_t data_len)
Definition utils.cpp:620
struct audio_desc audio_desc_from_audio_channel(const audio_channel *)
Definition utils.cpp:205
void change_bps2(char *out, int out_bps, const char *in, int in_bps, int in_len, bool dither)
changes bps with option to specify whether or not do the dithering
Definition utils.cpp:263
void interleaved2noninterleaved(char *out, const char *in, int bps, int in_len, int channel_count)
Definition utils.cpp:610
void mux_channel(char *out, const char *in, int bps, int in_len, int out_stream_channels, int chan_pos_stream, double scale)
Definition utils.cpp:371
void audio_frame_multiply_channel(struct audio_frame *frame, int new_channel_count)
Definition utils.cpp:328
void demux_channel(char *out, char *in, int bps, int in_len, int in_stream_channels, int pos_in_stream)
Definition utils.cpp:334
void change_bps(char *out, int out_bps, const char *in, int in_bps, int in_len)
Definition utils.cpp:258
double get_avg_volume(char *data, int bps, int in_len, int stream_channels, int chan_pos_stream)
Definition utils.cpp:461
double calculate_rms(audio_frame2 *frame, int channel, double *peak)
Calculates mean and peak RMS from audio samples.
Definition utils.cpp:150
void remux_channel(char *out, const char *in, int bps, int in_len, int in_stream_channels, int out_stream_channels, int pos_in_stream, int pos_out_stream)
Definition utils.cpp:352
bool audio_desc_eq(struct audio_desc, struct audio_desc)
Definition utils.cpp:189
int32_t downshift_with_dither(int32_t val, int shift)
Definition utils.cpp:227
void format_audio_channel_volume(int chan_idx, double rms, double peak, const char *format_color, char **volume_start, char *volume_end)
format per channel incrementally volume string (eg. "[0]-18.00/-14.99, [1] -18.00/-14....
Definition utils.cpp:828
int parse_audio_format(const char *str, struct audio_desc *ret)
Definition utils.cpp:655
struct audio_frame * audio_frame_copy(const struct audio_frame *src, bool keep_size)
Definition utils.cpp:633
void int2float(char *out, const char *in, int len)
Definition utils.cpp:496
void interleaved2noninterleaved_float(char **out, const char *in, int in_bps, int in_len, int channel_count)
Definition utils.cpp:578
void mux_and_mix_channel(char *out, const char *in, int bps, int in_len, int out_stream_channels, int chan_pos_stream, double scale)
Definition utils.cpp:402
const char * audio_desc_to_cstring(struct audio_desc desc)
Definition utils.cpp:644
Audio channel is a non-owning view on audio_frame2 isolating one channel.
Definition types.h:122
int bps
Definition types.h:77
struct used to comunicate with audio capture/playback device
Definition types.h:99
int * contributors
Definition utils.h:172
int max_output
Definition utils.h:174
int * sizes
Definition utils.h:171
void compute_contributors()
Definition utils.cpp:804
bool validate()
Definition utils.cpp:791
int size
Definition utils.h:173