本文整理匯總了Java中android.media.AudioTrack.MODE_STATIC屬性的典型用法代碼示例。如果您正苦於以下問題:Java AudioTrack.MODE_STATIC屬性的具體用法?Java AudioTrack.MODE_STATIC怎麽用?Java AudioTrack.MODE_STATIC使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在類android.media.AudioTrack
的用法示例。
在下文中一共展示了AudioTrack.MODE_STATIC屬性的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: playSound
/**
* This method plays the sound data in the specified buffer.
*
* @param buffer specifies the sound data buffer.
*/
public void playSound(short[] buffer)
{
final String funcName = "playSound";
if (debugEnabled)
{
dbgTrace.traceEnter(funcName, TrcDbgTrace.TraceLevel.API);
dbgTrace.traceExit(funcName, TrcDbgTrace.TraceLevel.API);
}
audioTrack = new AudioTrack(
AudioManager.STREAM_MUSIC,
sampleRate,
AudioFormat.CHANNEL_OUT_MONO,
AudioFormat.ENCODING_PCM_16BIT,
buffer.length*2, //buffer length in bytes
AudioTrack.MODE_STATIC);
audioTrack.write(buffer, 0, buffer.length);
audioTrack.setNotificationMarkerPosition(buffer.length);
audioTrack.setPlaybackPositionUpdateListener(this);
audioTrack.play();
playing = true;
}
示例2: generateTone
static private AudioTrack generateTone(double freqHz, int durationMs) {
int count = (int) (44100.0 * 2.0 * (durationMs / 1000.0)) & ~1;
short[] samples = new short[count];
int size = count * (Short.SIZE / 8);
Log.d(TAG, freqHz + "Hz for " + durationMs + "ms = " + count + " samples at 44.1Khz 2ch = " + size + " bytes");
for (int i = 0; i < count; i += 2) {
short sample = (short) (Math.sin(2 * Math.PI * i / (44100.0 / freqHz)) * 0x7FFF * .75);
samples[i + 0] = sample;
samples[i + 1] = sample;
}
AudioTrack track = new AudioTrack(AudioManager.STREAM_MUSIC, 44100,
AudioFormat.CHANNEL_OUT_STEREO, AudioFormat.ENCODING_PCM_16BIT,
size, AudioTrack.MODE_STATIC);
track.setNotificationMarkerPosition(count / 2);
track.write(samples, 0, count);
return track;
}
示例3: AndroidAudioPlayer
public AndroidAudioPlayer(final AudioConfig audioConfig) {
AudioAttributes audioAttributes = new AudioAttributes.Builder()
.setLegacyStreamType(AudioManager.STREAM_MUSIC)
.setUsage(AudioAttributes.USAGE_MEDIA)
.setContentType(AudioAttributes.CONTENT_TYPE_MUSIC)
.build();
AudioFormat audioFormat = new AudioFormat.Builder()
.setChannelMask(audioConfig.getOutputChannel())
.setEncoding(audioConfig.getOutputFormat())
.setSampleRate(audioConfig.getSampleRate())
.build();
audioTrack = new AudioTrack(audioAttributes,
audioFormat,
audioConfig.getOutputBufferSize(),
AudioTrack.MODE_STATIC,
AudioManager.AUDIO_SESSION_ID_GENERATE);
outputByteCount = audioConfig.getOutputFormatByteCount();
}
示例4: playSound
void playSound() {
AudioTrack audioTrack = new AudioTrack(AudioManager.STREAM_MUSIC,
sampleRate, AudioFormat.CHANNEL_CONFIGURATION_MONO,
AudioFormat.ENCODING_PCM_16BIT, numSamples,
AudioTrack.MODE_STATIC);
audioTrack.write(generatedSnd, 0, generatedSnd.length);
audioTrack.play();
}