0

Im writing a small fighting-game. Right now im creating Character maker with animations, combos, etc. I allready had some problems with my sprites, because BufferedImage can not be serialized. This was solved with PixelGrabber - when i click saveButton, this pixelGrabber grabs pixels from Image and saves them as array. This array can be serialized then. It can be deserialized, when i load this project, and used as an Image again. Now, my question - is it possible to save .wav file as an serializable array? And after this to deserialize and use it again as an audio file? p.s.sorry for my english

  • If any answers work for you, please select them as your chosen answer to help others with the same question. – Max Nov 13 '12 at 21:21

1 Answers1

0

Here is a simple framework for working with WAV files: http://www.labbookpages.co.uk/audio/javaWavFiles.html

I wrote this out pretty quickly so I apologize if there are any mistakes, but here is what loading the wav file into an ArrayList would look like:

//make sure to import java.util.ArrayList; 
try {
    // load the file, set up the buffer
    WavFile gameWav = WavFile.openWavFile( new File( "game_sound.wav" ) );
    ArrayList<double> gameWavArray = new ArrayList<double>();
    long framesRead = 0;
    long totalFrames = gameWav.getNumFrames();
    //read the buffer in 1000 frames at a time
    do {
        double[] gameWavBuffer = new double[1000];
        // Read the frames into array, increment framesRead
        framesRead = framesRead + Long.valueOf( gameWav.readFrames(gameWavBuffer, framesRead, 1000) );
        //add all of the new frames to our ArrayList
        Collections.addAll(gameWavArray, gameWavBuffer );
    }
    while (framesRead < totalFrames );
}
catch (Exception e) {
     System.err.println(e);
}
Max
  • 2,082
  • 19
  • 25