finding maximum gain in OpenAL - openal

I'm using OpenAL via the LWJGL bindings http://www.lwjgl.org/javadoc/.
I need to know the maximum possible gain for my volume setting function.
Unfortunately AL10.alGetSourcef(sources.get(0), AL10.AL_MAX_GAIN) always returns 0F, whether or not an AL instance is open. If I set the gain with alSourcef to some other value, that becomes the new AL_MAX_GAIN.
So how can I find the actual maximum gain? Without it I don' see how I can hook up an audio volume slider to the gain value.

AL_MAX_GAIN is not maximum gain of your sound system, its the value that you set. for example if you set max gain to 0.75 then you play a source with gain 1.0, the source will be played at 0.75 gain since you limit the maximum gain.
openAL concept of gain is relative in range of minimum 0.0 and maximum 1.0, its depend on your sound system : O/S, sound card, amplifier, etc to map how dB to apply to 1.0 value.

Related

AVSpeechUtterance 10% step rate changes

I need to implement AVSpeechUtterance rate change in range from 50% to 150% relative to normal speed with a step of 10%.
The problem is that I can't really find neither absolute, nor relative rate values to build on.
I do know that normal rate value is 0.5. But setting it to 0.6 at least doubles the speed.
Documentation mentions AVSpeechUtteranceMinimumSpeechRate and AVSpeechUtteranceMaximumSpeechRate, but I fail to understand how to make use of it since I can't even access it.
Any help is appreciated!

Why is the volume coming from -80db to 0 - not even starting at 0?

I'm very new to sound. I've never explored this area in my whole life.
I thought decibels was a measure starting at 0.
But in Unity, it starts at -80db and and "0db" it seems it's the "100%" level volume.
Moreover, when I change the sound to -40db it's not "half-way" between -80db and and 0 it seems it's much closer to -80db. So the user hears nothing when it's "half-way":
I couldn't find anywhere how to setup sound properly, and how to make the user choose "properly" the sound (= good scale).
Any idea / Unity valuable sample for this?
From Wikipedia -> Decibel
dB is a relative unit of measurement [...] It expresses the ratio of two values
This is very common for Audio Mixers and Amps that 0 means 100% of the configured Pre-Gain (-> in this case the input volume of your individual AudioSources).
Why? -> The given dB are just the additional "multiplicator" (as said it is a logarithmic ratio between two values).
Usually as an Audio manager you first configure all Pre-Gains in a way that basically everything has more or less the same absolute volume if all mixer sliders are at 0.
Then you start to actually mix them according to your needs and only move certain volumes up or down to increase or decrease the volume by a certain factor. (Except for fading it is usually pretty uncommon to actually pull a slider down to the minimum - usually you rather Mute the channel)
0dB just means 1:1 => Don't change.
e.g. 6dB means about 2:1 => twice as loud as the input volume
e.g. -6dB means about 1:2 => half as loud as the input volume
e.g. 20dB means about 10:1 => Ten times as loud as the input volume
e.g. -80dB means 1:10000 => So 0.0001 of the input volume
So the -80 is chosen a little bit arbitrary .. it could as well be -60 (=>factor of 0.001) or -100 (=> factor of 0.00001). "It doesn't really matter!". At a certain point the volume is simply so low that you won't hear it anymore depending on what the default maximum output of your Amp is and how precise you need the output to be.
You can e.g. use this dB calculator to check what dB value results in what actual factor.
For a better explanation of the dB measure itself see also e.g. these posts and What's the minimum decibel value?

Why does MATLAB change the sample rate while trying to acquire data?

I am using a DataQ acquisition device in Matlab 32-bit with the Data Acquisition toolbox.
On occasion, when I have my sample rate set to 300, it tells me:
Warning: This hardware could not support the requested value of 300
for SampleRate. SampleRate has been set to 1000"
However, if I set SampleRate to 1000, it sometimes sets it back to 300 with the same error message.
Also, if I set the program so that after the error displays and the device has started recording it returns the SampleRate, this is always at whatever I set it to, not what the program claims it changed it to.
Anyone have any idea how I find out what the actual sample rate was or keep it from resetting mine? I need to know how many samples there are per second for further calculations.
The problem is not with Matlab but with the DAQ. I have a similar "problem" with a NI DAQ. The hardware is set to sample at a very high rate to avoid aliasing. You could sample at a higher rate than required and then use the Matlab command "resample" to reduce your sampling rate. Resample will avoid any aliasing of higher frequencies.

How do I measure sound pressure using the iPhone internal microphone?

I want to measure the loudness of ambient sound. Having read a number of posts on stackoverflow I feel more confused than I was originally. Im not a sound engineer just a programmer.
I think I need to calculate dBSPL with the formula 20 * log10 (voltage / Voltage_Ref)
So for this I need to sample the internal microphone voltage (or pressure in Pascals?) level. The class AVAudioRecorder allows me to meter read the peakPowerForChannel but this gives a dbFS reading between 160 and 0. Where 0 is full power. How do I access the voltage/pressure levels, with another API perhaps?
I had read that roughly 0 dbFS = 99 db SPL. But that would mean the maximum db SPL I could read using the peakPowerForChannel reading would be 99 db SPL. I'm looking to read levels higher than this.
Any information on this would be most appreciated - im somewhat stuck at this point.
Thanks
Mike
The only way to do this is to test your particular iOS device model (and perhaps production batch) against a known sound source at a given distance and relationship to the mic in an anechoic chamber. The voltage and pressure relationship is neither specified by Apple nor available from any API.

Audible Click when pitch shifting in OpenAL

I am using OpenAL to pitch shift a note. e.g.
alSourcef(source, AL_PITCH, aPitch);
I am noticing however an audible click when I do this. Other than that the pitch is perfect, correct pitch etc.
Any ideas what might be causing this?
I haven't used OpenAL, but in other sound libraries I have seen this "artifact". There is usually, when dealing with tone generator etc. a variable for the time it takes a tone to reach 100% volume level, I can for the life of me not remember what it is called :)
like this:
playTone(400 Hz, 40 dB, 50 ms, 3000 ms).
where 400 is the Hz, 40 dB the volume, 3000 milliseconds is the duration and 50 milliseconds is the time it takes from starting the tone at volume 0 (or +100dB) to it reaches 40 dB. I simply can't find the word right now.
Anyways, if you have the ability to set this variable, try doing that, just set it to something like 10 ms. You wont be able to hear it, but it has removed clicking sounds for me in both an open source sound library I used for the iPhone and in some Java/Processing libraries I used in the past.
Maybe it has to do with the way the underlying code is triggering some hardware connected to the speaker?
i have experience on this one, mostly it is because you shift the pitch too high or too low, shifting pitch is stretching or shrinking wave-data length, the case is if your data does not have enough sample to stretch it will sound "weird", in case of shortening the length (pitch-up) if your playback buffer does not have enough sample to feed in time, it will lag or jitter because conceptually the playing rate is increased to due shortened the length of audio, mostly clicking or popping is what you heard.
to prevent this, you should limit the shifting range, mostly 0.5 to 2.0 is the limit on most sound-card, and it is vary across soundcard, since shifting the pitch could be make better by using some advanced smoothing and processing in DSP, so it will depend on processing power of your DSP or CPU to do such processing. i've tried it using onboard intel HDA that the limit is mostly 0.5 to 2.0, but using X-Fi soundcard it is better, shifting to 0.1 .. 5.0 doesn't have a problem