当前位置: 首页>>代码示例>>Java>>正文


Java AudioFormat.CHANNEL_CONFIGURATION_STEREO属性代码示例

本文整理汇总了Java中android.media.AudioFormat.CHANNEL_CONFIGURATION_STEREO属性的典型用法代码示例。如果您正苦于以下问题:Java AudioFormat.CHANNEL_CONFIGURATION_STEREO属性的具体用法?Java AudioFormat.CHANNEL_CONFIGURATION_STEREO怎么用?Java AudioFormat.CHANNEL_CONFIGURATION_STEREO使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在android.media.AudioFormat的用法示例。


在下文中一共展示了AudioFormat.CHANNEL_CONFIGURATION_STEREO属性的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

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

示例2: start

/**
 * 设置频率
 * @param rate
 */
@SuppressWarnings("deprecation")
public void start(int rate){
	stop();
	if(rate>0){
		Hz=rate;
		waveLen = RATE / Hz;
		length = waveLen * Hz;
		audioTrack=new AudioTrack(AudioManager.STREAM_MUSIC, RATE,
				AudioFormat.CHANNEL_CONFIGURATION_STEREO, // CHANNEL_CONFIGURATION_MONO,
				AudioFormat.ENCODING_PCM_8BIT, length, AudioTrack.MODE_STREAM);
		//生成正弦波
		wave=SinWave.sin(wave, waveLen, length);
		if(audioTrack!=null){
			audioTrack.play();
		}
	}else{
		return;
	}
	
}
 
开发者ID:Becavalier,项目名称:QRDataTransfer-Android,代码行数:24,代码来源:AudioTrackManager.java

示例3: AudioThread

public AudioThread(int sampleRateInHz, int channel, long streamId, long decoderId, Media media)
{
	if (channel == 1)
	{
		channel_configuration = AudioFormat.CHANNEL_CONFIGURATION_MONO;
	} else
	{
		channel_configuration = AudioFormat.CHANNEL_CONFIGURATION_STEREO;
	}
	this.mediaStreamId = streamId;
	this.decoderId = decoderId;
	this.media = media;
	int minBufferSize = AudioTrack.getMinBufferSize(sampleRateInHz, channel_configuration, AudioFormat.ENCODING_PCM_16BIT);
	if (minBufferSize > audioLength)
	{
		audioLength = minBufferSize;
	}
	mAudioBuffer = new byte[audioLength];
	mAudio = new AudioTrack(AudioManager.STREAM_MUSIC, sampleRateInHz, channel_configuration, AudioFormat.ENCODING_PCM_16BIT, audioLength, AudioTrack.MODE_STREAM);
}
 
开发者ID:OpenIchano,项目名称:Viewer,代码行数:20,代码来源:AudioThread.java

示例4: getRecordBufferSize

public static int getRecordBufferSize() {
    int frequency = Options.getInstance().audio.frequency;
    int audioEncoding = Options.getInstance().audio.encoding;
    int channelConfiguration = AudioFormat.CHANNEL_CONFIGURATION_MONO;
    if(Options.getInstance().audio.channelCount == 2) {
        channelConfiguration = AudioFormat.CHANNEL_CONFIGURATION_STEREO;
    }
    return AudioRecord.getMinBufferSize(frequency, channelConfiguration, audioEncoding);
}
 
开发者ID:wuyisheng,项目名称:libRtmp,代码行数:9,代码来源:AndroidUntil.java

示例5: getAudioRecord

@TargetApi(18)
public static AudioRecord getAudioRecord() {
    int frequency = Options.getInstance().audio.frequency;
    int audioEncoding = Options.getInstance().audio.encoding;
    int channelConfiguration = AudioFormat.CHANNEL_CONFIGURATION_MONO;
    if(Options.getInstance().audio.channelCount == 2) {
        channelConfiguration = AudioFormat.CHANNEL_CONFIGURATION_STEREO;
    }
    int audioSource = MediaRecorder.AudioSource.MIC;
    if(Options.getInstance().audio.aec) {
        audioSource = MediaRecorder.AudioSource.VOICE_COMMUNICATION;
    }
    return new AudioRecord(audioSource, frequency,
            channelConfiguration, audioEncoding, getRecordBufferSize());
}
 
开发者ID:wuyisheng,项目名称:libRtmp,代码行数:15,代码来源:AndroidUntil.java

示例6: AudioOutputQueue

public AudioOutputQueue(final AudioStreamInformationProvider streamInfoProvider) {
	convertUnsignedToSigned = true;
	
	//setup the Audio Format options
	streamType = AudioManager.STREAM_MUSIC;
	
	sampleRateInHz = streamInfoProvider.getSampleRate();
	channelConfig = streamInfoProvider.getChannels();
	audioFormat = streamInfoProvider. getAudioFormat();
	
	sampleRate = streamInfoProvider.getSampleRate();
	
	/* Audio format-dependent stuff */
	packetSizeFrames = streamInfoProvider.getFramesPerPacket();
	bytesPerFrame = streamInfoProvider.getChannels() * streamInfoProvider.getSampleSizeInBits() / 8;
	
	//calculate the buffer size in bytes
	bufferSizeInBytes = (int)Math.pow(2, Math.ceil(Math.log(BUFFER_SIZE_SECONDS * sampleRate * bytesPerFrame) / Math.log(2.0)));
	
	mode = AudioTrack.MODE_STREAM;
	
	//create the AudioTrack
	//audioTrack = new AudioTrack(streamType, sampleRateInHz, channelConfig, audioFormat, bufferSizeInBytes, mode);
	audioTrack = new AudioTrack(streamType, sampleRateInHz, AudioFormat.CHANNEL_CONFIGURATION_STEREO, audioFormat, bufferSizeInBytes, mode);//FIXME

	LOG.info("AudioTrack created succesfully with a buffer of : " + bufferSizeInBytes + " bytes and : " + bufferSizeInBytes / bytesPerFrame + " frames.");
		
	//create initial array of "filler" bytes ....
	lineLastFrame = new byte[bytesPerFrame];
	for(int b=0; b < lineLastFrame.length; ++b){
		lineLastFrame[b] = (b % 2 == 0) ? (byte)-128 : (byte)0;
	}

	/* Create enqueuer thread and wait for the line to start.
	 * The wait guarantees that the AudioClock functions return
	 * sensible values right after construction
	 */
	queueThread.setDaemon(true);
	queueThread.setName("Audio Enqueuer");
	queueThread.setPriority(Thread.MAX_PRIORITY);
	
	/*
	queueThread.start();
	
	//while ( queueThread.isAlive() && ! m_line.isActive() ){
	while ( queueThread.isAlive() && audioTrack.getPlayState() != AudioTrack.PLAYSTATE_PLAYING){
		Thread.yield();
	}
	*/

	/* Initialize the seconds time offset now that the line is running. */
	secondsTimeOffset = 2208988800.0 +  System.currentTimeMillis() * 1e-3;
}
 
开发者ID:SergioChan,项目名称:Android-Airplay-Server,代码行数:53,代码来源:AudioOutputQueue.java


注:本文中的android.media.AudioFormat.CHANNEL_CONFIGURATION_STEREO属性示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。