Sequencer audio waveform drawing fix, now assured to be within the strip bounds.
authorJoerg Mueller <nexyon@gmail.com>
Mon, 10 Oct 2011 14:59:13 +0000 (14:59 +0000)
committerJoerg Mueller <nexyon@gmail.com>
Mon, 10 Oct 2011 14:59:13 +0000 (14:59 +0000)
intern/audaspace/intern/AUD_C-API.cpp

index d5c3e368e282c625a2e539439374e506a5a60d56..af053df9c50ada6f091b019257bf11b372757d05 100644 (file)
@@ -1094,9 +1094,11 @@ int AUD_readSound(AUD_Sound* sound, sample_t* buffer, int length, int samples_pe
        specs.specs = reader->getSpecs();
        int len;
        float samplejump = specs.rate / samples_per_second;
-       float min, max, power;
+       float min, max, power, overallmax;
        bool eos;
 
+       overallmax = 0;
+
        for(int i = 0; i < length; i++)
        {
                len = floor(samplejump * (i+1)) - floor(samplejump * i);
@@ -1121,6 +1123,11 @@ int AUD_readSound(AUD_Sound* sound, sample_t* buffer, int length, int samples_pe
                buffer[i * 3 + 1] = max;
                buffer[i * 3 + 2] = sqrt(power) / len;
 
+               if(overallmax < max)
+                       overallmax = max;
+               if(overallmax < -min)
+                       overallmax = -min;
+
                if(eos)
                {
                        length = i;
@@ -1128,6 +1135,14 @@ int AUD_readSound(AUD_Sound* sound, sample_t* buffer, int length, int samples_pe
                }
        }
 
+       if(overallmax > 1.0f)
+       {
+               for(int i = 0; i < length * 3; i++)
+               {
+                       buffer[i] /= overallmax;
+               }
+       }
+
        return length;
 }