| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2010 Google Inc. All rights reserved. | 2 * Copyright (C) 2010 Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
| 6 * are met: | 6 * are met: |
| 7 * | 7 * |
| 8 * 1. Redistributions of source code must retain the above copyright | 8 * 1. Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * 2. Redistributions in binary form must reproduce the above copyright | 10 * 2. Redistributions in binary form must reproduce the above copyright |
| (...skipping 14 matching lines...) Expand all Loading... |
| 25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | 25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
| 26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 */ | 27 */ |
| 28 | 28 |
| 29 #include "config.h" | 29 #include "config.h" |
| 30 | 30 |
| 31 #if ENABLE(WEB_AUDIO) | 31 #if ENABLE(WEB_AUDIO) |
| 32 | 32 |
| 33 #include "platform/audio/AudioBus.h" | 33 #include "platform/audio/AudioBus.h" |
| 34 | 34 |
| 35 #include "platform/audio/AudioFileReader.h" |
| 35 #include "platform/audio/DenormalDisabler.h" | 36 #include "platform/audio/DenormalDisabler.h" |
| 37 #include "platform/audio/SincResampler.h" |
| 38 #include "platform/audio/VectorMath.h" |
| 39 #include "public/platform/Platform.h" |
| 40 #include "public/platform/WebAudioBus.h" |
| 41 #include "wtf/OwnPtr.h" |
| 36 | 42 |
| 37 #include <assert.h> | 43 #include <assert.h> |
| 38 #include <math.h> | 44 #include <math.h> |
| 39 #include <algorithm> | 45 #include <algorithm> |
| 40 #include "platform/audio/SincResampler.h" | |
| 41 #include "platform/audio/VectorMath.h" | |
| 42 #include "wtf/OwnPtr.h" | |
| 43 | 46 |
| 44 namespace WebCore { | 47 namespace WebCore { |
| 45 | 48 |
| 46 using namespace VectorMath; | 49 using namespace VectorMath; |
| 47 | 50 |
| 48 const unsigned MaxBusChannels = 32; | 51 const unsigned MaxBusChannels = 32; |
| 49 | 52 |
| 50 PassRefPtr<AudioBus> AudioBus::create(unsigned numberOfChannels, size_t length,
bool allocate) | 53 PassRefPtr<AudioBus> AudioBus::create(unsigned numberOfChannels, size_t length,
bool allocate) |
| 51 { | 54 { |
| 52 ASSERT(numberOfChannels <= MaxBusChannels); | 55 ASSERT(numberOfChannels <= MaxBusChannels); |
| (...skipping 572 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 625 } | 628 } |
| 626 return true; | 629 return true; |
| 627 } | 630 } |
| 628 | 631 |
| 629 void AudioBus::clearSilentFlag() | 632 void AudioBus::clearSilentFlag() |
| 630 { | 633 { |
| 631 for (size_t i = 0; i < m_channels.size(); ++i) | 634 for (size_t i = 0; i < m_channels.size(); ++i) |
| 632 m_channels[i]->clearSilentFlag(); | 635 m_channels[i]->clearSilentFlag(); |
| 633 } | 636 } |
| 634 | 637 |
| 638 PassRefPtr<AudioBus> decodeAudioFileData(const char* data, size_t size, double s
ampleRate) |
| 639 { |
| 640 blink::WebAudioBus webAudioBus; |
| 641 if (blink::Platform::current()->loadAudioResource(&webAudioBus, data, size,
sampleRate)) |
| 642 return webAudioBus.release(); |
| 643 return 0; |
| 644 } |
| 645 |
| 646 PassRefPtr<AudioBus> AudioBus::loadPlatformResource(const char* name, float samp
leRate) |
| 647 { |
| 648 const blink::WebData& resource = blink::Platform::current()->loadResource(na
me); |
| 649 if (resource.isEmpty()) |
| 650 return 0; |
| 651 |
| 652 // FIXME: the sampleRate parameter is ignored. It should be removed from the
API. |
| 653 RefPtr<AudioBus> audioBus = decodeAudioFileData(resource.data(), resource.si
ze(), sampleRate); |
| 654 |
| 655 if (!audioBus.get()) |
| 656 return 0; |
| 657 |
| 658 // If the bus is already at the requested sample-rate then return as is. |
| 659 if (audioBus->sampleRate() == sampleRate) |
| 660 return audioBus; |
| 661 |
| 662 return AudioBus::createBySampleRateConverting(audioBus.get(), false, sampleR
ate); |
| 663 } |
| 664 |
| 665 PassRefPtr<AudioBus> createBusFromInMemoryAudioFile(const void* data, size_t dat
aSize, bool mixToMono, float sampleRate) |
| 666 { |
| 667 // FIXME: the sampleRate parameter is ignored. It should be removed from the
API. |
| 668 RefPtr<AudioBus> audioBus = decodeAudioFileData(static_cast<const char*>(dat
a), dataSize, sampleRate); |
| 669 if (!audioBus.get()) |
| 670 return 0; |
| 671 |
| 672 // If the bus needs no conversion then return as is. |
| 673 if ((!mixToMono || audioBus->numberOfChannels() == 1) && audioBus->sampleRat
e() == sampleRate) |
| 674 return audioBus; |
| 675 |
| 676 return AudioBus::createBySampleRateConverting(audioBus.get(), mixToMono, sam
pleRate); |
| 677 } |
| 678 |
| 635 } // WebCore | 679 } // WebCore |
| 636 | 680 |
| 637 #endif // ENABLE(WEB_AUDIO) | 681 #endif // ENABLE(WEB_AUDIO) |
| OLD | NEW |