3 * MPEG Audio header dissection
4 * Written by Shaun Jackman <sjackman@gmail.com>
5 * Copyright 2007 Shaun Jackman
8 * SPDX-License-Identifier: GPL-2.0-or-later
15 #include "ws_symbol_export.h"
18 unsigned int emphasis
:2;
19 unsigned int original
:1;
20 unsigned int copyright
:1;
21 unsigned int modeext
:2;
24 unsigned int padding
:1;
25 unsigned int frequency
:2;
26 unsigned int bitrate
:4;
27 unsigned int protection
:1;
28 unsigned int layer
:2;
29 unsigned int version
:2;
30 unsigned int sync
:11;
33 #define MPA_UNMARSHAL_SYNC(n) ((n) >> 21 & 0x7ff)
34 #define MPA_UNMARSHAL_VERSION(n) ((n) >> 19 & 0x3)
35 #define MPA_UNMARSHAL_LAYER(n) ((n) >> 17 & 0x3)
36 #define MPA_UNMARSHAL_PROTECTION(n) ((n) >> 16 & 0x1)
37 #define MPA_UNMARSHAL_BITRATE(n) ((n) >> 12 & 0xf)
38 #define MPA_UNMARSHAL_FREQUENCY(n) ((n) >> 10 & 0x3)
39 #define MPA_UNMARSHAL_PADDING(n) ((n) >> 9 & 0x1)
40 #define MPA_UNMARSHAL_PRIVATE(n) ((n) >> 8 & 0x1)
41 #define MPA_UNMARSHAL_MODE(n) ((n) >> 6 & 0x3)
42 #define MPA_UNMARSHAL_MODEEXT(n) ((n) >> 4 & 0x3)
43 #define MPA_UNMARSHAL_COPYRIGHT(n) ((n) >> 3 & 0x1)
44 #define MPA_UNMARSHAL_ORIGINAL(n) ((n) >> 2 & 0x1)
45 #define MPA_UNMARSHAL_EMPHASIS(n) ((n) >> 0 & 0x3)
47 #define MPA_UNMARSHAL(mpa, n) do { \
48 (mpa)->sync = MPA_UNMARSHAL_SYNC(n); \
49 (mpa)->version = MPA_UNMARSHAL_VERSION(n); \
50 (mpa)->layer = MPA_UNMARSHAL_LAYER(n); \
51 (mpa)->protection = MPA_UNMARSHAL_PROTECTION(n); \
52 (mpa)->bitrate = MPA_UNMARSHAL_BITRATE(n); \
53 (mpa)->frequency = MPA_UNMARSHAL_FREQUENCY(n); \
54 (mpa)->padding = MPA_UNMARSHAL_PADDING(n); \
55 (mpa)->priv = MPA_UNMARSHAL_PRIVATE(n); \
56 (mpa)->mode = MPA_UNMARSHAL_MODE(n); \
57 (mpa)->modeext = MPA_UNMARSHAL_MODEEXT(n); \
58 (mpa)->copyright = MPA_UNMARSHAL_COPYRIGHT(n); \
59 (mpa)->original = MPA_UNMARSHAL_ORIGINAL(n); \
60 (mpa)->emphasis = MPA_UNMARSHAL_EMPHASIS(n); \
64 int mpa_version(const struct mpa
*);
66 int mpa_layer(const struct mpa
*);
68 unsigned int mpa_samples(const struct mpa
*);
70 unsigned int mpa_bitrate(const struct mpa
*);
72 unsigned int mpa_frequency(const struct mpa
*);
74 unsigned int mpa_padding(const struct mpa
*);
76 uint32_t decode_synchsafe_int(uint32_t);
78 #define MPA_DATA_BYTES(mpa) (mpa_bitrate(mpa) * mpa_samples(mpa) \
79 / mpa_frequency(mpa) / 8)
80 #define MPA_BYTES(mpa) (MPA_DATA_BYTES(mpa) + mpa_padding(mpa))
81 #define MPA_DURATION_NS(mpa) \
82 (1000000000 / mpa_frequency(mpa) * mpa_samples(mpa))
84 enum { MPA_SYNC
= 0x7ff };
86 #define MPA_SYNC_VALID(mpa) ((mpa)->sync == MPA_SYNC)
87 #define MPA_VERSION_VALID(mpa) (mpa_version(mpa) >= 0)
88 #define MPA_LAYER_VALID(mpa) (mpa_layer(mpa) >= 0)
89 #define MPA_BITRATE_VALID(mpa) (mpa_bitrate(mpa) > 0)
90 #define MPA_FREQUENCY_VALID(mpa) (mpa_frequency(mpa) > 0)
91 #define MPA_VALID(mpa) (MPA_SYNC_VALID(mpa) \
92 && MPA_VERSION_VALID(mpa) && MPA_LAYER_VALID(mpa) \
93 && MPA_BITRATE_VALID(mpa) && MPA_FREQUENCY_VALID(mpa))