Untitled

mail@pastecode.io avatar
unknown
plain_text
2 years ago
1.2 kB
3
Indexable
Never

public class Audio2 {


	
	public static void main(String[] args) {
		// read and play original wav file
		
		double[] signal = ZhawWavLib.read("Guitar.wav");
		ZhawWavLib.play("Guitar.wav");

		// change the volume
		double[] lowSignal = changeVolume(signal, 0.5);

		
		double[] highSignal = changeVolume(signal, 5);

		
		System.out.println("Signal "+lowSignal[100]);
		System.out.println("Signal "+highSignal[100]);
		
		
		// write and play modified wav file
		ZhawWavLib.write(lowSignal,"Guitar-lowvolume.wav");
		ZhawWavLib.play("Guitar-lowvolume.wav");
		ZhawWavLib.write(highSignal,"Guitar-highvolume.wav");
		ZhawWavLib.play("Guitar-highvolume.wav");
	}
	
	
	// TODO: add method changeVolume.
	// changes the volume by the given factor and return the new signal
	// limit the signal to +/-1.0
	
	
	public static double[] changeVolume(double[] signalNew, double volume2){
		
		System.out.println("Volume: "+volume2);
		
		for (int i = 0; i < signalNew.length; i++) {
					
			
			
			signalNew[i] *= volume2;
			
			if (signalNew[i] > 1.0) {
				signalNew[i] = 1.0;
			}
			
		}
		
		System.out.println("Signal "+signalNew[100]);
		
		return signalNew;
			
	}
	

	

}