/
CoreMixer.as
107 lines (89 loc) · 3.04 KB
/
CoreMixer.as
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
/*
Flod 3.0
2012/02/08
Christian Corti
Neoart Costa Rica
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
This work is licensed under the Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License.
To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-sa/3.0/ or send a letter to
Creative Commons, 171 Second Street, Suite 300, San Francisco, California, 94105, USA.
*/
package neoart.flod.core {
import flash.events.*;
import flash.utils.*;
public class CoreMixer {
public var
player : CorePlayer,
samplesTick : int;
protected var
buffer : Vector.<Sample>,
samplesLeft : int,
remains : int,
completed : int,
wave : ByteArray;
public function CoreMixer() {
wave = new ByteArray();
wave.endian = "littleEndian";
bufferSize = 8192;
}
public function get bufferSize():int { return buffer.length; }
public function set bufferSize(value:int):void {
var i:int, len:int;
if (value == len || value < 2048) return;
if (!buffer) {
buffer = new Vector.<Sample>(value, true);
} else {
len = buffer.length;
buffer.fixed = false;
buffer.length = value;
buffer.fixed = true;
}
if (value > len) {
buffer[len] = new Sample();
for (i = ++len; i < value; ++i)
buffer[i] = buffer[int(i - 1)].next = new Sample();
}
}
public function get complete():int { return completed; }
public function set complete(value:int):void {
completed = value ^ player.loopSong;
}
//js function reset
internal function initialize():void {
var sample:Sample = buffer[0];
samplesLeft = 0;
remains = 0;
completed = 0;
while (sample) {
sample.l = sample.r = 0.0;
sample = sample.next;
}
}
//js function restore
internal function reset():void { }
internal function fast(e:SampleDataEvent):void { }
internal function accurate(e:SampleDataEvent):void { }
internal function waveform():ByteArray {
var file:ByteArray = new ByteArray();
file.endian = "littleEndian";
file.writeUTFBytes("RIFF");
file.writeInt(wave.length + 44);
file.writeUTFBytes("WAVEfmt ");
file.writeInt(16);
file.writeShort(1);
file.writeShort(2);
file.writeInt(44100);
file.writeInt(44100 << 2);
file.writeShort(4);
file.writeShort(16);
file.writeUTFBytes("data");
file.writeInt(wave.length);
file.writeBytes(wave);
file.position = 0;
return file;
}
}
}