3
Copyright (C) 2004 Linus Walleij
5
This file is part of the GNOMAD package.
7
GNOMAD is free software; you can redistribute it and/or modify
8
it under the terms of the GNU General Public License as published by
9
the Free Software Foundation; either version 2, or (at your option)
12
You should have received a copy of the GNU General Public License
13
along with GNOMAD; see the file COPYING. If not, write to
14
the Free Software Foundation, 59 Temple Place - Suite 330,
15
Boston, MA 02111-1307, USA.
17
Much of the code in this file was derived from the getid3() code,
18
written in PHP. The C implementation here is however made from
25
#include "filesystem.h"
28
#include <sys/types.h>
32
static guint32 le_to_guint(guchar *data)
34
return data[3] << 24 | data[2] << 16 | data[1] << 8 | data[0];
37
/* -------------------------------------- */
38
/* EXPORTED FUNCTIONS */
39
/* -------------------------------------- */
42
get_tag_for_wavfile (metadata_t *meta)
46
gchar *tmppath = filename_fromutf8(meta->path);
49
// g_print("Getting WAV tag info for %s...\n", meta->path);
50
fd = (gint) open(tmppath, O_RDONLY, 0);
55
// g_print("Opened file\n");
58
// Read in some stuff...
59
n = read(fd,header,46);
61
// Hardcoded RIFF header
62
if ((header[0] == 'R' || header[0] == 'r') &&
63
(header[1] == 'I' || header[1] == 'i') &&
64
(header[2] == 'F' || header[2] == 'f') &&
65
(header[3] == 'F' || header[3] == 'f') &&
66
(header[8] == 'W' || header[8] == 'w') &&
67
(header[9] == 'A' || header[9] == 'a') &&
68
(header[10] == 'V' || header[10] == 'v') &&
69
(header[11] == 'E' || header[11] == 'e') &&
70
(header[12] == 'f' || header[12] == 'F') &&
71
(header[13] == 'm' || header[13] == 'M') &&
72
(header[14] == 't' || header[14] == 'T') &&
74
// This is indeed a RIFF/WAVE file
75
guint32 chunksize = le_to_guint(&header[4]);
76
guint32 fmtchunksize = le_to_guint(&header[16]);
77
guint32 samplerate = le_to_guint(&header[24]);
78
guint32 byterate = le_to_guint(&header[28]);
81
// Calculate the run time. Remove the format chunk size,
82
// the four remaining bytes of the RIFF header and the
83
// data header (8 bytes).
84
calctime = (chunksize - fmtchunksize - 8 - 4) / byterate;
86
// Atleast one second, please.
90
//g_print("RIFF/WAVE chunksize: %d bytes\n", chunksize);
91
//g_print("Sample rate: %d samples/s\n", samplerate);
92
//g_print("Byte rate: %d bytes/s\n", byterate);
93
//g_print("Calculated time: %d seconds\n", calctime);
94
if (meta->length != NULL) {
97
meta->length = seconds_to_mmss(calctime);