1 // Copyright 2020 The Chromium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #ifndef CHROMECAST_MEDIA_AUDIO_CAST_AUDIO_BUS_H_ 6 #define CHROMECAST_MEDIA_AUDIO_CAST_AUDIO_BUS_H_ 7 8 #include <memory> 9 #include <vector> 10 11 namespace chromecast { 12 namespace media { 13 14 // This class is a simplified version of ::media::AudioBus without any 15 // dependency on //media. 16 class CastAudioBus { 17 public: 18 // Creates a new CastAudioBus and allocates |channels| of length |frames|. 19 static std::unique_ptr<CastAudioBus> Create(int channels, int frames); 20 21 // Returns a raw pointer to the requested channel. channel(int channel)22 float* channel(int channel) { return channel_data_[channel]; } channel(int channel)23 const float* channel(int channel) const { return channel_data_[channel]; } 24 25 // Returns the number of channels. channels()26 int channels() const { return static_cast<int>(channel_data_.size()); } 27 // Returns the number of frames. frames()28 int frames() const { return frames_; } 29 30 // Helper method for zeroing out all channels of audio data. 31 void Zero(); 32 33 ~CastAudioBus(); 34 35 private: 36 CastAudioBus(int channels, int frames); 37 38 // Contiguous block of channel memory. 39 std::unique_ptr<float[]> data_; 40 41 // One float pointer per channel pointing to a contiguous block of memory for 42 // that channel. 43 std::vector<float*> channel_data_; 44 int frames_; 45 }; 46 47 } // namespace media 48 } // namespace chromecast 49 50 #endif // CHROMECAST_MEDIA_AUDIO_CAST_AUDIO_BUS_H_ 51