> For the complete documentation index, see [llms.txt](https://docs.sattern.dev/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.sattern.dev/tutorial/audio-graph.md).

# Audio Graph

As mentioned in the [Introduction](/master.md) section, Sattern operates around the Audio Graph concept. Audio Graphs are a way to house multiple "audio units" or nodes and interconnect them to each other.

Let's begin by adding some code to our "*main.js*" file that creates a new `Sampler` object and adds it to Sattern's main audio `graph` object.

```javascript
// main.js
// Arpeggiator
//
// Created by Jacob Sologub on 23 Jul 2020.
// Copyright © 2020 Jacob Sologub. All rights reserved.

const sampler = new sattern.Sampler();
sattern.graph.add (sampler);
```

The code on line `#7` creates a new `sampler` object and the code on line `#8` adds the newly created `sampler` object to Sattern's main `graph` object. You can copy the above code snippet and replace the contents of your "*main.js*" file. Press `Command + R` or `Command + S` to save and re-load the current file.

{% hint style="info" %}
The default`sattern.Graph.add()`method connects the specified `node` (sampler) object's *default* output channel(s) to the `graph` object's *default* output channel(s). You can specify what channel(s) are connected explicitly if you want to for example only connect the `sampler` object's left output channel to the `graph` object's right output channel etc. Please refer to the [JavaScript API Documentation](https://jacobsologub.s3.amazonaws.com/sattern/doc/modules/_sattern_.sattern.html) for more details.
{% endhint %}

Samplers need some sort of audio file(s) to make sound, so let's add some sounds to our `sampler` object.

```javascript
// main.js
// Arpeggiator
//
// Created by Jacob Sologub on 23 Jul 2020.
// Copyright © 2020 Jacob Sologub. All rights reserved.

const sampler = new sattern.Sampler();
sattern.graph.add (sampler);

const sound = new sattern.Sound ("./mcg_mp_064.wav", { 
    lowKey: 0, highKey: 127, rootKey: 64 
});
sampler.add (sound);
```

The newly added lines `#10-12` create a sound object for the specified `.wav` file and sets the `lowKey`, `highKey` and `rootKey` properties that will be used to "map" the specified sound one it is added to the `sampler` object. Line `#13` adds the newly created `sound` object to our `sampler` object. Again, copy the above code snippet and replace the contents of your "main.js" file. Press `Command + R` or `Command + S` to save and re-load the current file.

{% hint style="info" %}
The sample being used in this example is taken from [Linux Sampler Project](<https://www.linuxsampler.org/instruments.html >)'s [Maestro Concert Grand v2](https://www.linuxsampler.org/instruments.html) library and can be downloaded below. Place this file inside the project's root folder.
{% endhint %}

{% file src="/files/-MCy1kCzGfTz2v-eSvrg" %}
mcg\_mp\_064.wav
{% endfile %}

{% hint style="info" %}
`Command + S` saves the current file being edited, and `Command + R` reloads the entire Sattern JavaScript context.
{% endhint %}

Now it's time to actually make some sound.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.sattern.dev/tutorial/audio-graph.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
