chiark / gitweb /
plugins/tracklength-gstreamer.c: Rewrite to use `GstDiscoverer'.
[disorder] / plugins / tracklength-wav.c
CommitLineData
28e9141a
RK
1/*
2 * This file is part of DisOrder.
3 * Copyright (C) 2004, 2005, 2007 Richard Kettlewell
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18/** @file plugins/tracklength-wav.c
19 * @brief Compute track lengths for WAV files
20 */
21#include "tracklength.h"
22#include "wav.h"
23
24long tl_wav(const char *path) {
25 struct wavfile f[1];
26 int err, sample_frame_size;
27 long duration;
28
29 if((err = wav_init(f, path))) {
30 disorder_error(err, "error opening %s", path);
31 return -1;
32 }
33 sample_frame_size = (f->bits + 7) / 8 * f->channels;
34 if(sample_frame_size) {
35 const long long n_samples = f->datasize / sample_frame_size;
36 duration = (n_samples + f->rate - 1) / f->rate;
37 } else
38 duration = -1;
39 wav_destroy(f);
40 return duration;
41}
42
43/*
44Local Variables:
45c-basic-offset:2
46comment-column:40
47fill-column:79
48End:
49*/