=utf-8
4 |
--------------------------------------------------------------------------------
/README:
--------------------------------------------------------------------------------
1 | Bfrx API example.
2 |
3 | An example showing four types of sound generation.
4 |
5 | 1: synthesized on the fly
6 | 2: precached
7 | 3: mutated on the fly
8 | 4: precached mutations
9 |
10 | For realtime applications, I *strongly* recommend precaching :)
11 |
12 | And yes, you'll need a different Bfxr instance for each sound.
13 |
14 | One other note:
15 | - Synthesis is substantially slower in debug mode than final release
16 | builds, so don't get too down if it makes things a bit laggy while
17 | testing.
18 | - The caching API in this version is synchronous. This means that
19 | the program can't do anything while caching sounds.
20 | - Mixes take longer to generate than plain 'ol synths, so they can
21 | take substantially longer to generation mutations for.
22 |
23 | http://www.bfxr.net
24 |
25 | Stephen Lavelle
26 | analytic@gmail.com
27 |
28 | This is all distributed under the Apache License 2.0
29 | http://www.apache.org/licenses/LICENSE-2.0
30 |
--------------------------------------------------------------------------------
/bin-release/Bfxr_API_Example.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
13 |
14 |
15 |
16 |
17 |
23 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
61 |
62 |
63 |
67 |
68 |
69 | To view this page ensure that Adobe Flash Player version
70 | 10.0.0 or greater is installed.
71 |
72 |
77 |
78 |
79 |
107 |
108 |
109 |
--------------------------------------------------------------------------------
/bin-release/Bfxr_API_Example.swf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/increpare/bfxr-api-example/b74254e80b9d7cc334fee8d06a053440a63a4328/bin-release/Bfxr_API_Example.swf
--------------------------------------------------------------------------------
/bin-release/framework_4.1.0.16076.swz:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/increpare/bfxr-api-example/b74254e80b9d7cc334fee8d06a053440a63a4328/bin-release/framework_4.1.0.16076.swz
--------------------------------------------------------------------------------
/bin-release/history/history.css:
--------------------------------------------------------------------------------
1 | /* This CSS stylesheet defines styles used by required elements in a flex application page that supports browser history */
2 |
3 | #ie_historyFrame { width: 0px; height: 0px; display:none }
4 | #firefox_anchorDiv { width: 0px; height: 0px; display:none }
5 | #safari_formDiv { width: 0px; height: 0px; display:none }
6 | #safari_rememberDiv { width: 0px; height: 0px; display:none }
7 |
--------------------------------------------------------------------------------
/bin-release/history/historyFrame.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
27 | Hidden frame for Browser History support.
28 |
29 |
30 |
--------------------------------------------------------------------------------
/bin-release/osmf_flex.4.0.0.13495.swz:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/increpare/bfxr-api-example/b74254e80b9d7cc334fee8d06a053440a63a4328/bin-release/osmf_flex.4.0.0.13495.swz
--------------------------------------------------------------------------------
/bin-release/playerProductInstall.swf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/increpare/bfxr-api-example/b74254e80b9d7cc334fee8d06a053440a63a4328/bin-release/playerProductInstall.swf
--------------------------------------------------------------------------------
/bin-release/rpc_4.1.0.16076.swz:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/increpare/bfxr-api-example/b74254e80b9d7cc334fee8d06a053440a63a4328/bin-release/rpc_4.1.0.16076.swz
--------------------------------------------------------------------------------
/bin-release/spark_4.1.0.16076.swz:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/increpare/bfxr-api-example/b74254e80b9d7cc334fee8d06a053440a63a4328/bin-release/spark_4.1.0.16076.swz
--------------------------------------------------------------------------------
/bin-release/sparkskins_4.1.0.16076.swz:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/increpare/bfxr-api-example/b74254e80b9d7cc334fee8d06a053440a63a4328/bin-release/sparkskins_4.1.0.16076.swz
--------------------------------------------------------------------------------
/bin-release/srcview/Bfxr_API_Example.zip:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/increpare/bfxr-api-example/b74254e80b9d7cc334fee8d06a053440a63a4328/bin-release/srcview/Bfxr_API_Example.zip
--------------------------------------------------------------------------------
/bin-release/srcview/SourceIndex.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | Source of Bfxr_API_Example
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 |
--------------------------------------------------------------------------------
/bin-release/srcview/SourceStyles.css:
--------------------------------------------------------------------------------
1 | body {
2 | font-family: Courier New, Courier, monospace;
3 | font-size: medium;
4 | }
5 |
6 | .MXMLASDoc {
7 | color: #3f5fbf;
8 | }
9 |
10 | .MXMLComment {
11 | color: #800000;
12 | }
13 |
14 | .MXMLComponent_Tag {
15 | color: #0000ff;
16 | }
17 |
18 | .MXMLDefault_Text {
19 | }
20 |
21 | .MXMLProcessing_Instruction {
22 | }
23 |
24 | .MXMLSpecial_Tag {
25 | color: #006633;
26 | }
27 |
28 | .MXMLString {
29 | color: #990000;
30 | }
31 |
32 | .CSS@font-face {
33 | color: #990000;
34 | font-weight: bold;
35 | }
36 |
37 | .CSS@import {
38 | color: #006666;
39 | font-weight: bold;
40 | }
41 |
42 | .CSS@media {
43 | color: #663333;
44 | font-weight: bold;
45 | }
46 |
47 | .CSS@namespace {
48 | color: #923196;
49 | }
50 |
51 | .CSSComment {
52 | color: #999999;
53 | }
54 |
55 | .CSSDefault_Text {
56 | }
57 |
58 | .CSSDelimiters {
59 | }
60 |
61 | .CSSProperty_Name {
62 | color: #330099;
63 | }
64 |
65 | .CSSProperty_Value {
66 | color: #3333cc;
67 | }
68 |
69 | .CSSSelector {
70 | color: #ff00ff;
71 | }
72 |
73 | .CSSString {
74 | color: #990000;
75 | }
76 |
77 | .ActionScriptASDoc {
78 | color: #3f5fbf;
79 | }
80 |
81 | .ActionScriptBracket/Brace {
82 | }
83 |
84 | .ActionScriptComment {
85 | color: #009900;
86 | font-style: italic;
87 | }
88 |
89 | .ActionScriptDefault_Text {
90 | }
91 |
92 | .ActionScriptMetadata {
93 | color: #0033ff;
94 | font-weight: bold;
95 | }
96 |
97 | .ActionScriptOperator {
98 | }
99 |
100 | .ActionScriptReserved {
101 | color: #0033ff;
102 | font-weight: bold;
103 | }
104 |
105 | .ActionScriptString {
106 | color: #990000;
107 | font-weight: bold;
108 | }
109 |
110 | .ActionScriptclass {
111 | color: #9900cc;
112 | font-weight: bold;
113 | }
114 |
115 | .ActionScriptfunction {
116 | color: #339966;
117 | font-weight: bold;
118 | }
119 |
120 | .ActionScriptinterface {
121 | color: #9900cc;
122 | font-weight: bold;
123 | }
124 |
125 | .ActionScriptpackage {
126 | color: #9900cc;
127 | font-weight: bold;
128 | }
129 |
130 | .ActionScripttrace {
131 | color: #cc6666;
132 | font-weight: bold;
133 | }
134 |
135 | .ActionScriptvar {
136 | color: #6699cc;
137 | font-weight: bold;
138 | }
139 |
140 |
--------------------------------------------------------------------------------
/bin-release/srcview/SourceTree.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
13 |
14 |
15 |
16 |
21 |
27 |
28 |
29 |
33 |
34 |
35 |
66 |
67 |
68 |
72 |
73 |
74 | To view this page ensure that Adobe Flash Player version
75 | 10.0.0 or greater is installed.
76 |
77 |
82 |
83 |
84 |
112 |
113 |
114 |
--------------------------------------------------------------------------------
/bin-release/srcview/SourceTree.swf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/increpare/bfxr-api-example/b74254e80b9d7cc334fee8d06a053440a63a4328/bin-release/srcview/SourceTree.swf
--------------------------------------------------------------------------------
/bin-release/srcview/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | Source of Bfxr_API_Example
7 |
8 |
12 |
13 |
14 |
15 |
16 |
17 |
--------------------------------------------------------------------------------
/bin-release/srcview/playerProductInstall.swf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/increpare/bfxr-api-example/b74254e80b9d7cc334fee8d06a053440a63a4328/bin-release/srcview/playerProductInstall.swf
--------------------------------------------------------------------------------
/bin-release/srcview/source/Bfxr_API_Example.as.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | Bfxr_API_Example.as
7 |
8 |
9 |
10 |
39 | package
40 | {
41 | import com.increpare.bfxr.Bfxr;
42 |
43 | import flash.display.MovieClip;
44 | import flash.display.Sprite;
45 | import flash.events.MouseEvent;
46 | import flash.text.TextField;
47 | import flash.ui.Mouse;
48 |
49 | import ui.TinyButton;
50 |
51 | [SWF("220", height="120", backgroundColor="#C0B090")]
52 |
53 | public class Bfxr_API_Example extends Sprite
54 | {
55 | private const soundData:String = ",0.5,,0.3484,,0.2472,0.3,0.4135,,0.2198,,,,,,,,,,,0.015,,,,,0.4293,,,0.0539,,,,masterVolume";
57 |
58 | private var sound1:Bfxr;
59 | private var sound2:Bfxr;
60 | private var sound3:Bfxr;
61 |
62 | public function Bfxr_API_Example()
63 | {
64 | InitSounds();
66 |
67 | var b:TinyButton;
69 |
70 | b = new TinyButton(Button1Click,"Runtime Synthesize");
71 | b.x = 10; b.y = 10;
72 | this.addChild(b);
73 |
74 | b = new TinyButton(Button2Click,"Play Precached");
75 | b.x = 10; b.y = 40;
76 | this.addChild(b);
77 |
78 | b = new TinyButton(Button3Click,"Cached Mutation");
79 | b.x = 10; b.y = 70;
80 | this.addChild(b);
81 | }
82 |
83 | private function InitSounds():void
84 | {
85 | sound1 = new Bfxr();
87 | sound1.Load(soundData);
88 |
89 |
90 | sound2 = new Bfxr();
92 | sound2.Load(soundData);
93 | sound2.Cache();
94 |
95 | sound3 = new Bfxr();
97 | sound3.Load(soundData);
98 | sound3.CacheMutations(0.05,10); }
100 |
101 | private function Button1Click(caller:TinyButton):void
102 | {
103 | sound1.Play();
104 | }
105 |
106 | private function Button2Click(caller:TinyButton):void
107 | {
108 | sound2.Play();
109 | }
110 |
111 | private function Button3Click(caller:TinyButton):void
112 | {
113 | sound3.Play();
115 | }
116 |
117 | }
118 | }
119 |
120 |
--------------------------------------------------------------------------------
/bin-release/srcview/source/assets/amiga4ever.ttf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/increpare/bfxr-api-example/b74254e80b9d7cc334fee8d06a053440a63a4328/bin-release/srcview/source/assets/amiga4ever.ttf
--------------------------------------------------------------------------------
/bin-release/srcview/source/com/increpare/bfxr/Bfxr.as.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | Bfxr.as
7 |
8 |
9 |
10 | package com.increpare.bfxr
11 | {
12 | import com.increpare.bfxr.synthesis.IPlayerInterface;
13 | import com.increpare.bfxr.synthesis.Mixer.MixerPlayer;
14 | import com.increpare.bfxr.synthesis.Synthesizer.SfxrSynth;
15 |
16 | public class Bfxr
17 | {
18 | public function Load(data:String):void
19 | {
20 | if (data.indexOf("|")==-1)
21 | {
22 | _active = _synth;
23 | }
24 | else
25 | {
26 | _active = _mixer;
27 | }
28 | _active.Load(data);
29 | }
30 |
31 | public function Play(volume:Number=1):void
32 | {
33 | _active.Play(volume);
34 | }
35 |
36 | public function Cache():void
37 | {
38 | _active.Cache();
39 | }
40 |
41 | public function CacheMutations(mutationAmount:Number = 0.05, count:int=15):void
42 | {
43 | _active.CacheMutations(mutationAmount,count);
44 | }
45 |
46 | private var _synth:SfxrSynth;
47 | private var _mixer:MixerPlayer;
48 | private var _active:IPlayerInterface;
49 |
50 | public function Bfxr()
51 | {
52 | _synth = new SfxrSynth();
53 | _mixer = new MixerPlayer();
54 | }
55 | }
56 | }
57 |
58 |
--------------------------------------------------------------------------------
/bin-release/srcview/source/com/increpare/bfxr/dataClasses/ItemData.as.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | ItemData.as
7 |
8 |
9 |
10 | package com.increpare.bfxr.dataClasses
11 | {
12 | import flash.events.EventDispatcher;
13 |
14 | [Event("changeStart", type="mx.events.FlexEvent")]
16 | [Event("changeEnd", type="mx.events.FlexEvent")]
17 |
18 | [Bindable]public class ItemData extends EventDispatcher
19 | {
20 | public var label:String;
21 | public var data:String;
22 | public var id:int;
23 | public var modified:Boolean=false;
24 |
25 | public function ItemData(_label:String, _data:String,_id:int)
26 | {
27 | label=_label;
28 | data=_data;
29 | id=_id;
30 | }
31 |
32 | public function Clone():ItemData
33 | {
34 | var result:ItemData = new ItemData(label,data,id);
35 | result.modified=modified;
36 | return result;
37 | }
38 |
39 | public function Serialize():String
40 | {
41 | return label+":"+data+":"+id;
42 | }
43 | }
44 | }
45 |
46 |
--------------------------------------------------------------------------------
/bin-release/srcview/source/com/increpare/bfxr/dataClasses/LayerData.as.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | LayerData.as
7 |
8 |
9 |
10 | package com.increpare.bfxr.dataClasses
11 | {
12 | public class LayerData extends ItemData
13 | {
14 | public function LayerData(_label:String, _data:String, _id:int)
15 | {
16 | super(_label, _data, _id);
17 | }
18 |
19 | public static function Deserialize(source:String):LayerData
20 | {
21 | var a:Array = source.split(":");
22 |
23 | return new LayerData(a[0],a[1],int(a[2]));
24 | }
25 | }
26 | }
27 |
28 |
--------------------------------------------------------------------------------
/bin-release/srcview/source/com/increpare/bfxr/dataClasses/SfxLibrary.as.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | SfxLibrary.as
7 |
8 |
9 |
10 | package com.increpare.bfxr.dataClasses
11 | {
12 | import com.increpare.bfxr.synthesis.*;
13 | import com.increpare.bfxr.synthesis.Synthesizer.SfxrSynth;
14 |
15 | public class SfxLibrary
16 | {
17 | public var globals:String; public var synths:Array; public var mixes:Array;
21 | public function SfxLibrary()
22 | {
23 | globals = "";
24 | synths = new Array();
25 | mixes = new Array();
26 | }
27 |
28 | public static function LoadFrom(data:String):SfxLibrary
29 | {
30 | var result:SfxLibrary = new SfxLibrary();
31 |
32 | var lines:Array = data.split("\n");
37 | var version:int=int(lines[i]);
38 | if (lines[1]!="")
39 | throw new Error("file not of correct format");
40 |
41 |
43 | result.globals = lines[2];
44 |
45 | var i:int=4;
46 | while (i<lines.length && lines[i]!="")
47 | {
48 | result.synths.push(SoundData.Deserialize(lines[i]));
49 | i++;
50 | }
51 | i++;
52 | while (i<lines.length && lines[i]!="")
53 | {
54 | result.mixes.push(LayerData.Deserialize(lines[i]));
55 | i++;
56 | }
57 |
58 | return result;
59 | }
60 |
61 |
62 | /** Assumes members have already been populated */
63 | public function Save():String
64 | {
65 |
67 | var result:String = SfxrSynth.version.toString();
68 |
69 | result+="\n\n";
70 |
71 | result+=globals;
72 |
73 | result+="\n\n";
74 |
75 | for (var i:int=0;i<synths.length;i++)
77 | {
78 | result+=(synths[i] as SoundData).Serialize()+"\n";
79 | }
80 |
81 | result+="\n";
82 | for (i=0;i<mixes.length;i++)
84 | {
85 | result+=(mixes[i] as LayerData).Serialize()+"\n";
86 | }
87 |
88 | return result;
89 | }
90 | }
91 | }
92 |
93 |
--------------------------------------------------------------------------------
/bin-release/srcview/source/com/increpare/bfxr/dataClasses/SoundData.as.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | SoundData.as
7 |
8 |
9 |
10 | package com.increpare.bfxr.dataClasses
11 | {
12 | public class SoundData extends ItemData
13 | {
14 | public function SoundData(_label:String, _data:String, _id:int)
15 | {
16 | super(_label, _data, _id);
17 | }
18 |
19 |
20 | public static function Deserialize(source:String):SoundData
21 | {
22 | var a:Array = source.split(":");
23 |
24 | return new SoundData(a[0],a[1],int(a[2]));
25 | }
26 | }
27 | }
28 |
29 |
--------------------------------------------------------------------------------
/bin-release/srcview/source/com/increpare/bfxr/dataClasses/SoundListRowData.as.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | SoundListRowData.as
7 |
8 |
9 |
10 | package com.increpare.bfxr.dataClasses
11 | {
12 | import flash.events.Event;
13 | import flash.events.EventDispatcher;
14 |
15 | [Bindable]
16 | Event("flash.events.Event")]
17 | [Event("flash.events.Event")]
18 | [Event("flash.events.Event")]
19 | [Event("flash.events.Event")]
20 | public class SoundListRowData extends EventDispatcher {
21 |
22 | public static const SLIDER_BEGIN_CHANGE:String="SliderBeginChange";
23 | public static const SLIDER_CHANGE:String="SliderChange";
24 | public static const LOCKEDNESS_CHANGE:String="LockednessChange";
25 | public static const DEFAULT_CLICK:String="DefaultClick";
26 |
27 | public var odd:Boolean; public var square:Boolean;
29 | public var bggroup:int;
30 | public var min:Number;
31 | public var max:Number;
32 | public var defaultvalue:Number;
33 | public var value:Number;
34 | public var locked:Boolean;
35 | public var tag:String;
36 | public var label:String;
37 | public var enabled:Boolean = true;
38 | public var tooltip:String;
39 | }
40 | }
41 |
42 |
--------------------------------------------------------------------------------
/bin-release/srcview/source/com/increpare/bfxr/synthesis/IPlayerInterface.as.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | IPlayerInterface.as
7 |
8 |
9 |
10 | package com.increpare.bfxr.synthesis
11 | {
12 | import flash.utils.ByteArray;
13 |
14 | public interface IPlayerInterface
15 | {
16 | function Load(data:String):void;
17 |
18 | function Play(volume:Number=1):void;
19 |
20 | function Cache():void;
21 |
22 | function CacheMutations(amount:Number= 0.05,count:int=16):void;
23 | }
24 | }
25 |
26 |
--------------------------------------------------------------------------------
/bin-release/srcview/source/com/increpare/bfxr/synthesis/ISerializable.as.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | ISerializable.as
7 |
8 |
9 |
10 | package com.increpare.bfxr.synthesis
11 | {
12 | public interface ISerializable
13 | {
14 | function Serialize():String;
15 | function Deserialize(settings:String):void;
16 | }
17 | }
18 |
19 |
--------------------------------------------------------------------------------
/bin-release/srcview/source/com/increpare/bfxr/synthesis/Mixer/MixerSynth.as.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | MixerSynth.as
7 |
8 |
9 |
10 | package com.increpare.bfxr.synthesis.Mixer
11 | {
12 | public class MixerSynth
13 | {
14 | public static const TRACK_COUNT:int = 5;
15 |
16 | public function MixerSynth()
17 | {
18 | }
19 | }
20 | }
21 |
22 |
--------------------------------------------------------------------------------
/bin-release/srcview/source/com/increpare/bfxr/synthesis/Mixer/MixerTrackData.as.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | MixerTrackData.as
7 |
8 |
9 |
10 | package com.increpare.bfxr.synthesis.Mixer
11 | {
12 | import com.increpare.bfxr.synthesis.ISerializable;
13 |
14 | public class MixerTrackData implements ISerializable
15 | {
16 | public var id:int = -1 ; public var onset:Number = 0 ;
18 | public var volume:Number = 1 ;
19 | public var synthdata:String = "" ; public var reverse:Boolean = false;
21 |
22 | public function MixerTrackData()
23 | {
24 | }
25 |
26 | public function Serialize():String
27 | {
28 | var result:String="";
29 | result += id.toString()+"|";
30 | result += synthdata+"|";
31 | result += onset+"|";
32 | result += volume + "|";
33 | result += reverse;
34 | return result;
35 | }
36 |
37 | public function Deserialize(settings:String):void
38 | {
39 | var ar:Array = settings.split("|");
40 | id = int(ar[0]);
41 | synthdata = ar[1];
42 | onset = Number(ar[2]);
43 | volume = Number(ar[3]);
44 | reverse = ar[4]=="false"?false:true;
45 | }
46 | }
47 | }
48 |
49 |
--------------------------------------------------------------------------------
/bin-release/srcview/source/com/increpare/bfxr/synthesis/Mixer/MixerTrackPlayer.as.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | MixerTrackPlayer.as
7 |
8 |
9 |
10 | package com.increpare.bfxr.synthesis.Mixer
11 | {
12 | import com.increpare.bfxr.synthesis.ISerializable;
13 | import com.increpare.bfxr.synthesis.Synthesizer.SfxrSynth;
14 | import com.increpare.bfxr.synthesis.WavePlayer;
15 |
16 | import com.increpare.bfxr.dataClasses.SoundData;
17 |
18 | public class MixerTrackPlayer implements ISerializable
19 | {
20 | public var data:MixerTrackData;
21 | public var synth:SfxrSynth;
22 | public var waveplayer:WavePlayer;
23 |
24 |
25 | public function MixerTrackPlayer()
26 | {
27 | data = new MixerTrackData();
28 | synth = new SfxrSynth();
29 | waveplayer = new WavePlayer();
30 | }
32 |
33 | public function UnSet():void
34 | {
35 | LoadSynth(null);
36 | }
37 |
38 | public function IsSet():Boolean
39 | {
40 | return data.synthdata!="";
41 | }
42 |
43 | public function LoadSynth(sd:SoundData):void
44 | {
45 | if (sd!=null)
46 | {
47 | data.id=sd.id;
48 | data.synthdata=sd.data;
49 | synth.Load(data.synthdata);
50 | }
51 | else
52 | {
53 | data.id=-1;
54 | data.synthdata="";
55 | }
56 | }
57 |
58 | public function Serialize():String
59 | {
60 | return data.Serialize();
61 | }
62 |
63 | public function Deserialize(settings:String):void
64 | {
65 | data.Deserialize(settings);
66 | synth.Load(data.synthdata);
67 | }
68 | }
69 | }
70 |
71 |
--------------------------------------------------------------------------------
/bin-release/srcview/source/com/increpare/bfxr/synthesis/Synthesizer/PinkNumber.as.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | PinkNumber.as
7 |
8 |
9 |
10 |
13 | package com.increpare.bfxr.synthesis.Synthesizer
14 | {
15 | public class PinkNumber
16 | {
17 | private var max_key:int;
18 | private var key:int;
19 | private var white_values:Vector.<int> = new Vector.<int>();
20 | private var range:uint;
21 |
22 | public function PinkNumber()
23 | {
24 | max_key = 0x1f; this.range = 128;
26 | key = 0;
27 | for (var i:int = 0; i < 5; i++)
28 | white_values.push(Math.random() * (range/5))
29 | }
30 |
31 |
32 | public function GetNextValue():Number
34 | {
35 | var last_key:int = key;
36 | var sum:uint;
37 |
38 | key++;
39 | if (key > max_key)
40 | key = 0;
41 | var diff:int = last_key ^ key;
44 | sum = 0;
45 | for (var i:int = 0; i < 5; i++)
46 | {
47 | if (diff & (1 << i))
50 | white_values[i] = Math.random() * (range/5);
51 | sum += white_values[i];
52 | }
53 | return sum/64.0-1.0;
54 | }
55 | };
56 | }
57 |
58 |
--------------------------------------------------------------------------------
/bin-release/srcview/source/com/increpare/bfxr/synthesis/WavePlayer.as.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | WavePlayer.as
7 |
8 |
9 |
10 | package com.increpare.bfxr.synthesis
11 | {
12 | import com.increpare.bfxr.synthesis.Synthesizer.SfxrSynth;
13 |
14 | import flash.events.Event;
15 | import flash.events.EventDispatcher;
16 | import flash.events.SampleDataEvent;
17 | import flash.media.Sound;
18 | import flash.media.SoundChannel;
19 | import flash.media.SoundTransform;
20 | import flash.utils.ByteArray;
21 |
22 | public class WavePlayer extends EventDispatcher
23 | {
24 | public function WavePlayer()
25 | {
26 | }
27 |
28 | private var _sound:Sound;
29 | private var _channel:SoundChannel;
30 | private var _updateCallback:Function;
31 |
32 | private var _waveData:ByteArray; private var _waveDataPos:uint; private var _waveDataLength:uint; private var _waveDataBytes:uint;
37 | public function play(waveData:ByteArray,updateCallback:Function = null,volume:Number=1):void
38 | {
39 | stop();
40 |
41 | _waveData=waveData;
42 | _waveData.position=0;
43 | _waveDataLength = _waveData.length;
44 | _waveDataBytes = 24576;
45 | _waveDataPos = 0;
46 | _updateCallback=updateCallback;
47 |
48 | if (!_sound) (_sound = new Sound()).addEventListener(SampleDataEvent.SAMPLE_DATA, onSampleData);
49 |
50 | _channel = _sound.play(0,0,new SoundTransform(volume));
51 | }
52 |
53 | public function stop():void
54 | {
55 | if(_channel)
56 | {
57 | _channel.stop();
58 | _channel = null;
59 | }
60 | }
61 |
62 | private function onSampleData(e:SampleDataEvent):void
63 | {
64 | if (_updateCallback!=null)
65 | {
66 | _updateCallback(_waveDataPos/(4*44100));
67 | }
68 |
69 | if(_waveDataPos + _waveDataBytes > _waveDataLength)
70 | {
71 | _waveDataBytes = _waveDataLength - _waveDataPos;
72 | dispatchEvent(new Event(SfxrSynth.PLAY_COMPLETE));
73 | }
74 |
75 | if(_waveDataBytes > 0)
76 | {
77 | e.data.writeBytes(_waveData, _waveDataPos, _waveDataBytes);
78 | }
79 |
80 | _waveDataPos += _waveDataBytes;
81 | }
82 | }
83 | }
84 |
85 |
--------------------------------------------------------------------------------
/bin-release/srcview/source/html-template/history/history.css.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | history.css
7 |
8 |
9 |
10 |
11 |
12 | #ie_historyFrame { width: 0px; height: 0px; display:none }
13 | #firefox_anchorDiv { width: 0px; height: 0px; display:none }
14 | #safari_formDiv { width: 0px; height: 0px; display:none }
15 | #safari_rememberDiv { width: 0px; height: 0px; display:none }
16 |
17 |
18 |
--------------------------------------------------------------------------------
/bin-release/srcview/source/html-template/history/historyFrame.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
27 | Hidden frame for Browser History support.
28 |
29 |
30 |
--------------------------------------------------------------------------------
/bin-release/srcview/source/html-template/index.template.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
13 |
14 | ${title}
15 |
16 |
17 |
23 |
30 |
31 |
32 |
36 |
37 |
38 |
61 |
62 |
63 |
67 |
68 |
69 | To view this page ensure that Adobe Flash Player version
70 | ${version_major}.${version_minor}.${version_revision} or greater is installed.
71 |
72 |
77 |
78 |
79 |
107 |
108 |
109 |
--------------------------------------------------------------------------------
/bin-release/srcview/source/html-template/playerProductInstall.swf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/increpare/bfxr-api-example/b74254e80b9d7cc334fee8d06a053440a63a4328/bin-release/srcview/source/html-template/playerProductInstall.swf
--------------------------------------------------------------------------------
/bin-release/textLayout_1.1.0.604.swz:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/increpare/bfxr-api-example/b74254e80b9d7cc334fee8d06a053440a63a4328/bin-release/textLayout_1.1.0.604.swz
--------------------------------------------------------------------------------
/commit:
--------------------------------------------------------------------------------
1 | git checkout dev
2 | git commit -a
3 | git push -u origin dev
4 |
--------------------------------------------------------------------------------
/html-template/history/history.css:
--------------------------------------------------------------------------------
1 | /* This CSS stylesheet defines styles used by required elements in a flex application page that supports browser history */
2 |
3 | #ie_historyFrame { width: 0px; height: 0px; display:none }
4 | #firefox_anchorDiv { width: 0px; height: 0px; display:none }
5 | #safari_formDiv { width: 0px; height: 0px; display:none }
6 | #safari_rememberDiv { width: 0px; height: 0px; display:none }
7 |
--------------------------------------------------------------------------------
/html-template/history/historyFrame.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
27 | Hidden frame for Browser History support.
28 |
29 |
30 |
--------------------------------------------------------------------------------
/html-template/index.template.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
13 |
14 | ${title}
15 |
16 |
17 |
23 |
30 |
31 |
32 |
36 |
37 |
38 |
61 |
62 |
63 |
67 |
68 |
69 | To view this page ensure that Adobe Flash Player version
70 | ${version_major}.${version_minor}.${version_revision} or greater is installed.
71 |
72 |
77 |
78 |
79 |
107 |
108 |
109 |
--------------------------------------------------------------------------------
/html-template/playerProductInstall.swf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/increpare/bfxr-api-example/b74254e80b9d7cc334fee8d06a053440a63a4328/html-template/playerProductInstall.swf
--------------------------------------------------------------------------------
/release:
--------------------------------------------------------------------------------
1 | ./commit
2 | git checkout master
3 | git pull
4 | git push
5 | git merge dev
6 | git checkout dev
7 | git push -u origin dev
8 | git checkout master
9 | git push -u origin master
10 | git checkout dev
11 |
--------------------------------------------------------------------------------
/src/Bfxr_API_Example.as:
--------------------------------------------------------------------------------
1 | /*
2 | Bfrx API example.
3 |
4 | An example showing four types of sound generation.
5 |
6 | 1: synthesized on the fly
7 | 2: precached
8 | 3: mutated on the fly
9 | 4: precached mutations
10 |
11 | For realtime applications, I *strongly* recommend precaching :)
12 |
13 | And yes, you'll need a different Bfxr instance for each sound.
14 |
15 | One other note:
16 | - Synthesis is substantially slower in debug mode than final release
17 | builds, so don't get too down if it makes things a bit laggy while
18 | testing.
19 | - The caching API in this version is synchronous. This means that
20 | the program can't do anything while caching sounds.
21 | - Mixes take longer to generate than plain 'ol synths, so they can
22 | take substantially longer to generation mutations for.
23 |
24 | http://www.bfxr.net
25 |
26 | Stephen Lavelle
27 | analytic@gmail.com
28 |
29 | This is all distributed under the Apache License 2.0
30 | http://www.apache.org/licenses/LICENSE-2.0
31 |
32 | */
33 | package
34 | {
35 | import com.increpare.bfxr.Bfxr;
36 |
37 | import flash.display.MovieClip;
38 | import flash.display.Sprite;
39 | import flash.events.MouseEvent;
40 | import flash.text.TextField;
41 | import flash.ui.Mouse;
42 |
43 | import ui.TinyButton;
44 |
45 | [SWF(width="220", height="120", backgroundColor="#C0B090")]
46 |
47 | public class Bfxr_API_Example extends Sprite
48 | {
49 | // This is a sound data string, directly copied from Bfxr.
50 | private const soundData:String = ",0.5,,0.3484,,0.2472,0.3,0.4135,,0.2198,,,,,,,,,,,0.015,,,,,0.4293,,,0.0539,,,,masterVolume";
51 |
52 | private var sound1:Bfxr;
53 | private var sound2:Bfxr;
54 | private var sound3:Bfxr;
55 |
56 | public function Bfxr_API_Example()
57 | {
58 | //Cache sounds
59 | InitSounds();
60 |
61 | //Make GUI
62 | var b:TinyButton;
63 |
64 | b = new TinyButton(Button1Click,"Runtime Synthesize");
65 | b.x = 10; b.y = 10;
66 | this.addChild(b);
67 |
68 | b = new TinyButton(Button2Click,"Play Precached");
69 | b.x = 10; b.y = 40;
70 | this.addChild(b);
71 |
72 | b = new TinyButton(Button3Click,"Cached Mutation");
73 | b.x = 10; b.y = 70;
74 | this.addChild(b);
75 | }
76 |
77 | private function InitSounds():void
78 | {
79 | //sound 1 : load , but do not cache
80 | sound1 = new Bfxr();
81 | sound1.Load(soundData);
82 |
83 |
84 | //sound 2: load + cache
85 | sound2 = new Bfxr();
86 | sound2.Load(soundData);
87 | sound2.Cache();
88 |
89 | //sound 3: load + precache mutations
90 | sound3 = new Bfxr();
91 | sound3.Load(soundData);
92 | sound3.CacheMutations(0.05,10); //cache 5 mutations
93 | }
94 |
95 | private function Button1Click(caller:TinyButton):void
96 | {
97 | sound1.Play();
98 | }
99 |
100 | private function Button2Click(caller:TinyButton):void
101 | {
102 | sound2.Play();
103 | }
104 |
105 | private function Button3Click(caller:TinyButton):void
106 | {
107 | //If mutations have been cached, this will play a random one.
108 | sound3.Play();
109 | }
110 |
111 | }
112 | }
--------------------------------------------------------------------------------
/src/assets/amiga4ever.ttf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/increpare/bfxr-api-example/b74254e80b9d7cc334fee8d06a053440a63a4328/src/assets/amiga4ever.ttf
--------------------------------------------------------------------------------
/src/com/increpare/bfxr/Bfxr.as:
--------------------------------------------------------------------------------
1 | package com.increpare.bfxr
2 | {
3 | import com.increpare.bfxr.synthesis.IPlayerInterface;
4 | import com.increpare.bfxr.synthesis.Mixer.MixerPlayer;
5 | import com.increpare.bfxr.synthesis.Synthesizer.SfxrSynth;
6 |
7 | public class Bfxr
8 | {
9 | public function Load(data:String):void
10 | {
11 | if (data.indexOf("|")==-1)
12 | {
13 | _active = _synth;
14 | }
15 | else
16 | {
17 | _active = _mixer;
18 | }
19 | _active.Load(data);
20 | }
21 |
22 | public function Play(volume:Number=1):void
23 | {
24 | _active.Play(volume);
25 | }
26 |
27 | public function Cache():void
28 | {
29 | _active.Cache();
30 | }
31 |
32 | public function CacheMutations(mutationAmount:Number = 0.05, count:int=15):void
33 | {
34 | _active.CacheMutations(mutationAmount,count);
35 | }
36 |
37 | private var _synth:SfxrSynth;
38 | private var _mixer:MixerPlayer;
39 | private var _active:IPlayerInterface;
40 |
41 | public function Bfxr()
42 | {
43 | _synth = new SfxrSynth();
44 | _mixer = new MixerPlayer();
45 | }
46 | }
47 | }
--------------------------------------------------------------------------------
/src/com/increpare/bfxr/dataClasses/ItemData.as:
--------------------------------------------------------------------------------
1 | package com.increpare.bfxr.dataClasses
2 | {
3 | import flash.events.EventDispatcher;
4 |
5 | // triggers whether or not to display a * next to the name
6 | [Event(name="changeStart", type="mx.events.FlexEvent")]
7 | [Event(name="changeEnd", type="mx.events.FlexEvent")]
8 |
9 | [Bindable]
10 | public class ItemData extends EventDispatcher
11 | {
12 | public var label:String;
13 | public var data:String;
14 | public var id:int;
15 | public var modified:Boolean=false;
16 |
17 | public function ItemData(_label:String, _data:String,_id:int)
18 | {
19 | label=_label;
20 | data=_data;
21 | id=_id;
22 | }
23 |
24 | public function Clone():ItemData
25 | {
26 | var result:ItemData = new ItemData(label,data,id);
27 | result.modified=modified;
28 | return result;
29 | }
30 |
31 | public function Serialize():String
32 | {
33 | return label+":"+data+":"+id;
34 | }
35 | }
36 | }
--------------------------------------------------------------------------------
/src/com/increpare/bfxr/dataClasses/LayerData.as:
--------------------------------------------------------------------------------
1 | package com.increpare.bfxr.dataClasses
2 | {
3 | public class LayerData extends ItemData
4 | {
5 | public function LayerData(_label:String, _data:String, _id:int)
6 | {
7 | super(_label, _data, _id);
8 | }
9 |
10 | public static function Deserialize(source:String):LayerData
11 | {
12 | var a:Array = source.split(":");
13 |
14 | return new LayerData(a[0],a[1],int(a[2]));
15 | }
16 | }
17 | }
--------------------------------------------------------------------------------
/src/com/increpare/bfxr/dataClasses/SfxLibrary.as:
--------------------------------------------------------------------------------
1 | package com.increpare.bfxr.dataClasses
2 | {
3 | import com.increpare.bfxr.synthesis.*;
4 | import com.increpare.bfxr.synthesis.Synthesizer.SfxrSynth;
5 |
6 | public class SfxLibrary
7 | {
8 | public var globals:String;//array of global variables
9 | public var synths:Array;//ids are indices
10 | public var mixes:Array;//ids are indices
11 |
12 | public function SfxLibrary()
13 | {
14 | globals = "";
15 | synths = new Array();
16 | mixes = new Array();
17 | }
18 |
19 | public static function LoadFrom(data:String):SfxLibrary
20 | {
21 | var result:SfxLibrary = new SfxLibrary();
22 |
23 | //first compile strings -
24 | // they'll be of form
25 | // VERSION\n\nGLOBAL1,Global2,\n\nSOUNDNAME1=SOUNDDAT1\nSOUNDNAME2=SOUNDDAT2\n\nCOMPOUNDNAME1=COMPOUNDDAT1\n&c.
26 | //
27 | var lines:Array = data.split("\n");
28 | var version:int=int(lines[i]);
29 | if (lines[1]!="")
30 | throw new Error("file not of correct format");
31 |
32 | //read global variables
33 |
34 | result.globals = lines[2];
35 |
36 | var i:int=4;
37 | while (i;
22 |
23 |
24 | /*
25 | IPlayerInterface implementation
26 | */
27 |
28 |
29 | public function Load(data:String):void
30 | {
31 | this.Deserialize(data);
32 | }
33 |
34 | public function Play(volume:Number=1):void
35 | {
36 | if (this._mutations.length==0)
37 | {
38 | this.play(null,volume);
39 | }
40 | else
41 | {
42 | this.playRandomMutation(volume);
43 | }
44 | }
45 |
46 | public function Cache():void
47 | {
48 | PrepareMixForPlay();
49 | }
50 |
51 | private var _mutations:Vector. = new Vector.();
52 | public function CacheMutations(amount:Number = 0.05,count:int=16):void
53 | {
54 | _mutations = new Vector.();
55 |
56 | var original:String = this.Serialize();
57 |
58 | for (var i:int=0;i();
80 | for (var i:int=0;i=0;pos-=4)
104 | {
105 | ba.position=pos;
106 | result.writeFloat(ba.readFloat());
107 | }
108 | return result;
109 | }
110 |
111 | public function Serialize():String
112 | {
113 | var result:String="";
114 | result += id.toString() + ">";
115 | result += volume.toString() + ">";
116 | for (var i:int=0;i0)
119 | result+=">";
120 |
121 | result += tracks[i].Serialize();
122 | }
123 | return result;
124 | }
125 |
126 | public function Deserialize(settings:String):void
127 | {
128 | var ar:Array = settings.split(">");
129 | id = int(ar[0]);
130 | volume = Number(ar[1]);
131 | for (var i:int=2;i;
148 | private var _preparedvolumes:Vector.; //stores corresponding volumes
149 | private static var _zeros:ByteArray;
150 |
151 | private function PrepareMixForPlay(mutation:Boolean=false):void
152 | {
153 | var description:String = this.Serialize();
154 | if (_lastplayeddata!=description || mutation)
155 | {
156 | _lastplayeddata = description;
157 |
158 | //copy tracks over and add whitespace
159 | _preparedsounds = new Vector.();
160 | _preparedvolumes = new Vector.();
161 | for (var i:int=0;i0)
174 | {
175 | var bytestocopy:int=Math.min(silentbytes,_zeros.length);
176 |
177 | b.writeBytes(_zeros,0,bytestocopy);
178 |
179 | silentbytes-=bytestocopy;
180 | }
181 |
182 | var cached:ByteArray = mutation==false
183 | ? tracks[i].synth.cachedWave
184 | : tracks[i].synth.getCachedMutationWave(0);
185 | if (tracks[i].data.reverse)
186 | {
187 | cached=Reverse(cached);
188 | }
189 |
190 | b.writeBytes(cached);
191 |
192 | b.position=0;
193 | _preparedsounds.push(b);
194 | _preparedvolumes.push(tracks[i].data.volume);
195 | }
196 |
197 | Mix();
198 | }
199 | }
200 |
201 | public function playRandomMutation(vol:Number=1):void
202 | {
203 | _waveData = _mutations[int(Math.random()*_mutations.length)];
204 |
205 | if (_preparedsounds.length==0)
206 | {
207 | return;
208 | }
209 |
210 | if (_channel)
211 | {
212 | _channel.stop();
213 | }
214 |
215 | _waveData.position = 0;
216 | _waveDataLength = _waveData.length;
217 | _waveDataBytes = 24576;
218 | _waveDataPos = 0;
219 | _caching=true;
220 | if (!_sound) (_sound = new Sound()).addEventListener(SampleDataEvent.SAMPLE_DATA, onSoundData);
221 |
222 | _channel = _sound.play(0,0,new SoundTransform(vol,0));
223 | }
224 |
225 | public function play(updateCallback:Function=null, vol:Number=1):void
226 | {
227 | _updateCallback=updateCallback;
228 |
229 | PrepareMixForPlay();
230 |
231 | if (_preparedsounds.length==0)
232 | {
233 | return;
234 | }
235 |
236 | if (_channel)
237 | {
238 | _channel.stop();
239 | }
240 |
241 | _waveData.position = 0;
242 | _waveDataLength = _waveData.length;
243 | _waveDataBytes = 24576;
244 | _waveDataPos = 0;
245 | _caching=true;
246 | if (!_sound) (_sound = new Sound()).addEventListener(SampleDataEvent.SAMPLE_DATA, onSoundData);
247 |
248 | _channel = _sound.play(0,0,new SoundTransform(vol,0));
249 | }
250 |
251 | public function stop():void
252 | {
253 | if (_channel)
254 | {
255 | _channel.stop();
256 | _channel = null;
257 | }
258 | }
259 |
260 | /**
261 | * Returns a ByteArray of the wave in the form of a .wav file, ready to be saved out
262 | * @param sampleRate Sample rate to generate the .wav at
263 | * @param bitDepth Bit depth to generate the .wav at
264 | * @return Wave in a .wav file
265 | */
266 | public function getWavFile():ByteArray
267 | {
268 | stop();
269 |
270 | PrepareMixForPlay();
271 |
272 | var ww:WaveWriter = new WaveWriter(true,32);
273 |
274 | ww.addSamples(_waveData);
275 | ww.finalize();
276 |
277 | return ww.outBuffer;
278 | }
279 |
280 | /** param is whether to work in bytes, shorts, or floats (1,2,4)*/
281 | private function Mix(unitsize:int=4):void
282 | {
283 | var trackcount:int=_preparedsounds.length;
284 | _waveData = new ByteArray();
285 |
286 | var added:Boolean=true;
287 |
288 | var i:int;
289 |
290 | switch(unitsize)
291 | {
292 | case 1:
293 | while (added)
294 | {
295 | added=false;
296 | var val:int=0;
297 | for (i=0;i= (1<<7))
309 | val=1<<7;
310 | if (val<= -(1<<7))
311 | val=-(1<<7);
312 |
313 | _waveData.writeByte(val);
314 | }
315 | break;
316 | case 2:
317 | while (added)
318 | {
319 | added=false;
320 | val=0;
321 | for (i=0;i= (1<<15))
333 | val=1<<15;
334 | if (val<= -(1<<15))
335 | val=-(1<<15);
336 |
337 | _waveData.writeShort(val);
338 | }
339 | break;
340 | case 4:
341 | while (added)
342 | {
343 | added=false;
344 | var valf:Number=0;
345 | for (i=0;i _waveDataLength)
374 | {
375 | _waveDataBytes = _waveDataLength - _waveDataPos;
376 | dispatchEvent(new Event(SfxrSynth.PLAY_COMPLETE));
377 | }
378 |
379 | if(_waveDataBytes > 0) e.data.writeBytes(_waveData, _waveDataPos, _waveDataBytes);
380 |
381 | //if too short..append data
382 | if (e.data.position<24576)
383 | {
384 | _caching=false;
385 | while (e.data.position<24576)
386 | {
387 | e.data.writeFloat(0.0);
388 | }
389 | }
390 |
391 | _waveDataPos += _waveDataBytes;
392 | }
393 | }
394 |
395 |
396 | }
397 | }
--------------------------------------------------------------------------------
/src/com/increpare/bfxr/synthesis/Mixer/MixerSynth.as:
--------------------------------------------------------------------------------
1 | package com.increpare.bfxr.synthesis.Mixer
2 | {
3 | public class MixerSynth
4 | {
5 | public static const TRACK_COUNT:int = 5;
6 |
7 | public function MixerSynth()
8 | {
9 | }
10 | }
11 | }
--------------------------------------------------------------------------------
/src/com/increpare/bfxr/synthesis/Mixer/MixerTrackData.as:
--------------------------------------------------------------------------------
1 | package com.increpare.bfxr.synthesis.Mixer
2 | {
3 | import com.increpare.bfxr.synthesis.ISerializable;
4 |
5 | public class MixerTrackData implements ISerializable
6 | {
7 | public var id:int = -1 ; // id of target track
8 | public var onset:Number = 0 ;
9 | public var volume:Number = 1 ;
10 | public var synthdata:String = "" ; // if this is "", then track not set
11 | public var reverse:Boolean = false;
12 |
13 | public function MixerTrackData()
14 | {
15 | }
16 |
17 | public function Serialize():String
18 | {
19 | var result:String="";
20 | result += id.toString()+"|";
21 | result += synthdata+"|";
22 | result += onset+"|";
23 | result += volume + "|";
24 | result += reverse;
25 | return result;
26 | }
27 |
28 | public function Deserialize(settings:String):void
29 | {
30 | var ar:Array = settings.split("|");
31 | id = int(ar[0]);
32 | synthdata = ar[1];
33 | onset = Number(ar[2]);
34 | volume = Number(ar[3]);
35 | reverse = ar[4]=="false"?false:true;
36 | }
37 | }
38 | }
--------------------------------------------------------------------------------
/src/com/increpare/bfxr/synthesis/Mixer/MixerTrackPlayer.as:
--------------------------------------------------------------------------------
1 | package com.increpare.bfxr.synthesis.Mixer
2 | {
3 | import com.increpare.bfxr.synthesis.ISerializable;
4 | import com.increpare.bfxr.synthesis.Synthesizer.SfxrSynth;
5 | import com.increpare.bfxr.synthesis.WavePlayer;
6 |
7 | import com.increpare.bfxr.dataClasses.SoundData;
8 |
9 | public class MixerTrackPlayer implements ISerializable
10 | {
11 | public var data:MixerTrackData;
12 | public var synth:SfxrSynth;
13 | public var waveplayer:WavePlayer;
14 |
15 |
16 | public function MixerTrackPlayer()
17 | {
18 | data = new MixerTrackData();
19 | synth = new SfxrSynth();
20 | waveplayer = new WavePlayer();
21 | //synth.Load(data.synthdata);
22 | }
23 |
24 | public function UnSet():void
25 | {
26 | LoadSynth(null);
27 | }
28 |
29 | public function IsSet():Boolean
30 | {
31 | return data.synthdata!="";
32 | }
33 |
34 | public function LoadSynth(sd:SoundData):void
35 | {
36 | if (sd!=null)
37 | {
38 | data.id=sd.id;
39 | data.synthdata=sd.data;
40 | synth.Load(data.synthdata);
41 | }
42 | else
43 | {
44 | data.id=-1;
45 | data.synthdata="";
46 | }
47 | }
48 |
49 | public function Serialize():String
50 | {
51 | return data.Serialize();
52 | }
53 |
54 | public function Deserialize(settings:String):void
55 | {
56 | data.Deserialize(settings);
57 | synth.Load(data.synthdata);
58 | }
59 | }
60 | }
--------------------------------------------------------------------------------
/src/com/increpare/bfxr/synthesis/Synthesizer/PinkNumber.as:
--------------------------------------------------------------------------------
1 | /*
2 | class taken from http://www.firstpr.com.au/dsp/pink-noise/#Filtering
3 | */
4 | package com.increpare.bfxr.synthesis.Synthesizer
5 | {
6 | public class PinkNumber
7 | {
8 | private var max_key:int;
9 | private var key:int;
10 | private var white_values:Vector. = new Vector.();
11 | private var range:uint;
12 |
13 | public function PinkNumber()
14 | {
15 | max_key = 0x1f; // Five bits set
16 | this.range = 128;
17 | key = 0;
18 | for (var i:int = 0; i < 5; i++)
19 | white_values.push(Math.random() * (range/5))
20 | }
21 |
22 |
23 | //returns number between -1 and 1
24 | public function GetNextValue():Number
25 | {
26 | var last_key:int = key;
27 | var sum:uint;
28 |
29 | key++;
30 | if (key > max_key)
31 | key = 0;
32 | // Exclusive-Or previous value with current value. This gives
33 | // a list of bits that have changed.
34 | var diff:int = last_key ^ key;
35 | sum = 0;
36 | for (var i:int = 0; i < 5; i++)
37 | {
38 | // If bit changed get new random number for corresponding
39 | // white_value
40 | if (diff & (1 << i))
41 | white_values[i] = Math.random() * (range/5);
42 | sum += white_values[i];
43 | }
44 | return sum/64.0-1.0;
45 | }
46 | };
47 | }
--------------------------------------------------------------------------------
/src/com/increpare/bfxr/synthesis/WavePlayer.as:
--------------------------------------------------------------------------------
1 | package com.increpare.bfxr.synthesis
2 | {
3 | import com.increpare.bfxr.synthesis.Synthesizer.SfxrSynth;
4 |
5 | import flash.events.Event;
6 | import flash.events.EventDispatcher;
7 | import flash.events.SampleDataEvent;
8 | import flash.media.Sound;
9 | import flash.media.SoundChannel;
10 | import flash.media.SoundTransform;
11 | import flash.utils.ByteArray;
12 |
13 | public class WavePlayer extends EventDispatcher
14 | {
15 | public function WavePlayer()
16 | {
17 | }
18 |
19 | private var _sound:Sound;
20 | private var _channel:SoundChannel;
21 | private var _updateCallback:Function;
22 |
23 | private var _waveData:ByteArray; // Full wave, read out in chuncks by the onSampleData method
24 | private var _waveDataPos:uint; // Current position in the waveData
25 | private var _waveDataLength:uint; // Number of bytes in the waveData
26 | private var _waveDataBytes:uint; // Number of bytes to write to the soundcard
27 |
28 | public function play(waveData:ByteArray,updateCallback:Function = null,volume:Number=1):void
29 | {
30 | stop();
31 |
32 | _waveData=waveData;
33 | _waveData.position=0;
34 | _waveDataLength = _waveData.length;
35 | _waveDataBytes = 24576;
36 | _waveDataPos = 0;
37 | _updateCallback=updateCallback;
38 |
39 | if (!_sound) (_sound = new Sound()).addEventListener(SampleDataEvent.SAMPLE_DATA, onSampleData);
40 |
41 | _channel = _sound.play(0,0,new SoundTransform(volume));
42 | }
43 |
44 | public function stop():void
45 | {
46 | if(_channel)
47 | {
48 | _channel.stop();
49 | _channel = null;
50 | }
51 | }
52 |
53 | private function onSampleData(e:SampleDataEvent):void
54 | {
55 | if (_updateCallback!=null)
56 | {
57 | _updateCallback(_waveDataPos/(4*44100));
58 | }
59 |
60 | if(_waveDataPos + _waveDataBytes > _waveDataLength)
61 | {
62 | _waveDataBytes = _waveDataLength - _waveDataPos;
63 | dispatchEvent(new Event(SfxrSynth.PLAY_COMPLETE));
64 | }
65 |
66 | if(_waveDataBytes > 0)
67 | {
68 | e.data.writeBytes(_waveData, _waveDataPos, _waveDataBytes);
69 | }
70 |
71 | _waveDataPos += _waveDataBytes;
72 | }
73 | }
74 | }
--------------------------------------------------------------------------------
/src/com/increpare/bfxr/synthesis/WaveWriter.as:
--------------------------------------------------------------------------------
1 | package com.increpare.bfxr.synthesis
2 | {
3 | /*
4 | class by henke37,
5 | from http://webcache.googleusercontent.com/search?q=cache:bx2VN_2MqUwJ:www.actionscript.org/forums/showthread.php3%3Ft%3D248418+0x666D7420+floating+point&cd=1&hl=en&ct=clnk&gl=uk&source=www.google.co.uk
6 | */
7 |
8 | import flash.utils.*;
9 |
10 | public class WaveWriter {
11 |
12 |
13 | public var outBuffer:ByteArray;
14 |
15 | private var stereo:Boolean=true;
16 | private const sampleRate:uint=44100;
17 | private var bitsPerSample:uint=32;
18 | private var useFloat:Boolean=true;
19 |
20 | private var writePointer:uint;
21 |
22 | private var riffSizePointer:uint, dataSizePointer:uint, factSamplesPointer:uint;
23 |
24 | public function WaveWriter(stereo:Boolean,bits:uint=32,b:ByteArray=null) {
25 |
26 | this.stereo=stereo;
27 | bitsPerSample=bits;
28 | useFloat=bits>=32;
29 |
30 | if(b) {
31 | outBuffer=b;
32 | } else {
33 | outBuffer=new ByteArray();
34 | }
35 |
36 | writeWAVEHeader();
37 |
38 | }
39 |
40 | private function writeWAVEHeader():void {
41 | outBuffer.endian=Endian.BIG_ENDIAN;
42 |
43 | outBuffer.writeUnsignedInt(0x52494646);//riff marker
44 |
45 | riffSizePointer=outBuffer.position;
46 | outBuffer.writeUnsignedInt(0);//Size, to be filled in later
47 |
48 | outBuffer.writeUnsignedInt(0x57415645);//wave marker
49 |
50 | //write the fmt chunk now
51 |
52 | outBuffer.writeUnsignedInt(0x666D7420);//fmt marker
53 |
54 | outBuffer.endian=Endian.LITTLE_ENDIAN;
55 |
56 | var bytesPerSample:uint=bitsPerSample/8;
57 | var blockSize:uint=(stereo+1)*bytesPerSample;
58 |
59 | outBuffer.writeUnsignedInt((useFloat?(22+2):0)+16);//length of the chunk
60 | outBuffer.writeShort(useFloat?0xFFFE:1);//compression, uncompressed PCM or extended wave
61 | outBuffer.writeShort(stereo+1);//channel count
62 | outBuffer.writeUnsignedInt(sampleRate);//samplerate
63 | outBuffer.writeUnsignedInt(sampleRate*blockSize);//ByteRate
64 | outBuffer.writeShort(blockSize);//Block align
65 | outBuffer.writeShort(bitsPerSample);//bits per sample
66 |
67 | if(useFloat) {
68 |
69 | outBuffer.writeShort(22);//Extra data length
70 | outBuffer.writeShort(bitsPerSample);//valid bits per sample
71 | outBuffer.writeUnsignedInt(3);//channel order flag field thingy
72 |
73 | outBuffer.writeUnsignedInt(0x0003);//real type, float
74 |
75 | outBuffer.writeShort(0x0000);//rest of GUID
76 | outBuffer.writeShort(0x0010);
77 | outBuffer.writeByte(0x80);
78 | outBuffer.writeByte(0x00);
79 | outBuffer.writeByte(0x00);
80 | outBuffer.writeByte(0xaa);
81 | outBuffer.writeByte(0x00);
82 | outBuffer.writeByte(0x38);
83 | outBuffer.writeByte(0x9b);
84 | outBuffer.writeByte(0x71);
85 |
86 | //fact chunk
87 | outBuffer.endian=Endian.BIG_ENDIAN;
88 | outBuffer.writeUnsignedInt(0x66616374);//fact marker
89 | outBuffer.endian=Endian.LITTLE_ENDIAN;
90 | outBuffer.writeUnsignedInt(4);//chunk length, not counting the header
91 | factSamplesPointer=outBuffer.position
92 | outBuffer.writeUnsignedInt(1);//number of sample pairs, to be filled in later
93 | }
94 |
95 | //write the data chunk now
96 | outBuffer.endian=Endian.BIG_ENDIAN;
97 | outBuffer.writeUnsignedInt(0x64617461);//data marker
98 | outBuffer.endian=Endian.LITTLE_ENDIAN;
99 |
100 | dataSizePointer=outBuffer.position;
101 | outBuffer.writeUnsignedInt(0);//Size, to be filled in later
102 |
103 | writePointer=outBuffer.position;
104 |
105 | }
106 |
107 | public function finalize(): void {
108 | if( dataLength % 2 == 1) {//add one byte of padding to the data block, if needed
109 | outBuffer.position=writePointer;
110 | outBuffer.writeByte(0);
111 | writePointer=outBuffer.position;
112 | }
113 | updateSizeFields();
114 | }
115 |
116 | /** position difference from begining of data tag to end of data,
117 | not counting the size field itself
118 | */
119 | private function get dataLength():uint {
120 | return writePointer-(dataSizePointer+4);
121 | }
122 |
123 | public function updateSizeFields():void {
124 | //update length values that's not been updated during bulk writing
125 |
126 |
127 | var sampleByteLength:uint=dataLength;
128 |
129 | outBuffer.endian=Endian.LITTLE_ENDIAN;
130 |
131 | outBuffer.position=riffSizePointer;
132 | outBuffer.writeUnsignedInt(outBuffer.length-8);//RIFF header does not count in the RIFF header
133 |
134 | if(useFloat) {
135 | outBuffer.position=factSamplesPointer;
136 | outBuffer.writeUnsignedInt(sampleByteLength/(bitsPerSample/8));
137 | }
138 |
139 | outBuffer.position=dataSizePointer;
140 | outBuffer.writeUnsignedInt(sampleByteLength);
141 |
142 | }
143 |
144 | public function addSamples(sb:ByteArray):void {
145 | sb.position=0;
146 |
147 | outBuffer.position=writePointer;
148 | outBuffer.endian=Endian.LITTLE_ENDIAN;
149 |
150 | if(stereo && useFloat && bitsPerSample==32 && sb.endian==Endian.LITTLE_ENDIAN) {
151 | //endianness missmatch prevents a fast copy
152 | outBuffer.writeBytes(sb);
153 | } else if(stereo) {
154 | while(sb.position