本文整理匯總了Java中android.media.AudioRecord.setPositionNotificationPeriod方法的典型用法代碼示例。如果您正苦於以下問題:Java AudioRecord.setPositionNotificationPeriod方法的具體用法?Java AudioRecord.setPositionNotificationPeriod怎麽用?Java AudioRecord.setPositionNotificationPeriod使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類android.media.AudioRecord
的用法示例。
在下文中一共展示了AudioRecord.setPositionNotificationPeriod方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: initAudioRecorder
import android.media.AudioRecord; //導入方法依賴的package包/類
/**
* Initialize audio recorder
*/
private void initAudioRecorder() throws IOException {
mBufferSize = AudioRecord.getMinBufferSize(DEFAULT_SAMPLING_RATE,
DEFAULT_CHANNEL_CONFIG, DEFAULT_AUDIO_FORMAT.getAudioFormat());
int bytesPerFrame = DEFAULT_AUDIO_FORMAT.getBytesPerFrame();
/* Get number of samples. Calculate the buffer size
* (round up to the factor of given frame size)
* 使能被整除,方便下麵的周期性通知
* */
int frameSize = mBufferSize / bytesPerFrame;
if (frameSize % FRAME_COUNT != 0) {
frameSize += (FRAME_COUNT - frameSize % FRAME_COUNT);
mBufferSize = frameSize * bytesPerFrame;
}
/* Setup audio recorder */
mAudioRecord = new AudioRecord(DEFAULT_AUDIO_SOURCE,
DEFAULT_SAMPLING_RATE, DEFAULT_CHANNEL_CONFIG, DEFAULT_AUDIO_FORMAT.getAudioFormat(),
mBufferSize);
mPCMBuffer = new short[mBufferSize];
/*
* Initialize lame buffer
* mp3 sampling rate is the same as the recorded pcm sampling rate
* The bit rate is 32kbps
*
*/
Mp3NativeUtil.init(DEFAULT_SAMPLING_RATE, DEFAULT_LAME_IN_CHANNEL, DEFAULT_SAMPLING_RATE, DEFAULT_LAME_MP3_BIT_RATE, DEFAULT_LAME_MP3_QUALITY);
// Create and run thread used to encode data
// The thread will
mEncodeThread = new DataEncodeThread(mRecordFile, mBufferSize);
mEncodeThread.start();
mAudioRecord.setRecordPositionUpdateListener(mEncodeThread, mEncodeThread.getHandler());
mAudioRecord.setPositionNotificationPeriod(FRAME_COUNT);
}
示例2: initAudioRecord
import android.media.AudioRecord; //導入方法依賴的package包/類
private boolean initAudioRecord(Context context, int audioSource, int sampleRate, int channelConfig, int chanelNumber, int audioFormat, int nbBitsPerSample, int bufferSize)
{
witchRecorder = 1;
isAudioRecordRunning = false;
try
{
audioRecordSampleRate = sampleRate;
int timerInterval = 120;
audioRecordPeriodInFrames = sampleRate * timerInterval / 1000;
bufferSize = audioRecordPeriodInFrames * 2 * chanelNumber * nbBitsPerSample / 8;
if(bufferSize < AudioRecord.getMinBufferSize(sampleRate, channelConfig, audioFormat))
{
bufferSize = AudioRecord.getMinBufferSize(sampleRate, channelConfig, audioFormat);
audioRecordPeriodInFrames = bufferSize / ( 2 * nbBitsPerSample * chanelNumber / 8 );
}
audioRecord = new AudioRecord(audioSource, sampleRate, channelConfig, audioFormat, bufferSize);
if (audioRecord.getState() != AudioRecord.STATE_INITIALIZED)
{
Log.w("RecordFileWriter", "initAudioRecord : " + context.getString(R.string.log_record_file_writer_error_audiorecord_init));
databaseManager.insertLog(context, "" + context.getString(R.string.log_record_file_writer_error_audiorecord_init), new Date().getTime(), 2, false);
return false;
}
audioRecord.setRecordPositionUpdateListener(onAudioRecordPositionUpdateListener);
audioRecord.setPositionNotificationPeriod(audioRecordPeriodInFrames);
}
catch (Exception e)
{
Log.w("RecordFileWriter", "initAudioRecord : " + context.getString(R.string.log_record_file_writer_error_audiorecord_init) + " : " + e);
databaseManager.insertLog(context, "" + context.getString(R.string.log_record_file_writer_error_audiorecord_init), new Date().getTime(), 2, false);
return false;
}
return true;
}
示例3: ExtAudioRecorder
import android.media.AudioRecord; //導入方法依賴的package包/類
/**
*
*
* Default constructor
*
* Instantiates a new recorder, in case of compressed recording the
* parameters can be left as 0. In case of errors, no exception is thrown,
* but the state is set to ERROR
*
*/
@SuppressWarnings("deprecation")
public ExtAudioRecorder(boolean uncompressed, int audioSource,
int sampleRate, int channelConfig, int audioFormat) {
try {
rUncompressed = uncompressed;
if (rUncompressed) { // RECORDING_UNCOMPRESSED
if (audioFormat == AudioFormat.ENCODING_PCM_16BIT) {
bSamples = 16;
} else {
bSamples = 8;
}
if (channelConfig == AudioFormat.CHANNEL_CONFIGURATION_MONO) {
nChannels = 1;
} else {
nChannels = 2;
}
aSource = audioSource;
sRate = sampleRate;
aFormat = audioFormat;
framePeriod = sampleRate * TIMER_INTERVAL / 1000;
bufferSize = framePeriod * 2 * bSamples * nChannels / 8;
if (bufferSize < AudioRecord.getMinBufferSize(sampleRate,
channelConfig, audioFormat)) { // Check to make sure
// buffer size is not
// smaller than the
// smallest allowed one
bufferSize = AudioRecord.getMinBufferSize(sampleRate,
channelConfig, audioFormat);
// Set frame period and timer interval accordingly
framePeriod = bufferSize / (2 * bSamples * nChannels / 8);
Log.w(ExtAudioRecorder.class.getName(),
"Increasing buffer size to "
+ Integer.toString(bufferSize));
}
audioRecorder = new AudioRecord(audioSource, sampleRate,
channelConfig, audioFormat, bufferSize);
if (audioRecorder.getState() != AudioRecord.STATE_INITIALIZED)
throw new Exception("AudioRecord initialization failed");
audioRecorder.setRecordPositionUpdateListener(updateListener);
audioRecorder.setPositionNotificationPeriod(framePeriod);
} else { // RECORDING_COMPRESSED
mediaRecorder = new MediaRecorder();
mediaRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
mediaRecorder
.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
mediaRecorder
.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
}
cAmplitude = 0;
filePath = null;
state = State.INITIALIZING;
} catch (Exception e) {
if (e.getMessage() != null) {
Log.e(ExtAudioRecorder.class.getName(), e.getMessage());
} else {
Log.e(ExtAudioRecorder.class.getName(),
"Unknown error occured while initializing recording");
}
state = State.ERROR;
}
}