@Test public void shouldReturnTwoArraysPositionV2() { int barCount = 2; Integer[] expectedOne = new Integer[]{1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}; Integer[] expectedTwo = new Integer[]{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}; Double[] inputs = new Double[]{2.7325, 0.08, 5.7325}; List<Integer[]> actual = rhythmApp.getOnsetIndexes(inputs, barCount, 3.0f); assertThat(actual.size()).isEqualTo(2); assertThat(actual.get(0)).isEqualTo(expectedOne); assertThat(actual.get(1)).isEqualTo(expectedTwo); }
public List<Integer[]> getOnsetIndexes(Double[] onsetTimes, int barCount, float barInSec) { List<Integer[]> onsetIndexCollection = new ArrayList<>(); for (int bc = 0; bc < barCount; bc++) { Integer[] onsetIndexes = new Integer[]{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; double sixteenthInterval = 0.1875; double intervalWindow = sixteenthInterval / 2; for (int i = 0; i < onsetIndexes.length; i++) { for (double onsetTime : onsetTimes) { if (i == 0) { if (onsetTime - ((float) bc * barInSec) > (sixteenthInterval * i) - intervalWindow && onsetTime - ((float) bc * barInSec) <= (sixteenthInterval * i) + intervalWindow) { onsetIndexes[i] = 1; } } else { if (onsetTime - ((float) bc * barInSec) > (sixteenthInterval * i) - intervalWindow && onsetTime - ((float) bc * barInSec) <= (sixteenthInterval * i) + intervalWindow) { onsetIndexes[i] = 1; } } } } onsetIndexCollection.add(onsetIndexes); } return onsetIndexCollection; }
RhythmicExtractionUtil implements OnsetHandler { public List<Integer[]> getOnsetIndexes(Double[] onsetTimes, int barCount, float barInSec) { List<Integer[]> onsetIndexCollection = new ArrayList<>(); for (int bc = 0; bc < barCount; bc++) { Integer[] onsetIndexes = new Integer[]{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; double sixteenthInterval = 0.1875; double intervalWindow = sixteenthInterval / 2; for (int i = 0; i < onsetIndexes.length; i++) { for (double onsetTime : onsetTimes) { if (i == 0) { if (onsetTime - ((float) bc * barInSec) > (sixteenthInterval * i) - intervalWindow && onsetTime - ((float) bc * barInSec) <= (sixteenthInterval * i) + intervalWindow) { onsetIndexes[i] = 1; } } else { if (onsetTime - ((float) bc * barInSec) > (sixteenthInterval * i) - intervalWindow && onsetTime - ((float) bc * barInSec) <= (sixteenthInterval * i) + intervalWindow) { onsetIndexes[i] = 1; } } } } onsetIndexCollection.add(onsetIndexes); } return onsetIndexCollection; } }
RhythmicExtractionUtil implements OnsetHandler { public List<Integer[]> getOnsetIndexes(Double[] onsetTimes, int barCount, float barInSec) { List<Integer[]> onsetIndexCollection = new ArrayList<>(); for (int bc = 0; bc < barCount; bc++) { Integer[] onsetIndexes = new Integer[]{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; double sixteenthInterval = 0.1875; double intervalWindow = sixteenthInterval / 2; for (int i = 0; i < onsetIndexes.length; i++) { for (double onsetTime : onsetTimes) { if (i == 0) { if (onsetTime - ((float) bc * barInSec) > (sixteenthInterval * i) - intervalWindow && onsetTime - ((float) bc * barInSec) <= (sixteenthInterval * i) + intervalWindow) { onsetIndexes[i] = 1; } } else { if (onsetTime - ((float) bc * barInSec) > (sixteenthInterval * i) - intervalWindow && onsetTime - ((float) bc * barInSec) <= (sixteenthInterval * i) + intervalWindow) { onsetIndexes[i] = 1; } } } } onsetIndexCollection.add(onsetIndexes); } return onsetIndexCollection; } @Autowired  RhythmicExtractionUtil(IBeatLoopsDal beatLoopsDal,IHarmonicLoopsDal harmonicLoopsDal, AppConfigs appConfigs, IAudioUtils audioUtils); }
RhythmicExtractionUtil implements OnsetHandler { public List<Integer[]> getOnsetIndexes(Double[] onsetTimes, int barCount, float barInSec) { List<Integer[]> onsetIndexCollection = new ArrayList<>(); for (int bc = 0; bc < barCount; bc++) { Integer[] onsetIndexes = new Integer[]{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; double sixteenthInterval = 0.1875; double intervalWindow = sixteenthInterval / 2; for (int i = 0; i < onsetIndexes.length; i++) { for (double onsetTime : onsetTimes) { if (i == 0) { if (onsetTime - ((float) bc * barInSec) > (sixteenthInterval * i) - intervalWindow && onsetTime - ((float) bc * barInSec) <= (sixteenthInterval * i) + intervalWindow) { onsetIndexes[i] = 1; } } else { if (onsetTime - ((float) bc * barInSec) > (sixteenthInterval * i) - intervalWindow && onsetTime - ((float) bc * barInSec) <= (sixteenthInterval * i) + intervalWindow) { onsetIndexes[i] = 1; } } } } onsetIndexCollection.add(onsetIndexes); } return onsetIndexCollection; } @Autowired  RhythmicExtractionUtil(IBeatLoopsDal beatLoopsDal,IHarmonicLoopsDal harmonicLoopsDal, AppConfigs appConfigs, IAudioUtils audioUtils); void performBeatExtraction(); void performHarmonicExtraction(); List<BeatLoop> getBeatLoopsWithoutRhytmicAccents(); List<HarmonicLoop> getHarmonicLoopsWithoutRhytmicAccents(); @Override void handleOnset(double timeOfOnset, double v1); List<Integer[]> getOnsetIndexes(Double[] onsetTimes, int barCount, float barInSec); }
RhythmicExtractionUtil implements OnsetHandler { public List<Integer[]> getOnsetIndexes(Double[] onsetTimes, int barCount, float barInSec) { List<Integer[]> onsetIndexCollection = new ArrayList<>(); for (int bc = 0; bc < barCount; bc++) { Integer[] onsetIndexes = new Integer[]{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; double sixteenthInterval = 0.1875; double intervalWindow = sixteenthInterval / 2; for (int i = 0; i < onsetIndexes.length; i++) { for (double onsetTime : onsetTimes) { if (i == 0) { if (onsetTime - ((float) bc * barInSec) > (sixteenthInterval * i) - intervalWindow && onsetTime - ((float) bc * barInSec) <= (sixteenthInterval * i) + intervalWindow) { onsetIndexes[i] = 1; } } else { if (onsetTime - ((float) bc * barInSec) > (sixteenthInterval * i) - intervalWindow && onsetTime - ((float) bc * barInSec) <= (sixteenthInterval * i) + intervalWindow) { onsetIndexes[i] = 1; } } } } onsetIndexCollection.add(onsetIndexes); } return onsetIndexCollection; } @Autowired  RhythmicExtractionUtil(IBeatLoopsDal beatLoopsDal,IHarmonicLoopsDal harmonicLoopsDal, AppConfigs appConfigs, IAudioUtils audioUtils); void performBeatExtraction(); void performHarmonicExtraction(); List<BeatLoop> getBeatLoopsWithoutRhytmicAccents(); List<HarmonicLoop> getHarmonicLoopsWithoutRhytmicAccents(); @Override void handleOnset(double timeOfOnset, double v1); List<Integer[]> getOnsetIndexes(Double[] onsetTimes, int barCount, float barInSec); public AppConfigs appConfigs; public IAudioUtils audioUtils; }