1 // Copyright 2014 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 PPAPI_CPP_AUDIO_BUFFER_H_
6 #define PPAPI_CPP_AUDIO_BUFFER_H_
7 
8 #include <stdint.h>
9 
10 #include "ppapi/c/ppb_audio_buffer.h"
11 #include "ppapi/cpp/resource.h"
12 
13 namespace pp {
14 
15 class AudioBuffer : public Resource {
16  public:
17   /// Default constructor for creating an is_null()
18   /// <code>AudioBuffer</code> object.
19   AudioBuffer();
20 
21   /// The copy constructor for <code>AudioBuffer</code>.
22   ///
23   /// @param[in] other A reference to an <code>AudioBuffer</code>.
24   AudioBuffer(const AudioBuffer& other);
25 
26   /// Constructs an <code>AudioBuffer</code> from a <code>Resource</code>.
27   ///
28   /// @param[in] resource A <code>PPB_AudioBuffer</code> resource.
29   explicit AudioBuffer(const Resource& resource);
30 
31   /// A constructor used when you have received a <code>PP_Resource</code> as a
32   /// return value that has had 1 ref added for you.
33   ///
34   /// @param[in] resource A <code>PPB_AudioBuffer</code> resource.
35   AudioBuffer(PassRef, PP_Resource resource);
36 
37   virtual ~AudioBuffer();
38 
39   /// Gets the timestamp of the audio buffer.
40   ///
41   /// @return A <code>PP_TimeDelta</code> containing the timestamp of the audio
42   /// buffer. Given in seconds since the start of the containing audio stream.
43   PP_TimeDelta GetTimestamp() const;
44 
45   /// Sets the timestamp of the audio buffer.
46   ///
47   /// @param[in] timestamp A <code>PP_TimeDelta</code> containing the timestamp
48   /// of the audio buffer. Given in seconds since the start of the containing
49   /// audio stream.
50   void SetTimestamp(PP_TimeDelta timestamp);
51 
52   /// Gets the sample rate of the audio buffer.
53   ///
54   /// @return The sample rate of the audio buffer.
55   PP_AudioBuffer_SampleRate GetSampleRate() const;
56 
57   /// Gets the sample size of the audio buffer in bytes.
58   ///
59   /// @return The sample size of the audio buffer in bytes.
60   PP_AudioBuffer_SampleSize GetSampleSize() const;
61 
62   /// Gets the number of channels in the audio buffer.
63   ///
64   /// @return The number of channels in the audio buffer.
65   uint32_t GetNumberOfChannels() const;
66 
67   /// Gets the number of samples in the audio buffer.
68   ///
69   /// @return The number of samples in the audio buffer.
70   /// For example, at a sampling rate of 44,100 Hz in stereo audio, a buffer
71   /// containing 4,410 * 2 samples would have a duration of 100 milliseconds.
72   uint32_t GetNumberOfSamples() const;
73 
74   /// Gets the data buffer containing the audio buffer samples.
75   ///
76   /// @return A pointer to the beginning of the data buffer.
77   void* GetDataBuffer();
78 
79   /// Gets the size of data buffer in bytes.
80   ///
81   /// @return The size of the data buffer in bytes.
82   uint32_t GetDataBufferSize() const;
83 };
84 
85 }  // namespace pp
86 
87 #endif  // PPAPI_CPP_AUDIO_BUFFER_H_
88