diff --git a/packages/audiodocs/docs/fundamentals/lets-make-some-noise.mdx b/packages/audiodocs/docs/fundamentals/lets-make-some-noise.mdx index 0ff007d6..8ef6f3ab 100644 --- a/packages/audiodocs/docs/fundamentals/lets-make-some-noise.mdx +++ b/packages/audiodocs/docs/fundamentals/lets-make-some-noise.mdx @@ -108,3 +108,17 @@ import LetsMakeSomeNoiseSrc from '!!raw-loader!@site/src/examples/LetsMakeSomeNo In web environment you can use `decodeAudioDataSource` directly on the asset url, without the need to download it first. ::: + +## Summary + +In this guide, we have learned how to create a simple audio player using `AudioContext` and `AudioBufferSourceNode` as well as how we can load audio data from a remote source. To sum up: + +- `AudioContext` is the main object that controls the audio graph. +- `decodeAudioDataSource` method can be used to load audio data from a local audio source in form of `AudioBuffer`. +- `AudioBufferSourceNode` can be used to any `AudioBuffer`. +- In order to hear the sounds, we need to connect the source node to the destination node exposed by `AudioContext`. +- We can control the playback of the sound using `start` and `stop` methods of the `AudioBufferSourceNode` (And other source nodes which we show later). + +## What's next? + +In [the next section](/fundamentals/making-a-piano-keyboard) we will learn more about how the audio graph works, what are audio params and how we can use them to create a simple piano keyboard. diff --git a/packages/audiodocs/docs/fundamentals/making-a-piano-keyboard.mdx b/packages/audiodocs/docs/fundamentals/making-a-piano-keyboard.mdx new file mode 100644 index 00000000..0db740a6 --- /dev/null +++ b/packages/audiodocs/docs/fundamentals/making-a-piano-keyboard.mdx @@ -0,0 +1,362 @@ +--- +sidebar_position: 3 +--- + +# Making a piano keyboard + +In this section, we will use some of the core audio api interfaces to create a simple piano keyboard. We will learn what is an `AudioParam`, how to use it to change the pitch of the sound. + +## Base application + +Like in previous example, we will start with simple app with couple of buttons so we just don't need to worry about the UI later. +You can just copy and paste the code below to your project. + +```tsx +import React from 'react'; +import { View, Text, Pressable } from 'react-native'; + +type KeyName = 'A' | 'B' | 'C' | 'D' | 'E'; + +interface ButtonProps { + keyName: KeyName; + onPressIn: (key: KeyName) => void; + onPressOut: (key: KeyName) => void; +} + +const Button = ({ onPressIn, onPressOut, keyName }: ButtonProps) => ( + onPressIn(keyName)} + onPressOut={() => onPressOut(keyName)} + style={({ pressed }) => ({ + margin: 4, + padding: 12, + borderRadius: 2, + backgroundColor: pressed ? '#d2e6ff' : '#abcdef', + })} + > + {`${keyName}`} + +); + +export default function SimplePiano() { + const onKeyPressIn = (which: KeyName) => {}; + const onKeyPressOut = (which: KeyName) => {}; + + return ( + + {Keys.map((key) => ( +