diff options
| author | Andy Hung <hunga@google.com> | 2015-01-16 00:21:15 +0000 |
|---|---|---|
| committer | Android (Google) Code Review <android-gerrit@google.com> | 2015-01-16 00:21:17 +0000 |
| commit | 84a6d9e609ac6ad65e5bf43c8980d78917be543e (patch) | |
| tree | e71aaa45026daad5ecc31a8002506032a95629e3 | |
| parent | 61369de03ea5aea649f3db0b34bf9dc5d5fdcc28 (diff) | |
| parent | 2c0e17c029eccc06deb883d8d564a7e19d98f65e (diff) | |
| download | frameworks_base-84a6d9e609ac6ad65e5bf43c8980d78917be543e.zip frameworks_base-84a6d9e609ac6ad65e5bf43c8980d78917be543e.tar.gz frameworks_base-84a6d9e609ac6ad65e5bf43c8980d78917be543e.tar.bz2 | |
Merge "Allow AUDIO_FORMAT_PCM_8_BIT static AudioTrack buffers"
| -rw-r--r-- | core/jni/android_media_AudioTrack.cpp | 50 |
1 files changed, 5 insertions, 45 deletions
diff --git a/core/jni/android_media_AudioTrack.cpp b/core/jni/android_media_AudioTrack.cpp index c6f4199..a7a925f 100644 --- a/core/jni/android_media_AudioTrack.cpp +++ b/core/jni/android_media_AudioTrack.cpp @@ -215,19 +215,6 @@ android_media_AudioTrack_setup(JNIEnv *env, jobject thiz, jobject weak_this, return (jint) AUDIOTRACK_ERROR_SETUP_INVALIDFORMAT; } - // for the moment 8bitPCM in MODE_STATIC is not supported natively in the AudioTrack C++ class - // so we declare everything as 16bitPCM, the 8->16bit conversion for MODE_STATIC will be handled - // in android_media_AudioTrack_native_write_byte() - if ((format == AUDIO_FORMAT_PCM_8_BIT) - && (memoryMode == MODE_STATIC)) { - ALOGV("android_media_AudioTrack_setup(): requesting MODE_STATIC for 8bit \ - buff size of %dbytes, switching to 16bit, buff size of %dbytes", - buffSizeInBytes, 2*buffSizeInBytes); - format = AUDIO_FORMAT_PCM_16_BIT; - // we will need twice the memory to store the data - buffSizeInBytes *= 2; - } - // compute the frame count size_t frameCount; if (audio_is_linear_pcm(format)) { @@ -523,41 +510,14 @@ jint writeToTrack(const sp<AudioTrack>& track, jint audioFormat, const jbyte* da written = 0; } } else { - const audio_format_t format = audioFormatToNative(audioFormat); - switch (format) { - - default: - case AUDIO_FORMAT_PCM_FLOAT: - case AUDIO_FORMAT_PCM_16_BIT: { - // writing to shared memory, check for capacity - if ((size_t)sizeInBytes > track->sharedBuffer()->size()) { - sizeInBytes = track->sharedBuffer()->size(); - } - memcpy(track->sharedBuffer()->pointer(), data + offsetInBytes, sizeInBytes); - written = sizeInBytes; - } break; - - case AUDIO_FORMAT_PCM_8_BIT: { - // data contains 8bit data we need to expand to 16bit before copying - // to the shared memory - // writing to shared memory, check for capacity, - // note that input data will occupy 2X the input space due to 8 to 16bit conversion - if (((size_t)sizeInBytes)*2 > track->sharedBuffer()->size()) { - sizeInBytes = track->sharedBuffer()->size() / 2; - } - int count = sizeInBytes; - int16_t *dst = (int16_t *)track->sharedBuffer()->pointer(); - const uint8_t *src = (const uint8_t *)(data + offsetInBytes); - memcpy_to_i16_from_u8(dst, src, count); - // even though we wrote 2*sizeInBytes, we only report sizeInBytes as written to hide - // the 8bit mixer restriction from the user of this function - written = sizeInBytes; - } break; - + // writing to shared memory, check for capacity + if ((size_t)sizeInBytes > track->sharedBuffer()->size()) { + sizeInBytes = track->sharedBuffer()->size(); } + memcpy(track->sharedBuffer()->pointer(), data + offsetInBytes, sizeInBytes); + written = sizeInBytes; } return written; - } // ---------------------------------------------------------------------------- |
