Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1747)

Unified Diff: Source/platform/audio/AudioBus.cpp

Issue 100993004: Move chrome specific code from platform/audio/chromium to platform/audio (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: fixed atreat review commets Created 7 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | Source/platform/audio/AudioDestination.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/platform/audio/AudioBus.cpp
diff --git a/Source/platform/audio/AudioBus.cpp b/Source/platform/audio/AudioBus.cpp
index 81b4ccf56ada0292631861cecd926d7fdf5c6dc4..3173077ee18b788c429e04ab64058d4a2b612aae 100644
--- a/Source/platform/audio/AudioBus.cpp
+++ b/Source/platform/audio/AudioBus.cpp
@@ -32,14 +32,17 @@
#include "platform/audio/AudioBus.h"
+#include "platform/audio/AudioFileReader.h"
#include "platform/audio/DenormalDisabler.h"
+#include "platform/audio/SincResampler.h"
+#include "platform/audio/VectorMath.h"
+#include "public/platform/Platform.h"
+#include "public/platform/WebAudioBus.h"
+#include "wtf/OwnPtr.h"
#include <assert.h>
#include <math.h>
#include <algorithm>
-#include "platform/audio/SincResampler.h"
-#include "platform/audio/VectorMath.h"
-#include "wtf/OwnPtr.h"
namespace WebCore {
@@ -632,6 +635,47 @@ void AudioBus::clearSilentFlag()
m_channels[i]->clearSilentFlag();
}
+PassRefPtr<AudioBus> decodeAudioFileData(const char* data, size_t size, double sampleRate)
+{
+ blink::WebAudioBus webAudioBus;
+ if (blink::Platform::current()->loadAudioResource(&webAudioBus, data, size, sampleRate))
+ return webAudioBus.release();
+ return 0;
+}
+
+PassRefPtr<AudioBus> AudioBus::loadPlatformResource(const char* name, float sampleRate)
+{
+ const blink::WebData& resource = blink::Platform::current()->loadResource(name);
+ if (resource.isEmpty())
+ return 0;
+
+ // FIXME: the sampleRate parameter is ignored. It should be removed from the API.
+ RefPtr<AudioBus> audioBus = decodeAudioFileData(resource.data(), resource.size(), sampleRate);
+
+ if (!audioBus.get())
+ return 0;
+
+ // If the bus is already at the requested sample-rate then return as is.
+ if (audioBus->sampleRate() == sampleRate)
+ return audioBus;
+
+ return AudioBus::createBySampleRateConverting(audioBus.get(), false, sampleRate);
+}
+
+PassRefPtr<AudioBus> createBusFromInMemoryAudioFile(const void* data, size_t dataSize, bool mixToMono, float sampleRate)
+{
+ // FIXME: the sampleRate parameter is ignored. It should be removed from the API.
+ RefPtr<AudioBus> audioBus = decodeAudioFileData(static_cast<const char*>(data), dataSize, sampleRate);
+ if (!audioBus.get())
+ return 0;
+
+ // If the bus needs no conversion then return as is.
+ if ((!mixToMono || audioBus->numberOfChannels() == 1) && audioBus->sampleRate() == sampleRate)
+ return audioBus;
+
+ return AudioBus::createBySampleRateConverting(audioBus.get(), mixToMono, sampleRate);
+}
+
} // WebCore
#endif // ENABLE(WEB_AUDIO)
« no previous file with comments | « no previous file | Source/platform/audio/AudioDestination.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698