Commit 6f7a8903 authored by conrad's avatar conrad

- fixed bug in default linear metric (ratio was being multiplied not

   divided, leading to incorrect units)
 - added read-io example


git-svn-id: http://svn.annodex.net/liboggz/trunk@399 8158c8cd-e7e1-0310-9fa4-c5954c97daef
parent 43264c15
......@@ -14,7 +14,7 @@ endif
endif
if OGGZ_CONFIG_READ
oggz_read_programs = read-file
oggz_read_programs = read-file read-io
endif
if OGGZ_CONFIG_WRITE
......@@ -31,8 +31,11 @@ identity_LDADD = $(OGGZ_LIBS)
read_file_SOURCES = read-file.c
read_file_LDADD = $(OGGZ_LIBS)
read_io_SOURCES = read-io.c
read_io_LDADD = $(OGGZ_LIBS)
write_feed_SOURCES = write-feed.c
write_feed_LDADD = $(OGGZ_LIBS)
write_hungry_SOURCES = write-hungry.c
write_hungry_LDADD = $(OGGZ_LIBS)
\ No newline at end of file
write_hungry_LDADD = $(OGGZ_LIBS)
/*
Copyright (C) 2003 Commonwealth Scientific and Industrial Research
Organisation (CSIRO) Australia
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
- Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
- Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
- Neither the name of CSIRO Australia nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE ORGANISATION OR
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <stdio.h>
#include <stdlib.h>
#include <oggz/oggz.h>
static int got_an_eos = 0;
static int
read_packet (OGGZ * oggz, ogg_packet * op, long serialno, void * user_data)
{
#if 0
if (got_an_eos) {
printf ("[%010ld]\t%ld bytes\tgranulepos %ld\n", serialno, op->bytes,
(long)op->granulepos);
}
#endif
if (op->b_o_s) {
printf ("%010ld: [%lld] BOS %8s\n", serialno, op->granulepos, op->packet);
}
if (op->e_o_s) {
got_an_eos = 1;
printf ("%010ld: [%lld] EOS\n", serialno, op->granulepos);
}
return 0;
}
static size_t
my_io_read (void * user_handle, void * buf, size_t n)
{
FILE * f = (FILE *)user_handle;
return fread (buf, 1, n, f);
}
static int
my_io_seek (void * user_handle, long offset, int whence)
{
FILE * f = (FILE *)user_handle;
return (fseek (f, offset, whence));
}
static long
my_io_tell (void * user_handle)
{
FILE * f = (FILE *)user_handle;
return ftell (f);
}
int
main (int argc, char ** argv)
{
FILE * f;
OGGZ * oggz;
long n;
ogg_int64_t units;
if (argc < 2) {
printf ("usage: %s filename\n", argv[0]);
}
if ((f = fopen ((char *)argv[1], "rb")) == NULL) {
printf ("unable to open file %s\n", argv[1]);
exit (1);
}
if ((oggz = oggz_new (OGGZ_READ | OGGZ_AUTO)) == NULL) {
printf ("unable to create oggz\n");
exit (1);
}
oggz_io_set_read (oggz, my_io_read, f);
oggz_io_set_seek (oggz, my_io_seek, f);
oggz_io_set_tell (oggz, my_io_tell, f);
oggz_set_read_callback (oggz, -1, read_packet, NULL);
while ((n = oggz_read (oggz, 1024)) > 0);
units = oggz_tell_units (oggz);
printf ("Total length: %lld ms\n", units);
oggz_seek_units (oggz, units/2, SEEK_SET);
printf ("seeked to byte offset %lld\n", oggz_tell (oggz));
while ((n = oggz_read (oggz, 1024)) > 0);
oggz_close (oggz);
exit (0);
}
......@@ -367,7 +367,7 @@ oggz_metric_default_linear (OGGZ * oggz, long serialno, ogg_int64_t granulepos,
{
oggz_metric_linear_t * ldata = (oggz_metric_linear_t *)user_data;
return (ldata->gr_n * granulepos / ldata->gr_d);
return (ldata->gr_d * granulepos / ldata->gr_n);
}
int
......@@ -412,6 +412,13 @@ oggz_set_metric_linear (OGGZ * oggz, long serialno,
{
oggz_metric_linear_t * linear_data;
/* we divide by the granulerate, ie. mult by gr_d/gr_n, so ensure
* numerator is non-zero */
if (granule_rate_numerator == 0) {
granule_rate_numerator = 1;
granule_rate_denominator = 0;
}
linear_data = oggz_malloc (sizeof (oggz_metric_linear_t));
linear_data->gr_n = granule_rate_numerator;
linear_data->gr_d = granule_rate_denominator;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment