Skip to content

Commit 8b74874

Browse files
committed
added more tests
1 parent 02cbd4c commit 8b74874

16 files changed

+381
-77
lines changed

HephAudio/HeaderFiles/Audio.h

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#include "NativeAudio/NativeAudio.h"
44
#include "AudioEvents/AudioDeviceEventArgs.h"
55
#include "AudioEvents/AudioCaptureEventArgs.h"
6+
#include <memory>
67

78
/** @file */
89

@@ -45,7 +46,7 @@ namespace HephAudio
4546
class HEPH_API Audio final
4647
{
4748
private:
48-
Native::NativeAudio* pNativeAudio;
49+
std::shared_ptr<Native::NativeAudio> pNativeAudio;
4950

5051
public:
5152
void SetOnAudioDeviceAddedHandler(Heph::EventHandler handler);
@@ -66,17 +67,11 @@ namespace HephAudio
6667
*/
6768
Audio(AudioAPI api);
6869

69-
Audio(const Audio&) = delete;
70-
Audio& operator=(const Audio&) = delete;
71-
72-
/** @copydoc destructor */
73-
~Audio();
74-
7570
/**
76-
* gets the pointer to the native audio instance that's internally used.
71+
* gets the shared pointer to the native audio instance that's internally used.
7772
*
7873
*/
79-
Native::NativeAudio* GetNativeAudio() const;
74+
std::shared_ptr<Native::NativeAudio> GetNativeAudio() const;
8075

8176
/** @copydoc HephAudio::Native::NativeAudio::GetAudioDecoder */
8277
std::shared_ptr<IAudioDecoder> GetAudioDecoder() const;

HephAudio/HeaderFiles/AudioChannelLayout.h

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -329,22 +329,6 @@ namespace HephAudio
329329
return lhs;
330330
}
331331

332-
inline constexpr AudioChannelMask operator^(const AudioChannelMask& lhs, const AudioChannelMask& rhs)
333-
{
334-
return (AudioChannelMask)(((int)lhs) ^ ((int)rhs));
335-
}
336-
337-
inline constexpr AudioChannelMask& operator^=(AudioChannelMask& lhs, const AudioChannelMask& rhs)
338-
{
339-
lhs = lhs ^ rhs;
340-
return lhs;
341-
}
342-
343-
inline constexpr AudioChannelMask operator~(const AudioChannelMask& lhs)
344-
{
345-
return (AudioChannelMask)(~((int)lhs));
346-
}
347-
348332
/**
349333
* @brief stores information about the channel layout.
350334
*

HephAudio/HeaderFiles/AudioObject.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
/** @file */
1010

1111
/**
12-
* indicates to play the audio object infinitely.
12+
* indicates the audio object will be played infinitely.
1313
*
1414
*/
1515
#define HEPHAUDIO_INFINITE_LOOP (0)

HephAudio/HeaderFiles/AudioPlaylist.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,10 @@ namespace HephAudio
3434
/**
3535
* @copydoc constructor
3636
*
37-
* @param pNativeAudio pointer to the native audio instance that will be used for playing the files.
37+
* @param pNativeAudio shared pointer to the native audio instance that will be used for playing the files.
3838
*
3939
*/
40-
AudioPlaylist(Native::NativeAudio* pNativeAudio);
40+
AudioPlaylist(std::shared_ptr<Native::NativeAudio> pNativeAudio);
4141
/**
4242
* @copydoc constructor
4343
*
@@ -49,11 +49,11 @@ namespace HephAudio
4949
/**
5050
* @copydoc constructor
5151
*
52-
* @param pNativeAudio pointer to the native audio instance that will be used for playing the files.
52+
* @param pNativeAudio shared pointer to the native audio instance that will be used for playing the files.
5353
* @param files file paths.
5454
*
5555
*/
56-
AudioPlaylist(Native::NativeAudio* pNativeAudio, const std::vector<std::filesystem::path>& files);
56+
AudioPlaylist(std::shared_ptr<Native::NativeAudio> pNativeAudio, const std::vector<std::filesystem::path>& files);
5757

5858
/**
5959
* @copydoc constructor
@@ -81,10 +81,10 @@ namespace HephAudio
8181
size_t Size() const;
8282

8383
/**
84-
* gets the pointer to the native audio instance that's used for playing the files.
84+
* gets the shared pointer to the native audio instance that's used for playing the files.
8585
*
8686
*/
87-
Native::NativeAudio* GetNativeAudio() const;
87+
std::shared_ptr<Native::NativeAudio> GetNativeAudio() const;
8888

8989
/**
9090
* gets the pointer to the audio object instance that's created to play audio data.

HephAudio/HeaderFiles/AudioStream.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ namespace HephAudio
2222
class HEPH_API AudioStream final
2323
{
2424
private:
25-
Native::NativeAudio* pNativeAudio;
25+
std::shared_ptr<Native::NativeAudio> pNativeAudio;
2626
std::shared_ptr<IAudioDecoder> pAudioDecoder;
2727
AudioFormatInfo formatInfo;
2828
size_t frameCount;
@@ -33,9 +33,9 @@ namespace HephAudio
3333
/**
3434
* @copydoc constructor
3535
*
36-
* @param pNativeAudio pointer to the native audio instance that will be used for playing the files.
36+
* @param pNativeAudio shared pointer to the native audio instance that will be used for playing the files.
3737
*/
38-
AudioStream(Native::NativeAudio* pNativeAudio);
38+
AudioStream(std::shared_ptr<Native::NativeAudio> pNativeAudio);
3939

4040
/**
4141
* @copydoc constructor
@@ -47,10 +47,10 @@ namespace HephAudio
4747
/**
4848
* @copydoc constructor
4949
*
50-
* @param pNativeAudio pointer to the native audio instance that will be used for playing the files.
50+
* @param pNativeAudio shared pointer to the native audio instance that will be used for playing the files.
5151
* @param filePath file that will be played.
5252
*/
53-
AudioStream(Native::NativeAudio* pNativeAudio, const std::filesystem::path& filePath);
53+
AudioStream(std::shared_ptr<Native::NativeAudio> pNativeAudio, const std::filesystem::path& filePath);
5454

5555
/**
5656
* @copydoc constructor
@@ -72,10 +72,10 @@ namespace HephAudio
7272
AudioStream& operator=(AudioStream&& rhs) noexcept;
7373

7474
/**
75-
* gets the pointer to the native audio instance that's used for rendering audio data.
75+
* gets the shared pointer to the native audio instance that's used for rendering audio data.
7676
*
7777
*/
78-
Native::NativeAudio* GetNativeAudio() const;
78+
std::shared_ptr<Native::NativeAudio> GetNativeAudio() const;
7979

8080
/**
8181
* gets the shared pointer to the audio decoder instance.

HephAudio/HeaderFiles/EncodedAudioBuffer.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,13 +70,13 @@ namespace HephAudio
7070
virtual void Release() override;
7171

7272
/**
73-
* gets the \link HephAudio::AudioFormatInfo AudioFormatInfo \endlink of the buffer.
73+
* gets the audio format of the buffer.
7474
*
7575
*/
7676
const AudioFormatInfo& GetAudioFormatInfo() const;
7777

7878
/**
79-
* sets the \link HephAudio::AudioFormatInfo AudioFormatInfo \endlink of the buffer.
79+
* sets the audio format of the buffer.
8080
*
8181
*/
8282
void SetAudioFormatInfo(const AudioFormatInfo& newFormatInfo);

HephAudio/SourceFiles/Audio.cpp

Lines changed: 34 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -48,36 +48,42 @@ namespace HephAudio
4848
this->pNativeAudio->OnCapture += handler;
4949
}
5050

51-
Audio::Audio()
51+
Audio::Audio() : pNativeAudio(nullptr)
5252
{
5353
#if defined(_WIN32)
5454

5555
if (IsWindowsVistaOrGreater())
5656
{
57-
this->pNativeAudio = new WinAudio();
57+
this->pNativeAudio = std::shared_ptr<NativeAudio>(new WinAudio());
5858
}
5959
else
6060
{
61-
this->pNativeAudio = new WinAudioDS();
61+
this->pNativeAudio = std::shared_ptr<NativeAudio>(new WinAudioDS());
6262
}
6363

6464
#elif defined(__ANDROID__)
6565

6666
#if __ANDROID_API__ >= HEPHAUDIO_ANDROID_AAUDIO_MIN_API_LEVEL
67-
this->pNativeAudio = new AndroidAudioA();
67+
68+
this->pNativeAudio = std::shared_ptr<NativeAudio>(new AndroidAudioA());
69+
6870
#elif __ANDROID_API__ >= HEPHAUDIO_ANDROID_OPENSL_MIN_API_LEVEL
69-
this->pNativeAudio = new AndroidAudioSLES();
71+
72+
this->pNativeAudio = std::shared_ptr<NativeAudio>(new AndroidAudioSLES());
73+
7074
#else
75+
7176
#error unsupported API level
77+
7278
#endif
7379

7480
#elif defined(__linux__)
7581

76-
this->pNativeAudio = new LinuxAudio();
82+
this->pNativeAudio = std::shared_ptr<NativeAudio>(new LinuxAudio());
7783

7884
#elif defined(__APPLE__)
7985

80-
this->pNativeAudio = new AppleAudio();
86+
this->pNativeAudio = std::shared_ptr<NativeAudio>(new AppleAudio());
8187

8288
#else
8389

@@ -86,56 +92,65 @@ namespace HephAudio
8692
#endif
8793
}
8894

89-
Audio::Audio(AudioAPI api)
95+
Audio::Audio(AudioAPI api) : pNativeAudio(nullptr)
9096
{
9197
#if defined(_WIN32)
9298

9399
switch (api)
94100
{
95101
case AudioAPI::WASAPI:
96-
this->pNativeAudio = new WinAudio();
102+
this->pNativeAudio = std::shared_ptr<NativeAudio>(new WinAudio());
97103
break;
98104
case AudioAPI::DirectSound:
99-
this->pNativeAudio = new WinAudioDS();
105+
this->pNativeAudio = std::shared_ptr<NativeAudio>(new WinAudioDS());
100106
break;
101107
case AudioAPI::MMEAPI:
102-
this->pNativeAudio = new WinAudioMME();
108+
this->pNativeAudio = std::shared_ptr<NativeAudio>(new WinAudioMME());
103109
break;
104110
case AudioAPI::Default:
105111
default:
106-
this->pNativeAudio = IsWindowsVistaOrGreater() ? (NativeAudio*)new WinAudio() : (NativeAudio*)new WinAudioDS();
112+
this->pNativeAudio =
113+
(IsWindowsVistaOrGreater())
114+
? (std::shared_ptr<NativeAudio>(new WinAudio()))
115+
: (std::shared_ptr<NativeAudio>(new WinAudioDS()));
107116
break;
108117
}
109118

110119
#elif defined(__ANDROID__)
111120

112121
#if __ANDROID_API__ >= HEPHAUDIO_ANDROID_AAUDIO_MIN_API_LEVEL
122+
113123
switch (api)
114124
{
115125
case AudioAPI::AAudio:
116-
this->pNativeAudio = new AndroidAudioA();
126+
this->pNativeAudio = std::shared_ptr<NativeAudio>(new AndroidAudioA());
117127
break;
118128
case AudioAPI::OpenSLES:
119-
this->pNativeAudio = new AndroidAudioSLES();
129+
this->pNativeAudio = std::shared_ptr<NativeAudio>(new AndroidAudioSLES());
120130
break;
121131
case AudioAPI::Default:
122132
default:
123-
this->pNativeAudio = (NativeAudio*)new AndroidAudioA();
133+
this->pNativeAudio = std::shared_ptr<NativeAudio>(new AndroidAudioA());
124134
break;
125135
}
136+
126137
#elif __ANDROID_API__ >= HEPHAUDIO_ANDROID_OPENSL_MIN_API_LEVEL
127-
this->pNativeAudio = new AndroidAudioSLES();
138+
139+
this->pNativeAudio = std::shared_ptr<NativeAudio>(new AndroidAudioSLES());
140+
128141
#else
142+
129143
#error unsupported API level
144+
130145
#endif
131146

132147
#elif defined(__linux__)
133148

134-
this->pNativeAudio = new LinuxAudio();
149+
this->pNativeAudio = std::shared_ptr<NativeAudio>(new LinuxAudio());
135150

136151
#elif defined(__APPLE__)
137152

138-
this->pNativeAudio = new AppleAudio();
153+
this->pNativeAudio = std::shared_ptr<NativeAudio>(new AppleAudio());
139154

140155
#else
141156

@@ -144,16 +159,7 @@ namespace HephAudio
144159
#endif
145160
}
146161

147-
Audio::~Audio()
148-
{
149-
if (this->pNativeAudio != nullptr)
150-
{
151-
delete this->pNativeAudio;
152-
this->pNativeAudio = nullptr;
153-
}
154-
}
155-
156-
NativeAudio* Audio::GetNativeAudio() const
162+
std::shared_ptr<NativeAudio> Audio::GetNativeAudio() const
157163
{
158164
return this->pNativeAudio;
159165
}

HephAudio/SourceFiles/AudioObject.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ using namespace Heph;
1313
namespace HephAudio
1414
{
1515
AudioObject::AudioObject()
16-
: id(Guid::GenerateNew()), filePath(""), name(""), isPaused(true), playCount(1), volume(1.0), frameIndex(0)
16+
: id(Guid::GenerateNew()), filePath(""), name(""),
17+
isPaused(true), playCount(1), volume(1.0), frameIndex(0)
1718
{
1819
this->OnRender = HEPHAUDIO_RENDER_HANDLER_DEFAULT;
1920
}

HephAudio/SourceFiles/AudioPlaylist.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@ using namespace Heph;
66

77
namespace HephAudio
88
{
9-
AudioPlaylist::AudioPlaylist(Native::NativeAudio* pNativeAudio) : AudioPlaylist(pNativeAudio, {}) {}
9+
AudioPlaylist::AudioPlaylist(std::shared_ptr<Native::NativeAudio> pNativeAudio) : AudioPlaylist(pNativeAudio, {}) {}
1010

1111
AudioPlaylist::AudioPlaylist(Audio& audio) : AudioPlaylist(audio.GetNativeAudio()) {}
1212

13-
AudioPlaylist::AudioPlaylist(Native::NativeAudio* pNativeAudio, const std::vector<std::filesystem::path>& files)
13+
AudioPlaylist::AudioPlaylist(std::shared_ptr<Native::NativeAudio> pNativeAudio, const std::vector<std::filesystem::path>& files)
1414
: stream(pNativeAudio), files(files)
1515
{
1616
this->ChangeFile();
@@ -52,7 +52,7 @@ namespace HephAudio
5252
return this->files.size();
5353
}
5454

55-
Native::NativeAudio* AudioPlaylist::GetNativeAudio() const
55+
std::shared_ptr<Native::NativeAudio> AudioPlaylist::GetNativeAudio() const
5656
{
5757
return this->stream.GetNativeAudio();
5858
}

HephAudio/SourceFiles/AudioStream.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@ using namespace Heph;
1414

1515
namespace HephAudio
1616
{
17-
AudioStream::AudioStream(Native::NativeAudio* pNativeAudio) : AudioStream(pNativeAudio, "") {}
17+
AudioStream::AudioStream(std::shared_ptr<Native::NativeAudio> pNativeAudio) : AudioStream(pNativeAudio, "") {}
1818

1919
AudioStream::AudioStream(Audio& audio) : AudioStream(audio.GetNativeAudio()) {}
2020

21-
AudioStream::AudioStream(Native::NativeAudio* pNativeAudio, const std::filesystem::path& filePath)
21+
AudioStream::AudioStream(std::shared_ptr<Native::NativeAudio> pNativeAudio, const std::filesystem::path& filePath)
2222
: pNativeAudio(pNativeAudio), pAudioDecoder(new FFmpegAudioDecoder()), frameCount(0), pAudioObject(nullptr)
2323
{
2424
if (this->pNativeAudio == nullptr)
@@ -84,7 +84,7 @@ namespace HephAudio
8484
return *this;
8585
}
8686

87-
Native::NativeAudio* AudioStream::GetNativeAudio() const
87+
std::shared_ptr<Native::NativeAudio> AudioStream::GetNativeAudio() const
8888
{
8989
return this->pNativeAudio;
9090
}

0 commit comments

Comments
 (0)