###前提・実現したいこと
今、eclipseを使っていてwavファイルの波形表示をしているのですが、容量の多いwavファイルを読み込もうとするとOutOfMemoryのエラーが出力されてしまいます。エラーを発生させないようにするにはどうしたらいいでしょうか?
###発生している問題・エラーメッセージ
Caused by: java.lang.OutOfMemoryError: Java heap space at sample.SoundReader.getIntFromFrameByte(SoundReader.java:100) at sample.SoundReader.OneSecondRead(SoundReader.java:90) at sample.SoundReader.readFileFromTitle(SoundReader.java:38) at sample.SampleController3.lineview(SampleController3.java:627) at sample.SampleController3.hirakusyori(SampleController3.java:2198) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at sun.reflect.misc.Trampoline.invoke(MethodUtil.java:71) at sun.reflect.GeneratedMethodAccessor1.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at sun.reflect.misc.MethodUtil.invoke(MethodUtil.java:275) at javafx.fxml.FXMLLoader$MethodHandler.invoke(FXMLLoader.java:1771) at javafx.fxml.FXMLLoader$ControllerMethodEventHandler.handle(FXMLLoader.java:1657) at com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:86) at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:238) at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:191) at com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(CompositeEventDispatcher.java:59) at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:58) at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114) at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56) at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114) at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56) at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114) at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56) at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114) at com.sun.javafx.event.EventUtil.fireEventImpl(EventUtil.java:74) at com.sun.javafx.event.EventUtil.fireEvent(EventUtil.java:49) at javafx.event.Event.fireEvent(Event.java:198) at javafx.scene.Node.fireEvent(Node.java:8411)
###該当のソースコード
try{ File soundFile = new File(wavファイル); AudioInputStream audioInputStream = AudioSystem.getAudioInputStream(soundFile); AudioFormat audioFormat = audioInputStream.getFormat(); DataLine.Info info = new DataLine.Info(SourceDataLine.class,audioFormat); SourceDataLine line = (SourceDataLine) AudioSystem.getLine(info); //---// //---// line.open(audioFormat); // line.start(); nowPlaying=true; //--start OneSecondRead(audioInputStream,line,audioFormat); //end-- line.drain(); line.close(); }catch(Exception e){e.printStackTrace();} } private void OneSecondRead(AudioInputStream in,SourceDataLine dl,AudioFormat af)throws Exception { System.out.println("OneSecond"); BigDecimal bd = new BigDecimal(in.getFrameLength()/af.getSampleRate()); BigDecimal bd5 = bd.setScale(1, BigDecimal.ROUND_UP); double d = bd5.doubleValue(); System.out.println("d.length"); System.out.println(d); int size=(int)(af.getSampleRate()*af.getFrameSize()*d); System.out.println("size"); System.out.println(size); byte[] data=new byte[size]; in.read(data); WavePanel.display(getIntFromFrameByte(data,af,true),af); // return false; } private int[] getIntFromFrameByte(byte[] b,AudioFormat af,boolean isSecond){ System.out.println("getIntFrom"); int ch=0;if(isSecond && af.getChannels()==2)ch=2; int bytesize=af.getSampleSizeInBits()/8; int framesize=af.getFrameSize(); System.out.println("b.length"); System.out.println(b.length); int[] to=new int[b.length/framesize]; //ここでOutOfMemoryが発生してしまいます。 for(int i=0;i<to.length;i++){ to[i]=(int)b[i*framesize+ch]; if(bytesize==2)to[i]+=(int)b[i*framesize+ch+1]*256; } return to; }
###試したこと
eclipseから実行していてiniファイルを使い使用容量の変更等をしましたが、改善されませんでした。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。