is there an api to read wav files into an array of short[]?
i’m trying to read a wav file into short array.
i couldn’t find any built API for that
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Bring it in via an AudioInputStream as one normally does for sound.
With each buffer load you grab from the stream, iterate through it, two bytes at a time (if it is 16-bit encoding) and use your favorite algorithm to convert the two bytes to a single short int. (Depends if file is Big-Endian or Little-Endian.)
Then, save the results by appending to your preferred form of short array, instead of posting to a SourceDataLine like is done in the more usual playback situations.
Quote from Java Tutorials:
You might check out the code in this Java sound tutorial: Using Files and Format Converters, the section “Reading Sound Files” and note the comment: “Here, do something useful with the audio data that’s now in the audioBytes array…”
For example, that something useful might be:
buffer = byte buffer receiving the AudioInputStream.
i = index into the arrays.