音频R

// 32767
// MAX_VALUE
#if  0
* @param overload the overload (point) of <tt>signal</tt>.
	* For example, <tt>overload</tt> can be {@link Byte#MAX_VALUE}
	* for 8-bit signed samples or {@link Short#MAX_VALUE} for
	* 16-bit signed samples.
	*
#endif 
static int calculateAudioLevel(int samples[], int offset, int length, int overload)
{
	/*
	* Calculate the root mean square (RMS) of the signal.
	*/
	double rms = 0;
	for (; offset < length; offset++)
	{
		double sample = samples[offset];
		sample /= overload;
		rms += sample * sample;
	}
	rms = (length == 0) ? 0 : sqrt(rms / length);
	double db;
	double MIN_AUDIO_LEVEL = -127;
	double MAX_AUDIO_LEVEL = 0;
	if (rms > 0)
	{
		db = 20 *log10(rms);
		if (db < MIN_AUDIO_LEVEL)
			db = MIN_AUDIO_LEVEL;
		else if (db > MAX_AUDIO_LEVEL)
			db = MAX_AUDIO_LEVEL;
	}
	else
	{
		db = MIN_AUDIO_LEVEL;
	}
	return (int)round(db);
}

  

上一篇:audio和video样式兼容


下一篇:Android Q共享音频输入