The music is sent through a server. The music is received by a client. When all the music has been received, it sends it in a byte array (byte) to the following method :
Could the following line deteriorate the sound?
I am asking this because when it is sent through the server to the client and played, it has bad quality to the sound. I have posted this in different forums on Coderanch (one I believe, possible two). The difference is that this is asking a different question (about the ByteArrayInputStream). I am just trying to cover all my bases and figure out why the sound is so bad. I felt this belonged here because this is about sampled audio specifics.
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” (Mosher's Law of Software Engineering)
“If debugging is the process of removing bugs, then programming must be the process of putting them in.” (Edsger Dijkstra)
Just to give an example, a WAV file (raw audio) has each sound sample encoded as a signed short (16 bit integer). The value of the sample is dependent on the volume of the sound at that point in time. I could see sound getting messed up if someone were to try to play each sample of sound as two samples (i.e. encode a wav file in an array of bytes). (I've never actually tried to do this, so I don't know what it would sound like.)
Have you tried writing the byte stream out to file and playing it with a media player? That should help you isolate the problem, whether the songsToPlay variable contains bad data, or if, as you suppose, the ByteArrayInputStream is somehow at fault here.
Everything is theoretically impossible, until it is done. ~Robert A. Heinlein
Thank you for your suggestion. This is what I put in my code :
reRoute method :
I tried it and it still sounded really bad. It's not with reading it. It's with the network transfer. Thanks for you suggestion. I can now cross this off the list.
EDIT : I just thought, I'm saving the incoming bytes in a StringBuilder. Maybe that is the issue. I'm going to make a new post in the I/O section about StringBuilder to Bytes. Hopefully, that will be the problem and I will somehow be able to fix it.