| Start |
|---|
| Play a MIDI file MIDI files can be played by using several classes from the General playback of MIDI data can be done in this way: To stop the playback use: A sequencer can be set to mute one or more of the sequence's tracks during playback so none of the instruments in those specified play. The following example sets the first track in the sequence to be muted: A sequencer can play a sequence repeatedly if the loop count is given. The following sets the sequencer to play a sequence four times and indefinitely: The sequencer does not always have to play the sequence from the beginning, nor does it have to play the sequence until the end. It can start and end at any point by specifying the tick in the sequence to start and end at. It is also possible to specify manually which tick in the sequence the sequencer should play from: Sequencers can also play a MIDI file at a certain tempo, which can be controlled by specifying the tempo in beats per minute (BPM) or microseconds per quarter note (MPQ). The factor at which the sequence is played can be adjusted as well. When you finished using the |
| Play an Audio file Looped Needed imports: This code will create a clip and play it continuously once started: Get an Array with all supported file types: |
| Basic audio output The Hello Audio! of Java that plays a sound file from local or internet storage looks as follows. It works for uncompressed .wav files and should not be used for playing mp3 or compressed files. |
| Bare metal sound You can also go almost bare-metal when producing sound with java. This code will write raw binary data into the OS audio buffer to generate sound. It's extremely important to understand the limitations and necessary calculations to generating sound like this. Since playback is basically instantaneous, calculations need to be performed at almost real-time. As such this method is unusable for more complicated sound-sampling. For such purposes using specialized tools is the better approach. The following method generates and directly outputs a rectangle-wave of a given frequency in a given volume for a given duration. For a more differentiated way to generate different soundwaves sinus calculations and possibly larger sample sizes are necessary. This results in significantly more complex code and is accordingly omitted here. RemarksInstead of using the javax.sound.sampled |
Read Article
https://develop.horje.com/learn/1434/reference