Coverage Report

Created: 2025-03-04 07:22

/src/serenity/Userland/Libraries/LibAudio/SampleFormats.cpp
Line
Count
Source (jump to first uncovered line)
1
/*
2
 * Copyright (c) 2022, kleines Filmröllchen <filmroellchen@serenityos.org>.
3
 *
4
 * SPDX-License-Identifier: BSD-2-Clause
5
 */
6
7
#include "SampleFormats.h"
8
9
namespace Audio {
10
11
u16 pcm_bits_per_sample(PcmSampleFormat format)
12
1.35k
{
13
1.35k
    switch (format) {
14
946
    case PcmSampleFormat::Uint8:
15
946
        return 8;
16
90
    case PcmSampleFormat::Int16:
17
90
        return 16;
18
178
    case PcmSampleFormat::Int24:
19
178
        return 24;
20
0
    case PcmSampleFormat::Int32:
21
85
    case PcmSampleFormat::Float32:
22
85
        return 32;
23
58
    case PcmSampleFormat::Float64:
24
58
        return 64;
25
0
    default:
26
0
        VERIFY_NOT_REACHED();
27
1.35k
    }
28
1.35k
}
29
30
bool is_integer_format(PcmSampleFormat format)
31
0
{
32
0
    return format == PcmSampleFormat::Uint8 || format == PcmSampleFormat::Int16 || format == PcmSampleFormat::Int24 || format == PcmSampleFormat::Int32;
33
0
}
34
35
Optional<PcmSampleFormat> integer_sample_format_for(u16 bits_per_sample)
36
0
{
37
0
    switch (bits_per_sample) {
38
0
    case 8:
39
0
        return PcmSampleFormat::Uint8;
40
0
    case 16:
41
0
        return PcmSampleFormat::Int16;
42
0
    case 24:
43
0
        return PcmSampleFormat::Int24;
44
0
    case 32:
45
0
        return PcmSampleFormat::Int32;
46
0
    default:
47
0
        return {};
48
0
    }
49
0
}
50
51
ByteString sample_format_name(PcmSampleFormat format)
52
0
{
53
0
    bool is_float = format == PcmSampleFormat::Float32 || format == PcmSampleFormat::Float64;
54
0
    return ByteString::formatted("PCM {}bit {}", pcm_bits_per_sample(format), is_float ? "Float" : "LE");
55
0
}
56
57
}