use of java.lang.IllegalArgumentException in project translationstudio8 by heartsome.
the class FastLongBuffer method getLongArray.
/**
* Return a selected chuck of long buffer as a long array.
* @return long[]
* @param startingOffset int
* @param len int
*/
public long[] getLongArray(int startingOffset, int len) {
if (size <= 0 || startingOffset < 0) {
throw (new IllegalArgumentException());
}
if ((startingOffset + len) > size()) {
throw (new IndexOutOfBoundsException());
}
// allocate result array
long[] result = new long[len];
int first_index = (startingOffset >> exp);
int last_index = ((startingOffset + len) >> exp);
//if ((startingOffset + len) % pageSize == 0) {
if (((startingOffset + len) & r) == 0) {
last_index--;
}
if (first_index == last_index) {
// to see if there is a need to go across buffer boundry
System.arraycopy((long[]) (bufferArrayList.get(first_index)), // startingOffset % pageSize,
startingOffset & r, result, 0, len);
} else {
int long_array_offset = 0;
for (int i = first_index; i <= last_index; i++) {
long[] currentChunk = (long[]) bufferArrayList.get(i);
if (// first section
i == first_index) {
System.arraycopy(currentChunk, // startingOffset % pageSize,
startingOffset & r, result, 0, // pageSize - (startingOffset % r));
pageSize - (startingOffset & r));
long_array_offset += pageSize - (startingOffset & r);
} else if (// last sections
i == last_index) {
System.arraycopy(currentChunk, 0, result, long_array_offset, len - long_array_offset);
} else {
System.arraycopy(currentChunk, 0, result, long_array_offset, pageSize);
long_array_offset += pageSize;
}
}
}
return result;
}
use of java.lang.IllegalArgumentException in project XobotOS by xamarin.
the class AudioRecord method audioParamCheck.
// Convenience method for the constructor's parameter checks.
// This is where constructor IllegalArgumentException-s are thrown
// postconditions:
// mRecordSource is valid
// mChannelCount is valid
// mChannels is valid
// mAudioFormat is valid
// mSampleRate is valid
private void audioParamCheck(int audioSource, int sampleRateInHz, int channelConfig, int audioFormat) {
// audio source
if ((audioSource < MediaRecorder.AudioSource.DEFAULT) || (audioSource > MediaRecorder.getAudioSourceMax())) {
throw (new IllegalArgumentException("Invalid audio source."));
} else {
mRecordSource = audioSource;
}
// sample rate
if ((sampleRateInHz < 4000) || (sampleRateInHz > 48000)) {
throw (new IllegalArgumentException(sampleRateInHz + "Hz is not a supported sample rate."));
} else {
mSampleRate = sampleRateInHz;
}
//--------------
// channel config
mChannelConfiguration = channelConfig;
switch(channelConfig) {
// AudioFormat.CHANNEL_CONFIGURATION_DEFAULT
case AudioFormat.CHANNEL_IN_DEFAULT:
case AudioFormat.CHANNEL_IN_MONO:
case AudioFormat.CHANNEL_CONFIGURATION_MONO:
mChannelCount = 1;
mChannels = AudioFormat.CHANNEL_IN_MONO;
break;
case AudioFormat.CHANNEL_IN_STEREO:
case AudioFormat.CHANNEL_CONFIGURATION_STEREO:
mChannelCount = 2;
mChannels = AudioFormat.CHANNEL_IN_STEREO;
break;
default:
mChannelCount = 0;
mChannels = AudioFormat.CHANNEL_INVALID;
mChannelConfiguration = AudioFormat.CHANNEL_INVALID;
throw (new IllegalArgumentException("Unsupported channel configuration."));
}
// audio format
switch(audioFormat) {
case AudioFormat.ENCODING_DEFAULT:
mAudioFormat = AudioFormat.ENCODING_PCM_16BIT;
break;
case AudioFormat.ENCODING_PCM_16BIT:
case AudioFormat.ENCODING_PCM_8BIT:
mAudioFormat = audioFormat;
break;
default:
mAudioFormat = AudioFormat.ENCODING_INVALID;
throw (new IllegalArgumentException("Unsupported sample encoding." + " Should be ENCODING_PCM_8BIT or ENCODING_PCM_16BIT."));
}
}
use of java.lang.IllegalArgumentException in project XobotOS by xamarin.
the class AudioTrack method audioBuffSizeCheck.
// Convenience method for the contructor's audio buffer size check.
// preconditions:
// mChannelCount is valid
// mAudioFormat is valid
// postcondition:
// mNativeBufferSizeInBytes is valid (multiple of frame size, positive)
private void audioBuffSizeCheck(int audioBufferSize) {
// NB: this section is only valid with PCM data.
// To update when supporting compressed formats
int frameSizeInBytes = mChannelCount * (mAudioFormat == AudioFormat.ENCODING_PCM_8BIT ? 1 : 2);
if ((audioBufferSize % frameSizeInBytes != 0) || (audioBufferSize < 1)) {
throw (new IllegalArgumentException("Invalid audio buffer size."));
}
mNativeBufferSizeInBytes = audioBufferSize;
}
use of java.lang.IllegalArgumentException in project XobotOS by xamarin.
the class AudioTrack method audioParamCheck.
// Convenience method for the constructor's parameter checks.
// This is where constructor IllegalArgumentException-s are thrown
// postconditions:
// mStreamType is valid
// mChannelCount is valid
// mChannels is valid
// mAudioFormat is valid
// mSampleRate is valid
// mDataLoadMode is valid
private void audioParamCheck(int streamType, int sampleRateInHz, int channelConfig, int audioFormat, int mode) {
// stream type
if ((streamType != AudioManager.STREAM_ALARM) && (streamType != AudioManager.STREAM_MUSIC) && (streamType != AudioManager.STREAM_RING) && (streamType != AudioManager.STREAM_SYSTEM) && (streamType != AudioManager.STREAM_VOICE_CALL) && (streamType != AudioManager.STREAM_NOTIFICATION) && (streamType != AudioManager.STREAM_BLUETOOTH_SCO) && (streamType != AudioManager.STREAM_DTMF)) {
throw (new IllegalArgumentException("Invalid stream type."));
} else {
mStreamType = streamType;
}
// sample rate
if ((sampleRateInHz < 4000) || (sampleRateInHz > 48000)) {
throw (new IllegalArgumentException(sampleRateInHz + "Hz is not a supported sample rate."));
} else {
mSampleRate = sampleRateInHz;
}
//--------------
// channel config
mChannelConfiguration = channelConfig;
switch(channelConfig) {
//AudioFormat.CHANNEL_CONFIGURATION_DEFAULT
case AudioFormat.CHANNEL_OUT_DEFAULT:
case AudioFormat.CHANNEL_OUT_MONO:
case AudioFormat.CHANNEL_CONFIGURATION_MONO:
mChannelCount = 1;
mChannels = AudioFormat.CHANNEL_OUT_MONO;
break;
case AudioFormat.CHANNEL_OUT_STEREO:
case AudioFormat.CHANNEL_CONFIGURATION_STEREO:
mChannelCount = 2;
mChannels = AudioFormat.CHANNEL_OUT_STEREO;
break;
default:
mChannelCount = 0;
mChannels = AudioFormat.CHANNEL_INVALID;
mChannelConfiguration = AudioFormat.CHANNEL_CONFIGURATION_INVALID;
throw (new IllegalArgumentException("Unsupported channel configuration."));
}
// audio format
switch(audioFormat) {
case AudioFormat.ENCODING_DEFAULT:
mAudioFormat = AudioFormat.ENCODING_PCM_16BIT;
break;
case AudioFormat.ENCODING_PCM_16BIT:
case AudioFormat.ENCODING_PCM_8BIT:
mAudioFormat = audioFormat;
break;
default:
mAudioFormat = AudioFormat.ENCODING_INVALID;
throw (new IllegalArgumentException("Unsupported sample encoding." + " Should be ENCODING_PCM_8BIT or ENCODING_PCM_16BIT."));
}
// audio load mode
if ((mode != MODE_STREAM) && (mode != MODE_STATIC)) {
throw (new IllegalArgumentException("Invalid mode."));
} else {
mDataLoadMode = mode;
}
}
use of java.lang.IllegalArgumentException in project XobotOS by xamarin.
the class SIPDate method setYear.
/**
* Set the year member
* @param y int to set
* @throws IllegalArgumentException if y is not a valid year.
*/
public void setYear(int y) throws IllegalArgumentException {
if (y < 0)
throw new IllegalArgumentException("Illegal year : " + y);
javaCal = null;
year = y;
}
Aggregations