Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 1 | /* AudioStreamInALSA.cpp |
| 2 | ** |
| 3 | ** Copyright 2008-2009 Wind River Systems |
| 4 | ** Copyright (c) 2011-2012, Code Aurora Forum. All rights reserved. |
| 5 | ** |
| 6 | ** Licensed under the Apache License, Version 2.0 (the "License"); |
| 7 | ** you may not use this file except in compliance with the License. |
| 8 | ** You may obtain a copy of the License at |
| 9 | ** |
| 10 | ** http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | ** |
| 12 | ** Unless required by applicable law or agreed to in writing, software |
| 13 | ** distributed under the License is distributed on an "AS IS" BASIS, |
| 14 | ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 | ** See the License for the specific language governing permissions and |
| 16 | ** limitations under the License. |
| 17 | */ |
| 18 | |
| 19 | #include <errno.h> |
| 20 | #include <stdarg.h> |
| 21 | #include <sys/stat.h> |
| 22 | #include <fcntl.h> |
| 23 | #include <stdlib.h> |
| 24 | #include <unistd.h> |
| 25 | #include <dlfcn.h> |
| 26 | |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame^] | 27 | #define LOG_TAG "audio.primary.msm8960" |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 28 | //#define LOG_NDEBUG 0 |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 29 | #include <utils/Log.h> |
| 30 | #include <utils/String8.h> |
| 31 | |
| 32 | #include <cutils/properties.h> |
| 33 | #include <media/AudioRecord.h> |
| 34 | #include <hardware_legacy/power.h> |
| 35 | |
| 36 | #include "AudioHardwareALSA.h" |
| 37 | |
| 38 | extern "C" { |
| 39 | #if 0 |
| 40 | #include "csd_client.h" |
| 41 | #endif |
| 42 | #ifdef SSR_ENABLED |
| 43 | #include "surround_filters_interface.h" |
| 44 | #endif |
| 45 | } |
| 46 | |
| 47 | namespace android_audio_legacy |
| 48 | { |
| 49 | #ifdef SSR_ENABLED |
| 50 | #define SURROUND_FILE_1R "/system/etc/surround_sound/filter1r.pcm" |
| 51 | #define SURROUND_FILE_2R "/system/etc/surround_sound/filter2r.pcm" |
| 52 | #define SURROUND_FILE_3R "/system/etc/surround_sound/filter3r.pcm" |
| 53 | #define SURROUND_FILE_4R "/system/etc/surround_sound/filter4r.pcm" |
| 54 | |
| 55 | #define SURROUND_FILE_1I "/system/etc/surround_sound/filter1i.pcm" |
| 56 | #define SURROUND_FILE_2I "/system/etc/surround_sound/filter2i.pcm" |
| 57 | #define SURROUND_FILE_3I "/system/etc/surround_sound/filter3i.pcm" |
| 58 | #define SURROUND_FILE_4I "/system/etc/surround_sound/filter4i.pcm" |
| 59 | |
| 60 | // Use AAC/DTS channel mapping as default channel mapping: C,FL,FR,Ls,Rs,LFE |
| 61 | const int chanMap[] = { 1, 2, 4, 3, 0, 5 }; |
| 62 | #endif |
| 63 | |
| 64 | AudioStreamInALSA::AudioStreamInALSA(AudioHardwareALSA *parent, |
| 65 | alsa_handle_t *handle, |
| 66 | AudioSystem::audio_in_acoustics audio_acoustics) : |
| 67 | ALSAStreamOps(parent, handle), |
| 68 | mFramesLost(0), |
| 69 | mParent(parent), |
| 70 | mAcoustics(audio_acoustics) |
| 71 | #ifdef SSR_ENABLED |
| 72 | , mFp_4ch(NULL), |
| 73 | mFp_6ch(NULL), |
| 74 | mRealCoeffs(NULL), |
| 75 | mImagCoeffs(NULL), |
| 76 | mSurroundObj(NULL), |
| 77 | mSurroundOutputBuffer(NULL), |
| 78 | mSurroundInputBuffer(NULL), |
| 79 | mSurroundOutputBufferIdx(0), |
| 80 | mSurroundInputBufferIdx(0) |
| 81 | #endif |
| 82 | { |
| 83 | #ifdef SSR_ENABLED |
| 84 | char c_multi_ch_dump[128] = {0}; |
| 85 | status_t err = NO_ERROR; |
| 86 | |
| 87 | // Call surround sound library init if device is Surround Sound |
| 88 | if ( handle->channels == 6) { |
| 89 | if (!strncmp(handle->useCase, SND_USE_CASE_VERB_HIFI_REC, strlen(SND_USE_CASE_VERB_HIFI_REC)) |
| 90 | || !strncmp(handle->useCase, SND_USE_CASE_MOD_CAPTURE_MUSIC, strlen(SND_USE_CASE_MOD_CAPTURE_MUSIC))) { |
| 91 | |
| 92 | err = initSurroundSoundLibrary(handle->bufferSize); |
| 93 | if ( NO_ERROR != err) { |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame^] | 94 | ALOGE("initSurroundSoundLibrary failed: %d handle->bufferSize:%d", err,handle->bufferSize); |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 95 | } |
| 96 | |
| 97 | property_get("ssr.pcmdump",c_multi_ch_dump,"0"); |
| 98 | if (0 == strncmp("true",c_multi_ch_dump, sizeof("ssr.dump-pcm"))) { |
| 99 | //Remember to change file system permission of data(e.g. chmod 777 data/), |
| 100 | //otherwise, fopen may fail. |
| 101 | if ( !mFp_4ch) |
| 102 | mFp_4ch = fopen("/data/4ch_ssr.pcm", "wb"); |
| 103 | if ( !mFp_6ch) |
| 104 | mFp_6ch = fopen("/data/6ch_ssr.pcm", "wb"); |
| 105 | if ((!mFp_4ch) || (!mFp_6ch)) |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame^] | 106 | ALOGE("mfp_4ch or mfp_6ch open failed: mfp_4ch:%p mfp_6ch:%p",mFp_4ch,mFp_6ch); |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 107 | } |
| 108 | } |
| 109 | } |
| 110 | #endif |
| 111 | } |
| 112 | |
| 113 | AudioStreamInALSA::~AudioStreamInALSA() |
| 114 | { |
| 115 | close(); |
| 116 | } |
| 117 | |
| 118 | status_t AudioStreamInALSA::setGain(float gain) |
| 119 | { |
| 120 | return 0; //mixer() ? mixer()->setMasterGain(gain) : (status_t)NO_INIT; |
| 121 | } |
| 122 | |
| 123 | ssize_t AudioStreamInALSA::read(void *buffer, ssize_t bytes) |
| 124 | { |
| 125 | int period_size; |
| 126 | |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame^] | 127 | ALOGV("read:: buffer %p, bytes %d", buffer, bytes); |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 128 | |
| 129 | int n; |
| 130 | status_t err; |
| 131 | size_t read = 0; |
| 132 | char *use_case; |
| 133 | int newMode = mParent->mode(); |
| 134 | |
| 135 | if((mHandle->handle == NULL) && (mHandle->rxHandle == NULL) && |
| 136 | (strcmp(mHandle->useCase, SND_USE_CASE_VERB_IP_VOICECALL)) && |
| 137 | (strcmp(mHandle->useCase, SND_USE_CASE_MOD_PLAY_VOIP))) { |
| 138 | mParent->mLock.lock(); |
| 139 | snd_use_case_get(mHandle->ucMgr, "_verb", (const char **)&use_case); |
| 140 | if ((use_case != NULL) && (strcmp(use_case, SND_USE_CASE_VERB_INACTIVE))) { |
| 141 | if ((mHandle->devices == AudioSystem::DEVICE_IN_VOICE_CALL) && |
| 142 | (newMode == AudioSystem::MODE_IN_CALL)) { |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame^] | 143 | ALOGD("read:: mParent->mIncallMode=%d", mParent->mIncallMode); |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 144 | if ((mParent->mIncallMode & AudioSystem::CHANNEL_IN_VOICE_UPLINK) && |
| 145 | (mParent->mIncallMode & AudioSystem::CHANNEL_IN_VOICE_DNLINK)) { |
| 146 | #if 0 |
| 147 | if (mParent->mFusion3Platform) { |
| 148 | mParent->mALSADevice->setVocRecMode(INCALL_REC_STEREO); |
| 149 | strlcpy(mHandle->useCase, SND_USE_CASE_MOD_CAPTURE_VOICE, |
| 150 | sizeof(mHandle->useCase)); |
| 151 | csd_client_start_record(INCALL_REC_STEREO); |
| 152 | } else |
| 153 | #endif |
| 154 | { |
| 155 | strlcpy(mHandle->useCase, SND_USE_CASE_MOD_CAPTURE_VOICE_UL_DL, |
| 156 | sizeof(mHandle->useCase)); |
| 157 | } |
| 158 | } else if (mParent->mIncallMode & AudioSystem::CHANNEL_IN_VOICE_DNLINK) { |
| 159 | #if 0 |
| 160 | if (mParent->mFusion3Platform) { |
| 161 | mParent->mALSADevice->setVocRecMode(INCALL_REC_MONO); |
| 162 | strlcpy(mHandle->useCase, SND_USE_CASE_MOD_CAPTURE_VOICE, |
| 163 | sizeof(mHandle->useCase)); |
| 164 | csd_client_start_record(INCALL_REC_MONO); |
| 165 | } else |
| 166 | #endif |
| 167 | { |
| 168 | strlcpy(mHandle->useCase, SND_USE_CASE_MOD_CAPTURE_VOICE_DL, |
| 169 | sizeof(mHandle->useCase)); |
| 170 | } |
| 171 | } |
| 172 | #if 0 |
| 173 | } else if(mHandle->devices == AudioSystem::DEVICE_IN_FM_RX) { |
| 174 | strlcpy(mHandle->useCase, SND_USE_CASE_MOD_CAPTURE_FM, sizeof(mHandle->useCase)); |
| 175 | } else if (mHandle->devices == AudioSystem::DEVICE_IN_FM_RX_A2DP) { |
| 176 | strlcpy(mHandle->useCase, SND_USE_CASE_MOD_CAPTURE_A2DP_FM, sizeof(mHandle->useCase)); |
| 177 | #endif |
| 178 | } else if(!strcmp(mHandle->useCase, SND_USE_CASE_MOD_PLAY_VOIP)) { |
| 179 | strlcpy(mHandle->useCase, SND_USE_CASE_MOD_PLAY_VOIP, sizeof(mHandle->useCase)); |
| 180 | }else { |
| 181 | strlcpy(mHandle->useCase, SND_USE_CASE_MOD_CAPTURE_MUSIC, sizeof(mHandle->useCase)); |
| 182 | } |
| 183 | } else { |
| 184 | if ((mHandle->devices == AudioSystem::DEVICE_IN_VOICE_CALL) && |
| 185 | (newMode == AudioSystem::MODE_IN_CALL)) { |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame^] | 186 | ALOGD("read:: ---- mParent->mIncallMode=%d", mParent->mIncallMode); |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 187 | if ((mParent->mIncallMode & AudioSystem::CHANNEL_IN_VOICE_UPLINK) && |
| 188 | (mParent->mIncallMode & AudioSystem::CHANNEL_IN_VOICE_DNLINK)) { |
| 189 | #if 0 |
| 190 | if (mParent->mFusion3Platform) { |
| 191 | mParent->mALSADevice->setVocRecMode(INCALL_REC_STEREO); |
| 192 | strlcpy(mHandle->useCase, SND_USE_CASE_VERB_INCALL_REC, |
| 193 | sizeof(mHandle->useCase)); |
| 194 | csd_client_start_record(INCALL_REC_STEREO); |
| 195 | } else |
| 196 | #endif |
| 197 | { |
| 198 | strlcpy(mHandle->useCase, SND_USE_CASE_VERB_UL_DL_REC, |
| 199 | sizeof(mHandle->useCase)); |
| 200 | } |
| 201 | } else if (mParent->mIncallMode & AudioSystem::CHANNEL_IN_VOICE_DNLINK) { |
| 202 | #if 0 |
| 203 | if (mParent->mFusion3Platform) { |
| 204 | mParent->mALSADevice->setVocRecMode(INCALL_REC_MONO); |
| 205 | strlcpy(mHandle->useCase, SND_USE_CASE_VERB_INCALL_REC, |
| 206 | sizeof(mHandle->useCase)); |
| 207 | csd_client_start_record(INCALL_REC_MONO); |
| 208 | } else |
| 209 | #endif |
| 210 | { |
| 211 | strlcpy(mHandle->useCase, SND_USE_CASE_VERB_DL_REC, |
| 212 | sizeof(mHandle->useCase)); |
| 213 | } |
| 214 | } |
| 215 | #if 0 |
| 216 | } else if(mHandle->devices == AudioSystem::DEVICE_IN_FM_RX) { |
| 217 | strlcpy(mHandle->useCase, SND_USE_CASE_VERB_FM_REC, sizeof(mHandle->useCase)); |
| 218 | } else if (mHandle->devices == AudioSystem::DEVICE_IN_FM_RX_A2DP) { |
| 219 | strlcpy(mHandle->useCase, SND_USE_CASE_VERB_FM_A2DP_REC, sizeof(mHandle->useCase)); |
| 220 | #endif |
| 221 | } else if(!strcmp(mHandle->useCase, SND_USE_CASE_VERB_IP_VOICECALL)){ |
| 222 | strlcpy(mHandle->useCase, SND_USE_CASE_VERB_IP_VOICECALL, sizeof(mHandle->useCase)); |
| 223 | } else { |
| 224 | strlcpy(mHandle->useCase, SND_USE_CASE_VERB_HIFI_REC, sizeof(mHandle->useCase)); |
| 225 | } |
| 226 | } |
| 227 | free(use_case); |
| 228 | if((!strcmp(mHandle->useCase, SND_USE_CASE_VERB_IP_VOICECALL)) || |
| 229 | (!strcmp(mHandle->useCase, SND_USE_CASE_MOD_PLAY_VOIP))) { |
| 230 | #if 0 |
| 231 | if((mDevices & AudioSystem::DEVICE_IN_ANLG_DOCK_HEADSET) || |
| 232 | (mDevices & AudioSystem::DEVICE_OUT_ANLG_DOCK_HEADSET)) { |
| 233 | mHandle->module->route(mHandle, (mDevices | AudioSystem::DEVICE_IN_PROXY) , AudioSystem::MODE_IN_COMMUNICATION); |
| 234 | }else |
| 235 | #endif |
| 236 | { |
| 237 | mHandle->module->route(mHandle, mDevices , AudioSystem::MODE_IN_COMMUNICATION); |
| 238 | } |
| 239 | } else { |
| 240 | #if 0 |
| 241 | |
| 242 | if((mHandle->devices == AudioSystem::DEVICE_IN_ANLG_DOCK_HEADSET)|| |
| 243 | (mHandle->devices == AudioSystem::DEVICE_OUT_ANLG_DOCK_HEADSET)){ |
| 244 | mHandle->module->route(mHandle, AudioSystem::DEVICE_IN_PROXY , mParent->mode()); |
| 245 | } else |
| 246 | #endif |
| 247 | { |
| 248 | |
| 249 | mHandle->module->route(mHandle, mDevices , mParent->mode()); |
| 250 | } |
| 251 | } |
| 252 | if (!strcmp(mHandle->useCase, SND_USE_CASE_VERB_HIFI_REC) || |
| 253 | !strcmp(mHandle->useCase, SND_USE_CASE_VERB_FM_REC) || |
| 254 | !strcmp(mHandle->useCase, SND_USE_CASE_VERB_IP_VOICECALL) || |
| 255 | !strcmp(mHandle->useCase, SND_USE_CASE_VERB_FM_A2DP_REC) || |
| 256 | !strcmp(mHandle->useCase, SND_USE_CASE_VERB_UL_DL_REC) || |
| 257 | !strcmp(mHandle->useCase, SND_USE_CASE_VERB_DL_REC) || |
| 258 | !strcmp(mHandle->useCase, SND_USE_CASE_VERB_INCALL_REC)) { |
| 259 | snd_use_case_set(mHandle->ucMgr, "_verb", mHandle->useCase); |
| 260 | } else { |
| 261 | snd_use_case_set(mHandle->ucMgr, "_enamod", mHandle->useCase); |
| 262 | } |
| 263 | if((!strcmp(mHandle->useCase, SND_USE_CASE_VERB_IP_VOICECALL)) || |
| 264 | (!strcmp(mHandle->useCase, SND_USE_CASE_MOD_PLAY_VOIP))) { |
| 265 | err = mHandle->module->startVoipCall(mHandle); |
| 266 | } |
| 267 | else |
| 268 | mHandle->module->open(mHandle); |
| 269 | if(mHandle->handle == NULL) { |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame^] | 270 | ALOGE("read:: PCM device open failed"); |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 271 | mParent->mLock.unlock(); |
| 272 | |
| 273 | return 0; |
| 274 | } |
| 275 | #if 0 |
| 276 | if((mHandle->devices == AudioSystem::DEVICE_IN_ANLG_DOCK_HEADSET)|| |
| 277 | (mHandle->devices == AudioSystem::DEVICE_OUT_ANLG_DOCK_HEADSET)){ |
| 278 | if((!strcmp(mHandle->useCase, SND_USE_CASE_VERB_IP_VOICECALL)) || |
| 279 | (!strcmp(mHandle->useCase, SND_USE_CASE_MOD_PLAY_VOIP))) { |
| 280 | mParent->musbRecordingState |= USBRECBIT_VOIPCALL; |
| 281 | } else { |
| 282 | mParent->startUsbRecordingIfNotStarted(); |
| 283 | mParent->musbRecordingState |= USBRECBIT_REC; |
| 284 | } |
| 285 | } |
| 286 | #endif |
| 287 | mParent->mLock.unlock(); |
| 288 | } |
| 289 | #if 0 |
| 290 | if(((mDevices & AudioSystem::DEVICE_IN_ANLG_DOCK_HEADSET) || |
| 291 | (mDevices & AudioSystem::DEVICE_OUT_ANLG_DOCK_HEADSET)) && |
| 292 | (!mParent->musbRecordingState)) { |
| 293 | mParent->mLock.lock(); |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame^] | 294 | ALOGD("Starting UsbRecording thread"); |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 295 | mParent->startUsbRecordingIfNotStarted(); |
| 296 | if(!strcmp(mHandle->useCase, SND_USE_CASE_VERB_IP_VOICECALL) || |
| 297 | !strcmp(mHandle->useCase, SND_USE_CASE_MOD_PLAY_VOIP)) { |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame^] | 298 | ALOGD("Enabling voip recording bit"); |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 299 | mParent->musbRecordingState |= USBRECBIT_VOIPCALL; |
| 300 | }else{ |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame^] | 301 | ALOGD("Enabling HiFi Recording bit"); |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 302 | mParent->musbRecordingState |= USBRECBIT_REC; |
| 303 | } |
| 304 | mParent->mLock.unlock(); |
| 305 | } |
| 306 | #endif |
| 307 | period_size = mHandle->periodSize; |
| 308 | int read_pending = bytes; |
| 309 | |
| 310 | #ifdef SSR_ENABLED |
| 311 | if (mSurroundObj) { |
| 312 | int processed = 0; |
| 313 | int processed_pending; |
| 314 | int samples = bytes >> 1; |
| 315 | void *buffer_start = buffer; |
| 316 | int period_bytes = mHandle->handle->period_size; |
| 317 | int period_samples = period_bytes >> 1; |
| 318 | |
| 319 | do { |
| 320 | if (mSurroundOutputBufferIdx > 0) { |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame^] | 321 | ALOGV("AudioStreamInALSA::read() - copy processed output " |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 322 | "to buffer, mSurroundOutputBufferIdx = %d", |
| 323 | mSurroundOutputBufferIdx); |
| 324 | // Copy processed output to buffer |
| 325 | processed_pending = mSurroundOutputBufferIdx; |
| 326 | if (processed_pending > (samples - processed)) { |
| 327 | processed_pending = (samples - processed); |
| 328 | } |
| 329 | memcpy(buffer, mSurroundOutputBuffer, processed_pending * sizeof(Word16)); |
| 330 | buffer += processed_pending * sizeof(Word16); |
| 331 | processed += processed_pending; |
| 332 | if (mSurroundOutputBufferIdx > processed_pending) { |
| 333 | // Shift leftover samples to beginning of the buffer |
| 334 | memcpy(&mSurroundOutputBuffer[0], |
| 335 | &mSurroundOutputBuffer[processed_pending], |
| 336 | (mSurroundOutputBufferIdx - processed_pending) * sizeof(Word16)); |
| 337 | } |
| 338 | mSurroundOutputBufferIdx -= processed_pending; |
| 339 | } |
| 340 | |
| 341 | if (processed >= samples) { |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame^] | 342 | ALOGV("AudioStreamInALSA::read() - done processing buffer, " |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 343 | "processed = %d", processed); |
| 344 | // Done processing this buffer |
| 345 | break; |
| 346 | } |
| 347 | |
| 348 | // Fill input buffer until there is enough to process |
| 349 | read_pending = SSR_INPUT_FRAME_SIZE - mSurroundInputBufferIdx; |
| 350 | read = mSurroundInputBufferIdx; |
| 351 | while (mHandle->handle && read_pending > 0) { |
| 352 | n = pcm_read(mHandle->handle, &mSurroundInputBuffer[read], |
| 353 | period_bytes); |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame^] | 354 | ALOGV("pcm_read() returned n = %d buffer:%p size:%d", n, &mSurroundInputBuffer[read], period_bytes); |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 355 | if (n && n != -EAGAIN) { |
| 356 | //Recovery part of pcm_read. TODO:split recovery. |
| 357 | return static_cast<ssize_t>(n); |
| 358 | } |
| 359 | else if (n < 0) { |
| 360 | // Recovery is part of pcm_write. TODO split is later. |
| 361 | return static_cast<ssize_t>(n); |
| 362 | } |
| 363 | else { |
| 364 | read_pending -= period_samples; |
| 365 | read += period_samples; |
| 366 | } |
| 367 | } |
| 368 | |
| 369 | |
| 370 | if (mFp_4ch) { |
| 371 | fwrite( mSurroundInputBuffer, 1, |
| 372 | SSR_INPUT_FRAME_SIZE * sizeof(Word16), mFp_4ch); |
| 373 | } |
| 374 | |
| 375 | //apply ssr libs to conver 4ch to 6ch |
| 376 | surround_filters_intl_process(mSurroundObj, |
| 377 | &mSurroundOutputBuffer[mSurroundOutputBufferIdx], |
| 378 | (Word16 *)mSurroundInputBuffer); |
| 379 | |
| 380 | // Shift leftover samples to beginning of input buffer |
| 381 | if (read_pending < 0) { |
| 382 | memcpy(&mSurroundInputBuffer[0], |
| 383 | &mSurroundInputBuffer[SSR_INPUT_FRAME_SIZE], |
| 384 | (-read_pending) * sizeof(Word16)); |
| 385 | } |
| 386 | mSurroundInputBufferIdx = -read_pending; |
| 387 | |
| 388 | if (mFp_6ch) { |
| 389 | fwrite( &mSurroundOutputBuffer[mSurroundOutputBufferIdx], |
| 390 | 1, SSR_OUTPUT_FRAME_SIZE * sizeof(Word16), mFp_6ch); |
| 391 | } |
| 392 | |
| 393 | mSurroundOutputBufferIdx += SSR_OUTPUT_FRAME_SIZE; |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame^] | 394 | ALOGV("do_while loop: processed=%d, samples=%d\n", processed, samples); |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 395 | } while (mHandle->handle && processed < samples); |
| 396 | read = processed * sizeof(Word16); |
| 397 | buffer = buffer_start; |
| 398 | } else |
| 399 | #endif |
| 400 | { |
| 401 | |
| 402 | do { |
| 403 | if (read_pending < period_size) { |
| 404 | read_pending = period_size; |
| 405 | } |
| 406 | |
| 407 | n = pcm_read(mHandle->handle, buffer, |
| 408 | period_size); |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame^] | 409 | ALOGV("pcm_read() returned n = %d", n); |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 410 | if (n && (n == -EIO || n == -EAGAIN || n == -EPIPE || n == -EBADFD)) { |
| 411 | mParent->mLock.lock(); |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame^] | 412 | ALOGW("pcm_read() returned error n %d, Recovering from error\n", n); |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 413 | pcm_close(mHandle->handle); |
| 414 | mHandle->handle = NULL; |
| 415 | if((!strncmp(mHandle->useCase, SND_USE_CASE_VERB_IP_VOICECALL, strlen(SND_USE_CASE_VERB_IP_VOICECALL))) || |
| 416 | (!strncmp(mHandle->useCase, SND_USE_CASE_MOD_PLAY_VOIP, strlen(SND_USE_CASE_MOD_PLAY_VOIP)))) { |
| 417 | pcm_close(mHandle->rxHandle); |
| 418 | mHandle->rxHandle = NULL; |
| 419 | mHandle->module->startVoipCall(mHandle); |
| 420 | } |
| 421 | else |
| 422 | mHandle->module->open(mHandle); |
| 423 | mParent->mLock.unlock(); |
| 424 | continue; |
| 425 | } |
| 426 | else if (n < 0) { |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame^] | 427 | ALOGD("pcm_read() returned n < 0"); |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 428 | return static_cast<ssize_t>(n); |
| 429 | } |
| 430 | else { |
| 431 | read += static_cast<ssize_t>((period_size)); |
| 432 | read_pending -= period_size; |
| 433 | buffer += period_size; |
| 434 | } |
| 435 | |
| 436 | } while (mHandle->handle && read < bytes); |
| 437 | } |
| 438 | |
| 439 | return read; |
| 440 | } |
| 441 | |
| 442 | status_t AudioStreamInALSA::dump(int fd, const Vector<String16>& args) |
| 443 | { |
| 444 | return NO_ERROR; |
| 445 | } |
| 446 | |
| 447 | status_t AudioStreamInALSA::open(int mode) |
| 448 | { |
| 449 | Mutex::Autolock autoLock(mParent->mLock); |
| 450 | |
| 451 | status_t status = ALSAStreamOps::open(mode); |
| 452 | |
| 453 | return status; |
| 454 | } |
| 455 | |
| 456 | status_t AudioStreamInALSA::close() |
| 457 | { |
| 458 | Mutex::Autolock autoLock(mParent->mLock); |
| 459 | |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame^] | 460 | ALOGD("close"); |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 461 | if((!strcmp(mHandle->useCase, SND_USE_CASE_VERB_IP_VOICECALL)) || |
| 462 | (!strcmp(mHandle->useCase, SND_USE_CASE_MOD_PLAY_VOIP))) { |
| 463 | if((mParent->mVoipStreamCount)) { |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame^] | 464 | ALOGD("musbRecordingState: %d, mVoipStreamCount:%d",mParent->musbRecordingState, |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 465 | mParent->mVoipStreamCount ); |
| 466 | if(mParent->mVoipStreamCount == 1) { |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame^] | 467 | ALOGE("Deregistering VOIP Call bit, musbPlaybackState:%d," |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 468 | "musbRecordingState:%d", mParent->musbPlaybackState, mParent->musbRecordingState); |
| 469 | mParent->musbPlaybackState &= ~USBPLAYBACKBIT_VOIPCALL; |
| 470 | mParent->musbRecordingState &= ~USBRECBIT_VOIPCALL; |
| 471 | mParent->closeUsbRecordingIfNothingActive(); |
| 472 | mParent->closeUsbPlaybackIfNothingActive(); |
| 473 | } |
| 474 | return NO_ERROR; |
| 475 | } |
| 476 | mParent->mVoipStreamCount = 0; |
| 477 | mParent->mVoipMicMute = 0; |
| 478 | } else { |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame^] | 479 | ALOGD("Deregistering REC bit, musbRecordingState:%d", mParent->musbRecordingState); |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 480 | mParent->musbRecordingState &= ~USBRECBIT_REC; |
| 481 | } |
| 482 | #if 0 |
| 483 | if (mParent->mFusion3Platform) { |
| 484 | if((!strcmp(mHandle->useCase, SND_USE_CASE_VERB_INCALL_REC)) || |
| 485 | (!strcmp(mHandle->useCase, SND_USE_CASE_MOD_CAPTURE_VOICE))) { |
| 486 | csd_client_stop_record(); |
| 487 | } |
| 488 | } |
| 489 | #endif |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame^] | 490 | ALOGD("close"); |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 491 | mParent->closeUsbRecordingIfNothingActive(); |
| 492 | |
| 493 | ALSAStreamOps::close(); |
| 494 | |
| 495 | #ifdef SSR_ENABLED |
| 496 | if (mSurroundObj) { |
| 497 | surround_filters_release(mSurroundObj); |
| 498 | if (mSurroundObj) |
| 499 | free(mSurroundObj); |
| 500 | mSurroundObj = NULL; |
| 501 | if (mRealCoeffs){ |
| 502 | for (int i =0; i<COEFF_ARRAY_SIZE; i++ ) { |
| 503 | if (mRealCoeffs[i]) { |
| 504 | free(mRealCoeffs[i]); |
| 505 | mRealCoeffs[i] = NULL; |
| 506 | } |
| 507 | } |
| 508 | free(mRealCoeffs); |
| 509 | mRealCoeffs = NULL; |
| 510 | } |
| 511 | if (mImagCoeffs){ |
| 512 | for (int i =0; i<COEFF_ARRAY_SIZE; i++ ) { |
| 513 | if (mImagCoeffs[i]) { |
| 514 | free(mImagCoeffs[i]); |
| 515 | mImagCoeffs[i] = NULL; |
| 516 | } |
| 517 | } |
| 518 | free(mImagCoeffs); |
| 519 | mImagCoeffs = NULL; |
| 520 | } |
| 521 | if (mSurroundOutputBuffer){ |
| 522 | free(mSurroundOutputBuffer); |
| 523 | mSurroundOutputBuffer = NULL; |
| 524 | } |
| 525 | if (mSurroundInputBuffer) { |
| 526 | free(mSurroundInputBuffer); |
| 527 | mSurroundInputBuffer = NULL; |
| 528 | } |
| 529 | |
| 530 | if ( mFp_4ch ) fclose(mFp_4ch); |
| 531 | if ( mFp_6ch ) fclose(mFp_6ch); |
| 532 | |
| 533 | } |
| 534 | #endif |
| 535 | |
| 536 | return NO_ERROR; |
| 537 | } |
| 538 | |
| 539 | status_t AudioStreamInALSA::standby() |
| 540 | { |
| 541 | Mutex::Autolock autoLock(mParent->mLock); |
| 542 | |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame^] | 543 | ALOGD("standby"); |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 544 | |
| 545 | if((!strcmp(mHandle->useCase, SND_USE_CASE_VERB_IP_VOICECALL)) || |
| 546 | (!strcmp(mHandle->useCase, SND_USE_CASE_MOD_PLAY_VOIP))) { |
| 547 | return NO_ERROR; |
| 548 | } |
| 549 | |
| 550 | #if 0 |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame^] | 551 | ALOGD("standby"); |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 552 | if (mParent->mFusion3Platform) { |
| 553 | if((!strcmp(mHandle->useCase, SND_USE_CASE_VERB_INCALL_REC)) || |
| 554 | (!strcmp(mHandle->useCase, SND_USE_CASE_MOD_CAPTURE_VOICE))) { |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame^] | 555 | ALOGD(" into standby, stop record"); |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 556 | csd_client_stop_record(); |
| 557 | } |
| 558 | } |
| 559 | #endif |
| 560 | mHandle->module->standby(mHandle); |
| 561 | |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame^] | 562 | ALOGD("Checking for musbRecordingState %d", mParent->musbRecordingState); |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 563 | mParent->musbRecordingState &= ~USBRECBIT_REC; |
| 564 | mParent->closeUsbRecordingIfNothingActive(); |
| 565 | |
| 566 | return NO_ERROR; |
| 567 | } |
| 568 | |
| 569 | void AudioStreamInALSA::resetFramesLost() |
| 570 | { |
| 571 | mFramesLost = 0; |
| 572 | } |
| 573 | |
| 574 | unsigned int AudioStreamInALSA::getInputFramesLost() const |
| 575 | { |
| 576 | unsigned int count = mFramesLost; |
| 577 | // Stupid interface wants us to have a side effect of clearing the count |
| 578 | // but is defined as a const to prevent such a thing. |
| 579 | ((AudioStreamInALSA *)this)->resetFramesLost(); |
| 580 | return count; |
| 581 | } |
| 582 | |
| 583 | status_t AudioStreamInALSA::setAcousticParams(void *params) |
| 584 | { |
| 585 | Mutex::Autolock autoLock(mParent->mLock); |
| 586 | |
| 587 | return (status_t)NO_ERROR; |
| 588 | } |
| 589 | |
| 590 | #ifdef SSR_ENABLED |
| 591 | status_t AudioStreamInALSA::initSurroundSoundLibrary(unsigned long buffersize) |
| 592 | { |
| 593 | int subwoofer = 0; // subwoofer channel assignment: default as first microphone input channel |
| 594 | int low_freq = 4; // frequency upper bound for subwoofer: frequency=(low_freq-1)/FFT_SIZE*samplingRate, default as 4 |
| 595 | int high_freq = 100; // frequency upper bound for spatial processing: frequency=(high_freq-1)/FFT_SIZE*samplingRate, default as 100 |
| 596 | int ret = 0; |
| 597 | |
| 598 | mSurroundInputBufferIdx = 0; |
| 599 | mSurroundOutputBufferIdx = 0; |
| 600 | |
| 601 | if ( mSurroundObj ) { |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame^] | 602 | ALOGE("ola filter library is already initialized"); |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 603 | return ALREADY_EXISTS; |
| 604 | } |
| 605 | |
| 606 | // Allocate memory for input buffer |
| 607 | mSurroundInputBuffer = (Word16 *) calloc(2 * SSR_INPUT_FRAME_SIZE, |
| 608 | sizeof(Word16)); |
| 609 | if ( !mSurroundInputBuffer ) { |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame^] | 610 | ALOGE("Memory allocation failure. Not able to allocate memory for surroundInputBuffer"); |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 611 | goto init_fail; |
| 612 | } |
| 613 | |
| 614 | // Allocate memory for output buffer |
| 615 | mSurroundOutputBuffer = (Word16 *) calloc(2 * SSR_OUTPUT_FRAME_SIZE, |
| 616 | sizeof(Word16)); |
| 617 | if ( !mSurroundOutputBuffer ) { |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame^] | 618 | ALOGE("Memory allocation failure. Not able to allocate memory for surroundOutputBuffer"); |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 619 | goto init_fail; |
| 620 | } |
| 621 | |
| 622 | // Allocate memory for real and imag coeffs array |
| 623 | mRealCoeffs = (Word16 **) calloc(COEFF_ARRAY_SIZE, sizeof(Word16 *)); |
| 624 | if ( !mRealCoeffs ) { |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame^] | 625 | ALOGE("Memory allocation failure during real Coefficient array"); |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 626 | goto init_fail; |
| 627 | } |
| 628 | |
| 629 | mImagCoeffs = (Word16 **) calloc(COEFF_ARRAY_SIZE, sizeof(Word16 *)); |
| 630 | if ( !mImagCoeffs ) { |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame^] | 631 | ALOGE("Memory allocation failure during imaginary Coefficient array"); |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 632 | goto init_fail; |
| 633 | } |
| 634 | |
| 635 | if( readCoeffsFromFile() != NO_ERROR) { |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame^] | 636 | ALOGE("Error while loading coeffs from file"); |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 637 | goto init_fail; |
| 638 | } |
| 639 | |
| 640 | //calculate the size of data to allocate for mSurroundObj |
| 641 | ret = surround_filters_init(NULL, |
| 642 | 6, // Num output channel |
| 643 | 4, // Num input channel |
| 644 | mRealCoeffs, // Coeffs hardcoded in header |
| 645 | mImagCoeffs, // Coeffs hardcoded in header |
| 646 | subwoofer, |
| 647 | low_freq, |
| 648 | high_freq, |
| 649 | NULL); |
| 650 | |
| 651 | if ( ret > 0 ) { |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame^] | 652 | ALOGV("Allocating surroundObj size is %d", ret); |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 653 | mSurroundObj = (void *)malloc(ret); |
| 654 | memset(mSurroundObj,0,ret); |
| 655 | if (NULL != mSurroundObj) { |
| 656 | //initialize after allocating the memory for mSurroundObj |
| 657 | ret = surround_filters_init(mSurroundObj, |
| 658 | 6, |
| 659 | 4, |
| 660 | mRealCoeffs, |
| 661 | mImagCoeffs, |
| 662 | subwoofer, |
| 663 | low_freq, |
| 664 | high_freq, |
| 665 | NULL); |
| 666 | if (0 != ret) { |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame^] | 667 | ALOGE("surround_filters_init failed with ret:%d",ret); |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 668 | surround_filters_release(mSurroundObj); |
| 669 | goto init_fail; |
| 670 | } |
| 671 | } else { |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame^] | 672 | ALOGE("Allocationg mSurroundObj failed"); |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 673 | goto init_fail; |
| 674 | } |
| 675 | } else { |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame^] | 676 | ALOGE("surround_filters_init(mSurroundObj=Null) failed with ret: %d",ret); |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 677 | goto init_fail; |
| 678 | } |
| 679 | |
| 680 | (void) surround_filters_set_channel_map(mSurroundObj, chanMap); |
| 681 | |
| 682 | return NO_ERROR; |
| 683 | |
| 684 | init_fail: |
| 685 | if (mSurroundObj) { |
| 686 | free(mSurroundObj); |
| 687 | mSurroundObj = NULL; |
| 688 | } |
| 689 | if (mSurroundOutputBuffer) { |
| 690 | free(mSurroundOutputBuffer); |
| 691 | mSurroundOutputBuffer = NULL; |
| 692 | } |
| 693 | if (mSurroundInputBuffer) { |
| 694 | free(mSurroundInputBuffer); |
| 695 | mSurroundInputBuffer = NULL; |
| 696 | } |
| 697 | if (mRealCoeffs){ |
| 698 | for (int i =0; i<COEFF_ARRAY_SIZE; i++ ) { |
| 699 | if (mRealCoeffs[i]) { |
| 700 | free(mRealCoeffs[i]); |
| 701 | mRealCoeffs[i] = NULL; |
| 702 | } |
| 703 | } |
| 704 | free(mRealCoeffs); |
| 705 | mRealCoeffs = NULL; |
| 706 | } |
| 707 | if (mImagCoeffs){ |
| 708 | for (int i =0; i<COEFF_ARRAY_SIZE; i++ ) { |
| 709 | if (mImagCoeffs[i]) { |
| 710 | free(mImagCoeffs[i]); |
| 711 | mImagCoeffs[i] = NULL; |
| 712 | } |
| 713 | } |
| 714 | free(mImagCoeffs); |
| 715 | mImagCoeffs = NULL; |
| 716 | } |
| 717 | |
| 718 | return NO_MEMORY; |
| 719 | |
| 720 | } |
| 721 | |
| 722 | |
| 723 | // Helper function to read coeffs from File and updates real and imaginary |
| 724 | // coeff array member variable |
| 725 | status_t AudioStreamInALSA::readCoeffsFromFile() |
| 726 | { |
| 727 | FILE *flt1r; |
| 728 | FILE *flt2r; |
| 729 | FILE *flt3r; |
| 730 | FILE *flt4r; |
| 731 | FILE *flt1i; |
| 732 | FILE *flt2i; |
| 733 | FILE *flt3i; |
| 734 | FILE *flt4i; |
| 735 | |
| 736 | if ( (flt1r = fopen(SURROUND_FILE_1R, "rb")) == NULL ) { |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame^] | 737 | ALOGE("Cannot open filter co-efficient file %s", SURROUND_FILE_1R); |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 738 | return NAME_NOT_FOUND; |
| 739 | } |
| 740 | |
| 741 | if ( (flt2r = fopen(SURROUND_FILE_2R, "rb")) == NULL ) { |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame^] | 742 | ALOGE("Cannot open filter co-efficient file %s", SURROUND_FILE_2R); |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 743 | return NAME_NOT_FOUND; |
| 744 | } |
| 745 | |
| 746 | if ( (flt3r = fopen(SURROUND_FILE_3R, "rb")) == NULL ) { |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame^] | 747 | ALOGE("Cannot open filter co-efficient file %s", SURROUND_FILE_3R); |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 748 | return NAME_NOT_FOUND; |
| 749 | } |
| 750 | |
| 751 | if ( (flt4r = fopen(SURROUND_FILE_4R, "rb")) == NULL ) { |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame^] | 752 | ALOGE("Cannot open filter co-efficient file %s", SURROUND_FILE_4R); |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 753 | return NAME_NOT_FOUND; |
| 754 | } |
| 755 | |
| 756 | if ( (flt1i = fopen(SURROUND_FILE_1I, "rb")) == NULL ) { |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame^] | 757 | ALOGE("Cannot open filter co-efficient file %s", SURROUND_FILE_1I); |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 758 | return NAME_NOT_FOUND; |
| 759 | } |
| 760 | |
| 761 | if ( (flt2i = fopen(SURROUND_FILE_2I, "rb")) == NULL ) { |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame^] | 762 | ALOGE("Cannot open filter co-efficient file %s", SURROUND_FILE_2I); |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 763 | return NAME_NOT_FOUND; |
| 764 | } |
| 765 | |
| 766 | if ( (flt3i = fopen(SURROUND_FILE_3I, "rb")) == NULL ) { |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame^] | 767 | ALOGE("Cannot open filter co-efficient file %s", SURROUND_FILE_3I); |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 768 | return NAME_NOT_FOUND; |
| 769 | } |
| 770 | |
| 771 | if ( (flt4i = fopen(SURROUND_FILE_4I, "rb")) == NULL ) { |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame^] | 772 | ALOGE("Cannot open filter co-efficient file %s", SURROUND_FILE_4I); |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 773 | return NAME_NOT_FOUND; |
| 774 | } |
Iliyan Malchev | 4113f34 | 2012-06-11 14:39:47 -0700 | [diff] [blame^] | 775 | ALOGV("readCoeffsFromFile all filter files opened"); |
Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame] | 776 | |
| 777 | for (int i=0; i<COEFF_ARRAY_SIZE; i++) { |
| 778 | mRealCoeffs[i] = (Word16 *)calloc(FILT_SIZE, sizeof(Word16)); |
| 779 | } |
| 780 | for (int i=0; i<COEFF_ARRAY_SIZE; i++) { |
| 781 | mImagCoeffs[i] = (Word16 *)calloc(FILT_SIZE, sizeof(Word16)); |
| 782 | } |
| 783 | |
| 784 | // Read real co-efficients |
| 785 | if (NULL != mRealCoeffs[0]) { |
| 786 | fread(mRealCoeffs[0], sizeof(int16), FILT_SIZE, flt1r); |
| 787 | } |
| 788 | if (NULL != mRealCoeffs[0]) { |
| 789 | fread(mRealCoeffs[1], sizeof(int16), FILT_SIZE, flt2r); |
| 790 | } |
| 791 | if (NULL != mRealCoeffs[0]) { |
| 792 | fread(mRealCoeffs[2], sizeof(int16), FILT_SIZE, flt3r); |
| 793 | } |
| 794 | if (NULL != mRealCoeffs[0]) { |
| 795 | fread(mRealCoeffs[3], sizeof(int16), FILT_SIZE, flt4r); |
| 796 | } |
| 797 | |
| 798 | // read imaginary co-efficients |
| 799 | if (NULL != mImagCoeffs[0]) { |
| 800 | fread(mImagCoeffs[0], sizeof(int16), FILT_SIZE, flt1i); |
| 801 | } |
| 802 | if (NULL != mImagCoeffs[0]) { |
| 803 | fread(mImagCoeffs[1], sizeof(int16), FILT_SIZE, flt2i); |
| 804 | } |
| 805 | if (NULL != mImagCoeffs[0]) { |
| 806 | fread(mImagCoeffs[2], sizeof(int16), FILT_SIZE, flt3i); |
| 807 | } |
| 808 | if (NULL != mImagCoeffs[0]) { |
| 809 | fread(mImagCoeffs[3], sizeof(int16), FILT_SIZE, flt4i); |
| 810 | } |
| 811 | |
| 812 | fclose(flt1r); |
| 813 | fclose(flt2r); |
| 814 | fclose(flt3r); |
| 815 | fclose(flt4r); |
| 816 | fclose(flt1i); |
| 817 | fclose(flt2i); |
| 818 | fclose(flt3i); |
| 819 | fclose(flt4i); |
| 820 | |
| 821 | return NO_ERROR; |
| 822 | } |
| 823 | #endif |
| 824 | |
| 825 | } // namespace android_audio_legacy |