AudioBlock.h
1 /*
2 
3 Copyright (c) 2018, Johnathan Corkery. (jcorkery@umich.edu)
4 All rights reserved.
5 
6 This file is part of the Dynacoe project (https://github.com/jcorks/Dynacoe)
7 Dynacoe was released under the MIT License, as detailed below.
8 
9 
10 
11 Permission is hereby granted, free of charge, to any person obtaining a copy
12 of this software and associated documentation files (the "Software"), to deal
13 in the Software without restriction, including without limitation the rights
14 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
15 copies of the Software, and to permit persons to whom the Software is furnished
16 to do so, subject to the following conditions:
17 
18 The above copyright notice and this permission notice shall
19 be included in all copies or substantial portions of the Software.
20 
21 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
22 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
23 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
24 IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
25 DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
26 ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
27 DEALINGS IN THE SOFTWARE.
28 
29 
30 
31 */
32 
33 #ifndef H_DC_AUDIOBLOCk_INCLUDED
34 #define H_DC_AUDIOBLOCk_INCLUDED
35 
36 
37 #include <Dynacoe/Modules/Assets.h>
38 #include <Dynacoe/Modules/Sound.h>
39 #include <string>
40 #include <cstdint>
41 
42 namespace Dynacoe {
43 
44 
45 
46 
47 
48 
49 
64 class AudioBlock : public Asset {
65 
66 
67  public:
68 
69  AudioBlock(const std::string &);
70  ~AudioBlock();
71 
77  void Define(AudioSample * data, uint32_t numSamples);
78 
87  void SetVolume(float fraction);
88 
96  void SetPanning(float fraction);
97 
100  float GetVolume();
101 
104  float GetPanning();
105 
106 
107 
110  uint32_t NumBytes();
111 
115  uint32_t NumSamples();
116 
123  AudioBlock * GetSubBlock(uint32_t firstSample, uint32_t endSample);
124 
125 
130  void AppendBlock(AudioBlock * block);
131 
132 
137  void RemoveBlock(uint32_t beginSample, uint32_t endSample);
138 
139 
144  void InsertBlock(uint32_t beginSample, AudioBlock * block);
145 
152  float GetSecondsFromSamples(uint32_t i);
153 
156  uint32_t GetSampleFromSeconds(float f);
157 
158 
165  void EditSample(uint32_t sample, AudioSample sampleValue);
166 
167 
168 
176  AudioSample GetSample(uint32_t sample);
177 
178 
183  void Append(AudioSample * data, uint32_t size);
184 
192  static AudioBlock * CreateSine(float pitch, float roughness, uint8_t volume, float duration, int compound);
193 
194 
202  static AudioBlock * CreateHit(float pitch, float impact, float roughness, uint8_t volume, int compound);
203 
204  private:
205 
206 
207 
208  std::string path;
209  AssetID index;
210  char * data;
211  uint32_t size;
212  uint8_t volume;
213  float leftPanning;
214  float rightPanning;
215 
216 };
217 }
218 
219 #endif
float GetPanning()
Returns the current panning.
void Append(AudioSample *data, uint32_t size)
Adds the specified samples to the wave form.
void SetVolume(float fraction)
Sets volume according to a fraction.
A generalized structure representing an audio waveform.
Definition: AudioBlock.h:64
A unit of sound data.
Definition: AudioSample.h:45
void Define(AudioSample *data, uint32_t numSamples)
Clears the current data store of the AudioBlock and replaces it with the given data.
void InsertBlock(uint32_t beginSample, AudioBlock *block)
Inserts the collection of samples at the specified sample.
void RemoveBlock(uint32_t beginSample, uint32_t endSample)
Removes a section of samples.
Definition: AssetID.h:37
void AppendBlock(AudioBlock *block)
Appends the specified AudioBlock to the end of this one.
uint32_t NumBytes()
Returns the size in bytes stored in the AudioBlock.
void SetPanning(float fraction)
Sets panning according to a fraction.
float GetSecondsFromSamples(uint32_t i)
Convert to seconds of the sample.
AudioBlock * GetSubBlock(uint32_t firstSample, uint32_t endSample)
Returns a subsection of the AudioBlock as an independent AudioBlock.
Assets are referred to by an AssetID. The AssetID uniquely refers to an Asset stored within memory...
Definition: AssetID.h:42
uint32_t GetSampleFromSeconds(float f)
Same as GetSecondsFromSamples, but the other way.
void EditSample(uint32_t sample, AudioSample sampleValue)
Changes the value of the specified sample.
static AudioBlock * CreateHit(float pitch, float impact, float roughness, uint8_t volume, int compound)
Creates a new AudioBlock as a basic noise distribution with the given parameters. ...
static AudioBlock * CreateSine(float pitch, float roughness, uint8_t volume, float duration, int compound)
Creates a new AudioBlock as a basic sine wave with the given parameters. Refer to PitchReference for ...
uint32_t NumSamples()
Similar to numBytes; returns the number of samples that the AudioBlock consists of.
float GetVolume()
Returns the current volume.
AudioSample GetSample(uint32_t sample)
Retrieves the current value of the waveform at the given sample index.