[xiph-cvs] cvs commit: vorbis-tools/vorbiscomment vorbiscomment.c
Jack Moffitt
jack at xiph.org
Tue Sep 26 23:12:33 PDT 2000
jack 00/09/26 23:12:33
Modified: ogg123 ogg123.c
oggenc encode.c
vorbiscomment vorbiscomment.c
Log:
brought up to date with postbeta2
Revision Changes Path
1.2 +8 -6 vorbis-tools/ogg123/ogg123.c
Index: ogg123.c
===================================================================
RCS file: /usr/local/cvsroot/vorbis-tools/ogg123/ogg123.c,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- ogg123.c 2000/09/07 00:57:47 1.1
+++ ogg123.c 2000/09/27 06:12:32 1.2
@@ -14,7 +14,7 @@
* *
********************************************************************
- last mod: $Id: ogg123.c,v 1.1 2000/09/07 00:57:47 jack Exp $
+ last mod: $Id: ogg123.c,v 1.2 2000/09/27 06:12:32 jack Exp $
********************************************************************/
@@ -38,9 +38,9 @@
#include <fcntl.h> /* !!! */
#include <time.h> /* !!! */
#include <sys/time.h> /* !!! */
-#include <vorbis/codec.h>
-#include <vorbis/vorbisfile.h>
-#include <libao/audio_out.h>
+#include "vorbis/codec.h"
+#include "vorbis/vorbisfile.h"
+#include "libao/audio_out.h"
char convbuffer[4096]; /* take 8k out of the data segment, not the stack */
int convsize = 4096;
@@ -317,7 +317,8 @@
int current_section = -1, eos = 0, ret;
long t_min = 0, c_min = 0, r_min = 0;
double t_sec = 0, c_sec = 0, r_sec = 0;
-
+ int is_big_endian = ao_is_big_endian();
+
if (strcmp (param.read_file, "-")) /* input file not stdin */
{
if (!strncmp (param.read_file, "http://", 7))
@@ -462,7 +463,8 @@
while (! eos)
{
- switch ((ret = ov_read (&vf, convbuffer, sizeof (convbuffer), 0, 2, 1, ¤t_section))) {
+ switch ((ret = ov_read (&vf, convbuffer, sizeof (convbuffer),
+ is_big_endian, 2, 1, ¤t_section))) {
case 0: /* End of file */
eos = 1;
break;
1.4 +61 -50 vorbis-tools/oggenc/encode.c
Index: encode.c
===================================================================
RCS file: /usr/local/cvsroot/vorbis-tools/oggenc/encode.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- encode.c 2000/09/13 11:48:00 1.3
+++ encode.c 2000/09/27 06:12:32 1.4
@@ -21,6 +21,7 @@
#define READSIZE 1024
+static void update_statistics(char *fn, long total, long done, double time,long counter);
int oe_write_page(ogg_page *page, FILE *fp);
int oe_encode(oe_enc_opt *opt)
@@ -34,10 +35,11 @@
vorbis_block vb;
long samplesdone=0;
+ long counter=0,counter2=0;
int eos;
- long bytes_written = 0, packetsdone=0;
+ long bytes_written = 0;
- TIMER *timer;
+ void *timer;
/* get start time. */
@@ -67,9 +69,12 @@
/* And stream them out */
ogg_stream_packetin(&os,&header_main);
+ /* Possibly need to flush page here? */
ogg_stream_packetin(&os,&header_comments);
ogg_stream_packetin(&os,&header_codebooks);
+ /* Write out the headers - this ensures that the audio data starts at
+ * the start of a new page, making streaming easier */
while((result = ogg_stream_flush(&os, &og)))
{
if(!result) break;
@@ -93,16 +98,14 @@
{
samplesdone += samples_read;
- /* Call progress update every 10 pages */
- if(!opt->quiet && packetsdone>=10)
+ if((counter++%16==0) && !opt->quiet)
{
double time;
- packetsdone = 0;
time = timer_time(timer);
- opt->progress_update(opt->filename, opt->total_samples_per_channel,
- samplesdone, time);
+ update_statistics(opt->filename,
+ opt->total_samples_per_channel, samplesdone,time,counter2++);
}
/* Tell the library how many samples (per channel) we wrote
@@ -120,7 +123,6 @@
/* Add packet to bitstream */
ogg_stream_packetin(&os,&op);
- packetsdone++;
/* If we've gone over a page boundary, we can do actual output,
so do so (for however many pages are available) */
@@ -147,8 +149,27 @@
if(!opt->quiet)
{
- double time_elapsed = timer_time(timer);
- opt->end_encode(opt->filename, time_elapsed, opt->rate, samplesdone, bytes_written);
+ double time_elapsed, speed_ratio;
+ if(opt->filename)
+ fprintf(stderr, "\n\nDone encoding file \"%s\"\n", opt->filename);
+ else
+ fprintf(stderr, "\n\nDone encoding.\n");
+
+ time_elapsed = timer_time(timer);
+ speed_ratio = (double)samplesdone / (double)opt->rate / time_elapsed;
+
+
+ fprintf(stderr, "\n\tFile length: %dm %04.1fs\n",
+ (int)(samplesdone/opt->rate/60),
+ samplesdone/opt->rate -
+ floor(samplesdone/opt->rate/60)*60);
+ fprintf(stderr, "\tElapsed time: %dm %04.1fs\n",
+ (int)(time_elapsed/60),
+ time_elapsed - floor(time_elapsed/60)*60);
+ fprintf(stderr, "\tRate: %.4f\n", speed_ratio);
+ fprintf(stderr, "\tAverage bitrate: %.1f kb/s\n\n",
+ 8./1000.*((double)bytes_written/((double)samplesdone/(double)opt->rate)));
+
}
timer_clear(timer);
@@ -156,30 +177,41 @@
return 0;
}
-void update_statistics_full(char *fn, long total, long done, double time)
+static void update_statistics(char *fn, long total, long done, double time,long counter)
{
static char *spinner="|/-\\";
- static int spinpoint = 0;
double remain_time;
int minutes=0,seconds=0;
-
- remain_time = time/((double)done/(double)total) - time;
- minutes = ((int)remain_time)/60;
- seconds = (int)(remain_time - (double)((int)remain_time/60)*60);
-
- fprintf(stderr, "\rEncoding %s%s%s [%5.1f%%] [%2dm%.2ds remaining] %c",
- fn?"\"":"", fn?fn:"standard input", fn?"\"":"",
- done*100.0/total, minutes, seconds, spinner[spinpoint++%4]);
-}
-void update_statistics_notime(char *fn, long total, long done, double time)
-{
- static char *spinner="|/-\\";
- static int spinpoint =0;
-
- fprintf(stderr, "\rEncoding %s%s%s %c",
- fn?"\"":"", fn?fn:"standard input", fn?"\"":"",
- spinner[spinpoint++%4]);
+ if(total)
+ {
+ remain_time = time/((double)done/(double)total) - time;
+ minutes = ((int)remain_time)/60;
+ seconds = (int)(remain_time - (float)((int)remain_time/60)*60);
+ }
+
+ if(fn && total && time > 1.0)
+ fprintf(stderr, "\rEncoding \"%s\" [%5.1f%%] [%2dm%.2ds remaining] %c", fn,
+ done*100.0/total, minutes, seconds,
+ spinner[counter%4]);
+ else if(fn && total)
+ fprintf(stderr, "\rEncoding \"%s\" [%5.1f%%] %c", fn,
+ done*100.0/total,
+ spinner[counter%4]);
+ else if(fn)
+ fprintf(stderr, "\rEncoding \"%s\" [???%%] %c", fn,
+ spinner[counter%4]);
+ else if(total && time > 1.0)
+ fprintf(stderr, "\rEncoding to standard output [%5.1f%%] [%dm%ds remaining] %c",
+ done*100.0/total, minutes, seconds,
+ spinner[counter%4]);
+ else if(total)
+ fprintf(stderr, "\rEncoding to standard output [%5.1f%%] %c",
+ done*100.0/total,
+ spinner[counter%4]);
+ else
+ fprintf(stderr, "\rEncoding to standard output [???%%] %c",
+ spinner[counter%4]);
}
int oe_write_page(ogg_page *page, FILE *fp)
@@ -190,26 +222,5 @@
return page->header_len+page->body_len;
}
-void final_statistics(char *fn, double time, int rate, long samples, long bytes)
-{
- double speed_ratio;
- if(fn)
- fprintf(stderr, "\n\nDone encoding file \"%s\"\n", fn);
- else
- fprintf(stderr, "\n\nDone encoding.\n");
-
- speed_ratio = (double)samples / (double)rate / time;
-
- fprintf(stderr, "\n\tFile length: %dm %04.1fs\n",
- (int)(samples/rate/60),
- samples/rate -
- floor(samples/rate/60)*60);
- fprintf(stderr, "\tElapsed time: %dm %04.1fs\n",
- (int)(time/60),
- time - floor(time/60)*60);
- fprintf(stderr, "\tRate: %.4f\n", speed_ratio);
- fprintf(stderr, "\tAverage bitrate: %.1f kb/s\n\n",
- 8./1000.*((double)bytes/((double)samples/(double)rate)));
-}
1.2 +31 -7 vorbis-tools/vorbiscomment/vorbiscomment.c
Index: vorbiscomment.c
===================================================================
RCS file: /usr/local/cvsroot/vorbis-tools/vorbiscomment/vorbiscomment.c,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- vorbiscomment.c 2000/09/07 00:57:47 1.1
+++ vorbiscomment.c 2000/09/27 06:12:32 1.2
@@ -1,7 +1,22 @@
+/* This program is provided under the GNU General Public License, version 2,
+ * which is included with this program.
+ *
+ * (c) 2000 Michael Smith <msmith at labyrinth.net.au>
+ * Portions (c) 2000 Kenneth C. Arnold <kcarnold at yahoo.com>
+ *
+ * *********************************************************************
+ * Vorbis comment field editor - designed to be wrapped by scripts, etc.
+ * and as a proof of concept/example code/
+ *
+ * last mod: $Id: vorbiscomment.c,v 1.2 2000/09/27 06:12:32 jack Exp $
+ */
+
+
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
-#include <vorbis/codec.h>
+#include "vorbis/codec.h"
+#include "../lib/bitwise.h"
#define CHUNK 4096
@@ -10,10 +25,11 @@
int main(int argc, char **argv)
{
- unsigned char *buffer;
+ char *buffer;
int bytes;
int i;
int serial;
+ int result;
int eosin=0,eosout=0;
FILE *input, *output;
@@ -31,8 +47,10 @@
ogg_packet *header;
ogg_packet header_main;
+ ogg_packet header_main_original;
ogg_packet header_comments;
ogg_packet header_codebooks;
+ ogg_packet header_codebooks_original;
if(argc == 3)
{
@@ -108,13 +126,13 @@
exit(1);
}
- if(ogg_stream_packetout(&os,&header_main)!=1)
+ if(ogg_stream_packetout(&os,&header_main_original)!=1)
{
fprintf(stderr, "First header broken\n");
exit(1);
}
- if(vorbis_synthesis_headerin(&vi,&vc,&header_main)<0)
+ if(vorbis_synthesis_headerin(&vi,&vc,&header_main_original)<0)
{
fprintf(stderr, "ogg, but not vorbis\n");
exit(1);
@@ -140,7 +158,7 @@
}
vorbis_synthesis_headerin(&vi,&vc,header);
i++;
- header = &header_codebooks;
+ header = &header_codebooks_original;
}
}
}
@@ -200,13 +218,20 @@
ogg_stream_packetin(&out,&header_main);
ogg_stream_packetin(&out,&header_comments);
ogg_stream_packetin(&out,&header_codebooks);
+
+ while((result = ogg_stream_flush(&os, &og)))
+ {
+ if(!result) break;
+ fwrite(og.header,1, og.header_len, output);
+ fwrite(og.body,1,og.body_len, output);
+ }
/* Hard bit - stream ogg packets out, ogg packets in */
while(!(eosin && eosout)){
while(!(eosin && !eosout)){
- int result=ogg_sync_pageout(&oy,&og);
+ result=ogg_sync_pageout(&oy,&og);
if(result==0)break;
else if(result==-1)fprintf(stderr, "Error in bitstream, continuing\n");
else
@@ -259,7 +284,6 @@
int edit_comments(vorbis_comment *in, vorbis_comment *out)
{
char comment[1024];
- int pos = 0, ret = 0;
vorbis_comment_init(out);
while (1)
--- >8 ----
List archives: http://www.xiph.org/archives/
Ogg project homepage: http://www.xiph.org/ogg/
To unsubscribe from this list, send a message to 'cvs-request at xiph.org'
containing only the word 'unsubscribe' in the body. No subject is needed.
Unsubscribe messages sent to the list will be ignored/filtered.
More information about the commits
mailing list