@@ -739,6 +739,43 @@ The way we'll manage our audio graph is by hooking into the different actions in
739
739
our store. So we might connect two audio nodes when the ` addEdge ` action is called,
740
740
or update an audio node's properties when ` updateNode ` is called, and so on.
741
741
742
+ :::warning Hardcoded nodes
743
+
744
+ We hardcoded a couple of nodes in our store earlier on in this post but our audio
745
+ graph doesn't know anything about them! For the finished project we can do away
746
+ with all these hardcoded bits, but for now it's ** really important** that we also
747
+ hardcode some audio nodes.
748
+
749
+ Here's how we did it:
750
+
751
+ ``` js
752
+ const context = new AudioContext ();
753
+ const nodes = new Map ();
754
+
755
+ // highlight-start
756
+ const osc = context .createOscillator ();
757
+ osc .frequency .value = 220 ;
758
+ osc .type = ' square' ;
759
+ osc .start ();
760
+ // highlight-end
761
+
762
+ // highlight-start
763
+ const amp = context .createGain ();
764
+ amp .gain .value = 0.5 ;
765
+ // highlight-end
766
+
767
+ // highlight-next-line
768
+ const out = context .destination ;
769
+
770
+ // highlight-start
771
+ nodes .set (' a' , osc);
772
+ nodes .set (' b' , amp);
773
+ nodes .set (' c' , out);
774
+ // highlight-end
775
+ ```
776
+
777
+ :::
778
+
742
779
### 1. Node changes
743
780
744
781
Right now, there are two types of node changes that can happen in our graph and
@@ -958,36 +995,6 @@ Let's see what we have in action.
958
995
showEditor={false}
959
996
/>
960
997
961
- :::info
962
-
963
- We hardcoded a couple of nodes in our store early on in this blog post but our
964
- audio graph doesn't know anything about them! In the next section we'll do away
965
- with all these hardcoded nodes and set up how to create them dynamically, but
966
- just for this demo you _also_ need to hardcode some nodes in your audio graph.
967
-
968
- Here's how we did it:
969
-
970
- ` ` ` js
971
- const context = new AudioContext ();
972
- const nodes = new Map ();
973
-
974
- const osc = context .createOscillator ();
975
- osc .frequency .value = 220 ;
976
- osc .type = ' square' ;
977
- osc .start ();
978
-
979
- const amp = context .createGain ();
980
- amp .gain .value = 0.5 ;
981
-
982
- const out = context .destination ;
983
-
984
- nodes .set (' a' , osc);
985
- nodes .set (' b' , amp);
986
- nodes .set (' c' , out);
987
- ` ` `
988
-
989
- :::
990
-
991
998
### 4. Creating new nodes
992
999
993
1000
Up until now we have been dealing with a hard-coded set of nodes in our graph.
0 commit comments