summaryrefslogtreecommitdiff
path: root/cvorbis.c
diff options
context:
space:
mode:
authorGravatar waker <wakeroid@gmail.com>2009-07-07 00:44:09 +0200
committerGravatar waker <wakeroid@gmail.com>2009-07-07 00:44:09 +0200
commit70679eb6465814b368eb1ec91c6b450f324512b5 (patch)
treeb5e18a2c1d850a4886dc91241f2fc2d728a548d8 /cvorbis.c
parenta6aabe9020889e508fff49666cfc1c8506fcfe45 (diff)
added vorbis seeking
fixed 44100 mono playback fix volume control for streams that don't use SRC
Diffstat (limited to 'cvorbis.c')
-rw-r--r--cvorbis.c31
1 files changed, 27 insertions, 4 deletions
diff --git a/cvorbis.c b/cvorbis.c
index e5965d38..f8b427f9 100644
--- a/cvorbis.c
+++ b/cvorbis.c
@@ -2,6 +2,7 @@
#include <vorbis/vorbisfile.h>
#include <string.h>
#include <stdio.h>
+#include <stdlib.h>
#include "codec.h"
#include "cvorbis.h"
@@ -27,6 +28,8 @@ int cvorbis_init (const char *fname) {
cvorbis.info.dataSize = ov_pcm_total (&vorbis_file, -1) * vi->channels * 2;
cvorbis.info.channels = vi->channels;
cvorbis.info.samplesPerSecond = vi->rate;
+ cvorbis.info.duration = ov_seekable (&vorbis_file) ? ov_time_total (&vorbis_file, -1) : -1;
+// printf ("vorbis info: bps: %d, size: %d, chan: %d, rate: %d, dur: %f\n", cvorbis.info.bitsPerSample, cvorbis.info.dataSize, cvorbis.info.channels, cvorbis.info.samplesPerSecond, cvorbis.info.duration);
return 0;
}
@@ -55,13 +58,19 @@ cvorbis_read (char *bytes, int size)
memset (bytes, 0, size);
return -1;
}
+ else if (ret == 0) {
+ if (size > 0) {
+ memset (bytes, 0, size);
+ }
+ return -1;
+ }
else if (ret < size)
{
- if (ret == 0) {
- ov_raw_seek (&vorbis_file, 0);
- }
size -= ret;
bytes += ret;
+// if (ret == 0) {
+// ov_raw_seek (&vorbis_file, 0);
+// }
}
else {
break;
@@ -70,9 +79,23 @@ cvorbis_read (char *bytes, int size)
return 0;
}
+int
+cvorbis_seek (float time) {
+ if (!file) {
+ return -1;
+ }
+// printf ("seeking for %f\n");
+ int res = ov_time_seek (&vorbis_file, time);
+ if (res != 0 && res != OV_ENOSEEK)
+ return -1;
+// printf ("seek result: %d\n", res);
+ return 0;
+}
+
codec_t cvorbis = {
.init = cvorbis_init,
.free = cvorbis_free,
- .read = cvorbis_read
+ .read = cvorbis_read,
+ .seek = cvorbis_seek
};