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

Side by Side Diff: third_party/WebKit/Source/modules/webaudio/AudioDestinationNode.h

Issue 1967393002: [DO NOT SUBMIT] AudioWorklet FS2: audio thread (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@FS1-audioworklet-script-importing
Patch Set: Created 4 years, 7 months 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 unified diff | Download patch
OLDNEW
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 * 1. Redistributions of source code must retain the above copyright 7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer. 8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright 9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the 10 * notice, this list of conditions and the following disclaimer in the
(...skipping 23 matching lines...) Expand all
34 namespace blink { 34 namespace blink {
35 35
36 class AudioBus; 36 class AudioBus;
37 class AbstractAudioContext; 37 class AbstractAudioContext;
38 38
39 class AudioDestinationHandler : public AudioHandler, public AudioIOCallback { 39 class AudioDestinationHandler : public AudioHandler, public AudioIOCallback {
40 public: 40 public:
41 AudioDestinationHandler(AudioNode&, float sampleRate); 41 AudioDestinationHandler(AudioNode&, float sampleRate);
42 ~AudioDestinationHandler() override; 42 ~AudioDestinationHandler() override;
43 43
44 // AudioHandler 44 // Implements AudioHandler::process. However, this node is pulled by
45 void process(size_t) final { } // we're pulled by hardware so this is never called 45 // hardware isochronously so this is never called.
46 void process(size_t) final { }
46 47
47 // The audio hardware calls render() to get the next render quantum of audio into destinationBus. 48 // Implements AudioIOCallback::render. The audio hardware periodically calls
48 // It will optionally give us local/live audio input in sourceBus (if it's n ot 0). 49 // render() to get the next render quantum of audio into the destination
49 void render(AudioBus* sourceBus, AudioBus* destinationBus, size_t numberOfFr ames) final; 50 // bus.
51 void render(AudioBus* sourceBus, AudioBus* destinationBus, size_t framesToPr ocess) final;
50 52
51 size_t currentSampleFrame() const { return acquireLoad(&m_currentSampleFrame ); } 53 size_t currentSampleFrame() const { return acquireLoad(&m_currentSampleFrame ); }
52 double currentTime() const { return currentSampleFrame() / static_cast<doubl e>(sampleRate()); } 54 double currentTime() const { return currentSampleFrame() / static_cast<doubl e>(sampleRate()); }
53 55
54 virtual unsigned long maxChannelCount() const { return 0; } 56 virtual unsigned long maxChannelCount() const { return 0; }
55 57
56 virtual void startRendering() = 0; 58 virtual void startRendering() = 0;
57 virtual void stopRendering() = 0; 59 virtual void stopRendering() = 0;
58 60
59 protected: 61 protected:
60 // LocalAudioInputProvider allows us to expose an AudioSourceProvider for lo cal/live audio input. 62 // LocalAudioInputProvider allows us to expose an AudioSourceProvider for
61 // If there is local/live audio input, we call set() with the audio input da ta every render quantum. 63 // local/live audio input. If there is local/live audio input, we call set()
64 // with the audio input data every render quantum.
62 class LocalAudioInputProvider final : public AudioSourceProvider { 65 class LocalAudioInputProvider final : public AudioSourceProvider {
63 public: 66 public:
67 // TODO(hongchan): handle non-stereo local input.
64 LocalAudioInputProvider() 68 LocalAudioInputProvider()
65 : m_sourceBus(AudioBus::create(2, ProcessingSizeInFrames)) // FIXME: handle non-stereo local input. 69 : m_sourceBus(AudioBus::create(2, ProcessingSizeInFrames))
66 { 70 {
67 } 71 }
68 72
69 void set(AudioBus* bus) 73 void setSourceBus(AudioBus* sourceBus)
70 { 74 {
71 if (bus) 75 if (sourceBus)
72 m_sourceBus->copyFrom(*bus); 76 m_sourceBus->copyFrom(*sourceBus);
73 } 77 }
74 78
75 // AudioSourceProvider. 79 // Implements AudioSourceProvider::provideInput.
76 void provideInput(AudioBus* destinationBus, size_t numberOfFrames) overr ide 80 void provideInput(AudioBus* destinationBus, size_t numberOfFrames) overr ide
77 { 81 {
78 bool isGood = destinationBus && destinationBus->length() == numberOf Frames && m_sourceBus->length() == numberOfFrames; 82 bool isGood =
83 destinationBus && destinationBus->length() == numberOfFrames
84 && m_sourceBus->length() == numberOfFrames;
85
79 ASSERT(isGood); 86 ASSERT(isGood);
80 if (isGood) 87 if (isGood)
81 destinationBus->copyFrom(*m_sourceBus); 88 destinationBus->copyFrom(*m_sourceBus);
82 } 89 }
83 90
84 private: 91 private:
85 RefPtr<AudioBus> m_sourceBus; 92 RefPtr<AudioBus> m_sourceBus;
86 }; 93 };
87 94
88 // Counts the number of sample-frames processed by the destination. 95 // Counts the number of sample-frames processed by the destination.
89 size_t m_currentSampleFrame; 96 size_t m_currentSampleFrame;
90 97
91 LocalAudioInputProvider m_localAudioInputProvider; 98 LocalAudioInputProvider m_localAudioInputProvider;
92 }; 99 };
93 100
94 class AudioDestinationNode : public AudioNode { 101 class AudioDestinationNode : public AudioNode {
95 DEFINE_WRAPPERTYPEINFO(); 102 DEFINE_WRAPPERTYPEINFO();
96 public: 103 public:
97 AudioDestinationHandler& audioDestinationHandler() const; 104 AudioDestinationHandler& audioDestinationHandler() const;
98 105
99 unsigned long maxChannelCount() const; 106 unsigned long maxChannelCount() const;
100 107
101 protected: 108 protected:
102 AudioDestinationNode(AbstractAudioContext&); 109 AudioDestinationNode(AbstractAudioContext&);
103 }; 110 };
104 111
105 } // namespace blink 112 } // namespace blink
106 113
107 #endif // AudioDestinationNode_h 114 #endif // AudioDestinationNode_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698