function GroupDataAnalyzer(members,periodStartTime,periodEndTime) {
    var wonSamples = []; // List of samples in which member was the loudest. Array of arrays.
    var intervals = [];

    // init pos indexes for all members
    dataLog("Init pos");
    var membersPos = [];
    $.each(members, function (index, member) {
        var pos = -1;
        if (member.dataAnalyzer.getSamples().length > 0) {
            pos = 0;
        }
        membersPos[index] = pos;
        wonSamples[index] = [];
        intervals[index] = [];
    });

    // compare volumes
    for (var d = periodStartTime; d <= periodEndTime ; d = d + INTERVAL_INCREMENTS) {
        var dStart = d;
        var dEnd = d + INTERVAL_INCREMENTS;

        var newValue = {'timestamp':dStart,'memberIndex':-1,'vol':-1};
        //dataLog("Looking to match",dateToString(d));
        // progress pos in all members to point to relevant sample
        // and check if it's the loudest speaker for this interval
        $.each(members, function (index, member) {
            var samples = member.dataAnalyzer.getSamples();
            var pos = membersPos[index];
            if (pos == -1) return; // already reached end of array, move to the next member

            // keep going until you find intersection. also, stop if none was found
            while (pos < samples.length) {
                var sample = samples[pos];
                var sampleStart = sample.timestamp;
                var sampleEnd = sample.timestamp+sample.duration-1;

                if (checkIntersect(d,dEnd,sampleStart,sampleEnd)) {
                    //dataLog(index,"Found a match for ",dateToString(d),"Found!",dateToString(sampleStart));
                    // Only use samples that are louder than what we got, AND are
                    // louder than the threshold
                    if (sample.isSpeak && sample.volClippedSmooth > newValue.vol) {
                        newValue.memberIndex = index;
                        newValue.vol = sample.volClippedSmooth;
                        newValue.duration = INTERVAL_INCREMENTS;
                        //dataLog(index,"New max volume !",newValue.vol);
                    }
                    break;
                } else if (sampleStart > dEnd) {
                    // this condition handles gaps in data
                    //dataLog(index,"Not found, breaking");
                    break;
                } else {
                    pos++;
                }
            }
            // store for the next iteration
            membersPos[index] = pos;
        }); 

        // add sample to the "winning" member
        if (newValue.memberIndex > -1) {
            //dataLog("Pushing", newValue);
            wonSamples[newValue.memberIndex].push(newValue);
        }
    }

    // generate speaking intervals
    dataLog("Generating speaking intervals");
    $.each(members, function (index, member) {
        var v = generateTalkIntervals(wonSamples[index]);
        dataLog("intervals for "+index+" are "+v+" . had winning samples: "+wonSamples[index].length);
        $.each(v, function(index, iv) {
            dataLog(" -- "+iv.startTime+" "+iv.endTime+ " "+(iv.endTime-iv.startTime));
        });
        intervals[index] = v;
    });

    return intervals;
}
/*
 This function compares volume data from group members and creates speaking
 intervals. Expects a members object
 */
This function compares volume data from group members and creates speaking
intervals. Expects a members object
This function compares volume data from group members and creates speaking intervals . Expects a members object
function GroupDataAnalyzer(members,periodStartTime,periodEndTime) {
    var wonSamples = []; 
    var intervals = [];
    dataLog("Init pos");
    var membersPos = [];
    $.each(members, function (index, member) {
        var pos = -1;
        if (member.dataAnalyzer.getSamples().length > 0) {
            pos = 0;
        }
        membersPos[index] = pos;
        wonSamples[index] = [];
        intervals[index] = [];
    });
    for (var d = periodStartTime; d <= periodEndTime ; d = d + INTERVAL_INCREMENTS) {
        var dStart = d;
        var dEnd = d + INTERVAL_INCREMENTS;
        var newValue = {'timestamp':dStart,'memberIndex':-1,'vol':-1};
        $.each(members, function (index, member) {
            var samples = member.dataAnalyzer.getSamples();
            var pos = membersPos[index];
            if (pos == -1) return; 
            while (pos < samples.length) {
                var sample = samples[pos];
                var sampleStart = sample.timestamp;
                var sampleEnd = sample.timestamp+sample.duration-1;
                if (checkIntersect(d,dEnd,sampleStart,sampleEnd)) {
                    if (sample.isSpeak && sample.volClippedSmooth > newValue.vol) {
                        newValue.memberIndex = index;
                        newValue.vol = sample.volClippedSmooth;
                        newValue.duration = INTERVAL_INCREMENTS;
                    }
                    break;
                } else if (sampleStart > dEnd) {
                    break;
                } else {
                    pos++;
                }
            }
            membersPos[index] = pos;
        }); 
        if (newValue.memberIndex > -1) {
            wonSamples[newValue.memberIndex].push(newValue);
        }
    }
    dataLog("Generating speaking intervals");
    $.each(members, function (index, member) {
        var v = generateTalkIntervals(wonSamples[index]);
        dataLog("intervals for "+index+" are "+v+" . had winning samples: "+wonSamples[index].length);
        $.each(v, function(index, iv) {
            dataLog(" -- "+iv.startTime+" "+iv.endTime+ " "+(iv.endTime-iv.startTime));
        });
        intervals[index] = v;
    });
    return intervals;
}
function GroupDataAnalyzer ( members , periodStartTime , periodEndTime ) { var wonSamples = [ ] ; var intervals = [ ] ; dataLog ( "Init pos" ) ; var membersPos = [ ] ; $ . each ( members , function ( index , member ) { var pos = - 1 ; if ( member . dataAnalyzer . getSamples ( ) . length > 0 ) { pos = 0 ; } membersPos [ index ] = pos ; wonSamples [ index ] = [ ] ; intervals [ index ] = [ ] ; } ) ; for ( var d = periodStartTime ; d <= periodEndTime ; d = d + INTERVAL_INCREMENTS ) { var dStart = d ; var dEnd = d + INTERVAL_INCREMENTS ; var newValue = { 'timestamp' : dStart , 'memberIndex' : - 1 , 'vol' : - 1 } ; $ . each ( members , function ( index , member ) { var samples = member . dataAnalyzer . getSamples ( ) ; var pos = membersPos [ index ] ; if ( pos == - 1 ) return ; while ( pos < samples . length ) { var sample = samples [ pos ] ; var sampleStart = sample . timestamp ; var sampleEnd = sample . timestamp + sample . duration - 1 ; if ( checkIntersect ( d , dEnd , sampleStart , sampleEnd ) ) { if ( sample . isSpeak && sample . volClippedSmooth > newValue . vol ) { newValue . memberIndex = index ; newValue . vol = sample . volClippedSmooth ; newValue . duration = INTERVAL_INCREMENTS ; } break ; } else if ( sampleStart > dEnd ) { break ; } else { pos ++ ; } } membersPos [ index ] = pos ; } ) ; if ( newValue . memberIndex > - 1 ) { wonSamples [ newValue . memberIndex ] . push ( newValue ) ; } } dataLog ( "Generating speaking intervals" ) ; $ . each ( members , function ( index , member ) { var v = generateTalkIntervals ( wonSamples [ index ] ) ; dataLog ( "intervals for " + index + " are " + v + " . had winning samples: " + wonSamples [ index ] . length ) ; $ . each ( v , function ( index , iv ) { dataLog ( " -- " + iv . startTime + " " + iv . endTime + " " + ( iv . endTime - iv . startTime ) ) ; } ) ; intervals [ index ] = v ; } ) ; return intervals ; }
This function compares volume data from group members and creates speaking
intervals.
This function compares volume data from group members and creates speaking intervals .
// List of samples in which member was the loudest. Array of arrays. // init pos indexes for all members // compare volumes //dataLog("Looking to match",dateToString(d)); // progress pos in all members to point to relevant sample // and check if it's the loudest speaker for this interval // already reached end of array, move to the next member // keep going until you find intersection. also, stop if none was found //dataLog(index,"Found a match for ",dateToString(d),"Found!",dateToString(sampleStart)); // Only use samples that are louder than what we got, AND are // louder than the threshold //dataLog(index,"New max volume !",newValue.vol); // this condition handles gaps in data //dataLog(index,"Not found, breaking"); // store for the next iteration // add sample to the "winning" member //dataLog("Pushing", newValue); // generate speaking intervals