2
This file is part of libcanberra.
4
Copyright 2008 Lennart Poettering
6
libcanberra is free software; you can redistribute it and/or modify
7
it under the terms of the GNU Lesser General Public License as
8
published by the Free Software Foundation, either version 2.1 of the
9
License, or (at your option) any later version.
11
libcanberra is distributed in the hope that it will be useful, but
12
WITHOUT ANY WARRANTY; without even the implied warranty of
13
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14
Lesser General Public License for more details.
16
You should have received a copy of the GNU Lesser General Public
17
License along with libcanberra. If not, If not, see
18
<http://www.gnu.org/licenses/>.
25
#include <vorbis/vorbisfile.h>
26
#include <vorbis/codec.h>
29
#include "read-vorbis.h"
33
#define FILE_SIZE_MAX (64U*1024U*1024U)
40
static int convert_error(int or) {
53
return CA_ERROR_NOTSUPPORTED;
58
return CA_ERROR_CORRUPT;
61
return CA_ERROR_INVALID;
68
int ca_vorbis_open(ca_vorbis **_v, FILE *f) {
73
ca_return_val_if_fail(_v, CA_ERROR_INVALID);
74
ca_return_val_if_fail(f, CA_ERROR_INVALID);
76
if (!(v = ca_new0(ca_vorbis, 1)))
79
if ((or = ov_open(f, &v->ovf, NULL, 0)) < 0) {
80
ret = convert_error(or);
84
if ((n = ov_pcm_total(&v->ovf, -1)) < 0) {
85
ret = convert_error(or);
90
if (n * sizeof(int16_t) > FILE_SIZE_MAX) {
91
ret = CA_ERROR_TOOBIG;
96
v->size = n * sizeof(int16_t) * ca_vorbis_get_nchannels(v);
108
void ca_vorbis_close(ca_vorbis *v) {
115
unsigned ca_vorbis_get_nchannels(ca_vorbis *v) {
116
const vorbis_info *vi;
119
ca_assert_se(vi = ov_info(&v->ovf, -1));
124
unsigned ca_vorbis_get_rate(ca_vorbis *v) {
125
const vorbis_info *vi;
128
ca_assert_se(vi = ov_info(&v->ovf, -1));
130
return (unsigned) vi->rate;
133
int ca_vorbis_read_s16ne(ca_vorbis *v, int16_t *d, unsigned *n){
139
ca_return_val_if_fail(v, CA_ERROR_INVALID);
140
ca_return_val_if_fail(d, CA_ERROR_INVALID);
141
ca_return_val_if_fail(n, CA_ERROR_INVALID);
142
ca_return_val_if_fail(*n > 0, CA_ERROR_INVALID);
144
length = *n * sizeof(int16_t);
148
r = ov_read(&v->ovf, (char*) d, length,
149
#ifdef WORDS_BIGENDIAN
157
return convert_error(r);
162
/* We only read the first section */
167
d += r/sizeof(int16_t);
170
} while (length >= 4096);
172
ca_assert(v->size >= n_read);
175
*n = (unsigned) n_read/sizeof(int16_t);
180
size_t ca_vorbis_get_size(ca_vorbis *v) {
181
ca_return_val_if_fail(v, CA_ERROR_INVALID);