History

add WAV support

Sigrid Solveig Haflínudóttir committed 6 years ago

Commit 2bb82e21 parent 48c672211 files · +85 −8Browse files

Unified · Split

11 files
  1. README.md +1 −0
  2. flac.c +0 −2
  3. id3v2.c +0 −1
  4. m4a.c +0 −1
  5. mkfile +1 −0
  6. opus.c +0 −2
  7. tags.c +2 −0
  8. tags.h +3 −0
  9. tagspriv.h +3 −0
  10. vorbis.c +0 −2
  11. wav.c +75 −0
README.md+1−0
@@ -12,6 +12,7 @@ Comparison to id3lib and taglib: · 11 unmodified lines
12| FLAC | yes | no | yes |12| FLAC | yes | no | yes |
13| m4a | yes | no | yes |13| m4a | yes | no | yes |
14| opus | yes | no | yes |14| opus | yes | no | yes |
15| WAV | yes | no | yes |
15| replay gain | yes | no | ??? |16| replay gain | yes | no | ??? |
16| size | tiny | bloated | more bloated |17| size | tiny | bloated | more bloated |
17| license | MIT | LGPL | LGPL/MPL |18| license | MIT | LGPL | LGPL/MPL |
flac.c+0−2
@@ -2,8 +2,6 @@ · 1 unmodified line
2#include "tagspriv.h"2#include "tagspriv.h"
3 3
4#define beu3(d) ((d)[0]<<16 | (d)[1]<<8 | (d)[2]<<0)4#define beu3(d) ((d)[0]<<16 | (d)[1]<<8 | (d)[2]<<0)
5#define beuint(d) (uint)((d)[0]<<24 | (d)[1]<<16 | (d)[2]<<8 | (d)[3]<<0)
6#define leuint(d) (uint)((d)[3]<<24 | (d)[2]<<16 | (d)[1]<<8 | (d)[0]<<0)
7 5
8int6int
9tagflac(Tagctx *ctx)7tagflac(Tagctx *ctx)
id3v2.c+0−1
@@ -12,7 +12,6 @@ · 11 unmodified lines
12#include "tagspriv.h"12#include "tagspriv.h"
13 13
14#define synchsafe(d) (uint)(((d)[0]&127)<<21 | ((d)[1]&127)<<14 | ((d)[2]&127)<<7 | ((d)[3]&127)<<0)14#define synchsafe(d) (uint)(((d)[0]&127)<<21 | ((d)[1]&127)<<14 | ((d)[2]&127)<<7 | ((d)[3]&127)<<0)
15#define beuint(d) (uint)((d)[0]<<24 | (d)[1]<<16 | (d)[2]<<8 | (d)[3]<<0)
16 15
17static int16static int
18v2cb(Tagctx *ctx, char *k, char *v)17v2cb(Tagctx *ctx, char *k, char *v)
m4a.c+0−1
@@ -2,7 +2,6 @@ · 1 unmodified line
2/* https://developer.apple.com/library/mac/documentation/QuickTime/QTFF/QTFFChap2/qtff2.html */2/* https://developer.apple.com/library/mac/documentation/QuickTime/QTFF/QTFFChap2/qtff2.html */
3#include "tagspriv.h"3#include "tagspriv.h"
4 4
5#define beuint(d) (uint)((d)[0]<<24 | (d)[1]<<16 | (d)[2]<<8 | (d)[3]<<0)
6#define beuint16(d) (ushort)((d)[0]<<8 | (d)[1]<<0)5#define beuint16(d) (ushort)((d)[0]<<8 | (d)[1]<<0)
7 6
8int7int
mkfile+1−0
@@ -12,6 +12,7 @@ OFILES=\ · 11 unmodified lines
12 tags.$O\12 tags.$O\
13 utf16.$O\13 utf16.$O\
14 vorbis.$O\14 vorbis.$O\
15 wav.$O\
15 16
16HFILES=\17HFILES=\
17 /sys/include/tags.h\18 /sys/include/tags.h\
opus.c+0−2
@@ -1,7 +1,5 @@
1#include "tagspriv.h"1#include "tagspriv.h"
2 2
3#define leuint(d) (uint)(((uchar*)(d))[3]<<24 | ((uchar*)(d))[2]<<16 | ((uchar*)(d))[1]<<8 | ((uchar*)(d))[0]<<0)
4
5int3int
6tagopus(Tagctx *ctx)4tagopus(Tagctx *ctx)
7{5{
tags.c+2−0
@@ -14,6 +14,7 @@ extern int tagid3v2(Tagctx *ctx); · 13 unmodified lines
14extern int tagid3v1(Tagctx *ctx);14extern int tagid3v1(Tagctx *ctx);
15extern int tagm4a(Tagctx *ctx);15extern int tagm4a(Tagctx *ctx);
16extern int tagopus(Tagctx *ctx);16extern int tagopus(Tagctx *ctx);
17extern int tagwav(Tagctx *ctx);
17 18
18static const Getter g[] =19static const Getter g[] =
19{20{
@@ -23,6 +24,7 @@ static const Getter g[] = · 3 unmodified lines
23 {tagflac, Fflac},24 {tagflac, Fflac},
24 {tagm4a, Fm4a},25 {tagm4a, Fm4a},
25 {tagopus, Fopus},26 {tagopus, Fopus},
27 {tagwav, Fwav},
26};28};
27 29
28void30void
tags.h+3−0
@@ -31,6 +31,9 @@ enum · 30 unmodified lines
31 Fflac,31 Fflac,
32 Fm4a,32 Fm4a,
33 Fopus,33 Fopus,
34 Fwav,
35
36 Fmax,
34};37};
35 38
36/* Tag parser context. You need to set it properly before parsing an audio file using libtags. */39/* Tag parser context. You need to set it properly before parsing an audio file using libtags. */
tagspriv.h+3−0
@@ -20,6 +20,9 @@ enum · 19 unmodified lines
20 Numgenre = 192,20 Numgenre = 192,
21};21};
22 22
23#define beuint(d) (uint)((d)[0]<<24 | (d)[1]<<16 | (d)[2]<<8 | (d)[3]<<0)
24#define leuint(d) (uint)((d)[3]<<24 | (d)[2]<<16 | (d)[1]<<8 | (d)[0]<<0)
25
23extern const char *id3genres[Numgenre];26extern const char *id3genres[Numgenre];
24 27
25/*28/*
vorbis.c+0−2
@@ -4,8 +4,6 @@ · 3 unmodified lines
4 */4 */
5#include "tagspriv.h"5#include "tagspriv.h"
6 6
7#define leuint(d) (uint)(((uchar*)(d))[3]<<24 | ((uchar*)(d))[2]<<16 | ((uchar*)(d))[1]<<8 | ((uchar*)(d))[0]<<0)
8
9void7void
10cbvorbiscomment(Tagctx *ctx, char *k, char *v){8cbvorbiscomment(Tagctx *ctx, char *k, char *v){
11 if(*v == 0)9 if(*v == 0)
wav.c+75−0
@@ -0,0 +1,75 @@
1#include "tagspriv.h"
2
3#define le16u(d) (u16int)((d)[0] | (d)[1]<<8)
4
5int
6tagwav(Tagctx *ctx)
7{
8 uchar *d;
9 int i;
10 u32int sz, csz;
11
12 d = (uchar*)ctx->buf;
13
14 sz = 1;
15 for(i = 0; i < 8 && sz > 0; i++){
16 if(ctx->read(ctx, d, 4+4+(i?0:4)) != 4+4+(i?0:4))
17 return -1;
18 if(i == 0){
19 if(memcmp(d, "RIFF", 4) != 0 || memcmp(d+8, "WAVE", 4) != 0)
20 return -1;
21 if((sz = beuint(d+4)) < 4)
22 return -1;
23 sz -= 4;
24 continue;
25 }else if(memcmp(d, "INFO", 4) == 0){
26 ctx->seek(ctx, -4, 1);
27 continue;
28 }
29
30 sz -= 4+4;
31 csz = leuint(d+4);
32 if(csz > sz)
33 return -1;
34 sz -= csz;
35
36 if(i == 1){
37 if(memcmp(d, "fmt ", 4) != 0 || csz < 16)
38 return -1;
39 if(ctx->read(ctx, d, 16) != 16)
40 return -1;
41 csz -= 16;
42 ctx->channels = le16u(d+2);
43 ctx->samplerate = leuint(d+4);
44 ctx->duration = sz*1000 / leuint(d+8);
45 }else if(memcmp(d, "LIST", 4) == 0){
46 sz = csz - 4;
47 continue;
48 }else if(memcmp(d, "IART", 4) == 0){
49 if(ctx->read(ctx, d, csz) != csz)
50 return -1;
51 d[csz] = 0;
52 txtcb(ctx, Tartist, "", d);
53 csz = 1;
54 }else if(memcmp(d, "IPRD", 4) == 0){
55 if(ctx->read(ctx, d, csz) != csz)
56 return -1;
57 d[csz] = 0;
58 txtcb(ctx, Talbum, "", d);
59 csz = 1;
60 }else if(memcmp(d, "INAM", 4) == 0){
61 if(ctx->read(ctx, d, csz) != csz)
62 return -1;
63 d[csz] = 0;
64 txtcb(ctx, Ttitle, "", d);
65 csz = 1;
66 }else if(memcmp(d, "data", 4) == 0){
67 break;
68 }
69
70 if(ctx->seek(ctx, csz, 1) < 0)
71 return -1;
72 }
73
74 return i > 0 ? 0 : -1;
75}

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t