VB. NET implements directsound9 (9) to implement an oscilloscope

Source: Internet
Author: User

Keywords: Player oscilloscope VB.net directsound9 Author: Dong Hanjun

Reprinted please indicate from http://blog.csdn.net/a11s

As the most basic function of a player, for example, hero Winamp mediaplayer real QuickTime has its own oscilloscope. Some interfaces are also provided to allow plugin to add more graphic effects.

Many players do not have this basic function, probably because most of them directly use mediaplayer or RealONE controls. this article does not discuss these issues. this article introduces some basic knowledge and implementation steps. some directsound and DirectDraw knowledge may be used.

1 directsoundcapture: starts from the recording

Let's take a look at the recording. At that time, we set up a buffer for writing data. The data is actually used to display waves. It just requires some changes. You can directly display the buffer content.

2. During directsound playback

We read WAV from a new buffer, and the next step is play. note that you will find a read () method that can read the content of the buffer. let's see what we wrote at the time.

3. draw lines

It is not intuitive to use numbers because we are used to watching images to perceive the pattern of voice changes. we can use DirectDraw to visualize the buffer content. first, use the read () method to get a byte (), and then use the for loop to draw a picture. As to when to call read (), you can use a timer. note: The purpose of this operation is to describe the data and image laws in it. instead of a perfect oscilloscope. for more information about the use of DirectDraw, see my original hosted directdraw9. to ensure the speed, there is no better solution than ddraw.

The bottom right is the image (thanks to the FPS provided by strong winds ).Algorithm) Click to enlarge the blog by 1024x768.

The image will respond to changes based on changes in sound. but you will feel different from Winamp. the following explains in detail why. now you only need to "know it. this is actually an oscilloscope for Windows recorders.

 

4. About riff files

After the last WAV capture, we should understand what Riff is. store the data to the buffer zone based on the/D Conversion Result and format it according to the file format (the size of the struct varies ). a wav without compression is actually a file header added to the result of A/D conversion. since the signal is converted from analog signals, the sound changes are essentially a continuous curve. if you are interested, you can create a wave editor by yourself. that is, you can draw a sound with the mouse.

5 if you do not want to know about A/D/A conversion, you can jump over. Here we will tell you "why"

Once you understand it, you can create your own balancer, but this article will not discuss it first.

Sampling Rate: The frequency of A/D conversion. For details, refer to the interface technology single-chip microcomputer and other related information. Because I am not very familiar with it, I hope you can criticize and correct the mistakes.

The process of converting analog audio into digital audio is called sampling. Simply put, the method of waveform sampling is used to record the amount of data required for a sound with a length of 1 second. The sound at a 44 KHz sampling rate takes 44000 pieces of data to describe the sound waveform for one second. In principle, the higher the sampling rate, the better the sound quality.

Number of digits: in short, it is precision. For example, a 24-bit conversion has a 24-bit conversion precision.

In fact, there is another strong voice level. We don't need to care too much here (mainly for fear of making mistakes)

Combined with the features of riff files, you can know how much buffer you should read () and what each byte represents.

6. Real oscilloscope, similar to Winamp

How many Hz are they divided, from 1 K to 10 K to 32 K ....

In fact, the data is integrated to calculate the number from 0 to 1 K, and then accumulated. It is displayed on the oscilloscope.

What we showed just now is "content" and Winamp shows "quantity", because the human ears are sensitive to a certain segment of data, rather than the machine sampling. here is a simple example. people can feel the heavy bass. At this time, a broken area of Winamp can see a sharp increase, while our original oscilloscope can not see at most the volume changes.

I learned that there is no pressure to create an oscilloscope on my own.

7. graphical oscilloscope and External Interfaces

The rendering process is actually a rendering function. You pass the "Features" of the buffer to the past (or even the entire buffer), and it will draw a response pattern based on the parameters, of course, you can add your own characteristics, such as the common attenuation (the sound does not suddenly disappear, but gradually disappears after the end), so people feel more comfortable. an interface is provided for external users. Anyone can use it to create their own graphical oscilloscope.

For details, refer to the principle and production process of plugin.

8. Files in other formats.

The above only gives some explanations for WAV. other formats such as MP3 cannot be used directly, but the principle is the same. after all, the D/A conversion is required during playback. you need to convert the MP3 result into a buffer similar to riff, and then play it. that's all.

======== End ========================

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.