shithub: opus-tools

Download patch

ref: ca4927a9acf69e35788e146201284609d9a86240
parent: 790ac62cf333c202a8d566c0c88ccaeb0689b7a0
author: Gregory Maxwell <greg@xiph.org>
date: Sat May 19 19:52:34 EDT 2012

Now all wav files >2GiB encode completely.

--- a/src/audio-in.c
+++ b/src/audio-in.c
@@ -575,13 +575,13 @@
                                             of trying to abstract stuff. */
         wav->samplesize = format.samplesize;
 
-        if(len)
+        if(len>(format.channels*samplesize*4U) && len<((1U<<31)-65536)) /*Length provided is plausible.*/
         {
             opt->total_samples_per_channel = len/(format.channels*samplesize);
         }
         else
         {
-            long pos;
+            opus_int64 pos;
             pos = ftell(in);
             if(fseek(in, 0, SEEK_END) == -1)
             {
@@ -626,14 +626,9 @@
     signed char *buf = alloca(samples*sampbyte*f->channels);
     long bytes_read = fread(buf, 1, samples*sampbyte*f->channels, f->f);
     int i,j;
-    long realsamples;
+    opus_int64 realsamples;
     int *ch_permute = f->channel_permute;
 
-    if(f->totalsamples && f->samplesread +
-            bytes_read/(sampbyte*f->channels) > f->totalsamples) {
-        bytes_read = sampbyte*f->channels*(f->totalsamples - f->samplesread);
-    }
-
     realsamples = bytes_read/(sampbyte*f->channels);
     f->samplesread += realsamples;
 
@@ -709,11 +704,8 @@
     float *buf = alloca(samples*4*f->channels); /* de-interleave buffer */
     long bytes_read = fread(buf,1,samples*4*f->channels, f->f);
     int i,j;
-    long realsamples;
+    opus_int64 realsamples;
 
-    if(f->totalsamples && f->samplesread +
-            bytes_read/(4*f->channels) > f->totalsamples)
-        bytes_read = 4*f->channels*(f->totalsamples - f->samplesread);
     realsamples = bytes_read/(4*f->channels);
     f->samplesread += realsamples;
 
--- a/src/opusdec.c
+++ b/src/opusdec.c
@@ -6,14 +6,14 @@
    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.
-   
+
    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/src/opusenc.c
+++ b/src/opusenc.c
@@ -152,7 +152,7 @@
 
 static inline void print_time(double seconds)
 {
-  long long hours, minutes;
+  opus_int64 hours, minutes;
   hours=seconds/3600;
   seconds-=hours*3600.;
   minutes=seconds/60;
--- a/src/opusenc.h
+++ b/src/opusenc.h
@@ -1,6 +1,8 @@
 #ifndef __OPUSENC_H
 #define __OPUSENC_H
 
+#include <opus_types.h>
+
 #ifdef ENABLE_NLS
 #include <libintl.h>
 #define _(X) gettext(X)
@@ -21,7 +23,7 @@
 {
     audio_read_func read_samples;
     void *readdata;
-    long total_samples_per_channel;
+    opus_int64 total_samples_per_channel;
     int rawmode;
     int channels;
     long rate;
@@ -31,7 +33,7 @@
     int ignorelength;
     int skip;
     int extraout;
-} oe_enc_opt;            
+} oe_enc_opt;
 
 void setup_scaler(oe_enc_opt *opt, float scale);
 void clear_scaler(oe_enc_opt *opt);
@@ -63,16 +65,16 @@
 typedef struct {
     short channels;
     short samplesize;
-    long totalsamples;
-    long samplesread;
+    opus_int64 totalsamples;
+    opus_int64 samplesread;
     FILE *f;
     short bigendian;
-        int *channel_permute;
+    int *channel_permute;
 } wavfile;
 
 typedef struct {
     short channels;
-    int totalframes;
+    opus_int64 totalframes;
     short samplesize;
     int rate;
     int offset;
--- a/src/stack_alloc.h
+++ b/src/stack_alloc.h
@@ -7,18 +7,18 @@
    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 the Xiph.org Foundation 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
@@ -101,7 +101,7 @@
 #endif
 
 #if defined(VAR_ARRAYS)
-#define VARDECL(var) 
+#define VARDECL(var)
 #define ALLOC(var, size, type) type var[size]
 #elif defined(USE_ALLOCA)
 #define VARDECL(var) var