summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2008-05-27 19:59:53 +0000
committerLennart Poettering <lennart@poettering.net>2008-05-27 19:59:53 +0000
commitb0bd4e0ff0719f8f5d1bb1cd5b62cee7e6a3c2c8 (patch)
treef4707a4e8aa50fcc55eff3b3b8dc65e3a080b44c
parentf9cdbbad89aed30df636235a6407503b5e955d4b (diff)
make vorbis sound events work
git-svn-id: file:///home/lennart/svn/public/libcanberra/trunk@27 01b60673-d06a-42c0-afdd-89cb8e0f78ac
-rw-r--r--src/read-sound-file.c1
-rw-r--r--src/read-vorbis.c37
2 files changed, 26 insertions, 12 deletions
diff --git a/src/read-sound-file.c b/src/read-sound-file.c
index e32aecf..3a1f93c 100644
--- a/src/read-sound-file.c
+++ b/src/read-sound-file.c
@@ -158,7 +158,6 @@ int ca_sound_file_read_arbitrary(ca_sound_file *f, void *d, size_t *n) {
ca_return_val_if_fail(d, CA_ERROR_INVALID);
ca_return_val_if_fail(n, CA_ERROR_INVALID);
ca_return_val_if_fail(*n > 0, CA_ERROR_INVALID);
- ca_return_val_if_fail(f->wav && !f->vorbis, CA_ERROR_STATE);
switch (f->type) {
case CA_SAMPLE_S16NE:
diff --git a/src/read-vorbis.c b/src/read-vorbis.c
index e61defc..be35f2a 100644
--- a/src/read-vorbis.c
+++ b/src/read-vorbis.c
@@ -75,7 +75,7 @@ int ca_vorbis_open(ca_vorbis **_v, FILE *f) {
ca_return_val_if_fail(_v, CA_ERROR_INVALID);
ca_return_val_if_fail(f, CA_ERROR_INVALID);
- if (!(v = ca_new(ca_vorbis, 1)))
+ if (!(v = ca_new0(ca_vorbis, 1)))
return CA_ERROR_OOM;
if ((or = ov_open(f, &v->ovf, NULL, 0)) < 0) {
@@ -135,28 +135,43 @@ unsigned ca_vorbis_get_rate(ca_vorbis *v) {
int ca_vorbis_read_s16ne(ca_vorbis *v, int16_t *d, unsigned *n){
long r;
int section;
+ int length;
+ size_t n_read = 0;
ca_return_val_if_fail(v, CA_ERROR_INVALID);
ca_return_val_if_fail(d, CA_ERROR_INVALID);
ca_return_val_if_fail(n, CA_ERROR_INVALID);
ca_return_val_if_fail(*n > 0, CA_ERROR_INVALID);
- r = ov_read(&v->ovf, (char*) d, *n * sizeof(float),
+ length = *n * sizeof(int16_t);
+
+ do {
+
+ r = ov_read(&v->ovf, (char*) d, length,
#ifdef WORDS_BIGENDIAN
- 1,
+ 1,
#else
- 0,
+ 0,
#endif
- 2, 1, &section);
+ 2, 1, &section);
+
+ if (r < 0)
+ return convert_error(r);
+
+ if (r == 0)
+ break;
+
+ /* We only read the first section */
+ if (section != 0)
+ break;
- if (r < 0)
- return convert_error(r);
+ length -= r;
+ d += r/sizeof(int16_t);
+ n_read += r;
- /* We only read the first section */
- if (section != 0)
- return 0;
+ } while (length >= 4096);
- *n = (unsigned) r;
+ *n = (unsigned) n_read/sizeof(int16_t);
return CA_SUCCESS;
}