1//************************************ bs::framework - Copyright 2018 Marko Pintera **************************************//
2//*********** Licensed under the MIT license. See LICENSE.md for full terms. This notice is not to be removed. ***********//
3#include "Audio/BsAudioClip.h"
4#include "Resources/BsResources.h"
5#include "Audio/BsAudio.h"
6#include "Private/RTTI/BsAudioClipRTTI.h"
7
8namespace bs
9{
10 AudioClip::AudioClip(const SPtr<DataStream>& samples, UINT32 streamSize, UINT32 numSamples, const AUDIO_CLIP_DESC& desc)
11 : Resource(false), mDesc(desc), mNumSamples(numSamples), mStreamSize(streamSize), mStreamData(samples)
12 {
13 if (samples != nullptr)
14 mStreamOffset = (UINT32)samples->tell();
15
16 mKeepSourceData = desc.keepSourceData;
17 }
18
19 void AudioClip::initialize()
20 {
21 mLength = mNumSamples / mDesc.numChannels / (float)mDesc.frequency;
22
23 Resource::initialize();
24 }
25
26 HAudioClip AudioClip::create(const SPtr<DataStream>& samples, UINT32 streamSize, UINT32 numSamples, const AUDIO_CLIP_DESC& desc)
27 {
28 return static_resource_cast<AudioClip>(gResources()._createResourceHandle(_createPtr(samples, streamSize, numSamples, desc)));
29 }
30
31 SPtr<AudioClip> AudioClip::_createPtr(const SPtr<DataStream>& samples, UINT32 streamSize, UINT32 numSamples, const AUDIO_CLIP_DESC& desc)
32 {
33 SPtr<AudioClip> newClip = gAudio().createClip(samples, streamSize, numSamples, desc);
34 newClip->_setThisPtr(newClip);
35 newClip->initialize();
36
37 return newClip;
38 }
39
40 SPtr<AudioClip> AudioClip::createEmpty()
41 {
42 AUDIO_CLIP_DESC desc;
43
44 SPtr<AudioClip> newClip = gAudio().createClip(nullptr, 0, 0, desc);
45 newClip->_setThisPtr(newClip);
46
47 return newClip;
48 }
49
50 RTTITypeBase* AudioClip::getRTTIStatic()
51 {
52 return AudioClipRTTI::instance();
53 }
54
55 RTTITypeBase* AudioClip::getRTTI() const
56 {
57 return getRTTIStatic();
58 }
59}