[marf-cvs] resources/SampleLoading/WaveLoader Wave.java,1.2,1.3
Brought to you by:
mokhov
From: <pwr...@us...> - 2002-11-17 07:52:00
|
Update of /cvsroot/marf/resources/SampleLoading/WaveLoader In directory usw-pr-cvs1:/tmp/cvs-serv25229/resources/SampleLoading/WaveLoader Modified Files: Wave.java Log Message: Newer Version of Wave Class Index: Wave.java =================================================================== RCS file: /cvsroot/marf/resources/SampleLoading/WaveLoader/Wave.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** Wave.java 10 Nov 2002 01:33:41 -0000 1.2 --- Wave.java 17 Nov 2002 07:51:57 -0000 1.3 *************** *** 9,13 **** import java.io.*; ! public class Wave { private AudioFormat waveFormat; //Properties of a wave. private AudioInputStream waveStream; //Stream representing wave sample. --- 9,14 ---- import java.io.*; ! public class Wave //extends Sample ! { private AudioFormat waveFormat; //Properties of a wave. private AudioInputStream waveStream; //Stream representing wave sample. *************** *** 51,56 **** int MSB, LSB; byte[] audioBuffer = new byte[audioData.length*2]; ! ! wcount = waveStream.read(audioBuffer) / 2; for (int i = 0; i < wcount; i++) { if (waveFormat.isBigEndian()) { --- 52,57 ---- int MSB, LSB; byte[] audioBuffer = new byte[audioData.length*2]; ! int nbrBytes = waveStream.read(audioBuffer); ! wcount = (nbrBytes/ 2) + (nbrBytes % 2); for (int i = 0; i < wcount; i++) { if (waveFormat.isBigEndian()) { *************** *** 80,83 **** --- 81,85 ---- public void writeAudioData(double[] audioData, int nbrWords) throws Exception{ int word = 0; + byte[] audioBytes; byte[] audioBuffer = new byte[nbrWords*2]; *************** *** 89,102 **** } outStream.write(audioBuffer,0,audioBuffer.length); } //Saves the wave into a file for playback public void saveSample(File outFile) throws Exception{ - byte audioBytes[] = outStream.toByteArray(); - outStream.reset(); - ByteArrayInputStream bais = new ByteArrayInputStream(audioBytes); - waveStream = new AudioInputStream(bais, waveFormat, - audioBytes.length/waveFormat.getFrameSize()); AudioSystem.write(waveStream,AudioFileFormat.Type.WAVE,outFile); } --- 91,104 ---- } outStream.write(audioBuffer,0,audioBuffer.length); + audioBytes = outStream.toByteArray(); + ByteArrayInputStream bais = new ByteArrayInputStream(audioBytes); + waveStream = new AudioInputStream(bais, waveFormat, + audioBytes.length/waveFormat.getFrameSize()); } //Saves the wave into a file for playback public void saveSample(File outFile) throws Exception{ AudioSystem.write(waveStream,AudioFileFormat.Type.WAVE,outFile); + outStream.reset(); } |