File: Sound.cpp

package info (click to toggle)
libexadrums 0.7.0-1.1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 652 kB
  • sloc: cpp: 6,970; ansic: 220; makefile: 160; sh: 12
file content (138 lines) | stat: -rw-r--r-- 1,976 bytes parent folder | download | duplicates (3)
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
/*
 * SoundSample.cpp
 *
 *  Created on: 27 Feb 2016
 *      Author: jeremy
 */

#include "Sound.h"

#include <chrono>

using namespace std::chrono;

namespace Sound
{

	Sound::Sound() : Sound(std::vector<short>{})
	{

		return;
	}

	Sound::Sound(Sound& s) : Sound()
	{

		swap(*this, s);

		return;
	}

	Sound::Sound(Sound&& s) : Sound()
	{

		swap(*this, s);

		return;
	}


	Sound::Sound(int id, const std::vector<short>& soundData, float vol)
	: id(id), loop(false), data(soundData), length(data.size())
	{

		volume.store(vol);
		idx.store(0);

		lastStartTime.store(time_point_cast<microseconds>(high_resolution_clock::now()).time_since_epoch().count(), std::memory_order_relaxed);

		return;
	}


	Sound::Sound(int id, const std::vector<short>& soundData) : Sound(id, soundData, 1.0f)
	{

		return;
	}

	Sound::Sound(const std::vector<short>& soundData, float volume) : Sound(-1, soundData, volume)
	{

		return;
	}

	Sound::Sound(const std::vector<short>& soundData) : Sound(-1, soundData, 1.0f)
	{

		return;
	}

	Sound::~Sound()
	{

		return;
	}



	bool Sound::HasMoreData(std::size_t index, std::size_t length) const
	{

		if(loop) return true;

		if(index + length <= data.size())
		{
			return true;
		}
		else
		{
			return false;
		}
	}

	void Sound::SetVolume(float volume)
	{

		float newVolume = std::min<float>(std::max<float>(0., volume), 1.);

		this->volume.store(newVolume);

		return;
	}

	void Sound::SetStartTime()
	{

		this->lastStartTime.store(time_point_cast<microseconds>(high_resolution_clock::now()).time_since_epoch().count(), std::memory_order_relaxed);

		return;
	}

	/*void Sound::AddToIndex(int offset)
	{

		if(!HasMoreData(offset))
		{
			idx.store(0);
		}
		else
		{

			long prevIdx = idx.fetch_add(offset);

			if(prevIdx % length < offset)
			{
				this->lastStartTime.store(time_point_cast<microseconds>(high_resolution_clock::now()).time_since_epoch().count());
			}

		}

		return;
	}*/


	// PRIVATE


} /* namespace Sound */