schrum2 / MM-NEATv2

MM-NEAT version 2.0 is no longer supported. Please get MM-NEAT 3+ from https://github.com/schrum2/MM-NEAT
Other
11 stars 5 forks source link

Sound loading in all formats #340

Closed schrum2 closed 7 years ago

schrum2 commented 7 years ago

Currently, we know that our code can really only load 16-bit mono WAV files. We need to generalize this. Getting the current code to work with 8-bit mono files should be straight-forward (hopefully). We should also add support for stereo, bu that level of support may require more drastic changes.

A last issue related to this is making sure that the RemixBreeder generates sounds with a frequency and sample rate that is consistent with whatever file is being remixed.

schrum2 commented 7 years ago

I suppose that long term, also being able to load MP3s is important, even if we do it by immediately converting them to WAV.

schrum2 commented 7 years ago

Please clean up the examples in SoundUtilExamples. In particular, each example should have a comment explaining what it is testing, and the current tests should probably be spread out across methods that are not commented out (though the test methods are not called).

In particular, I would like examples where wave files with each encoding that you can find (8 vs 16 bit, signed vs unsigned, different sample rates, stereo vs mono) are loaded, played, and saved. Then the comments can explain what does and does not work.

Are we able to successfully play any wave file? What if we convert it to a byte stream and/or a double array of amplitudes? Can we still play that correctly? Can we also save it successfully back to a file that sounds the same? Have tests for every possibility, and have the comments indicate what does and does not work.

schrum2 commented 7 years ago

This webpage indicates how to convert (but with some noise) from 16 bit to 8 bit: https://stackoverflow.com/questions/17345287/from-audio-pcm-16-bit-to-8-bit-getting-noise

This is not what we want to do, but maybe we can reverse the process. We have both a byte[] of 8 bits values, and I think that the int[] of 8-bit values that we can extract from it might be accurate.

Let's say we take an int[] generated from an 8-bit wave. Subtract 128 from each value, and then multiply by 256. The result is an int array. Convert it to a double amplitude array, but using an AudioFormat that specifies 16 bits and a signed format. See if the result can be played correctly.

twerisa commented 7 years ago

This link code contains some useful examples regarding conversions between AudioFormats: http://coweb.cc.gatech.edu/mediaComp-plan/uploads/55/JavaSound.java I'll try to parse some of the methods to see if I can convert 8 bit files to a 16 bit format so that they can be played back with the sound remixer. There seem to be a lot of magic numbers in this class - haven't looked them over closely so I'm not sure if the magic numbers are due to the complexity of AudioFormats or due to the code not being generalized.

schrum2 commented 7 years ago

I think we're at a point where we should stop fiddling with this issue. However, I do want you to insert some clear indications of what does and does not work. Specifically, any time an attempt to play back an unsupported audio format occurs, I want you to throw an UnsupportedOperationException that clarifies that the designated format is not supported. Basically, instead of playing back something that sounds weird, or crashing for some other reason, the code should always crash immediately and give a clear indication that the particular type of audio file is not supported.

In this GitHub issue, I also want you to give a comment that clearly lists out all types of formats that are still not supported.

Once this is completed, be sure to remove System.out.print(ln) statements that give audio format troubleshooting information.

Finally, you can close the issue after completing these final steps.

twerisa commented 7 years ago

Supported AudioFormats: