Making of Web Applet recorder

Source: Internet
Author: User
Tags range

Network Multimedia is a developing direction of Web application at present. Make a recording on the Web page and send it to a friend and believe they will be very happy to hear from you. Now this is a very common multimedia application technology, the author used the Java language to develop a Web page can be embedded in the applet recorder (interface appearance as shown in the image below). If you have an interest in programming, try it. Here, I will introduce this kind of technology to everyone programming enthusiasts.

Basic concepts and common sense of multimedia

To develop multimedia audio software, we must understand some basic concepts of multimedia, such as sampling, quantization, quantization bit, sampling frequency, mono-channel, audio codec, audio compression format and so on. Sampling is a signal that the continuous analog signal in time becomes a discrete, finite sample value in time. Quantization is a digital signal that transforms the analog signal of a continuous value into a discrete value on the amplitude. In the time axis has become a discrete sample value pulse, in the amplitude axis will still have a continuous value in the dynamic range, there may be any amplitude, that is, in the amplitude axis is still the nature of analog signals, so must use a finite electric equality level to represent the actual measure. A quantization bit is a range of data that can be represented by each sampling point, often using 8, 12, and 16 bits. The sampling frequency is the number of acoustic amplitude samples taken per second when the analog sound waveform is converted to a number, and the sampling frequency is Hz (Hz). According to the sampling theory, in order to ensure the sound is not distorted, the sampling frequency should be about twice times the sound frequency. When recording sound, if one sound wave data is generated at a time, it is called Mono, and two acoustic data is generated each time, which becomes stereo (dual channel). The higher the quantization bit and the sampling frequency, the better the sound quality is.

Normal ear auditory sound frequency range between 20Hz to 20KHz, the voice frequency of people probably between 300Hz to 3.4KHz. For speech, the 8KHz sampling frequency is sufficient. So we use 8KHz sampling frequency, 16-bit quantization bit, mono to record and play voice, you can meet the voice demand on the page.

The process of making a web recorder

Understand the above common sense, the following to see the production process of the recorder.

The first thing to encounter is audio capture. There are many kinds of audio capture, and the Targetdataline class instance is built in JDK 1.3 to achieve sound data acquisition. In this example, I used Visual J + + J/direct to invoke the Windows API function to capture the sound.

Sound capture consists primarily of three classes of Audiocapture, Audiodataevent, and Audiodatalistener. We followed 0.1 seconds to sample the size of the block (that is, 1600 bytes) as the size of the recorded data buffer sent to the system, which is equivalent to a sound card that is submitted to us once every 0.1 seconds. In addition, there is a benefit to using the Windows API method for sound capture, which does not require the creation of separate threads. This is because of the large function of the callback function, which saves the system resources and improves the stability of the program.

//Sound capture class:
...
public class audiocapture{
...
Public audiocapture () {
...
Waveincaps=new waveincaps ();
Wavehdr=new Wavehdr[bufferlen];
}
public void Addaudiodatalistener (Audiodatalistener lter) {
Listeners.addelement (lter);
}
void Applybuffer () {
for (int i=0;i<bufferlen;i++) {
Wavehdr[i]=new wavehdr ();
int
Adr= Dlllib.addrofpinnedobject (Dlllib.getpinnedhandle (data[i));
Wavehdr[i].lpdata=adr;
...
}
}
int Chkdata (byte[] a) {//to cross and convert int low 16-bit height to byte
...
}
public void Close () {
if (!useful) return;
Isclose=true;
Waveinstop (deviceid[0]);
}
...
synchronized void Notifylistener (int minvalue,byte[] audiodata) {
Audiodataevent evt=new (This, Minvalue,audiodata);
for (enumeration enu=listeners.elements (); enu.hasmoreelements ();)
((Audiodatalistener) enu.nextelement ()). Onaudiodataarrived (EVT);
}
...
public void Setmutevalue (int mutevalue) {
This.mutevalue=mutevalue;
}
/** @dll. Import ("winmm", Auto) */
...
public static native int waveinreset (int hwi);
Private Class C extends callback{
Audiocapture record;
C (audiocapture tt) {
Record=tt;
}
...
}

//Buffered data Submission event class:
Import java.util.EventObject;
public class Audiodataevent extends eventobject{
...
}
//Event Listening Interface
Import java.util.EventListener
Public interface Audiodatalistener extends eventlistener{
Public abstract void onaudiodataarrived (Audiodataevent evt);
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.