From 23829240432813e8c084bdb2c594269e6e3bf12a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mathias=20Panzenb=C3=B6ck?= Date: Fri, 28 Dec 2012 20:01:40 +0100 Subject: [PATCH] less stupid way to define magics --- audioextract.h | 14 +------------- id3.h | 20 +++----------------- midi.h | 17 ++--------------- ogg.h | 15 +-------------- wave.h | 27 +++++---------------------- 5 files changed, 12 insertions(+), 81 deletions(-) diff --git a/audioextract.h b/audioextract.h index 6155ec5..0a76890 100644 --- a/audioextract.h +++ b/audioextract.h @@ -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__ */ diff --git a/id3.h b/id3.h index 827c1f2..fc77ecf 100644 --- a/id3.h +++ b/id3.h @@ -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) diff --git a/midi.h b/midi.h index 4404c6f..4db9d1a 100644 --- a/midi.h +++ b/midi.h @@ -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 diff --git a/ogg.h b/ogg.h index ac686ed..5c93197 100644 --- a/ogg.h +++ b/ogg.h @@ -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) diff --git a/wave.h b/wave.h index 0fdb6cb..8bd7b0f 100644 --- a/wave.h +++ b/wave.h @@ -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