Revision: 39211
          
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=39211
Author:   nexyon
Date:     2011-08-09 14:10:32 +0000 (Tue, 09 Aug 2011)
Log Message:
-----------
3D Audio GSoC:
Improved waveform drawing in the sequencer.

* Drawing the waveform of a sequencer strip is now independent from whether the 
sound is cached or not.
* Improved drawing of the waveform in the sequencer (especially speed!).
* Making it possible to vertically zoom more in the sequencer to better see the 
waveform for lipsync.
* Fixed a bug which crashed blender on loading a sound file via ffmpeg.

Modified Paths:
--------------
    branches/soc-2011-pepper/intern/audaspace/ffmpeg/AUD_FFMPEGReader.cpp
    branches/soc-2011-pepper/intern/audaspace/intern/AUD_C-API.cpp
    branches/soc-2011-pepper/intern/audaspace/intern/AUD_C-API.h
    branches/soc-2011-pepper/release/scripts/startup/bl_ui/space_sequencer.py
    branches/soc-2011-pepper/source/blender/blenkernel/BKE_sound.h
    branches/soc-2011-pepper/source/blender/blenkernel/intern/sound.c
    branches/soc-2011-pepper/source/blender/blenloader/intern/readfile.c
    
branches/soc-2011-pepper/source/blender/editors/space_sequencer/sequencer_draw.c
    
branches/soc-2011-pepper/source/blender/editors/space_sequencer/space_sequencer.c
    branches/soc-2011-pepper/source/blender/makesdna/DNA_sequence_types.h
    branches/soc-2011-pepper/source/blender/makesdna/DNA_sound_types.h
    branches/soc-2011-pepper/source/blender/makesrna/intern/rna_sequencer.c

Modified: branches/soc-2011-pepper/intern/audaspace/ffmpeg/AUD_FFMPEGReader.cpp
===================================================================
--- branches/soc-2011-pepper/intern/audaspace/ffmpeg/AUD_FFMPEGReader.cpp       
2011-08-09 13:50:27 UTC (rev 39210)
+++ branches/soc-2011-pepper/intern/audaspace/ffmpeg/AUD_FFMPEGReader.cpp       
2011-08-09 14:10:32 UTC (rev 39211)
@@ -177,6 +177,7 @@
 
 AUD_FFMPEGReader::AUD_FFMPEGReader(std::string filename) :
        m_pkgbuf(AVCODEC_MAX_AUDIO_FRAME_SIZE<<1),
+       m_formatCtx(NULL),
        m_aviocontext(NULL),
        m_membuf(NULL)
 {

Modified: branches/soc-2011-pepper/intern/audaspace/intern/AUD_C-API.cpp
===================================================================
--- branches/soc-2011-pepper/intern/audaspace/intern/AUD_C-API.cpp      
2011-08-09 13:50:27 UTC (rev 39210)
+++ branches/soc-2011-pepper/intern/audaspace/intern/AUD_C-API.cpp      
2011-08-09 14:10:32 UTC (rev 39211)
@@ -816,7 +816,7 @@
        if(high < rate)
                sound = new AUD_LowpassFactory(sound, high);
        if(low > 0)
-               sound = new AUD_HighpassFactory(sound, low);;
+               sound = new AUD_HighpassFactory(sound, low);
 
        sound = new AUD_EnvelopeFactory(sound, attack, release, threshold, 
0.1f);
        sound = new AUD_LinearResampleFactory(sound, specs);
@@ -1055,7 +1055,7 @@
        return -1;
 }
 
-int AUD_readSound(AUD_Sound* sound, sample_t* buffer, int length)
+int AUD_readSound(AUD_Sound* sound, sample_t* buffer, int length, int 
samples_per_second)
 {
        AUD_DeviceSpecs specs;
        sample_t* buf;
@@ -1067,39 +1067,41 @@
 
        AUD_Reference<AUD_IReader> reader = AUD_ChannelMapperFactory(*sound, 
specs).createReader();
 
-       int len = reader->getLength();
-       float samplejump = (float)len / (float)length;
-       float min, max;
+       specs.specs = reader->getSpecs();
+       int len;
+       float samplejump = specs.rate / samples_per_second;
+       float min, max, power;
        bool eos;
 
        for(int i = 0; i < length; i++)
        {
                len = floor(samplejump * (i+1)) - floor(samplejump * i);
 
-               if(aBuffer.getSize() < len * 
AUD_SAMPLE_SIZE(reader->getSpecs()))
-               {
-                       aBuffer.resize(len * 
AUD_SAMPLE_SIZE(reader->getSpecs()));
-                       buf = aBuffer.getBuffer();
-               }
+               aBuffer.assureSize(len * AUD_SAMPLE_SIZE(specs));
+               buf = aBuffer.getBuffer();
 
                reader->read(len, eos, buf);
 
-               if(eos)
-               {
-                       length = i;
-                       break;
-               }
-
                max = min = *buf;
+               power = *buf * *buf;
                for(int j = 1; j < len; j++)
                {
                        if(buf[j] < min)
                                min = buf[j];
                        if(buf[j] > max)
                                max = buf[j];
-                       buffer[i * 2] = min;
-                       buffer[i * 2 + 1] = max;
+                       power += buf[j] * buf[j];
                }
+
+               buffer[i * 3] = min;
+               buffer[i * 3 + 1] = max;
+               buffer[i * 3 + 2] = sqrt(power) / len;
+
+               if(eos)
+               {
+                       length = i;
+                       break;
+               }
        }
 
        return length;

Modified: branches/soc-2011-pepper/intern/audaspace/intern/AUD_C-API.h
===================================================================
--- branches/soc-2011-pepper/intern/audaspace/intern/AUD_C-API.h        
2011-08-09 13:50:27 UTC (rev 39210)
+++ branches/soc-2011-pepper/intern/audaspace/intern/AUD_C-API.h        
2011-08-09 14:10:32 UTC (rev 39211)
@@ -502,7 +502,7 @@
 
 extern int AUD_doesPlayback(void);
 
-extern int AUD_readSound(AUD_Sound* sound, sample_t* buffer, int length);
+extern int AUD_readSound(AUD_Sound* sound, sample_t* buffer, int length, int 
samples_per_second);
 
 extern AUD_Sound* AUD_copy(AUD_Sound* sound);
 

Modified: 
branches/soc-2011-pepper/release/scripts/startup/bl_ui/space_sequencer.py
===================================================================
--- branches/soc-2011-pepper/release/scripts/startup/bl_ui/space_sequencer.py   
2011-08-09 13:50:27 UTC (rev 39210)
+++ branches/soc-2011-pepper/release/scripts/startup/bl_ui/space_sequencer.py   
2011-08-09 14:10:32 UTC (rev 39211)
@@ -638,6 +638,7 @@
 
         row.prop(strip.sound, "use_memory_cache")
 
+        layout.prop(strip, "waveform")
         layout.prop(strip, "volume")
         layout.prop(strip, "attenuation")
         layout.prop(strip, "pitch")

Modified: branches/soc-2011-pepper/source/blender/blenkernel/BKE_sound.h
===================================================================
--- branches/soc-2011-pepper/source/blender/blenkernel/BKE_sound.h      
2011-08-09 13:50:27 UTC (rev 39210)
+++ branches/soc-2011-pepper/source/blender/blenkernel/BKE_sound.h      
2011-08-09 14:10:32 UTC (rev 39211)
@@ -35,6 +35,8 @@
  *  \author nzc
  */
 
+#define SOUND_WAVE_SAMPLES_PER_SECOND 250
+
 struct PackedFile;
 struct bSound;
 struct bContext;
@@ -42,6 +44,12 @@
 struct Main;
 struct Sequence;
 
+typedef struct SoundWaveform
+{
+       int length;
+       float *data;
+} SoundWaveform;
+
 void sound_init_once(void);
 
 void sound_init(struct Main *main);
@@ -122,8 +130,10 @@
 
 int sound_scene_playing(struct Scene *scene);
 
-int sound_read_sound_buffer(struct bSound* sound, float* buffer, int length, 
float start, float end);
+void sound_free_waveform(struct bSound* sound);
 
+void sound_read_waveform(struct bSound* sound);
+
 int sound_get_channels(struct bSound* sound);
 
 void sound_update_scene(struct Main* bmain, struct Scene* scene);

Modified: branches/soc-2011-pepper/source/blender/blenkernel/intern/sound.c
===================================================================
--- branches/soc-2011-pepper/source/blender/blenkernel/intern/sound.c   
2011-08-09 13:50:27 UTC (rev 39210)
+++ branches/soc-2011-pepper/source/blender/blenkernel/intern/sound.c   
2011-08-09 14:10:32 UTC (rev 39211)
@@ -24,6 +24,7 @@
 #include "DNA_sound_types.h"
 #include "DNA_speaker_types.h"
 
+#define WITH_AUDASPACE
 #ifdef WITH_AUDASPACE
 #  include "AUD_C-API.h"
 #endif
@@ -96,6 +97,8 @@
                AUD_unload(sound->cache);
                sound->cache = NULL;
        }
+
+       sound_free_waveform(sound);
 #endif // WITH_AUDASPACE
 }
 
@@ -608,14 +611,36 @@
                return -1;
 }
 
-int sound_read_sound_buffer(struct bSound* sound, float* buffer, int length, 
float start, float end)
+void sound_free_waveform(struct bSound* sound)
 {
-       AUD_Sound* limiter = AUD_limitSound(sound->cache, start, end);
-       int ret= AUD_readSound(limiter, buffer, length);
-       AUD_unload(limiter);
-       return ret;
+       if(sound->waveform)
+       {
+               MEM_freeN(((SoundWaveform*)sound->waveform)->data);
+               MEM_freeN(sound->waveform);
+       }
+
+       sound->waveform = NULL;
 }
 
+void sound_read_waveform(struct bSound* sound)
+{
+       AUD_SoundInfo info;
+
+       info = AUD_getInfo(sound->playback_handle);
+
+       if(info.length > 0)
+       {
+               SoundWaveform* waveform = MEM_mallocN(sizeof(SoundWaveform), 
"SoundWaveform");;
+               int length = info.length * SOUND_WAVE_SAMPLES_PER_SECOND;
+
+               waveform->data = MEM_mallocN(length * sizeof(float) * 3, 
"SoundWaveform.samples");
+               waveform->length = AUD_readSound(sound->playback_handle, 
waveform->data, length, SOUND_WAVE_SAMPLES_PER_SECOND);
+
+               sound_free_waveform(sound);
+               sound->waveform = waveform;
+       }
+}
+
 int sound_get_channels(struct bSound* sound)
 {
        AUD_SoundInfo info;

Modified: branches/soc-2011-pepper/source/blender/blenloader/intern/readfile.c
===================================================================
--- branches/soc-2011-pepper/source/blender/blenloader/intern/readfile.c        
2011-08-09 13:50:27 UTC (rev 39210)
+++ branches/soc-2011-pepper/source/blender/blenloader/intern/readfile.c        
2011-08-09 14:10:32 UTC (rev 39211)
@@ -5609,6 +5609,7 @@
 {
        sound->handle = NULL;
        sound->playback_handle = NULL;
+       sound->waveform = NULL;
 
        // versioning stuff, if there was a cache, then we enable caching:
        if(sound->cache)
@@ -11767,6 +11768,36 @@
                        }
                }
                {
+                       bScreen *screen;
+                       for(screen= main->screen.first; screen; screen= 
screen->id.next) {
+                               ScrArea *sa;
+                               /* add regions */
+                               for(sa= screen->areabase.first; sa; sa= 
sa->next) {
+                                       SpaceLink *sl= sa->spacedata.first;
+                                       if(sl->spacetype==SPACE_SEQ) {
+                                               ARegion *ar;
+                                               for (ar=sa->regionbase.first; 
ar; ar= ar->next) {
+                                                       if(ar->regiontype == 
RGN_TYPE_WINDOW) {
+                                                               
if(ar->v2d.min[1] == 4.0f)
+                                                                       
ar->v2d.min[1]= 0.5f;
+                                                       }
+                                               }
+                                       }
+                                       for (sl= sa->spacedata.first; sl; sl= 
sl->next) {
+                                               if(sl->spacetype==SPACE_SEQ) {
+                                                       ARegion *ar;
+                                                       for 
(ar=sl->regionbase.first; ar; ar= ar->next) {
+                                                               
if(ar->regiontype == RGN_TYPE_WINDOW) {
+                                                                       
if(ar->v2d.min[1] == 4.0f)
+                                                                               
ar->v2d.min[1]= 0.5f;
+                                                               }
+                                                       }
+                                               }
+                                       }
+                               }
+                       }
+               }
+               {
                        /* Make "auto-clamped" handles a per-keyframe setting 
instead of per-FCurve 
                         *
                         * We're only patching F-Curves in Actions here, since 
it is assumed that most

Modified: 
branches/soc-2011-pepper/source/blender/editors/space_sequencer/sequencer_draw.c
===================================================================
--- 
branches/soc-2011-pepper/source/blender/editors/space_sequencer/sequencer_draw.c
    2011-08-09 13:50:27 UTC (rev 39210)
+++ 
branches/soc-2011-pepper/source/blender/editors/space_sequencer/sequencer_draw.c
    2011-08-09 14:10:32 UTC (rev 39211)
@@ -173,30 +173,63 @@
        x2 the end x value, same for y1 and y2
        stepsize is width of a pixel.
        */
-       if(seq->sound->cache)
+       if(seq->flag & SEQ_AUDIO_DRAW_WAVEFORM)
        {
-               int i;
+               int i, j, pos;
                int length = floor((x2-x1)/stepsize)+1;
                float ymid = (y1+y2)/2;
                float yscale = (y2-y1)/2;
-               float* samples = MEM_mallocN(length * sizeof(float) * 2, 
"seqwave_samples");
-               if(!samples)
-                       return;
-               if(sound_read_sound_buffer(seq->sound, samples, length,
-                                                                  
(seq->startofs + seq->anim_startofs)/FPS,
-                                                                  
(seq->startofs + seq->anim_startofs + seq->enddisp - seq->startdisp)/FPS) != 
length)
+               float samplestep;
+               float startsample, endsample;
+               float value;
+
+               SoundWaveform* waveform;
+
+               if(!seq->sound->waveform)
+                       sound_read_waveform(seq->sound);
+
+               waveform = seq->sound->waveform;
+
+               startsample = floor((seq->startofs + seq->anim_startofs)/FPS * 
SOUND_WAVE_SAMPLES_PER_SECOND);
+               endsample = ceil((seq->startofs + seq->anim_startofs + 
seq->enddisp - seq->startdisp)/FPS * SOUND_WAVE_SAMPLES_PER_SECOND);
+               samplestep = (endsample-startsample) * stepsize / (x2-x1);
+
+               if(length > floor((waveform->length - startsample) / 
samplestep))
+                       length = floor((waveform->length - startsample) / 
samplestep);
+
+               glBegin(GL_LINE_STRIP);
+               for(i = 0; i < length; i++)
                {
-                       MEM_freeN(samples);
-                       return;
+                       pos = startsample + i * samplestep;
+
+                       value = waveform->data[pos * 3];
+
+                       for(j = pos+1; (j < waveform->length) && (j < pos + 
samplestep); j++)
+                       {
+                               if(value > waveform->data[j * 3])
+                                       value = waveform->data[j * 3];
+                       }
+
+                       glVertex2f(x1+i*stepsize, ymid + value * yscale);
                }
-               glBegin(GL_LINES);
+               glEnd();
+
+               glBegin(GL_LINE_STRIP);

@@ Diff output truncated at 10240 characters. @@
_______________________________________________
Bf-blender-cvs mailing list
[email protected]
http://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to