less stupid way to define magics

This commit is contained in:
Mathias Panzenböck 2012-12-28 20:01:40 +01:00
parent b2f1bae729
commit 2382924043
5 changed files with 12 additions and 81 deletions

View File

@ -33,18 +33,6 @@
#endif
#ifndef __BYTE_ORDER
# ifndef __WINDOWS__
# error cannot detect byte order
# else
/* assume little endian byte order on windows */
# define __LITTLE_ENDIAN 1234
# define __BIG_ENDIAN 4321
# define __PDP_ENDIAN 3412
# define __BYTE_ORDER __LITTLE_ENDIAN
# endif
#elif __BYTE_ORDER != __LITTLE_ENDIAN && __BYTE_ORDER != __BIG_ENDIAN
# error unsupported byte order
#endif
#define MAGIC(STR) (*(const uint32_t*)(STR))
#endif /* AUDIOEXTRACT_H__ */

20
id3.h
View File

@ -3,23 +3,9 @@
#include "audioextract.h"
#if __BYTE_ORDER == __LITTLE_ENDIAN
# define ID3_MASK (uint32_t)0x00FFFFFF
# define ID3v1_MAGIC (uint32_t)0x00474154 /* "\0GAT" */
# define ID3v2_MAGIC (uint32_t)0x00334449 /* "\03DI" */
#elif __BYTE_ORDER == __BIG_ENDIAN
# define ID3_MASK (uint32_t)0xFFFFFF00
# define ID3v1_MAGIC (uint32_t)0x54414700 /* "TAG\0" */
# define ID3v2_MAGIC (uint32_t)0x49443300 /* "ID3\0" */
#else
# error unsupported endian
#endif
#define ID3_MASK MAGIC("\xff\xff\xff\x00")
#define ID3v1_MAGIC MAGIC("TAG\0")
#define ID3v2_MAGIC MAGIC("ID3\0")
#define IS_ID3v1_MAGIC(hdr) ((*(uint32_t *)(hdr) & ID3_MASK) == ID3v1_MAGIC)
#define IS_ID3v2_MAGIC(hdr) ((*(uint32_t *)(hdr) & ID3_MASK) == ID3v2_MAGIC)

17
midi.h
View File

@ -3,21 +3,8 @@
#include "audioextract.h"
#if __BYTE_ORDER == __LITTLE_ENDIAN
# define MIDI_MAGIC 0x6468544D /* "dhTM" */
# define MIDI_TRACK_MAGIC 0x6B72544D /* "krTM" */
#elif __BYTE_ORDER == __BIG_ENDIAN
# define MIDI_MAGIC 0x4D546864 /* "MThd" */
# define MIDI_TRACK_MAGIC 0x4D54726B /* "MTrk" */
#else
# error unsupported endian
#endif
#define MIDI_MAGIC MAGIC("MThd")
#define MIDI_TRACK_MAGIC MAGIC("MTrk")
#define MIDI_HEADER_SIZE 14
#define MIDI_TRACK_HEADER_SIZE 8

15
ogg.h
View File

@ -3,20 +3,7 @@
#include "audioextract.h"
#if __BYTE_ORDER == __LITTLE_ENDIAN
# define OGG_MAGIC 0x5367674f /* "SggO" */
#elif __BYTE_ORDER == __BIG_ENDIAN
# define OGG_MAGIC 0x5367674f /* "OggS" */
#else
# error unsupported endian
#endif
#define OGG_MAGIC MAGIC("OggS")
#define OGG_HEADER_SIZE 27
#define ogg_isinitial(data) ((data)[5] & 2)

27
wave.h
View File

@ -3,29 +3,12 @@
#include "audioextract.h"
#if __BYTE_ORDER == __LITTLE_ENDIAN
#define RIFF_MAGIC MAGIC("RIFF")
#define WAVE_MAGIC MAGIC("WAVE")
# define RIFF_MAGIC 0x46464952 /* "RIFF" (reversed) */
# define WAVE_MAGIC 0x45564157 /* "WAVE" (reversed) */
# define FORM_MAGIC 0x4d524f46 /* "FORM" (reversed) */
# define AIFF_MAGIC 0x46464941 /* "AIFF" (reversed) */
# define AIFC_MAGIC 0x43464941 /* "AIFC" (reversed) */
#elif __BYTE_ORDER == __BIG_ENDIAN
# define RIFF_MAGIC 0x46464952 /* "RIFF" */
# define WAVE_MAGIC 0x57415645 /* "WAVE" */
# define FORM_MAGIC 0x464f524d /* "FORM" */
# define AIFF_MAGIC 0x41494646 /* "AIFF" */
# define AIFC_MAGIC 0x41494643 /* "AIFC" */
#else
# error unsupported endian
#endif
#define FORM_MAGIC MAGIC("FORM")
#define AIFF_MAGIC MAGIC("AIFF")
#define AIFC_MAGIC MAGIC("AIFC")
#define WAVE_HEADER_SIZE 8