summaryrefslogtreecommitdiff
path: root/Runtime/Audio/AudioClip_Flash.h
blob: b3a9f102a663d0b296ca9305f9aee1ca6595b0c6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#ifndef AUDIOCLIP_FLASH_H
#define AUDIOCLIP_FLASH_H
#include "Configuration/UnityConfigure.h"

#if (UNITY_FLASH || UNITY_WEBGL) && ENABLE_AUDIO

#include "Runtime/BaseClasses/NamedObject.h"
#include "Runtime/Misc/Allocator.h"
#include "Runtime/Utilities/dynamic_array.h"
#include "Runtime/Serialize/CacheWrap.h"
#include "Runtime/Scripting/ScriptingUtility.h"
#include "Runtime/Audio/AudioSource.h"
#include "PlatformDependent/FlashSupport/cpp/AudioChannel.h"

#if ENABLE_WWW
class WWW;
#endif

class AudioClip : public NamedObject
{

public:
	REGISTER_DERIVED_CLASS 	 (AudioClip, NamedObject)
	DECLARE_OBJECT_SERIALIZE (AudioClip)

	AudioClip (MemLabelId label, ObjectCreationMode mode);
	// virtual ~AudioClip (); - declared-by-macro 
	
	void AwakeFromLoad (AwakeFromLoadMode awakeMode);
	float GetLengthSec();

	bool ReadyToPlay() { return true; }
	int GetFrequency() { return 44100; }
	unsigned int GetSampleCount() { return m_SampleCount; }
	int GetChannelCount() { return 2; }
	AudioChannel* CreateChannel(AudioSource* forSource = NULL);
	
	bool Get3D() const { return m_3D; }
	void Set3D(bool threeD) { m_3D = threeD; }	

	void SetData(const float* data, unsigned lengthSamples, unsigned offsetSamples = 0) {}
	void GetData(float* data, unsigned lengthSamples, unsigned offsetSamples = 0) const {}

	void SetReadAllowed (bool allowed) { m_ReadAllowed = allowed; }
	bool GetReadAllowed () const { return m_ReadAllowed; }
	
	bool InitStream (WWW* streamData, void* movie, bool realStream = false);

private:
	void LoadSound();
	bool LoadSoundFrom(void* ptr, size_t length);
	
	bool			m_IsWWWAudioClip;
	bool			m_ReadAllowed;
	bool			m_3D;
	UInt8*			m_Mp3InMemory;
	int				m_Mp3InMemoryLength;
	unsigned int	m_SampleCount;
#if UNITY_FLASH
	AS3Handle		m_SoundObject;
#elif UNITY_WEBGL
	int				m_SoundObject;
#endif
	WWW*			m_StreamData;
	


	friend class AudioManager;

};

#endif //UNITY_FLASH
#endif