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
1212 | FLAC | yes | no | yes |
1313 | m4a | yes | no | yes |
1414 | opus | yes | no | yes |
15+| WAV | yes | no | yes |
1516 | replay gain | yes | no | ??? |
1617 | size | tiny | bloated | more bloated |
1718 | license | MIT | LGPL | LGPL/MPL |
flac.c+0−2
@@ -2,8 +2,6 @@ · 1 unmodified line
22 #include "tagspriv.h"
33
44 #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)
75
86 int
97 tagflac(Tagctx *ctx)
id3v2.c+0−1
@@ -12,7 +12,6 @@ · 11 unmodified lines
1212 #include "tagspriv.h"
1313
1414 #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)
1615
1716 static int
1817 v2cb(Tagctx *ctx, char *k, char *v)
m4a.c+0−1
@@ -2,7 +2,6 @@ · 1 unmodified line
22 /* https://developer.apple.com/library/mac/documentation/QuickTime/QTFF/QTFFChap2/qtff2.html */
33 #include "tagspriv.h"
44
5−#define beuint(d) (uint)((d)[0]<<24 | (d)[1]<<16 | (d)[2]<<8 | (d)[3]<<0)
65 #define beuint16(d) (ushort)((d)[0]<<8 | (d)[1]<<0)
76
87 int
mkfile+1−0
@@ -12,6 +12,7 @@ OFILES=\ · 11 unmodified lines
1212 tags.$O\
1313 utf16.$O\
1414 vorbis.$O\
15+ wav.$O\
1516
1617 HFILES=\
1718 /sys/include/tags.h\
opus.c+0−2
@@ -1,7 +1,5 @@
11 #include "tagspriv.h"
22
3−#define leuint(d) (uint)(((uchar*)(d))[3]<<24 | ((uchar*)(d))[2]<<16 | ((uchar*)(d))[1]<<8 | ((uchar*)(d))[0]<<0)
4−
53 int
64 tagopus(Tagctx *ctx)
75 {
tags.c+2−0
@@ -14,6 +14,7 @@ extern int tagid3v2(Tagctx *ctx); · 13 unmodified lines
1414 extern int tagid3v1(Tagctx *ctx);
1515 extern int tagm4a(Tagctx *ctx);
1616 extern int tagopus(Tagctx *ctx);
17+extern int tagwav(Tagctx *ctx);
1718
1819 static const Getter g[] =
1920 {
@@ -23,6 +24,7 @@ static const Getter g[] = · 3 unmodified lines
2324 {tagflac, Fflac},
2425 {tagm4a, Fm4a},
2526 {tagopus, Fopus},
27+ {tagwav, Fwav},
2628 };
2729
2830 void
tags.h+3−0
@@ -31,6 +31,9 @@ enum · 30 unmodified lines
3131 Fflac,
3232 Fm4a,
3333 Fopus,
34+ Fwav,
35+
36+ Fmax,
3437 };
3538
3639 /* 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
2020 Numgenre = 192,
2121 };
2222
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+
2326 extern const char *id3genres[Numgenre];
2427
2528 /*
vorbis.c+0−2
@@ -4,8 +4,6 @@ · 3 unmodified lines
44 */
55 #include "tagspriv.h"
66
7−#define leuint(d) (uint)(((uchar*)(d))[3]<<24 | ((uchar*)(d))[2]<<16 | ((uchar*)(d))[1]<<8 | ((uchar*)(d))[0]<<0)
8−
97 void
108 cbvorbiscomment(Tagctx *ctx, char *k, char *v){
119 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+
5+int
6+tagwav(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