cpp-filetype
 
Loading...
Searching...
No Matches
audio.hpp
1#ifndef FILETYPE_TYPES_AUDIO_TYPES_HPP
2#define FILETYPE_TYPES_AUDIO_TYPES_HPP
3
4#include <array>
5#include <cstdint>
6#include "filetype/type.hpp"
7namespace filetype {
8namespace audio {
9
10using Type = ::filetype::Type;
11
12//------------------------------------------------------------------------------
13// Audio file type definitions
14//------------------------------------------------------------------------------
15
16// MP3 audio format
17// Magic: FF FB or ID3 tags: 49 44 33 ("ID3")
18inline const std::array<uint8_t, 2> MP3_MAGIC = {0xFF, 0xFB};
19inline const std::array<uint8_t, 3> MP3_ID3_MAGIC = {0x49, 0x44, 0x33};
20inline const Type TYPE_MP3{"audio/mpeg", "mp3"};
21
22// WAV audio format
23// Magic: 52 49 46 46 XX XX XX XX 57 41 56 45 ("RIFF....WAVE")
24inline const std::array<uint8_t, 12> WAV_MAGIC = {
25 0x52, 0x49, 0x46, 0x46, 0x00, 0x00, 0x00, 0x00, 0x57, 0x41, 0x56, 0x45};
26inline const Type TYPE_WAV{"audio/wav", "wav"};
27
28// MIDI audio format
29// Magic: 4D 54 68 64 ("MThd")
30inline const std::array<uint8_t, 4> MIDI_MAGIC = {0x4D, 0x54, 0x68, 0x64};
31inline const Type TYPE_MIDI{"audio/midi", "mid"};
32
33// FLAC audio format
34// Magic: 66 4C 61 43 ("fLaC")
35inline const std::array<uint8_t, 4> FLAC_MAGIC = {0x66, 0x4C, 0x61, 0x43};
36inline const Type TYPE_FLAC{"audio/flac", "flac"};
37
38// AAC audio format
39// Magic: FF F1 (ADTS) or FF F9 (we use FF F1 here)
40inline const std::array<uint8_t, 2> AAC_MAGIC = {0xFF, 0xF1};
41inline const Type TYPE_AAC{"audio/aac", "aac"};
42
43// OGG audio format
44// Magic: 4F 67 67 53 ("OggS")
45inline const std::array<uint8_t, 4> OGG_MAGIC = {0x4F, 0x67, 0x67, 0x53};
46inline const Type TYPE_OGG{"audio/ogg", "ogg"};
47
48// WMA audio format
49// Magic: 30 26 B2 75 8E 66 CF 11
50inline const std::array<uint8_t, 8> WMA_MAGIC = {0x30, 0x26, 0xB2, 0x75, 0x8E, 0x66, 0xCF, 0x11};
51inline const Type TYPE_WMA{"audio/x-ms-wma", "wma"};
52
53// AIFF audio format
54// Magic: 46 4F 52 4D XX XX XX XX 41 49 46 46 ("FORM....AIFF")
55inline const std::array<uint8_t, 12> AIFF_MAGIC = {
56 0x46, 0x4F, 0x52, 0x4D, 0x00, 0x00, 0x00, 0x00, 0x41, 0x49, 0x46, 0x46};
57inline const Type TYPE_AIFF{"audio/aiff", "aiff"};
58
59// M4A audio format
60// Magic: 00 00 00 XX 66 74 79 70 4D 34 41 20 ("....ftypM4A ")
61inline const std::array<uint8_t, 12> M4A_MAGIC = {
62 0x00, 0x00, 0x00, 0x20, 0x66, 0x74, 0x79, 0x70, 0x4D, 0x34, 0x41, 0x20};
63inline const Type TYPE_M4A{"audio/mp4", "m4a"};
64
65} // namespace audio
66} // namespace filetype
67
68#endif // FILETYPE_TYPES_AUDIO_TYPES_HPP