Skip to content

Commit

Permalink
Documentation update
Browse files Browse the repository at this point in the history
  • Loading branch information
VoidXH committed Jun 23, 2024
1 parent f257175 commit 3e5acc2
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 3 deletions.
10 changes: 7 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,8 @@ To open any supported audio file for reading, use the following static function:
```
AudioReader reader = AudioReader.Open(string path);
```
After opening a file, the following workflows are available.
There is an overload for `AudioReader.Open` to read audio files from an
arbitrary `Stream`. After opening a file, the following workflows are available.

##### Getting all samples
The `Read()` function of an `AudioReader` returns all samples from the file in
Expand Down Expand Up @@ -191,10 +192,9 @@ component browser, under audio, and they will automatically add all their Unity
dependencies.

## Development documents
* [Documentations of specific use-cases](./docs)
* [Scripting API](http://cavern.sbence.hu/cavern/doc.php?if=api/index) with descriptions of all public members for all public classes
* [Virtualizer repository](https://github.com/VoidXH/HRTF) which contains the raw IR measurements and detailed information about their use
* [Limitless Audio Format](./docs/Limitless%20Audio%20Format.md) for storing Cavern mixes in a CPU-effective spatial format
* [Cavern DCP channel order](./docs/Cavern%20DCP%20channel%20order.md) compared to DCP standards

## Disclaimers
### Code
Expand All @@ -215,3 +215,7 @@ downloaded from the [Cavern website](http://cavern.sbence.hu).
## Licence
By downloading, using, copying, modifying, or compiling the source code or a
build, you are accepting the licence [available here](LICENSE.md).

This licence heavily discourages commercial usage. If you're not supporting the
open source community with your work, you will need to contact the original
author for a Cavern Pro licence through the Cavern website's contact form.
50 changes: 50 additions & 0 deletions docs/Adding Cavern to a Media Player.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# Adding Cavern to a Media Player
Integrating Cavern into an application to replace the channel-based downmixes
with an actual spatial mix is easy. It requires wrapping the audio bitstream in
a .NET `Stream`, initializing the Cavern renderer, and attaching the audio
track.

## Stream Wrapping
Cavern supports two sources for encoded audio data: loading from a file or
reading from a `Stream`. For real-time applications, `Stream`s are preferred.
The easiest way to pass this from your own container is to write the bitstream
to a `MemoryStream`, which can then be opened by Cavern with the following:
```
AudioReader track = AudioReader.Open(stream);
```
Cavern will detect the codec automatically if it's supported. The stream should
always contain at least one frame in advance, as Cavern reads ahead for the next
header to check for modifying subframes or changed bitrate.

## Creating a Listener Environment
Initialize a listening environment with an update rate of the content, which is
1536 samples for an E-AC-3 track:
```
Listener listener = new() {
SampleRate = track.SampleRate,
UpdateRate = 1536
};
```
The listening environment shall be set up by the user in Cavern Driver, and this
is to be respected. If you plan on creating your own channel setup screen, refer
to the main README.

## Attach the Track to the Listener
Each track has a `Renderer` that matches in-track objects or channels to Cavern
`Source`s. These `Source`s are self-updating when attached to a `Listener` and
that `Listener` is updated. First, attach all `Source`s:
```
listener.AttachSources(track.GetRenderer().Objects);
```

## Output
With this setup, every call to `listener.Render();` will process the next frame
in the provided `Stream`. It returns interlaced samples for all the user's
channels in the order as it's set up in `Listener.Channels`. Each channel will
contain as many samples as the `UpdateRate` of the listener.

To support seeking, many formats support if the frame sought to is provided to
the `Stream` as all frames contain a valid header. This is also the case for
E-AC-3. When switching tracks of different types, the `Listener` doesn't have to
be recreated, just use `listener.DetachAllSources();` to remove the previous
track and attach the new.

0 comments on commit 3e5acc2

Please sign in to comment.