當前位置: 首頁>>代碼示例>>Java>>正文


Java AudioTrack.MODE_STATIC屬性代碼示例

本文整理匯總了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;
}
 
開發者ID:trc492,項目名稱:Ftc2018RelicRecovery,代碼行數:28,代碼來源:FtcAndroidTone.java

示例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;
}
 
開發者ID:tharvey,項目名稱:BlocklyBot,代碼行數:17,代碼來源:Tone.java

示例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();
}
 
開發者ID:chRyNaN,項目名稱:Android-Guitar-Tuner,代碼行數:21,代碼來源:AndroidAudioPlayer.java

示例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();
}
 
開發者ID:zh-h,項目名稱:IoTApp,代碼行數:8,代碼來源:PlaySoundActivity.java


注:本文中的android.media.AudioTrack.MODE_STATIC屬性示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。