Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Your main problem is in this function:</p> <pre><code>/** * createMusicArray reads the stream and returns a list of short objects (the samples) */ public List&lt;Short&gt; createMusicArray (InputStream ins) throws IOException { List&lt;Short&gt; musicList = new ArrayList&lt;Short&gt;(); ByteArrayOutputStream baos = new ByteArrayOutputStream(); byte[] byteArray = new byte[50*1024]; int i = Integer.MAX_VALUE; while ((i = ins.read(byteArray, 0, byteArray.length)) &gt; 0) { baos.write(byteArray, 0, i); } for (int j = 0; j &lt; byteArray.length; j++) { short objShort = (short)(byteArray[j]); musicList.add(objShort); } return musicList; } </code></pre> <p>It seems you are taking raw bytes and simply casting them to shorts, but each short needs the data rom two bytes in the file. (see how you handled this correctly in your shortArrayToByteArray function). The easiest way to read raw shorts off a file is with a DataInputStream. Unfortunately, you also need to worry about byte order, so you need to get LittleEndianDataInputStream from <a href="https://code.google.com/p/guava-libraries/" rel="nofollow noreferrer">guava</a>, or you could write your own class to do the same thing, like <a href="https://stackoverflow.com/questions/8028094/java-datainputstream-replacement-for-endianness">this</a>, if you don't want to import the whole guava library. Try this (untested, so you might have to tweak it):</p> <pre><code>/** * createMusicArray reads the stream and returns a list of short objects (the samples) */ public List&lt;Short&gt; createMusicArray (InputStream ins) throws IOException { LittleEndianDataInputStream dis = new LittleEndianDataInputStream(ins); while (true) { try { short d = dis.readShort(); musicList.add(d); } catch( EOFException e ) { break; } } return musicList; } </code></pre> <p>As a side note, it's pretty inefficient (and confusing) to store all that data in list and then transfer it to an array. You should consider just using an ArrayList, or better yet getting the size of the media data and using that to build an array of the correct size in the first place. However, none of those things will ensure that you can still perform the operation because you are trying to put the whole file in memory. Instead, try reading smaller chucnks of each file, and mixing those, and then reading the next chunk.</p> <p>But I wouldn't worry about all that until you get this working.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload