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


Java AudioFormat.CHANNEL_OUT_STEREO屬性代碼示例

本文整理匯總了Java中android.media.AudioFormat.CHANNEL_OUT_STEREO屬性的典型用法代碼示例。如果您正苦於以下問題:Java AudioFormat.CHANNEL_OUT_STEREO屬性的具體用法?Java AudioFormat.CHANNEL_OUT_STEREO怎麽用?Java AudioFormat.CHANNEL_OUT_STEREO使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在android.media.AudioFormat的用法示例。


在下文中一共展示了AudioFormat.CHANNEL_OUT_STEREO屬性的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: initAudioTrack

private void initAudioTrack(int sampleRate, int channels) {
    if (sampleRate <= 0) {
        sampleRate = AUDIO_FORMAT_PCM8K;
    }
    if (channels <= 0) {
        channels = 1;
    }
    if (channels == 1) {
        mChannelConfig = AudioFormat.CHANNEL_OUT_MONO;
    } else if (channels == 2) {
        mChannelConfig = AudioFormat.CHANNEL_OUT_STEREO;
    }
    if (iCurrentQueueAudioFormat == sampleRate) {
        if (mAudioTrack == null) {
            mAudioTrack = createAudioTrack(iCurrentQueueAudioFormat);
        }
    } else {
        Log.d(TAG, "Decoder-initAudioTrack-sampleRate=" + sampleRate);
        Log.d(TAG, "Decoder-initAudioTrack-channels=" + channels);
        mAudioTrack = createAudioTrack(sampleRate);
        iCurrentQueueAudioFormat = sampleRate;
    }
}
 
開發者ID:dueros,項目名稱:dcs-sdk-java,代碼行數:23,代碼來源:AudioTrackPlayerImpl.java

示例2: getMinBufferSize

private int getMinBufferSize(int sampleRate, int channelConfig, int audioFormat) {
    minBufferSize = AudioTrack.getMinBufferSize(sampleRate, channelConfig, audioFormat);
    // 解決異常IllegalArgumentException: Invalid audio buffer size
    int channelCount = 1;
    switch (channelConfig) {
        // AudioFormat.CHANNEL_CONFIGURATION_DEFAULT
        case AudioFormat.CHANNEL_OUT_DEFAULT:
        case AudioFormat.CHANNEL_OUT_MONO:
        case AudioFormat.CHANNEL_CONFIGURATION_MONO:
            channelCount = 1;
            break;
        case AudioFormat.CHANNEL_OUT_STEREO:
        case AudioFormat.CHANNEL_CONFIGURATION_STEREO:
            channelCount = 2;
            break;
        default:
            channelCount = Integer.bitCount(channelConfig);
    }
    // 判斷minBufferSize是否在範圍內,如果不在設定默認值為1152
    int frameSizeInBytes = channelCount * (audioFormat == AudioFormat.ENCODING_PCM_8BIT ? 1 : 2);
    if ((minBufferSize % frameSizeInBytes != 0) || (minBufferSize < 1)) {
        minBufferSize = 1152;
    }
    return minBufferSize;
}
 
開發者ID:dueros,項目名稱:dcs-sdk-java,代碼行數:25,代碼來源:AudioTrackPlayerImpl.java

示例3: createAudioTrack

public AudioTrack createAudioTrack(int frameRate) {
    int minBufferSizeBytes = AudioTrack.getMinBufferSize(frameRate,
            AudioFormat.CHANNEL_OUT_STEREO, AudioFormat.ENCODING_PCM_FLOAT);
    Log.i(TAG, "AudioTrack.minBufferSize = " + minBufferSizeBytes
            + " bytes = " + (minBufferSizeBytes / BYTES_PER_FRAME)
            + " frames");
    int bufferSize = 8 * minBufferSizeBytes / 8;
    int outputBufferSizeFrames = bufferSize / BYTES_PER_FRAME;
    Log.i(TAG, "actual bufferSize = " + bufferSize + " bytes = "
            + outputBufferSizeFrames + " frames");

    AudioTrack player = new AudioTrack(AudioManager.STREAM_MUSIC,
            mFrameRate, AudioFormat.CHANNEL_OUT_STEREO,
            AudioFormat.ENCODING_PCM_FLOAT, bufferSize,
            AudioTrack.MODE_STREAM);
    Log.i(TAG, "created AudioTrack");
    return player;
}
 
開發者ID:sdrausty,項目名稱:buildAPKsSamples,代碼行數:18,代碼來源:SimpleAudioOutput.java

示例4: audioTrackInit

@SuppressLint("NewApi")

    private int audioTrackInit(int sampleRateInHz, int channels) {
        //  this.sampleRateInHz=sampleRateInHz;
        //  this.channels=channels;
        //   return 0;

        audioTrackRelease();
        int channelConfig = channels >= 2 ? AudioFormat.CHANNEL_OUT_STEREO : AudioFormat.CHANNEL_OUT_MONO;
        try {
            mAudioTrackBufferSize = AudioTrack.getMinBufferSize(sampleRateInHz, channelConfig, AudioFormat.ENCODING_PCM_16BIT);
            mAudioTrack = new AudioTrack(AudioManager.STREAM_MUSIC, sampleRateInHz, channelConfig, AudioFormat.ENCODING_PCM_16BIT, mAudioTrackBufferSize, AudioTrack.MODE_STREAM);
        } catch (Exception e) {
            mAudioTrackBufferSize = 0;
            Log.e("audioTrackInit", e);
        }
        return mAudioTrackBufferSize;
    }
 
開發者ID:WangZhiYao,項目名稱:VideoDemo,代碼行數:18,代碼來源:MediaPlayer.java

示例5: generateTrack

public AudioTrack generateTrack(int sampleRate, short[] buf, int len) {
    int end = len;

    int c = 0;

    if (RawSamples.CHANNEL_CONFIG == AudioFormat.CHANNEL_IN_MONO)
        c = AudioFormat.CHANNEL_OUT_MONO;

    if (RawSamples.CHANNEL_CONFIG == AudioFormat.CHANNEL_IN_STEREO)
        c = AudioFormat.CHANNEL_OUT_STEREO;

    // old phones bug.
    // http://stackoverflow.com/questions/27602492
    //
    // with MODE_STATIC setNotificationMarkerPosition not called
    AudioTrack track = new AudioTrack(AudioManager.STREAM_MUSIC, sampleRate,
            c, RawSamples.AUDIO_FORMAT,
            len * (Short.SIZE / 8), AudioTrack.MODE_STREAM);
    track.write(buf, 0, len);
    if (track.setNotificationMarkerPosition(end) != AudioTrack.SUCCESS)
        throw new RuntimeException("unable to set marker");
    return track;
}
 
開發者ID:NandagopalR,項目名稱:Android-Audio-Recorder,代碼行數:23,代碼來源:Sound.java

示例6: 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

示例7: prepare

@Override
    protected void prepare() throws IOException {
        if (mState < STATE_PREPARED) {
            MediaFormat format;
            if (mState == STATE_UNINITIALIZED) {
                mTrackIndex = selectTrack();
                if (mTrackIndex < 0) {
                    setState(STATE_NO_TRACK_FOUND);
                    return;
                }
                mExtractor.selectTrack(mTrackIndex);
                format = mExtractor.getTrackFormat(mTrackIndex);
                mSampleRate = format.getInteger(MediaFormat.KEY_SAMPLE_RATE);
                int audioChannels = format.getInteger(MediaFormat.KEY_CHANNEL_COUNT);
                mAudioTrack = new AudioTrack(
                        AudioManager.STREAM_MUSIC,
                        mSampleRate,
                        (audioChannels == 1 ? AudioFormat.CHANNEL_OUT_MONO : AudioFormat.CHANNEL_OUT_STEREO),
                        AudioFormat.ENCODING_PCM_16BIT,
                        AudioTrack.getMinBufferSize(
                                mSampleRate,
                                (audioChannels == 1 ? AudioFormat.CHANNEL_OUT_MONO : AudioFormat.CHANNEL_OUT_STEREO),
                                AudioFormat.ENCODING_PCM_16BIT
                        ),
                        AudioTrack.MODE_STREAM
                );
                mState = STATE_INITIALIZED;
            } else {
                format = mExtractor.getTrackFormat(mTrackIndex);
            }

            String mime = format.getString(MediaFormat.KEY_MIME);
            Log.d(TAG, mime);
            mMediaCodec = MediaCodec.createDecoderByType(mime);
//            mMediaCodec.setCallback(mCallback);
            mMediaCodec.configure(format, null, null, 0);
            setState(STATE_PREPARED);
        }
        super.prepare();
    }
 
開發者ID:Tai-Kimura,項目名稱:VideoApplication,代碼行數:40,代碼來源:AudioDecoder.java

示例8: audioDecoderTest

public void audioDecoderTest(String filePath) throws IOException {
  AudioDecoder audioDecoderThread = new AudioDecoder(this, this);
  audioDecoderThread.initExtractor(filePath);
  audioDecoderThread.prepareAudio();

  int buffsize = AudioTrack.getMinBufferSize(audioDecoderThread.getSampleRate(),
      AudioFormat.CHANNEL_OUT_STEREO, AudioFormat.ENCODING_PCM_16BIT);
  audioTrack = new AudioTrack(AudioManager.STREAM_MUSIC, audioDecoderThread.getSampleRate(),
      AudioFormat.CHANNEL_OUT_STEREO, AudioFormat.ENCODING_PCM_16BIT, buffsize,
      AudioTrack.MODE_STREAM);
  audioTrack.play();
  audioDecoderThread.start();
}
 
開發者ID:pedroSG94,項目名稱:rtmp-rtsp-stream-client-java,代碼行數:13,代碼來源:DecodersTest.java

示例9: getMinOutputFrameSize

private static int getMinOutputFrameSize(int sampleRateInHz, int numChannels) {
  final int bytesPerFrame = numChannels * (BITS_PER_SAMPLE / 8);
  final int channelConfig =
      (numChannels == 1 ? AudioFormat.CHANNEL_OUT_MONO : AudioFormat.CHANNEL_OUT_STEREO);
  return AudioTrack.getMinBufferSize(
             sampleRateInHz, channelConfig, AudioFormat.ENCODING_PCM_16BIT)
      / bytesPerFrame;
}
 
開發者ID:Piasy,項目名稱:AppRTC-Android,代碼行數:8,代碼來源:WebRtcAudioManager.java

示例10: createAudioTrack

private AudioTrack createAudioTrack(int sampleRate, int channelCount) {
    int channelConfig = channelCount == 1 ? AudioFormat.CHANNEL_OUT_MONO : AudioFormat.CHANNEL_OUT_STEREO;
    int bufferSize = ((sampleRate * 2) * channelCount / 100) * 8;//最多緩衝80毫秒的數據
    return new AudioTrack(
            AudioManager.STREAM_MUSIC,
            sampleRate,
            channelConfig,
            AudioFormat.ENCODING_PCM_16BIT,
            bufferSize,
            AudioTrack.MODE_STREAM);
}
 
開發者ID:vipycm,項目名稱:mao-android,代碼行數:11,代碼來源:AudioDecoderFragment.java

示例11: audioTrackInit

public int audioTrackInit() {
//	  Log.e("  ffff mediaplayer audiotrackinit start .  sampleRateInHz:=" + sampleRateInHz + " channels:=" + channels );
	    audioTrackRelease();
	    int channelConfig = channels >= 2 ? AudioFormat.CHANNEL_OUT_STEREO : AudioFormat.CHANNEL_OUT_MONO;
	    try {
	      mAudioTrackBufferSize = AudioTrack.getMinBufferSize(sampleRateInHz, channelConfig, AudioFormat.ENCODING_PCM_16BIT);
	      mAudioTrack = new AudioTrack(AudioManager.STREAM_MUSIC, sampleRateInHz, channelConfig, AudioFormat.ENCODING_PCM_16BIT, mAudioTrackBufferSize, AudioTrack.MODE_STREAM);
	    } catch (Exception e) {
	      mAudioTrackBufferSize = 0;
	      Log.e("audioTrackInit", e);
	    }
	    return mAudioTrackBufferSize;
	  }
 
開發者ID:coding-dream,項目名稱:TPlayer,代碼行數:13,代碼來源:MediaPlayer.java

示例12: start

@Override
public void start()    {
    minBufferSize = AudioTrack.getMinBufferSize(frameRate,
            AudioFormat.CHANNEL_OUT_STEREO,
            AudioFormat.ENCODING_PCM_16BIT);
    System.out.println("Audio minBufferSize = " + minBufferSize);
    bufferSize = (3 * (minBufferSize / 2)) & ~3;
    System.out.println("Audio bufferSize = " + bufferSize);
    audioTrack = new AudioTrack(
            AudioManager.STREAM_MUSIC, frameRate,
            AudioFormat.CHANNEL_OUT_STEREO,
            AudioFormat.ENCODING_PCM_16BIT, bufferSize,
            AudioTrack.MODE_STREAM);
    audioTrack.play();
}
 
開發者ID:google,項目名稱:science-journal,代碼行數:15,代碼來源:AndroidAudioForJSyn.java

示例13: audioTrackInit

private int audioTrackInit(int sampleRateInHz, int channels) {
  audioTrackRelease();
  int channelConfig = channels >= 2 ? AudioFormat.CHANNEL_OUT_STEREO : AudioFormat.CHANNEL_OUT_MONO;
  try {
    mAudioTrackBufferSize = AudioTrack.getMinBufferSize(sampleRateInHz, channelConfig, AudioFormat.ENCODING_PCM_16BIT);
    mAudioTrack = new AudioTrack(AudioManager.STREAM_MUSIC, sampleRateInHz, channelConfig, AudioFormat.ENCODING_PCM_16BIT, mAudioTrackBufferSize, AudioTrack.MODE_STREAM);
  } catch (Exception e) {
    mAudioTrackBufferSize = 0;
    Log.e("audioTrackInit", e);
  }
  return mAudioTrackBufferSize;
}
 
開發者ID:shegang,項目名稱:meishiDemo,代碼行數:12,代碼來源:MediaPlayer.java

示例14: findFormatFromChannels

private int findFormatFromChannels(int numChannels) {
    switch (numChannels) {
        case 1:
            return AudioFormat.CHANNEL_OUT_MONO;
        case 2:
            return AudioFormat.CHANNEL_OUT_STEREO;
        default:
            return -1; // Error
    }
}
 
開發者ID:jcodeing,項目名稱:K-Sonic,代碼行數:10,代碼來源:Track.java

示例15: init

@Override
public void init(int streamType) {
	int sampleRateInHz = 16000;
	int channelConfig = AudioFormat.CHANNEL_OUT_STEREO;
	int audioFormat = AudioFormat.ENCODING_PCM_16BIT;
	int bufferSizeInBytes = AudioTrack.getMinBufferSize(sampleRateInHz, channelConfig, audioFormat);
	int mode = AudioTrack.MODE_STREAM;
	
	audioTrack = new AudioTrack(streamType, sampleRateInHz, channelConfig, audioFormat, bufferSizeInBytes, mode);
}
 
開發者ID:leleliu008,項目名稱:Newton_for_Android_AS,代碼行數:10,代碼來源:PlayWithAudioTrack.java


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