Java sound processing

xiaoxiao2021-03-06  99

Java sound processing

There are many species of digital audio format, and its quality is related to sampling frequency and sampling accuracy. Frequency table

The unit is Hertz [Hz], which means the number of samples per second. The higher the sampling frequency, the better the sound quality. sampling

Accuracy is the amount of data stored at each sample, which determines the discrete amplitude that can be represented by each digital signal

quantity. The more data that stores each sample, the better the sound quality. But high quality sound needs to take up

The amount of memory and disk space. Considering the network bandwidth, it takes a long time to transfer in the Internet connection.

time. For Applet, the minimization of the sound file is extremely important.

Java can support the following four sound formats:

◆ au

◆ AIFF

◆ Wave

◆ MIDI

The first sound format AU is the only sound format supported by previous Java 1.1 versions. Sampling frequency is 80

00 Hertz, sampling accuracy is 8 bits. AIFF and WAVE are used in the AU format used to represent digital sounds.

Among them, Wave format provides a wider range of sound quality. MIDI format is dedicated to music, and with musical notes and music

The sound is not a digital sound to describe the sound.

About the creation of sound: The most spoken sound wearing key tools for standard applications in Windows 9x - recording

machine. The recorded format is WAVE. There are also many professional applications, science samples and editing numbers.

The sound of the sound, and the conversion of formats.

Resource demand:

■ Hardware resource requirements:

(1) sound card

(2) speaker

# If you need to record sound, this also needs a microphone.

■ Software resource requirements:

(1) Windows9X operating system

(2) Web browser

(3) Java plugin / running time environment

Treatment plan

Java2 begins, Java language can support the above four sound formats. Simple method is to pass A in Java

The AUDIOCLIP () interface of the Pplet class is loaded. This interface is a common method for sound pieces.

, With minimal support for playing sound pieces.

This interface defines the following method:

■ play ()

Grammar: void play ()

Function: Start playing sound pieces.

Regardless of whether the sound piece is already playing, it is played from the beginning. Play over, but not repeated.

■ loop ()

Grammar: void loop ()

Function: Cyclic play sound pieces.

Calling this method is to start playing from the head regardless of whether the sound piece is already playing.

■ STOP ()

Grammar: void stop ()

Function: Stop playing sound pieces.

AUDIOCLIP interface can get sound pieces through GetAudioclip () and getCodeBase () methods and

URL address.

This method can be utilized to play the specified sound piece in the web page.

# Demand: Based on the development environment of JDK1.2 or later. If only play the sound file in the AU format, JDK1

.1 can be. 1.

Addition: Soundtest.html Source Code

</p> <p>HTML Test Page</p> <p></ Title></p> <p></ HEAD></p> <p><Body></p> <p><Applet</p> <p>Codebase = "" Code = "Test.class" name = "testapplet" WID</p> <p>TH = 400 height = 200 hspace = 0 vSpace = 0 align = mi</p> <p>DDLE></p> <p><Param name = "clip" value = "snound.au"></p> <p></ Applet></p> <p></ Body></p> <p></ Html></p> <p>Attached: TEST, Java Source Code Package Soundtest;</p> <p>Import java.awt. *;</p> <p>Import java.awt.event. *;</p> <p>Import java.applet. *;</p> <p>Import javax.swing. *;</p> <p>Import java.net. *;</p> <p>Public class test extends japplet {</p> <p>Boolean isstandalone = false;</p> <p>String sound;</p> <p>JButton JButtonPlay = new jbutton ();</p> <p>JButton jbuttonloop = new jbutton ();</p> <p>JButton JButtonStop = New jbutton ();</p> <p>Jlabel Jlabel1 = new jlabel ();</p> <p>Audioclip clip;</p> <p>// Get a parameter Value</p> <p>Public String getParameter (String Key, String DEF) {</p> <p>RETURN ISSTANDALONE? System.GetProperty (key, def):</p> <p>(GetParameter (key)! = null? getParameter (key): DEF);</p> <p>}</p> <p>// conntruct the applet</p> <p>Public test () {</p> <p>}</p> <p>// Initialize the applet</p> <p>Public void init () {</p> <p>Try {</p> <p>Jbinit ();</p> <p>}</p> <p>Catch (Exception E) {</p> <p>E.PrintStackTrace ();</p> <p>}</p> <p>}</p> <p>// Component Initialization</p> <p>Private void jbinit () throws exception {</p> <p>JButtonPlay.Settext ("Play");</p> <p>JButtonPlay.setBounds (New Rectangle (50, 85, 80, 40);</p> <p>JButtonPlay.AddmouseListener (New java.awt.event.mouseadapter () {</p> <p>Public void mouseclicked (mouseevent e) {</p> <p>JButtonPlay_MouseClicked (e);</p> <p>}</p> <p>});</p> <p>This.Setsize (New Dimension (400, 200));</p> <p>THIS.GETCONTENTPANE (). setLayout (NULL);</p> <p>JButtonLoop.Settext ("loop");</p> <p>JButtonloop.setBounds (New Rectangle (150, 85, 80, 40);</p> <p>JButtonLoop.Addmouselistener (new java.awt.event.mouseadapter () {</p> <p>Public void mouseclicked (mouseevent e) {</p> <p>JButtonLoop_MouseClicked (e);</p> <p>}</p> <p>});</p> <p>JButtonStop.Settext ("STOP");</p> <p>JButtonStop.setBounds (New Rectangle (250, 85, 80, 40);</p> <p>JButtonStop.Addmouselistener (New java.awt.event.mouseadapter () {</p> <p>Public void mouseclicked (mouseevent e) {</p> <p>JButtonStop_mouseclicked (e);</p> <p>}</p> <p>});</p> <p>Jlabel1.Settext ("Sound Test Demo");</p> <p>Jlabel1.SetBounds (New Rectangle (109, 28, 186, 28);</p> <p>THIS.GETCONTENTPANE (). Add (jbuttonplay, null); this.getContentPane (). add (jbuttonstop, null);</p> <p>THIS.GETCONTENTPANE (). Add (jbuttonloop, null);</p> <p>THIS.GETCONTENTPANE (). Add (jlabel1, null);</p> <p>Try {sound = this.getParameter ("clip", "sound.au");} catch (Exce)</p> <p>Ption e) {E.PrintStackTrace ();</p> <p>IF (sound! = null) {</p> <p>Try {</p> <p>Clip = japplet.newaudioClip (New URL (getCodeBase (), SOUND);</p> <p>}</p> <p>Catch (Malformedurlexcection E) {</p> <p>System.out.println ("BAD URL");</p> <p>}</p> <p>}</p> <p>}</p> <p>// Get Applet Information</p> <p>Public string getAppletInfo () {</p> <p>Return "Applet Information";</p> <p>}</p> <p>// Get Parameter Info</p> <p>Public String [] [] getParameterInfo () {</p> <p>String [] PINFO =</p> <p>{</p> <p>{"Clip", "String", "Sound.au"},</p> <p>}</p> <p>Return Pinfo;</p> <p>}</p> <p>Void JButtonPlay_MouseClicked (MouseEvent E) {</p> <p>Clip.Play ();</p> <p>}</p> <p>Void JButtonLoop_MouseClicked (MouseEvent E) {</p> <p>Clip.loop ();</p> <p>}</p> <p>Void jbuttonstop_mouseclicked (mouseevent e) {</p> <p>Clip.stop ();</p> <p>}</p> <p>}</p> <p>Treatment plan</p> <p>Use the Sound API in the Java Media framework to handle sound pieces. Sound API is included in Sun</p> <p>In the Java Media Frame, it is also included in the JDK1.3 version. Compilation source code needs to support JDK1.3 development</p> <p>Environment and runtime environment.</p> <p>You can use the Sound API to join the applet to add the applet to the web page. But browser needs to pass JAV</p> <p>A plugin or running time environment support.</p> <p>The Sound API mainly includes the following four parts:</p> <p>Packages</p> <p>Javax.Sound.midi provides I / O of MIDI (Musical Instrument Digital Interface),</p> <p>Sequence, synthetic interfaces and classes.</p> <p>Javax.Sound.Midi.SPI Suppirl Interfaces for Service Providers to Impl</p> <p>Ement When Offering New Midi Devices, Midi File Readers and Writers, O</p> <p>R Sound Bank Readers.</p> <p>Javax.sound.sample provides interfaces and classes for capture, processing, and playback of sample digital audio.</p> <p>Javax.sound.sampled.SPI Supplies Abstract Classes for Service Provider</p> <p>S To Subclass When Offering New Audio Devices, Sound File Readers and</p> <p>Writers, or Audio format control.</p> <p>Treatment plan</p> <p>Use the Sound class in Java 3D. Abstract definitions of the like sound resource. Every specific sound object</p> <p>You can apply the Sound method.</p> <p>The class relationship of the Sound class is as follows:</p> <p>Java.lang.object</p> <p> -javax.media.j3d.scenegraphObject -javax.media.j3d.node</p> <p> -javax.media.j3d.leaf</p> <p> -Javax.media.j3d.sound</p> <p>Subcaters from the Sound class are:</p> <p>⒈Backgroundsound</p> <p>⒉Pointsound</p> <p>⒊CONESOUND</p> <p>The steps of using the above three sounds are as follows:</p> <p>⒈ Define and generate a MediaContainer object, and provide sound files required for objects, usually</p> <p>To separately set a directory where the AU / WAV sound file is stored.</p> <p>⒉ Define a Background Sound / PointSound / consound object, set the sound as needed</p> <p>Whether the sound is looped, the intensity size is parameters, set its role range and setenable uses it to start</p> <p>.</p> <p>⒊ Set the coordinate system according to the specific object.</p> <p>#Java 3D Application can only play the sound file in the AU / WAV format. Can't play the MIDI file.</p> <p>Author: unknown</p> <p>Source: Unknown</p></div><div class="text-center mt-3 text-grey"> 转载请注明原文地址:https://www.9cbs.com/read-104767.html</div><div class="plugin d-flex justify-content-center mt-3"></div><hr><div class="row"><div class="col-lg-12 text-muted mt-2"><i class="icon-tags mr-2"></i><span class="badge border border-secondary mr-2"><h2 class="h6 mb-0 small"><a class="text-secondary" href="tag-2.html">9cbs</a></h2></span></div></div></div></div><div class="card card-postlist border-white shadow"><div class="card-body"><div class="card-title"><div class="d-flex justify-content-between"><div><b>New Post</b>(<span class="posts">0</span>) </div><div></div></div></div><ul class="postlist list-unstyled"> </ul></div></div><div class="d-none threadlist"><input type="checkbox" name="modtid" value="104767" checked /></div></div></div></div></div><footer class="text-muted small bg-dark py-4 mt-3" id="footer"><div class="container"><div class="row"><div class="col">CopyRight © 2020 All Rights Reserved </div><div class="col text-right">Processed: <b>0.044</b>, SQL: <b>9</b></div></div></div></footer><script src="./lang/en-us/lang.js?2.2.0"></script><script src="view/js/jquery.min.js?2.2.0"></script><script src="view/js/popper.min.js?2.2.0"></script><script src="view/js/bootstrap.min.js?2.2.0"></script><script src="view/js/xiuno.js?2.2.0"></script><script src="view/js/bootstrap-plugin.js?2.2.0"></script><script src="view/js/async.min.js?2.2.0"></script><script src="view/js/form.js?2.2.0"></script><script> var debug = DEBUG = 0; var url_rewrite_on = 1; var url_path = './'; var forumarr = {"1":"Tech"}; var fid = 1; var uid = 0; var gid = 0; xn.options.water_image_url = 'view/img/water-small.png'; </script><script src="view/js/wellcms.js?2.2.0"></script><a class="scroll-to-top rounded" href="javascript:void(0);"><i class="icon-angle-up"></i></a><a class="scroll-to-bottom rounded" href="javascript:void(0);" style="display: inline;"><i class="icon-angle-down"></i></a></body></html><script> var forum_url = 'list-1.html'; var safe_token = 'dTkGZISLTJKNz79ZDKBxzM9TFj_2Bs9tRFdYXQ_2BsdHm1_2FEf7OtF_2FFp4ttqjVODh_2FKIdUVVVsSGA_2BonPFlV9pIRtQ_3D_3D'; var body = $('body'); body.on('submit', '#form', function() { var jthis = $(this); var jsubmit = jthis.find('#submit'); jthis.reset(); jsubmit.button('loading'); var postdata = jthis.serializeObject(); $.xpost(jthis.attr('action'), postdata, function(code, message) { if(code == 0) { location.reload(); } else { $.alert(message); jsubmit.button('reset'); } }); return false; }); function resize_image() { var jmessagelist = $('div.message'); var first_width = jmessagelist.width(); jmessagelist.each(function() { var jdiv = $(this); var maxwidth = jdiv.attr('isfirst') ? first_width : jdiv.width(); var jmessage_width = Math.min(jdiv.width(), maxwidth); jdiv.find('img, embed, iframe, video').each(function() { var jimg = $(this); var img_width = this.org_width; var img_height = this.org_height; if(!img_width) { var img_width = jimg.attr('width'); var img_height = jimg.attr('height'); this.org_width = img_width; this.org_height = img_height; } if(img_width > jmessage_width) { if(this.tagName == 'IMG') { jimg.width(jmessage_width); jimg.css('height', 'auto'); jimg.css('cursor', 'pointer'); jimg.on('click', function() { }); } else { jimg.width(jmessage_width); var height = (img_height / img_width) * jimg.width(); jimg.height(height); } } }); }); } function resize_table() { $('div.message').each(function() { var jdiv = $(this); jdiv.find('table').addClass('table').wrap('<div class="table-responsive"></div>'); }); } $(function() { resize_image(); resize_table(); $(window).on('resize', resize_image); }); var jmessage = $('#message'); jmessage.on('focus', function() {if(jmessage.t) { clearTimeout(jmessage.t); jmessage.t = null; } jmessage.css('height', '6rem'); }); jmessage.on('blur', function() {jmessage.t = setTimeout(function() { jmessage.css('height', '2.5rem');}, 1000); }); $('#nav li[data-active="fid-1"]').addClass('active'); </script>