@Test public void ShouldConcatinateMultipleLoopsAndShims() throws Exception { double shimLengthOne = 15.4; double shimLengthTwo = 29.7; String shimToGenerateOne = appConfigs.MOCK_AUDIO_PATH + "shimConcateTestOne.wav"; String shimToGenerateTwo = appConfigs.MOCK_AUDIO_PATH + "shimConcateTestTwo.wav"; String targetOutput = appConfigs.MOCK_AUDIO_PATH + "concateTest.wav"; File shimFileOne = new File(shimToGenerateOne); if(shimFileOne != null || shimFileOne.exists()){ deleteFolderAndContents(shimFileOne); } File shimFileTwo = new File(shimToGenerateTwo); if(shimFileTwo != null || shimFileTwo.exists()){ deleteFolderAndContents(shimFileTwo); } List<BeatLoop> beatLoops = beatLoopsDal.findByNormalizedLength(1); List<HarmonicLoop> harmonicLoops = harmonicLoopsDal.findByNormalizedLength(1); BeatLoop beatLoop = beatLoops.get((new Random()).nextInt(beatLoops.size())); HarmonicLoop harmonicLoop = harmonicLoops.get((new Random()).nextInt(harmonicLoops.size())); shimGenerator.generateSilence(shimLengthOne, shimToGenerateOne, 1); shimGenerator.generateSilence(shimLengthTwo, shimToGenerateTwo, 2); System.out.println("MonoStereo = " + audioUtils.isMonoOrStereo(shimToGenerateTwo)); List<String> sourceFilesList = new ArrayList<String>(); sourceFilesList.add(shimToGenerateOne); sourceFilesList.add(shimToGenerateTwo); sourceFilesList.add(beatLoop.getFilePath(appConfigs) + beatLoop.getFileName()); sourceFilesList.add(harmonicLoop.getFilePath(appConfigs) + harmonicLoop.getFileName()); BaseRenderer baseRenderer = new BaseRenderer(); baseRenderer.concatenateFiles(sourceFilesList, targetOutput); float targetLength = (float)shimLengthOne + (float)shimLengthTwo + beatLoop.getAudioLength() + harmonicLoop.getAudioLength(); float actualLength = audioUtils.getAudioLength(targetOutput); shimFileOne = new File(shimToGenerateOne); if(shimFileOne != null || shimFileOne.exists()){ deleteFolderAndContents(shimFileOne); } shimFileTwo = new File(shimToGenerateTwo); if(shimFileTwo != null || shimFileTwo.exists()){ deleteFolderAndContents(shimFileTwo); } File target = new File(targetOutput); if(target != null || target.exists()){ deleteFolderAndContents(target); } Assert.assertEquals(targetLength,actualLength,0.01f); }
public Boolean concatenateFiles(List<String> sourceFilesList, String destinationFileName) throws Exception { destinationFileName = correctFilePath(destinationFileName); try { Vector<AudioInputStream> inputStreams = new Vector<>(); AudioFormat audioFormat = null; long frameLength = 0; for (String source : sourceFilesList) { AudioInputStream inputStream = AudioSystem.getAudioInputStream(new File(source)); inputStreams.add(inputStream); audioFormat = inputStream.getFormat(); frameLength = frameLength + inputStream.getFrameLength(); } Enumeration<AudioInputStream> enumeration = inputStreams.elements(); AudioInputStream appendedFiles = new AudioInputStream( new SequenceInputStream(enumeration), audioFormat, frameLength); Application.logger.debug("LOG: %%%%%%% RENDERED: " + destinationFileName); AudioSystem.write(appendedFiles, AudioFileFormat.Type.WAVE, new File(destinationFileName)); } catch (Exception e) { Application.logger.debug("LOG:",e); return false; } return true; }
BaseRenderer { public Boolean concatenateFiles(List<String> sourceFilesList, String destinationFileName) throws Exception { destinationFileName = correctFilePath(destinationFileName); try { Vector<AudioInputStream> inputStreams = new Vector<>(); AudioFormat audioFormat = null; long frameLength = 0; for (String source : sourceFilesList) { AudioInputStream inputStream = AudioSystem.getAudioInputStream(new File(source)); inputStreams.add(inputStream); audioFormat = inputStream.getFormat(); frameLength = frameLength + inputStream.getFrameLength(); } Enumeration<AudioInputStream> enumeration = inputStreams.elements(); AudioInputStream appendedFiles = new AudioInputStream( new SequenceInputStream(enumeration), audioFormat, frameLength); Application.logger.debug("LOG: %%%%%%% RENDERED: " + destinationFileName); AudioSystem.write(appendedFiles, AudioFileFormat.Type.WAVE, new File(destinationFileName)); } catch (Exception e) { Application.logger.debug("LOG:",e); return false; } return true; } }
BaseRenderer { public Boolean concatenateFiles(List<String> sourceFilesList, String destinationFileName) throws Exception { destinationFileName = correctFilePath(destinationFileName); try { Vector<AudioInputStream> inputStreams = new Vector<>(); AudioFormat audioFormat = null; long frameLength = 0; for (String source : sourceFilesList) { AudioInputStream inputStream = AudioSystem.getAudioInputStream(new File(source)); inputStreams.add(inputStream); audioFormat = inputStream.getFormat(); frameLength = frameLength + inputStream.getFrameLength(); } Enumeration<AudioInputStream> enumeration = inputStreams.elements(); AudioInputStream appendedFiles = new AudioInputStream( new SequenceInputStream(enumeration), audioFormat, frameLength); Application.logger.debug("LOG: %%%%%%% RENDERED: " + destinationFileName); AudioSystem.write(appendedFiles, AudioFileFormat.Type.WAVE, new File(destinationFileName)); } catch (Exception e) { Application.logger.debug("LOG:",e); return false; } return true; }  }
BaseRenderer { public Boolean concatenateFiles(List<String> sourceFilesList, String destinationFileName) throws Exception { destinationFileName = correctFilePath(destinationFileName); try { Vector<AudioInputStream> inputStreams = new Vector<>(); AudioFormat audioFormat = null; long frameLength = 0; for (String source : sourceFilesList) { AudioInputStream inputStream = AudioSystem.getAudioInputStream(new File(source)); inputStreams.add(inputStream); audioFormat = inputStream.getFormat(); frameLength = frameLength + inputStream.getFrameLength(); } Enumeration<AudioInputStream> enumeration = inputStreams.elements(); AudioInputStream appendedFiles = new AudioInputStream( new SequenceInputStream(enumeration), audioFormat, frameLength); Application.logger.debug("LOG: %%%%%%% RENDERED: " + destinationFileName); AudioSystem.write(appendedFiles, AudioFileFormat.Type.WAVE, new File(destinationFileName)); } catch (Exception e) { Application.logger.debug("LOG:",e); return false; } return true; }  Boolean concatenateFiles(List<String> sourceFilesList, String destinationFileName); }
BaseRenderer { public Boolean concatenateFiles(List<String> sourceFilesList, String destinationFileName) throws Exception { destinationFileName = correctFilePath(destinationFileName); try { Vector<AudioInputStream> inputStreams = new Vector<>(); AudioFormat audioFormat = null; long frameLength = 0; for (String source : sourceFilesList) { AudioInputStream inputStream = AudioSystem.getAudioInputStream(new File(source)); inputStreams.add(inputStream); audioFormat = inputStream.getFormat(); frameLength = frameLength + inputStream.getFrameLength(); } Enumeration<AudioInputStream> enumeration = inputStreams.elements(); AudioInputStream appendedFiles = new AudioInputStream( new SequenceInputStream(enumeration), audioFormat, frameLength); Application.logger.debug("LOG: %%%%%%% RENDERED: " + destinationFileName); AudioSystem.write(appendedFiles, AudioFileFormat.Type.WAVE, new File(destinationFileName)); } catch (Exception e) { Application.logger.debug("LOG:",e); return false; } return true; }  Boolean concatenateFiles(List<String> sourceFilesList, String destinationFileName);  }