summaryrefslogtreecommitdiff
path: root/cflac.c
diff options
context:
space:
mode:
authorGravatar Alexey Yakovenko <wakeroid@gmail.com>2009-07-09 18:56:02 +0200
committerGravatar Alexey Yakovenko <wakeroid@gmail.com>2009-07-09 18:56:02 +0200
commit09593aac1e50f5139f894cc7640df7f72cd2f1a9 (patch)
tree5649adebbea45034edadb084659ba491d78627d4 /cflac.c
parent05a29e994a6ab12dfd851cdb2cfb693054f4410f (diff)
fixed flac/cue support
Diffstat (limited to 'cflac.c')
-rw-r--r--cflac.c29
1 files changed, 16 insertions, 13 deletions
diff --git a/cflac.c b/cflac.c
index 391c8a50..69b5f341 100644
--- a/cflac.c
+++ b/cflac.c
@@ -77,17 +77,17 @@ cflac_init (const char *fname, int track, float start, float end) {
if (timeend > timestart || timeend < 0) {
// take from cue and seek
if (timeend < 0) {
- printf ("starting last track in cue!\n");
// must be last (or broken) track
timeend = cflac.info.duration; // set from metainfo
}
- cflac.info.duration = end - start;
+ cflac.info.duration = timeend - timestart;
cflac.seek (0);
}
if (cflac.info.duration == -1) {
printf ("FLAC duration calculation failed\n");
return -1;
}
+
remaining = 0;
return 0;
}
@@ -102,6 +102,7 @@ cflac_free (void) {
int
cflac_read (char *bytes, int size) {
+ int initsize = size;
int nsamples = size / (cflac.info.channels * cflac.info.bitsPerSample / 8);
do {
if (remaining) {
@@ -113,26 +114,28 @@ cflac_read (char *bytes, int size) {
remaining -= sz;
bytes += sz;
size -= sz;
+ cflac.info.position += (float)sz / (cflac.info.channels * cflac.info.samplesPerSecond * cflac.info.bitsPerSample / 8);
+ if (timeend > timestart) {
+ if (cflac.info.position + timestart > timeend) {
+ break;
+ }
+ }
}
if (!size) {
break;
}
if (!FLAC__stream_decoder_process_single (decoder)) {
- memset (bytes, 0, size);
- return -1;
+ break;
+// memset (bytes, 0, size);
+// return -1;
}
if (FLAC__stream_decoder_get_state (decoder) == FLAC__STREAM_DECODER_END_OF_STREAM) {
- return -1;
+ break;
+// return -1;
}
} while (size > 0);
- cflac.info.position += (float)nsamples / cflac.info.samplesPerSecond;
- if (timeend > timestart) {
-// printf ("pos: %f, end: %f\n", cflac.info.position, timeend);
- if (cflac.info.position + timestart > timeend) {
- return -1;
- }
- }
- return 0;
+
+ return initsize - size;
}
int