I want to play some audio of two byte arrays. I was wondering whether it would be better to play them as two separate arrays both calling the method, or to put them into one array and play it from there.
Note: The starting from position 4 because the first 4 bytes are saved for the sequence number in the array.
All in one array:
byte[] das = ByteBuffer.allocate((temp.length-4)*2)
.put(Arrays.copyOfRange(temp, 4, temp.length - 4))
.put(Arrays.copyOfRange(udpPacketBytes, 4, udpPacketBytes.length - 4))
.array();
player.playBlock(das);
or split like this:
byte[] filteredByteArray = Arrays.copyOfRange(temp, 4, temp.length - 4);
player.playBlock(filteredByteArray);
// play the current one
byte[] fba = Arrays.copyOfRange(udpPacketBytes, 4, udpPacketBytes.length - 4);
player.playBlock(fba);
I was also wondering whether there'd be a way to calculate the complexity of the two.
1 Answer 1
Implementation
Better
is a nebulous concept. The first one assumes that both arrays are the same length and fails to play all audio otherwise, so I'll say that's worse. I would suggest pulling the subarray computation into a method.
private void playAudio(final byte[] audio) {
this.player.playBlock(Arrays.copyOfRange(audio, 4, audio.length - 4));
}
-
\$\begingroup\$ Thank you, so I'd just call this method twice in my case? \$\endgroup\$user3667111– user36671112016年02月21日 14:31:16 +00:00Commented Feb 21, 2016 at 14:31
-
\$\begingroup\$ Yes, you would. \$\endgroup\$Eric Stein– Eric Stein2016年02月21日 17:29:53 +00:00Commented Feb 21, 2016 at 17:29
-
\$\begingroup\$ Had to move a few things around to get it to fit in my code, works great thanks \$\endgroup\$user3667111– user36671112016年02月21日 18:25:34 +00:00Commented Feb 21, 2016 at 18:25
Explore related questions
See similar questions with these tags.
player
? \$\endgroup\$