Course 7 Doppler Effect in joal tutorial

Source: Internet
Author: User

Joal tutorial

Address: http://jogamp.org/joal-demos/www/devmaster/lesson7.html

Original article athomas Goldberg

3-way slate brick

Retained the above information.


Study Notes for this course: http://blog.csdn.net/shuzhe66/article/details/40393371


Lesson 7 Doppler Effect

 

This article is the joal version of The openal tutorial for devmaster.net (http://devmaster.net. Originally translated in C language by jessemaurais


Acoustics in the real world


I know that it is boring to let everyone review the physics knowledge learned in high school, but let's move on to it. Doppler effect is a very complicated concept for some people, but it is indeed a logical process. When you go deeper, you will find some content very interesting. To understand the Doppler effect, we must first correctly understand what "sound" is. In general, sound is the explanation of the computation wave in the air. When the air is disturbed, the spherical fluctuations of the compressed air molecules are generated from the disturbance point, And the bubbles spread out from the producing point. Consider the following figure:

In the left figure, the red uppercase s indicates the location of the sound source. The red uppercase L indicates you (you have guessed it), that is, the location of the audience. The sound source and audience are not moved. The sound source continuously emits a compressed wave, which is represented by a blue circle. The audience is accurately hearing the sound produced by the sound source, as shown in the figure below. Because there is no movement, the Doppler effect does not appear in this example. It only occurs when the acoustic deformation is caused by motion.

Here you can think of an image as an animation, where the sound source constantly produces sound waves (that is, circles) and then the production points spread outward along the radius. The Reed ripple in the pond is a good example similar to it. When you put a stone into a calm water body, it emits ripple from the drop point. Believe it or not, water waves and sound waves do have the same physical nature. But what is the relationship between this and the Doppler effect?

See the picture on the right: Oh, what happened here? The sound source begins to move, which is represented by a Red Arrow. In fact, the sound source is moving to the audience at a certain speed. Pay special attention to the fact that the newly generated wave moves inside the front wave, and the direction is the same as that of the source motion path that generates them. This is the key to the Doppler effect. Essentially, what happens here is that the sound source emits Multiple Waves in its motion path, but the wave itself does not move with the sound source, but starts to spread outward from the emitted point.

So how does this effect affect the listener's hearing? Let's take a look at the figure above. The sound waves between the sound source and the audience are compressed to some extent, which will make them come together and sound like playing faster. The frequency of sound is discussed here. The distance between sound waves affects the frequency of sound. When the sound source is moved, the frequency changes. You will also find that the distance between sound waves is also different in space. For example, the distance between sound waves in the opposite direction of sound source motion (the trajectory of the previous motion) is wider, which will lead to a decrease in frequency (the distance is inversely proportional to the frequency ). This means that the actual frequency of audience hearing depends on the specific location.

The movements of the audience also affect the frequency, but such a scenario is too hard to imagine. If the sound source does not move and the audience moves to it, the actual frequency of hearing is the same as that in the source movement example just discussed.

If you are confused, take a look at the following two figures:


The two images show two different sounds in the form of a sine wave. First, let's look at the first one and think of its peak as a sound instance. The highest point of the waveform corresponds to the Blue Circle in the previous two figures, and the Valley corresponds to the distance between the blue circles. The second figure represents the compressed wave. When you compare the two images, you can find that the differences are obvious. In a space of the same size, the second figure obviously contains more waves. In other words, they appear more, more regular, and more frequently.
A bit of additional information for people who want to know more: the velocity represents the Sound speed. If the sound source speed is greater than the velocity, it will break through the sound barrier.


Acoustics in openal


Now you have understood the long article about the Doppler effect above, or you have skipped it, I have fully understood the Doppler effect and just want to know how it works on the openal rendering pipeline. I think the best way to start this part is to directly reference the openal document:


"The influence of Doppler effect on the speed of sound source and audience in the medium, and the corresponding propagation speed of sound in the medium"-Chapter 3 Section 7.


We can understand it as three factors determine the frequency of the sound source that the audience finally hear. They are the velocity of the sound source, the speed of the audience, and the defined velocity. When we mention "Media", it refers to the materials that the audience and the sound source are "in" at the same time. For example, the sounds in the water are very different from those in the air. Air and water are typical representatives of different media. The reason why the sound sounds so different is that the molecular density of different media is different. As we said before, sound is just the movement of molecules in the air. The sound in medium with high molecular density is significantly different because the contact between molecules is closer, which makes sound propagation easier. Another opposite example: imagine that in space, the molecular density here is extremely low. In fact, there are only scattered molecules (mainly hydrogen), which explains the phenomenon that sounds cannot be heard in space.

Well, back to our topic, openal helps us calculate the Doppler effect from the source, so we only need to provide some parameters to influence the calculation result. What we do here may not be a realistic rendering, but a desire to expand or reduce the impact of the Doppler effect. The formula is as follows:

Shift = doppler_factor * freq * (doppler_velocity-L. velocity)/(doppler_velocity + S. velocity)

Use uppercase letters to represent constants. "L" and "S" indicate the final sound source. "Freq" indicates the wave without Frequency Shift, while "shift" indicates the wave after the frequency shift. The term "Frequency Shift" properly associates with the frequency of change, which we will use from now on. The final frequency change will be sampled by openal and applied to all affected audio streams.

We have learned to use 'al _ velocity 'as the parameters of the 'allistenerfv' and 'alsourcefv 'functions to define the sound source and audience speed, when a file is loaded, the 'freq' parameter is directly obtained by the buffer property. The following function is used to set the constant of the above formula:

public void alDopplerFactor(float factor);public void alDopplerVelocity(float velocity);

Any non-negative number is accepted for the 'alpplerface' function. If a negative number is input, the error mark is set to 'al _ invalid_value 'and the operation is ignored. 0 is a valid parameter, which will disable the Doppler effect and may lead to performance improvement (but not ideal ). The direct effect of the Doppler factor equivalence is very large. 1.0 does not change the equation, and the value 0 to 1 will reduce the effect of the Doppler effect, any number greater than 1 will expand the impact.


Any positive value will be accepted for 'aldoplervelocity. If the input value is 0 or a negative number, the error mark is set to 'al _ invalid_value 'and the operation is ignored. In essence, Doppler speed should be the speed of sound, which is like setting the speed of sound in the media. Openal does not have a media concept, but this parameter will have the same effect as the media. Openal also does not have the concept of units (kilometers, Miles, seconds gap [length units, about and 3.26 light years -- comming ), so remember that the constants you set are related to the unit of length defined in your application.

Course 7 Doppler Effect in joal tutorial

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.