]>
code.delx.au - pulseaudio/blob - polyp/sample.c
4 This file is part of polypaudio.
6 polypaudio is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published
8 by the Free Software Foundation; either version 2 of the License,
9 or (at your option) any later version.
11 polypaudio is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with polypaudio; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
31 size_t pa_frame_size(const struct pa_sample_spec
*spec
) {
35 switch (spec
->format
) {
45 case PA_SAMPLE_FLOAT32LE
:
46 case PA_SAMPLE_FLOAT32BE
:
53 return b
* spec
->channels
;
56 size_t pa_bytes_per_second(const struct pa_sample_spec
*spec
) {
58 return spec
->rate
*pa_frame_size(spec
);
61 uint32_t pa_bytes_to_usec(size_t length
, const struct pa_sample_spec
*spec
) {
64 return (uint32_t) (((double) length
/pa_frame_size(spec
))/spec
->rate
*1000000);
67 int pa_sample_spec_valid(const struct pa_sample_spec
*spec
) {
70 if (!spec
->rate
|| !spec
->channels
)
73 if (spec
->format
>= PA_SAMPLE_MAX
)
79 int pa_sample_spec_equal(const struct pa_sample_spec
*a
, const struct pa_sample_spec
*b
) {
82 return (a
->format
== b
->format
) && (a
->rate
== b
->rate
) && (a
->channels
== b
->channels
);
85 void pa_sample_snprint(char *s
, size_t l
, const struct pa_sample_spec
*spec
) {
86 static const char* const table
[]= {
87 [PA_SAMPLE_U8
] = "U8",
88 [PA_SAMPLE_ALAW
] = "ALAW",
89 [PA_SAMPLE_ULAW
] = "ULAW",
90 [PA_SAMPLE_S16LE
] = "S16LE",
91 [PA_SAMPLE_S16BE
] = "S16BE",
92 [PA_SAMPLE_FLOAT32LE
] = "FLOAT32LE",
93 [PA_SAMPLE_FLOAT32BE
] = "FLOAT32BE",
96 assert(pa_sample_spec_valid(spec
));
97 snprintf(s
, l
, "%s %uch %uHz", table
[spec
->format
], spec
->channels
, spec
->rate
);