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 349 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
360 { | 360 { |
361 int ret(0); | 361 int ret(0); |
362 int lenOut(0); | 362 int 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 uint16_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 = | 370 const uint16_t nBytesPerSampleIn = packet->nBytesPerSample; |
371 packet->nBytesPerSample; | |
372 | 371 |
373 int32_t fsInHz(samplesPerSecIn); | 372 int32_t fsInHz(samplesPerSecIn); |
374 int32_t fsOutHz(samplesPerSec); | 373 int32_t fsOutHz(samplesPerSec); |
375 | 374 |
376 if (fsInHz == 44100) | 375 if (fsInHz == 44100) |
377 fsInHz = 44000; | 376 fsInHz = 44000; |
378 | 377 |
379 if (fsOutHz == 44100) | 378 if (fsOutHz == 44100) |
380 fsOutHz = 44000; | 379 fsOutHz = 44000; |
381 | 380 |
382 if (nChannelsIn == 2 && nBytesPerSampleIn == 4) | 381 if (nChannelsIn == 2 && nBytesPerSampleIn == 4) |
383 { | 382 { |
384 // input is stereo => we will resample in stereo | 383 // input is stereo => we will resample in stereo |
385 ret = _resampler.ResetIfNeeded(fsInHz, fsOutHz, 2); | 384 ret = _resampler.ResetIfNeeded(fsInHz, fsOutHz, 2); |
386 if (ret == 0) | 385 if (ret == 0) |
387 { | 386 { |
388 if (nChannels == 2) | 387 if (nChannels == 2) |
389 { | 388 { |
390 _resampler.Push( | 389 _resampler.Push( |
391 (const int16_t*) packet->dataBuffer, | 390 (const int16_t*) packet->dataBuffer, |
392 2 * nSamplesIn, | 391 2 * nSamplesIn, (int16_t*) audioSamples, |
393 (int16_t*) audioSamples, 2 | 392 2 * nSamples, lenOut); |
394 * nSamples, lenOut); | |
395 } else | 393 } else |
396 { | 394 { |
397 _resampler.Push( | 395 _resampler.Push( |
398 (const int16_t*) packet->dataBuffer, | 396 (const int16_t*) packet->dataBuffer, |
399 2 * nSamplesIn, tmpBuf_96kHz, 2 | 397 2 * nSamplesIn, tmpBuf_96kHz, 2 * nSamples, |
400 * nSamples, lenOut); | 398 lenOut); |
401 | 399 |
402 ptr16In = &tmpBuf_96kHz[0]; | 400 ptr16In = &tmpBuf_96kHz[0]; |
403 ptr16Out = (int16_t*) audioSamples; | 401 ptr16Out = (int16_t*) audioSamples; |
404 | 402 |
405 // do stereo -> mono | 403 // do stereo -> mono |
406 for (unsigned int i = 0; i < nSamples; i++) | 404 for (unsigned int i = 0; i < nSamples; i++) |
407 { | 405 { |
408 *ptr16Out = *ptr16In; // use left channel | 406 *ptr16Out = *ptr16In; // use left channel |
409 ptr16Out++; | 407 ptr16Out++; |
410 ptr16In++; | 408 ptr16In++; |
(...skipping 11 matching lines...) Expand all Loading... |
422 } else | 420 } else |
423 { | 421 { |
424 // input is mono (can be "reduced from stereo" as well) => | 422 // input is mono (can be "reduced from stereo" as well) => |
425 // we will resample in mono | 423 // we will resample in mono |
426 ret = _resampler.ResetIfNeeded(fsInHz, fsOutHz, 1); | 424 ret = _resampler.ResetIfNeeded(fsInHz, fsOutHz, 1); |
427 if (ret == 0) | 425 if (ret == 0) |
428 { | 426 { |
429 if (nChannels == 1) | 427 if (nChannels == 1) |
430 { | 428 { |
431 _resampler.Push( | 429 _resampler.Push( |
432 (const int16_t*) packet->dataBuffer, | 430 (const int16_t*) packet->dataBuffer, nSamplesIn, |
433 nSamplesIn, | 431 (int16_t*) audioSamples, nSamples, lenOut); |
434 (int16_t*) audioSamples, | |
435 nSamples, lenOut); | |
436 } else | 432 } else |
437 { | 433 { |
438 _resampler.Push( | 434 _resampler.Push( |
439 (const int16_t*) packet->dataBuffer, | 435 (const int16_t*) packet->dataBuffer, nSamplesIn, |
440 nSamplesIn, tmpBuf_96kHz, nSamples, | 436 tmpBuf_96kHz, nSamples, lenOut); |
441 lenOut); | |
442 | 437 |
443 ptr16In = &tmpBuf_96kHz[0]; | 438 ptr16In = &tmpBuf_96kHz[0]; |
444 ptr16Out = (int16_t*) audioSamples; | 439 ptr16Out = (int16_t*) audioSamples; |
445 | 440 |
446 // do mono -> stereo | 441 // do mono -> stereo |
447 for (unsigned int i = 0; i < nSamples; i++) | 442 for (unsigned int i = 0; i < nSamples; i++) |
448 { | 443 { |
449 *ptr16Out = *ptr16In; // left | 444 *ptr16Out = *ptr16In; // left |
450 ptr16Out++; | 445 ptr16Out++; |
451 *ptr16Out = *ptr16In; // right (same as left sam
ple) | 446 *ptr16Out = *ptr16In; // right (same as left sam
ple) |
(...skipping 13 matching lines...) Expand all Loading... |
465 delete packet; | 460 delete packet; |
466 } | 461 } |
467 } | 462 } |
468 } // if (_fullDuplex) | 463 } // if (_fullDuplex) |
469 | 464 |
470 if (_playFromFile && _playFile.Open()) | 465 if (_playFromFile && _playFile.Open()) |
471 { | 466 { |
472 int16_t fileBuf[480]; | 467 int16_t fileBuf[480]; |
473 | 468 |
474 // read mono-file | 469 // read mono-file |
475 int32_t len = _playFile.Read((int8_t*) fileBuf, 2 | 470 int32_t len = _playFile.Read((int8_t*) fileBuf, 2 * nSamples); |
476 * nSamples); | |
477 if (len != 2 * (int32_t) nSamples) | 471 if (len != 2 * (int32_t) nSamples) |
478 { | 472 { |
479 _playFile.Rewind(); | 473 _playFile.Rewind(); |
480 _playFile.Read((int8_t*) fileBuf, 2 * nSamples); | 474 _playFile.Read((int8_t*) fileBuf, 2 * nSamples); |
481 } | 475 } |
482 | 476 |
483 // convert to stero if required | 477 // convert to stero if required |
484 if (nChannels == 1) | 478 if (nChannels == 1) |
485 { | 479 { |
486 memcpy(audioSamples, fileBuf, 2 * nSamples); | 480 memcpy(audioSamples, fileBuf, 2 * nSamples); |
(...skipping 2281 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2768 | 2762 |
2769 TEST_LOG("\n"); | 2763 TEST_LOG("\n"); |
2770 PRINT_TEST_RESULTS; | 2764 PRINT_TEST_RESULTS; |
2771 | 2765 |
2772 return 0; | 2766 return 0; |
2773 } | 2767 } |
2774 | 2768 |
2775 } // namespace webrtc | 2769 } // namespace webrtc |
2776 | 2770 |
2777 // EOF | 2771 // EOF |
OLD | NEW |