| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
| 5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
| 6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
| 7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
| 8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
| 9 */ | 9 */ |
| 10 | 10 |
| (...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 185 | 185 |
| 186 for (AudioPacketList::iterator iter = _audioList.begin(); | 186 for (AudioPacketList::iterator iter = _audioList.begin(); |
| 187 iter != _audioList.end(); ++iter) { | 187 iter != _audioList.end(); ++iter) { |
| 188 delete *iter; | 188 delete *iter; |
| 189 } | 189 } |
| 190 _audioList.clear(); | 190 _audioList.clear(); |
| 191 } | 191 } |
| 192 | 192 |
| 193 int32_t AudioTransportImpl::RecordedDataIsAvailable( | 193 int32_t AudioTransportImpl::RecordedDataIsAvailable( |
| 194 const void* audioSamples, | 194 const void* audioSamples, |
| 195 const uint32_t nSamples, | 195 const size_t nSamples, |
| 196 const uint8_t nBytesPerSample, | 196 const size_t nBytesPerSample, |
| 197 const uint8_t nChannels, | 197 const uint8_t nChannels, |
| 198 const uint32_t samplesPerSec, | 198 const uint32_t samplesPerSec, |
| 199 const uint32_t totalDelayMS, | 199 const uint32_t totalDelayMS, |
| 200 const int32_t clockDrift, | 200 const int32_t clockDrift, |
| 201 const uint32_t currentMicLevel, | 201 const uint32_t currentMicLevel, |
| 202 const bool keyPressed, | 202 const bool keyPressed, |
| 203 uint32_t& newMicLevel) | 203 uint32_t& newMicLevel) |
| 204 { | 204 { |
| 205 if (_fullDuplex && _audioList.size() < 15) | 205 if (_fullDuplex && _audioList.size() < 15) |
| 206 { | 206 { |
| 207 AudioPacket* packet = new AudioPacket(); | 207 AudioPacket* packet = new AudioPacket(); |
| 208 memcpy(packet->dataBuffer, audioSamples, nSamples * nBytesPerSample); | 208 memcpy(packet->dataBuffer, audioSamples, nSamples * nBytesPerSample); |
| 209 packet->nSamples = (uint16_t) nSamples; | 209 packet->nSamples = nSamples; |
| 210 packet->nBytesPerSample = nBytesPerSample; | 210 packet->nBytesPerSample = nBytesPerSample; |
| 211 packet->nChannels = nChannels; | 211 packet->nChannels = nChannels; |
| 212 packet->samplesPerSec = samplesPerSec; | 212 packet->samplesPerSec = samplesPerSec; |
| 213 _audioList.push_back(packet); | 213 _audioList.push_back(packet); |
| 214 } | 214 } |
| 215 | 215 |
| 216 _recCount++; | 216 _recCount++; |
| 217 if (_recCount % 100 == 0) | 217 if (_recCount % 100 == 0) |
| 218 { | 218 { |
| 219 bool addMarker(true); | 219 bool addMarker(true); |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 330 { | 330 { |
| 331 // TEST_LOG("=> emulated mono (one channel exctracted from stereo in
put)\n"); | 331 // TEST_LOG("=> emulated mono (one channel exctracted from stereo in
put)\n"); |
| 332 } | 332 } |
| 333 } | 333 } |
| 334 | 334 |
| 335 return 0; | 335 return 0; |
| 336 } | 336 } |
| 337 | 337 |
| 338 | 338 |
| 339 int32_t AudioTransportImpl::NeedMorePlayData( | 339 int32_t AudioTransportImpl::NeedMorePlayData( |
| 340 const uint32_t nSamples, | 340 const size_t nSamples, |
| 341 const uint8_t nBytesPerSample, | 341 const size_t nBytesPerSample, |
| 342 const uint8_t nChannels, | 342 const uint8_t nChannels, |
| 343 const uint32_t samplesPerSec, | 343 const uint32_t samplesPerSec, |
| 344 void* audioSamples, | 344 void* audioSamples, |
| 345 uint32_t& nSamplesOut, | 345 size_t& nSamplesOut, |
| 346 int64_t* elapsed_time_ms, | 346 int64_t* elapsed_time_ms, |
| 347 int64_t* ntp_time_ms) | 347 int64_t* ntp_time_ms) |
| 348 { | 348 { |
| 349 if (_fullDuplex) | 349 if (_fullDuplex) |
| 350 { | 350 { |
| 351 if (_audioList.empty()) | 351 if (_audioList.empty()) |
| 352 { | 352 { |
| 353 // use zero stuffing when not enough data | 353 // use zero stuffing when not enough data |
| 354 memset(audioSamples, 0, nBytesPerSample * nSamples); | 354 memset(audioSamples, 0, nBytesPerSample * nSamples); |
| 355 } else | 355 } else |
| 356 { | 356 { |
| 357 AudioPacket* packet = _audioList.front(); | 357 AudioPacket* packet = _audioList.front(); |
| 358 _audioList.pop_front(); | 358 _audioList.pop_front(); |
| 359 if (packet) | 359 if (packet) |
| 360 { | 360 { |
| 361 int ret(0); | 361 int ret(0); |
| 362 int lenOut(0); | 362 size_t lenOut(0); |
| 363 int16_t tmpBuf_96kHz[80 * 12]; | 363 int16_t tmpBuf_96kHz[80 * 12]; |
| 364 int16_t* ptr16In = NULL; | 364 int16_t* ptr16In = NULL; |
| 365 int16_t* ptr16Out = NULL; | 365 int16_t* ptr16Out = NULL; |
| 366 | 366 |
| 367 const uint16_t nSamplesIn = packet->nSamples; | 367 const size_t nSamplesIn = packet->nSamples; |
| 368 const uint8_t nChannelsIn = packet->nChannels; | 368 const uint8_t nChannelsIn = packet->nChannels; |
| 369 const uint32_t samplesPerSecIn = packet->samplesPerSec; | 369 const uint32_t samplesPerSecIn = packet->samplesPerSec; |
| 370 const uint16_t nBytesPerSampleIn = packet->nBytesPerSample; | 370 const size_t nBytesPerSampleIn = packet->nBytesPerSample; |
| 371 | 371 |
| 372 int32_t fsInHz(samplesPerSecIn); | 372 int32_t fsInHz(samplesPerSecIn); |
| 373 int32_t fsOutHz(samplesPerSec); | 373 int32_t fsOutHz(samplesPerSec); |
| 374 | 374 |
| 375 if (fsInHz == 44100) | 375 if (fsInHz == 44100) |
| 376 fsInHz = 44000; | 376 fsInHz = 44000; |
| 377 | 377 |
| 378 if (fsOutHz == 44100) | 378 if (fsOutHz == 44100) |
| 379 fsOutHz = 44000; | 379 fsOutHz = 44000; |
| 380 | 380 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 394 { | 394 { |
| 395 _resampler.Push( | 395 _resampler.Push( |
| 396 (const int16_t*) packet->dataBuffer, | 396 (const int16_t*) packet->dataBuffer, |
| 397 2 * nSamplesIn, tmpBuf_96kHz, 2 * nSamples, | 397 2 * nSamplesIn, tmpBuf_96kHz, 2 * nSamples, |
| 398 lenOut); | 398 lenOut); |
| 399 | 399 |
| 400 ptr16In = &tmpBuf_96kHz[0]; | 400 ptr16In = &tmpBuf_96kHz[0]; |
| 401 ptr16Out = (int16_t*) audioSamples; | 401 ptr16Out = (int16_t*) audioSamples; |
| 402 | 402 |
| 403 // do stereo -> mono | 403 // do stereo -> mono |
| 404 for (unsigned int i = 0; i < nSamples; i++) | 404 for (size_t i = 0; i < nSamples; i++) |
| 405 { | 405 { |
| 406 *ptr16Out = *ptr16In; // use left channel | 406 *ptr16Out = *ptr16In; // use left channel |
| 407 ptr16Out++; | 407 ptr16Out++; |
| 408 ptr16In++; | 408 ptr16In++; |
| 409 ptr16In++; | 409 ptr16In++; |
| 410 } | 410 } |
| 411 } | 411 } |
| 412 assert(2*nSamples == (uint32_t)lenOut); | 412 assert(2*nSamples == lenOut); |
| 413 } else | 413 } else |
| 414 { | 414 { |
| 415 if (_playCount % 100 == 0) | 415 if (_playCount % 100 == 0) |
| 416 TEST_LOG( | 416 TEST_LOG( |
| 417 "ERROR: unable to resample from %d to %d\n"
, | 417 "ERROR: unable to resample from %d to %d\n"
, |
| 418 samplesPerSecIn, samplesPerSec); | 418 samplesPerSecIn, samplesPerSec); |
| 419 } | 419 } |
| 420 } else | 420 } else |
| 421 { | 421 { |
| 422 // input is mono (can be "reduced from stereo" as well) => | 422 // input is mono (can be "reduced from stereo" as well) => |
| 423 // we will resample in mono | 423 // we will resample in mono |
| 424 ret = _resampler.ResetIfNeeded(fsInHz, fsOutHz, 1); | 424 ret = _resampler.ResetIfNeeded(fsInHz, fsOutHz, 1); |
| 425 if (ret == 0) | 425 if (ret == 0) |
| 426 { | 426 { |
| 427 if (nChannels == 1) | 427 if (nChannels == 1) |
| 428 { | 428 { |
| 429 _resampler.Push( | 429 _resampler.Push( |
| 430 (const int16_t*) packet->dataBuffer, nSamplesIn, | 430 (const int16_t*) packet->dataBuffer, nSamplesIn, |
| 431 (int16_t*) audioSamples, nSamples, lenOut); | 431 (int16_t*) audioSamples, nSamples, lenOut); |
| 432 } else | 432 } else |
| 433 { | 433 { |
| 434 _resampler.Push( | 434 _resampler.Push( |
| 435 (const int16_t*) packet->dataBuffer, nSamplesIn, | 435 (const int16_t*) packet->dataBuffer, nSamplesIn, |
| 436 tmpBuf_96kHz, nSamples, lenOut); | 436 tmpBuf_96kHz, nSamples, lenOut); |
| 437 | 437 |
| 438 ptr16In = &tmpBuf_96kHz[0]; | 438 ptr16In = &tmpBuf_96kHz[0]; |
| 439 ptr16Out = (int16_t*) audioSamples; | 439 ptr16Out = (int16_t*) audioSamples; |
| 440 | 440 |
| 441 // do mono -> stereo | 441 // do mono -> stereo |
| 442 for (unsigned int i = 0; i < nSamples; i++) | 442 for (size_t i = 0; i < nSamples; i++) |
| 443 { | 443 { |
| 444 *ptr16Out = *ptr16In; // left | 444 *ptr16Out = *ptr16In; // left |
| 445 ptr16Out++; | 445 ptr16Out++; |
| 446 *ptr16Out = *ptr16In; // right (same as left sam
ple) | 446 *ptr16Out = *ptr16In; // right (same as left sam
ple) |
| 447 ptr16Out++; | 447 ptr16Out++; |
| 448 ptr16In++; | 448 ptr16In++; |
| 449 } | 449 } |
| 450 } | 450 } |
| 451 assert(nSamples == (uint32_t)lenOut); | 451 assert(nSamples == lenOut); |
| 452 } else | 452 } else |
| 453 { | 453 { |
| 454 if (_playCount % 100 == 0) | 454 if (_playCount % 100 == 0) |
| 455 TEST_LOG("ERROR: unable to resample from %d to %d\n"
, | 455 TEST_LOG("ERROR: unable to resample from %d to %d\n"
, |
| 456 samplesPerSecIn, samplesPerSec); | 456 samplesPerSecIn, samplesPerSec); |
| 457 } | 457 } |
| 458 } | 458 } |
| 459 nSamplesOut = nSamples; | 459 nSamplesOut = nSamples; |
| 460 delete packet; | 460 delete packet; |
| 461 } | 461 } |
| (...skipping 14 matching lines...) Expand all Loading... |
| 476 | 476 |
| 477 // convert to stero if required | 477 // convert to stero if required |
| 478 if (nChannels == 1) | 478 if (nChannels == 1) |
| 479 { | 479 { |
| 480 memcpy(audioSamples, fileBuf, 2 * nSamples); | 480 memcpy(audioSamples, fileBuf, 2 * nSamples); |
| 481 } else | 481 } else |
| 482 { | 482 { |
| 483 // mono sample from file is duplicated and sent to left and right | 483 // mono sample from file is duplicated and sent to left and right |
| 484 // channels | 484 // channels |
| 485 int16_t* audio16 = (int16_t*) audioSamples; | 485 int16_t* audio16 = (int16_t*) audioSamples; |
| 486 for (unsigned int i = 0; i < nSamples; i++) | 486 for (size_t i = 0; i < nSamples; i++) |
| 487 { | 487 { |
| 488 (*audio16) = fileBuf[i]; // left | 488 (*audio16) = fileBuf[i]; // left |
| 489 audio16++; | 489 audio16++; |
| 490 (*audio16) = fileBuf[i]; // right | 490 (*audio16) = fileBuf[i]; // right |
| 491 audio16++; | 491 audio16++; |
| 492 } | 492 } |
| 493 } | 493 } |
| 494 } // if (_playFromFile && _playFile.Open()) | 494 } // if (_playFromFile && _playFile.Open()) |
| 495 | 495 |
| 496 _playCount++; | 496 _playCount++; |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 571 nSamplesOut = nSamples; | 571 nSamplesOut = nSamples; |
| 572 | 572 |
| 573 return 0; | 573 return 0; |
| 574 } | 574 } |
| 575 | 575 |
| 576 int AudioTransportImpl::OnDataAvailable(const int voe_channels[], | 576 int AudioTransportImpl::OnDataAvailable(const int voe_channels[], |
| 577 int number_of_voe_channels, | 577 int number_of_voe_channels, |
| 578 const int16_t* audio_data, | 578 const int16_t* audio_data, |
| 579 int sample_rate, | 579 int sample_rate, |
| 580 int number_of_channels, | 580 int number_of_channels, |
| 581 int number_of_frames, | 581 size_t number_of_frames, |
| 582 int audio_delay_milliseconds, | 582 int audio_delay_milliseconds, |
| 583 int current_volume, | 583 int current_volume, |
| 584 bool key_pressed, | 584 bool key_pressed, |
| 585 bool need_audio_processing) { | 585 bool need_audio_processing) { |
| 586 return 0; | 586 return 0; |
| 587 } | 587 } |
| 588 | 588 |
| 589 void AudioTransportImpl::PushCaptureData(int voe_channel, | 589 void AudioTransportImpl::PushCaptureData(int voe_channel, |
| 590 const void* audio_data, | 590 const void* audio_data, |
| 591 int bits_per_sample, int sample_rate, | 591 int bits_per_sample, int sample_rate, |
| 592 int number_of_channels, | 592 int number_of_channels, |
| 593 int number_of_frames) {} | 593 size_t number_of_frames) {} |
| 594 | 594 |
| 595 void AudioTransportImpl::PullRenderData(int bits_per_sample, int sample_rate, | 595 void AudioTransportImpl::PullRenderData(int bits_per_sample, int sample_rate, |
| 596 int number_of_channels, | 596 int number_of_channels, |
| 597 int number_of_frames, | 597 size_t number_of_frames, |
| 598 void* audio_data, | 598 void* audio_data, |
| 599 int64_t* elapsed_time_ms, | 599 int64_t* elapsed_time_ms, |
| 600 int64_t* ntp_time_ms) {} | 600 int64_t* ntp_time_ms) {} |
| 601 | 601 |
| 602 FuncTestManager::FuncTestManager() : | 602 FuncTestManager::FuncTestManager() : |
| 603 _audioDevice(NULL), | 603 _audioDevice(NULL), |
| 604 _audioEventObserver(NULL), | 604 _audioEventObserver(NULL), |
| 605 _audioTransport(NULL) | 605 _audioTransport(NULL) |
| 606 { | 606 { |
| 607 _playoutFile48 = webrtc::test::ResourcePath("audio_device\\audio_short48", | 607 _playoutFile48 = webrtc::test::ResourcePath("audio_device\\audio_short48", |
| (...skipping 2154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2762 | 2762 |
| 2763 TEST_LOG("\n"); | 2763 TEST_LOG("\n"); |
| 2764 PRINT_TEST_RESULTS; | 2764 PRINT_TEST_RESULTS; |
| 2765 | 2765 |
| 2766 return 0; | 2766 return 0; |
| 2767 } | 2767 } |
| 2768 | 2768 |
| 2769 } // namespace webrtc | 2769 } // namespace webrtc |
| 2770 | 2770 |
| 2771 // EOF | 2771 // EOF |
| OLD | NEW |