forked from baresip/baresip
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathauframe.c
74 lines (60 loc) · 1.17 KB
/
auframe.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
/**
* @file auframe.c Audio frame
*
* Copyright (C) 2010 - 2020 Creytiv.com
*/
#include <string.h>
#include <re.h>
#include <rem.h>
#include <baresip.h>
/**
* Initialize an audio frame
*
* @param af Audio frame
* @param fmt Sample format (enum aufmt)
* @param sampv Audio samples
* @param sampc Total number of audio samples
*/
void auframe_init(struct auframe *af, int fmt, void *sampv, size_t sampc)
{
if (!af)
return;
if (0 == aufmt_sample_size(fmt)) {
warning("auframe: init: unsupported sample format %d (%s)\n",
fmt, aufmt_name(fmt));
}
memset(af, 0, sizeof(*af));
af->fmt = fmt;
af->sampv = sampv;
af->sampc = sampc;
}
/**
* Get the size of an audio frame
*
* @param af Audio frame
*
* @return Number of bytes
*/
size_t auframe_size(const struct auframe *af)
{
size_t sz;
if (!af)
return 0;
sz = aufmt_sample_size(af->fmt);
if (sz == 0) {
warning("auframe: size: illegal format %d (%s)\n",
af->fmt, aufmt_name(af->fmt));
}
return af->sampc * sz;
}
/**
* Silence all samples in an audio frame
*
* @param af Audio frame
*/
void auframe_mute(struct auframe *af)
{
if (!af)
return;
memset(af->sampv, 0, auframe_size(af));
}