Ocean
LiveAudio.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) Meta Platforms, Inc. and affiliates.
3  *
4  * This source code is licensed under the MIT license found in the
5  * LICENSE file in the root directory of this source tree.
6  */
7 
8 #ifndef META_OCEAN_MEDIA_LIVE_AUDIO_H
9 #define META_OCEAN_MEDIA_LIVE_AUDIO_H
10 
11 #include "ocean/media/Media.h"
13 #include "ocean/media/LiveMedium.h"
15 
16 namespace Ocean
17 {
18 
19 namespace Media
20 {
21 
22 // Forward declaration.
23 class LiveAudio;
24 
25 /**
26  * Definition of a smart medium reference holding a live audio object.
27  * @see SmartMediumRef, LiveAudio.
28  * @ingroup media
29  */
31 
32 /**
33  * This class is the base class for all live audios.
34  * @ingroup media
35  */
36 class OCEAN_MEDIA_EXPORT LiveAudio :
37  public virtual LiveMedium,
38  public virtual SoundMedium
39 {
40  public:
41 
42  /**
43  * Definition of individual sample types.
44  */
45  enum SampleType : uint32_t
46  {
47  /// An invalid sample type
48  ST_INVALID = 0u,
49  /// A sample with 16bit signed integer precision as mono channel and 48kHz
51  /// A sample with 16bit signed integer precision as stereo channel and 48kHz
52  ST_INTEGER_16_STEREO_48
53  };
54 
55  public:
56 
57  /**
58  * Adds new samples in case this audio object receives the audio data from a buffer/stream.
59  * @param sampleType The type of the samples, must be valid
60  * @param data The sample data, must be valid
61  * @param size The size of the sample data, in bytes, with range [1, infinity)
62  * @return True, if succeeded
63  */
64  virtual bool addSamples(const SampleType sampleType, const void* data, const size_t size);
65 
66  /**
67  * Returns whether a new samples needs to be added.
68  * @return True, if so
69  */
70  virtual bool needNewSamples() const = 0;
71 
72  /**
73  * Writes a WAV file with given sample data.
74  * @param filename The name of the WAV file to create, must be valid
75  * @param sampleType The type of the samples, must be valid
76  * @param data The sample data, must be valid
77  * @param size The size of the sample data, in bytes, with range [1, infinity)
78  * @return True, if succeeded
79  */
80  static bool writeWavFile(const std::string& filename, const SampleType sampleType, const void* data, const size_t size);
81 
82  protected:
83 
84  /**
85  * Creates a new live audio source by a given url.
86  * @param url Url of the live audio source
87  */
88  explicit LiveAudio(const std::string& url);
89 };
90 
91 }
92 
93 }
94 
95 #endif // META_OCEAN_MEDIA_LIVE_AUDIO_H
This class is the base class for all live audios.
Definition: LiveAudio.h:39
virtual bool addSamples(const SampleType sampleType, const void *data, const size_t size)
Adds new samples in case this audio object receives the audio data from a buffer/stream.
LiveAudio(const std::string &url)
Creates a new live audio source by a given url.
SampleType
Definition of individual sample types.
Definition: LiveAudio.h:46
@ ST_INTEGER_16_MONO_48
A sample with 16bit signed integer precision as mono channel and 48kHz.
Definition: LiveAudio.h:50
static bool writeWavFile(const std::string &filename, const SampleType sampleType, const void *data, const size_t size)
Writes a WAV file with given sample data.
virtual bool needNewSamples() const =0
Returns whether a new samples needs to be added.
This class it the base class for all live mediums.
Definition: LiveMedium.h:38
This class implements a smart medium reference.
Definition: MediumRef.h:33
This class is the base class for all sound mediums.
Definition: SoundMedium.h:38
SmartMediumRef< LiveAudio > LiveAudioRef
Definition of a smart medium reference holding a live audio object.
Definition: LiveAudio.h:23
The namespace covering the entire Ocean framework.
Definition: Accessor.h:15