Gabriel M. Beddingfield wrote:
Gabriel M. Beddingfield wrote:
Sebastian Moors wrote:
after more tests i found out that the change appears with revision 210.
This is the revision in which the lead and lag feature was introduced.
It would be great if someone with more knowledge of the audio-internals could look
into that part of code..

Fixed in Rev 527.  Commit messages/patches attached, FYI.

Thanks,
Gabriel

commit 3e820e3d31c42e697cb39ae69784ce66652d1855
Author: gabriel <[EMAIL PROTECTED]>
Date:   Sat Sep 27 17:46:55 2008 +0000

    Redefine getTickPosition() to return the actual tick position (without any 
lookahead).
    
    A forum user reported [1] that MIDI notes are *sounding* at the right time,
    but being *recorded* about 1/16th late.  Sebastian Moors (smoors) said [2]
    that he isolated to SVN rev 210, where lead-lag was introduced.  In
    that commit, the value of m_nPatternTickPosition was adjusted to
    include a lookahead factor.  This allowed notes with positive lead and
    positive humanize (i.e. before the beat) to be correctly scheduled.
    However, realtime notes were then recorded *with* the leadlag, putting
    notes 5 ticks + 2000 frames late (typ. 8-11 ticks).  It was typically
    not noticeable with quantize on -- but with quantize off, it was
    always present.  To correct this, I rewrote getTickPosition() to
    recalculate the tick... rather than use the global
    m_nPatternTickPosition (which is integral to updateNoteQueue's
    scheduling).
    
    This commit has one (minor) issue:  If you turn on quantize and you
    give a note that is way out in front of the beat (at the edge of the
    quantize window), you will probably hear the note twice:  Once for the
    realtime event, and once for the note that was recorded in the
    pattern.  I believe that this only happens when the realtime note and
    the scheduled (quantized) note differ by the amount of lookahead.
    
    [1] 
http://www.hydrogen-music.org/forum/?action=show_thread&thread=882&fid=5&page=1
    [2] e-mail to [EMAIL PROTECTED], 08SEP2008.
    
    git-svn-id: http://hydrogen-music.org/svn/[EMAIL PROTECTED] 
3b3fb362-3133-0410-aa15-cf69e0a59cb7

diff --git a/libs/hydrogen/src/hydrogen.cpp b/libs/hydrogen/src/hydrogen.cpp
index ac27db4..06ebcfc 100644
--- a/libs/hydrogen/src/hydrogen.cpp
+++ b/libs/hydrogen/src/hydrogen.cpp
@@ -1414,12 +1414,6 @@ void audioEngine_noteOff( Note *note )
 
 
 
-// unsigned long audioEngine_getTickPosition()
-// {
-//     return m_nPatternTickPosition;
-// }
-
-
 AudioOutput* createDriver( const QString& sDriver )
 {
        _INFOLOG( QString( "Driver: '%1'" ).arg( sDriver ) );
@@ -1888,8 +1882,8 @@ void Hydrogen::addRealtimeNote( int instrument,
                                );
 
                        // hear note if its not in the future
-                       if ( pref->getHearNewNotes()
-                            && position <= getTickPosition() ) {
+                       // Let the scheduler worry if it's in the future or not.
+                       if ( pref->getHearNewNotes() ) {
                                hearnote = true;
                        }
 
@@ -1930,10 +1924,31 @@ float Hydrogen::getMasterPeak_R()
 }
 
 
-
+// Returns the current (real-time) tick, relative to the current
+// (or first) pattern being played.
 unsigned long Hydrogen::getTickPosition()
 {
-       return m_nPatternTickPosition;
+       if( m_pSong == 0 ) {
+               return 0;
+       }
+       TransportInfo& xsp = m_pAudioDriver->m_transport;
+       int tick, starttick, patsize, rv;
+       tick = xsp.m_nFrames / xsp.m_nTickSize;
+       starttick = 0;
+       patsize = 1;
+       if( m_pSong->get_mode() == Song::SONG_MODE ) {
+               rv = findPatternInTick( tick, m_pSong->is_loop_enabled(), 
&starttick);
+               if(m_nSongSizeInTicks > 0) patsize = m_nSongSizeInTicks;
+       } else if( (m_pSong->get_mode() == Song::PATTERN_MODE)
+                  && (m_pPlayingPatterns->get_size() != 0)) {
+               starttick = m_nPatternStartTick;
+               patsize = m_pPlayingPatterns->get(0)->get_lenght();
+       } // else make do with the absolute tick.
+       tick = ( tick - starttick );
+       if(patsize > 1) tick %= patsize;
+       if(tick < 0) tick += patsize;
+       assert(tick >= 0);
+       return (unsigned)tick;
 }
 
 

commit 1278e6eaceb612af3d4da64c26433199e0d4d819
Author: gabriel <[EMAIL PROTECTED]>
Date:   Sat Sep 27 17:46:48 2008 +0000

    Add bounds checking to Note::set_leadlag().
    
    The Note queueing logic (hydrogen.cpp) assume that get_leadlag()
    will return a value between -1.0 and 1.0 (inclusive).  This enforces
    that assumption.
    
    git-svn-id: http://hydrogen-music.org/svn/[EMAIL PROTECTED] 
3b3fb362-3133-0410-aa15-cf69e0a59cb7

diff --git a/libs/hydrogen/include/hydrogen/note.h 
b/libs/hydrogen/include/hydrogen/note.h
index 68455af..b275159 100644
--- a/libs/hydrogen/include/hydrogen/note.h
+++ b/libs/hydrogen/include/hydrogen/note.h
@@ -23,6 +23,7 @@
 #ifndef H2_NOTE_H
 #define H2_NOTE_H
 
+#include <cassert>
 #include <hydrogen/Object.h>
 #include <hydrogen/adsr.h>
 
@@ -170,9 +171,17 @@ public:
 
 
        void set_leadlag( float leadlag ) {
-               __leadlag = leadlag;
+               if(leadlag > 1.0) {
+                       __leadlag = 1.0;
+               } else if (leadlag < -1.0) {
+                       __leadlag = -1.0;
+               } else {
+                       __leadlag = leadlag;
+               }
        }
        float get_leadlag() const {
+               assert(__leadlag <=  1.0);
+               assert(__leadlag >= -1.0);
                return __leadlag;
        }
 
-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
Hydrogen-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/hydrogen-devel

Reply via email to