public static void main(String[] args) throws UnsupportedAudioFileException, IOException { AudioInputStream inputAudio = AudioSystem.getAudioInputStream(new File(args[0])); int samplingRate = (int) inputAudio.getFormat().getSampleRate(); AudioDoubleDataSource signal = new AudioDoubleDataSource(inputAudio); double[] x = signal.getAllData(); int i; int numBands = 4; double overlapAround1000Hz = 100.0; FIRBandPassFilterBankAnalyser analyser = new FIRBandPassFilterBankAnalyser(numBands, samplingRate, overlapAround1000Hz); Subband[] subbands = analyser.apply(x); DDSAudioInputStream outputAudio; AudioFormat outputFormat; String outFileName; // Write highpass components 0 to numLevels-1 for (i = 0; i < subbands.length; i++) { outputFormat = new AudioFormat( (int) (subbands[i].samplingRate), inputAudio.getFormat().getSampleSizeInBits(), inputAudio.getFormat().getChannels(), true, true); outputAudio = new DDSAudioInputStream(new BufferedDoubleDataSource(subbands[i].waveform), outputFormat); outFileName = args[0].substring(0, args[0].length() - 4) + "_band" + String.valueOf(i + 1) + ".wav"; AudioSystem.write(outputAudio, AudioFileFormat.Type.WAVE, new File(outFileName)); } }
public static void main(String[] args) throws UnsupportedAudioFileException, IOException { // File input AudioInputStream inputAudio = AudioSystem.getAudioInputStream(new File(args[0])); int samplingRate = (int) inputAudio.getFormat().getSampleRate(); AudioDoubleDataSource signal = new AudioDoubleDataSource(inputAudio); double[] x = signal.getAllData(); double maxOrig = MathUtils.getAbsMax(x); SinusoidalAnalyzer sa = null; SinusoidalTracks st = null; PitchSynchronousSinusoidalAnalyzer pa = null; // // Analysis float deltaInHz = SinusoidalAnalysisParams.DEFAULT_DELTA_IN_HZ; float numPeriods = PitchSynchronousSinusoidalAnalyzer.DEFAULT_ANALYSIS_PERIODS; boolean isSilentSynthesis = false; int windowType = Window.HANNING; boolean bRefinePeakEstimatesParabola = false; boolean bRefinePeakEstimatesBias = false; boolean bSpectralReassignment = false; boolean bAdjustNeighFreqDependent = false; // int spectralEnvelopeType = SinusoidalAnalysisParams.LP_SPEC; int spectralEnvelopeType = SinusoidalAnalysisParams.SEEVOC_SPEC; float[] initialPeakLocationsInHz = null; initialPeakLocationsInHz = new float[1]; for (int i = 0; i < 1; i++) initialPeakLocationsInHz[i] = (i + 1) * 350.0f; boolean isFixedRateAnalysis = false; boolean isRealSpeech = true; double startFreqInHz = 0.0; double endFreqInHz = 0.5 * samplingRate; SinusoidalAnalysisParams params = new SinusoidalAnalysisParams( samplingRate, startFreqInHz, endFreqInHz, windowType, bRefinePeakEstimatesParabola, bRefinePeakEstimatesBias, bSpectralReassignment, bAdjustNeighFreqDependent); if (isFixedRateAnalysis) { // Fixed window size and skip rate analysis double[] f0s = null; float ws_f0 = -1.0f; float ss_f0 = -1.0f; sa = new SinusoidalAnalyzer(params); if (spectralEnvelopeType == SinusoidalAnalysisParams.SEEVOC_SPEC) // Pitch info needed { String strPitchFile = args[0].substring(0, args[0].length() - 4) + ".ptc"; PitchReaderWriter f0 = new PitchReaderWriter(strPitchFile); f0s = f0.contour; ws_f0 = (float) f0.header.windowSizeInSeconds; ss_f0 = (float) f0.header.skipSizeInSeconds; } st = sa.analyzeFixedRate( x, 0.020f, 0.010f, deltaInHz, spectralEnvelopeType, f0s, ws_f0, ss_f0); // } else { // Pitch synchronous analysis String strPitchFile = args[0].substring(0, args[0].length() - 4) + ".ptc"; PitchReaderWriter f0 = new PitchReaderWriter(strPitchFile); int pitchMarkOffset = 0; PitchMarks pm = SignalProcUtils.pitchContour2pitchMarks( f0.contour, samplingRate, x.length, f0.header.windowSizeInSeconds, f0.header.skipSizeInSeconds, true, pitchMarkOffset); pa = new PitchSynchronousSinusoidalAnalyzer(params); st = pa.analyzePitchSynchronous( x, pm, numPeriods, -1.0f, deltaInHz, spectralEnvelopeType, initialPeakLocationsInHz); isSilentSynthesis = false; } // // Resynthesis PeakMatchedSinusoidalSynthesizer ss = new PeakMatchedSinusoidalSynthesizer(samplingRate); x = ss.synthesize(st, isSilentSynthesis); // // File output DDSAudioInputStream outputAudio = new DDSAudioInputStream(new BufferedDoubleDataSource(x), inputAudio.getFormat()); String outFileName = args[0].substring(0, args[0].length() - 4) + "_sinResynthFullbandPitchSynch.wav"; AudioSystem.write(outputAudio, AudioFileFormat.Type.WAVE, new File(outFileName)); // }