Skip to content

Commit

Permalink
Adds bolson to ocarina (#69)
Browse files Browse the repository at this point in the history
* Updates to newest deku

* Updates

* Adds bolson

* Adds workflow

* pnpm

* Adds to spago

* Fixes spago.yaml
  • Loading branch information
mikesol authored Apr 24, 2024
1 parent 722afe5 commit 4fe1618
Show file tree
Hide file tree
Showing 81 changed files with 5,066 additions and 10,261 deletions.
39 changes: 39 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: Unit test only
on:
push:
branches-ignore:
- main
jobs:
container-job:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [14.x]
steps:
- name: Check out repository code
uses: actions/checkout@v2
- name: Cache dependencies
uses: actions/cache@v2
with:
path: |
~/.npm
.spago
${{ env.spago_global_cache }}
output
key: >-
${{ hashFiles('pnpm-lock.yaml') }}-
${{ hashFiles('spago.yaml') }}
- uses: pnpm/action-setup@v2.2.4
name: Install pnpm
id: pnpm-install
with:
version: 7.13.2
run_install: false
- name: Get pnpm store directory
id: pnpm-cache
run: |
echo "STORE_PATH=$(pnpm store path)" >> $GITHUB_OUTPUT
- name: Install
run: pnpm i
- name: Build
run: pnpm build
47 changes: 0 additions & 47 deletions .github/workflows/deploy.yml

This file was deleted.

30 changes: 0 additions & 30 deletions .github/workflows/unit-tests.yml

This file was deleted.

17 changes: 8 additions & 9 deletions examples/src/atari-speaks/AtariSpeaks.purs
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ import Effect (Effect)
import Effect.Aff (Aff, launchAff_)
import Effect.Class (liftEffect)
import FRP.Event (create, filterMap, subscribe)
import FRP.Event.AnimationFrame (animationFrame)
import FRP.Poll (Poll, sample, sample_, sham)
import Ocarina.Clock (WriteHead, fot, writeHead)
import FRP.Event.AnimationFrame (animationFrame')
import FRP.Poll (Poll, sample, sham)
import Ocarina.Clock (WriteHead, fot, withWriteHead)
import Ocarina.Control (analyser_, gain_, loopBuf, speaker2)
import Ocarina.Core (Audible, bangOn, opticN)
import Ocarina.Example.Utils (RaiseCancellation)
Expand Down Expand Up @@ -106,9 +106,8 @@ atariSpeaks atari rc = Deku.do
rf0 <- liftST $ RRef.new 0
rf1 <- liftST $ RRef.new Map.empty
ffi2 <- makeFFIAudioSnapshot ctx
afe <- animationFrame
afe <- animationFrame' (withWriteHead 0.04 ctx)
let exec audio = audio ffi2
let wh = writeHead 0.04 ctx
let
audioE = speaker2
[ scene atari
Expand All @@ -118,19 +117,19 @@ atariSpeaks atari rc = Deku.do
pure (analyserE.push Nothing)
)
)
(sample_ wh (sham afe.event))
(sham $ map _.ac (afe.event))
]
(effectfulAudioInterpret rf0 rf1 exec)

unsub0 <- liftST $ subscribe (sample audioE start.event) exec
unsub1 <- liftST $ subscribe analyserE.event \analyser -> do
unsub0 <- subscribe (sample audioE start.event) exec
unsub1 <- subscribe analyserE.event \analyser -> do
for_ analyser \a -> do
frequencyData <- getByteFrequencyData a
arr <- toArray frequencyData
push $ AsciiMixer $ intercalate "\n" $
map (\ii -> fold ((0 .. toInt ii) $> ">")) arr
start.push identity
let unsub = liftST unsub0 *> liftST unsub1 *> afe.unsubscribe
let unsub = unsub0 *> unsub1 *> afe.unsubscribe
rc $ Just { unsub, ctx }
push $ TurnOff { unsub, ctx }
Just { unsub, ctx } -> do
Expand Down
8 changes: 3 additions & 5 deletions examples/src/docs/AudioUnits/Allpass.purs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module Ocarina.Example.Docs.AudioUnits.Allpass where
import Prelude

import Deku.Core (Nut)
import Deku.Pursx (makePursx')
import Deku.Pursx (pursx')
import Effect (Effect)
import FRP.Poll (Poll)
import Ocarina.Control (allpass_, fan1, gain_, loopBuf)
Expand All @@ -12,10 +12,8 @@ import Ocarina.Example.Docs.Types (CancelCurrentAudio, Page, SingleSubgraphEvent
import Ocarina.Example.Docs.Util (audioWrapper)
import Ocarina.Interpret (decodeAudioDataFromUri)
import Ocarina.Run (run2)
import Type.Proxy (Proxy(..))

px =
Proxy :: Proxy """<section>
type Px = """<section>
<h2 id="allpass">Allpass filter</h2>
<p>An <a href="https://developer.mozilla.org/en-US/docs/Web/API/BiquadFilterNode">all-pass filter</a> <a href="https://en.wikipedia.org/wiki/All-pass_filter">passes through all frequencies of a source at equal volume but changes their phase</a>. Its use by itself is imperceptible, as the human ear (mostly) does not pick up on phase shifts by themselves. However, when an all-pass filter's output is mixed with several chained all-pass filters plus the original source, you hear a neat phaser effect.</p>

Expand All @@ -42,7 +40,7 @@ px =
allpass
:: CancelCurrentAudio -> (Page -> Effect Unit) -> Poll SingleSubgraphEvent -> Nut
allpass ccb _ ev = makePursx' (Proxy :: _ "@") px
allpass ccb _ ev = pursx' @"@" @Px
{ allpass:
( audioWrapper ev ccb (\ctx -> decodeAudioDataFromUri ctx "https://freesound.org/data/previews/320/320873_527080-hq.mp3")
\ctx buf -> run2 ctx
Expand Down
16 changes: 7 additions & 9 deletions examples/src/docs/AudioUnits/Analyser.purs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import Deku.DOM as D
import Deku.DOM.Attributes as DA
import Deku.Do as Deku
import Deku.Hooks (useState')
import Deku.Pursx ((~~))
import Deku.Pursx (pursx)
import Effect (Effect, foreachE)
import Effect.Ref (modify_, new, read, write)
import FRP.Event (create, subscribe)
Expand Down Expand Up @@ -82,7 +82,7 @@ mkSt i0 i1 e = DA.style $ map (\v -> if V.index (V.index v i0) i1 then V.index (

analyserEx
:: CancelCurrentAudio -> (Page -> Effect Unit) -> Poll SingleSubgraphEvent -> Nut
analyserEx ccb _ ev = px ~~
analyserEx ccb _ ev = pursx @Px
{ analyser: Deku.do
push /\ event' <- useState'
let
Expand Down Expand Up @@ -113,8 +113,8 @@ analyserEx ccb _ ev = px ~~
]
(effectfulAudioInterpret rf rf1 exec)
afe <- animationFrame
unsub0 <- liftST $ subscribe (sample audioE ep.event) exec
unsub1 <- liftST $ subscribe afe.event
unsub0 <- subscribe (sample audioE ep.event) exec
unsub1 <- subscribe afe.event

( \_ -> do
analyser <- read analyserE
Expand Down Expand Up @@ -156,8 +156,8 @@ analyserEx ccb _ ev = px ~~
)
ep.push identity
pure do
liftST unsub0
liftST unsub1
unsub0
unsub1
afe.unsubscribe
contextState ctx >>= \st -> when (st /= "closed") (close ctx)
push $ Left (V.fill (const (V.fill (const false))))
Expand Down Expand Up @@ -222,9 +222,7 @@ analyserEx ccb _ ev = px ~~
]
}

px =
Proxy
:: Proxy
type Px =
"""<section>
<h2 id="analyser">Analyser</h2>
<p>An <a href="https://developer.mozilla.org/en-US/docs/Web/API/AnalyserNode">analyser node</a> provides methods to recuperate the analysed data of an input. This is how, for example, Google Meet shows the little animation around a microphone icon. Ocarina provides the possibility to use the analyser as the terminus of an audio graph <i>or</i> as part of a longer DSP chain, as in the following example. The example uses an FFT size of 256, which is indicated in Ocarina as <code>TTT8</code> (two to the eighth power).</p>
Expand Down
8 changes: 3 additions & 5 deletions examples/src/docs/AudioUnits/Bandpass.purs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module Ocarina.Example.Docs.AudioUnits.Bandpass where
import Prelude

import Deku.Core (Nut)
import Deku.Pursx (makePursx')
import Deku.Pursx (pursx')
import Effect (Effect)
import FRP.Poll (Poll)
import Ocarina.Control (bandpass_, fan1, gain_, loopBuf)
Expand All @@ -12,10 +12,8 @@ import Ocarina.Example.Docs.Types (CancelCurrentAudio, Page, SingleSubgraphEvent
import Ocarina.Example.Docs.Util (audioWrapper)
import Ocarina.Interpret (decodeAudioDataFromUri)
import Ocarina.Run (run2)
import Type.Proxy (Proxy(..))

px =
Proxy :: Proxy """<section>
type Px = """<section>
<h2 id="bandpass">Bandpass filter</h2>
<p>A <a href="https://developer.mozilla.org/en-US/docs/Web/API/BiquadFilterNode">bandpass filter</a> isolates a single frequency range of a source. When you crank up a bandpass node's Q value, the isolation gets more intense. At the extreme, the source signal is almost lost and you get a pure sound that resembles a sine-wave oscillator.</p>

Expand All @@ -35,7 +33,7 @@ px =
"""
bandpass :: CancelCurrentAudio -> (Page -> Effect Unit) -> Poll SingleSubgraphEvent -> Nut
bandpass ccb _ ev = makePursx' (Proxy :: _ "@") px
bandpass ccb _ ev = pursx' @"@" @Px
{ bandpass:
( audioWrapper ev ccb (\ctx -> decodeAudioDataFromUri ctx "https://freesound.org/data/previews/320/320873_527080-hq.mp3")
\ctx buf -> run2 ctx
Expand Down
7 changes: 3 additions & 4 deletions examples/src/docs/AudioUnits/Compression.purs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import Prelude


import Deku.Core (Nut)
import Deku.Pursx ((~~))
import Deku.Pursx (pursx)
import Effect (Effect)
import FRP.Poll (Poll)
import Ocarina.Control (dynamicsCompressor_, loopBuf)
Expand All @@ -13,9 +13,8 @@ import Ocarina.Example.Docs.Types (CancelCurrentAudio, Page, SingleSubgraphEvent
import Ocarina.Example.Docs.Util (audioWrapper)
import Ocarina.Interpret (decodeAudioDataFromUri)
import Ocarina.Run (run2)
import Type.Proxy (Proxy(..))

px = Proxy :: Proxy """<section>
type Px = """<section>
<h2 id="compression">Compression</h2>
<p><a href="https://developer.mozilla.org/en-US/docs/Web/API/DynamicsCompressorNode">Compression</a>, when used judiciously, can make certain sounds sit better in a mix, like for example vocals. The <a href="https://developer.mozilla.org/en-US/docs/Web/API/DynamicsCompressorNode">MDN Web Audio documentation</a> does an excellent job explaining how its parameters work. When used not-judiciously, it makes everything sound loud, and who likes that? So let's use it judiciously, like in the example below. We'll pass an object that only specifies the threshold and otherwise use the default options for the compressor.</p>

Expand All @@ -37,7 +36,7 @@ run2_
"""
compression :: CancelCurrentAudio -> (Page -> Effect Unit) -> Poll SingleSubgraphEvent -> Nut
compression ccb _ ev = px ~~
compression ccb _ ev = pursx @Px
{ compression:
( audioWrapper ev ccb (\ctx -> decodeAudioDataFromUri ctx "https://freesound.org/data/previews/320/320873_527080-hq.mp3")
\ctx buf -> run2 ctx
Expand Down
8 changes: 3 additions & 5 deletions examples/src/docs/AudioUnits/Constant.purs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import Data.Array ((..))
import Data.FunctorWithIndex (mapWithIndex)
import Deku.Control (text_)
import Deku.Core (Nut)
import Deku.Pursx ((~~))
import Deku.Pursx (pursx)
import Effect (Effect)
import FRP.Poll (Poll)
import Ocarina.Control (gain_, constant)
Expand All @@ -17,10 +17,8 @@ import Ocarina.Example.Docs.Types (CancelCurrentAudio, Page, SingleSubgraphEvent
import Ocarina.Example.Docs.Util (audioWrapper)
import Ocarina.Properties (offset)
import Ocarina.Run (run2)
import Type.Proxy (Proxy(..))

px =
Proxy :: Proxy """<section>
type Px = """<section>
<h2 id="constant">Constant value</h2>
<p><a href="https://developer.mozilla.org/en-US/docs/Web/API/ConstantSourceNode">Constant values</a>, or DC offset, is a way to output an unchanging stream of values. This is only really useful when testing the performance of speakers or microphones and/or when working with a custom audio node that supports constant streaming values. Note that the constant source node in the web audio API can <i>also</i> be used to control audio parameters. Ocarina uses this feature of constant nodes under the hood to optimize certain computations.</p>

Expand All @@ -34,7 +32,7 @@ px =
constantEx
:: CancelCurrentAudio -> (Page -> Effect Unit) -> Poll SingleSubgraphEvent -> Nut
constantEx ccb _ ev = px ~~
constantEx ccb _ ev = pursx @Px
{ tf: (text_ "<|>")
, txt:
( text_
Expand Down
7 changes: 3 additions & 4 deletions examples/src/docs/AudioUnits/Convolution.purs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import Prelude


import Deku.Core (Nut)
import Deku.Pursx ((~~))
import Deku.Pursx (pursx)
import Effect (Effect)
import FRP.Poll (Poll)
import Ocarina.Control (convolver, loopBuf)
Expand All @@ -13,9 +13,8 @@ import Ocarina.Example.Docs.Types (CancelCurrentAudio, Page, SingleSubgraphEvent
import Ocarina.Example.Docs.Util (audioWrapper)
import Ocarina.Interpret (decodeAudioDataFromUri)
import Ocarina.Run (run2)
import Type.Proxy (Proxy(..))

px = Proxy :: Proxy """<section>
type Px = """<section>
<h2 id="convolution">Convolution</h2>
<p><a href="https://developer.mozilla.org/en-US/docs/Web/API/ConvolverNode">Convolution</a>, aka reverb, is a way to graft the shape of one sound (usually an <a href="https://en.wikipedia.org/wiki/Impulse_response">impulse response</a>) onto another. Convolution can sound great, but it is a <i>very expensive operation</i> that will cause noticeable artifacts on low-end devices. When shipping audio code to production, you're usually better off using an Audio Worklet Node with reverb optimized for your specific case. That said, for PoCs or hobbyist projects, convolution is great!</p>

Expand All @@ -27,7 +26,7 @@ px = Proxy :: Proxy """<section>
"""
convolution :: CancelCurrentAudio -> (Page -> Effect Unit) -> Poll SingleSubgraphEvent -> Nut
convolution ccb _ ev = px ~~
convolution ccb _ ev =pursx @Px
{ convolution:
( audioWrapper ev ccb (\ctx -> { loop: _, verb: _ }
<$> decodeAudioDataFromUri ctx "https://freesound.org/data/previews/320/320873_527080-hq.mp3" <*> decodeAudioDataFromUri ctx "https://cdn.jsdelivr.net/gh/andibrae/Reverb.js/Library/StMarysAbbeyReconstructionPhase3.m4a")
Expand Down
8 changes: 3 additions & 5 deletions examples/src/docs/AudioUnits/Delay.purs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module Ocarina.Example.Docs.AudioUnits.Delay where
import Prelude

import Deku.Core (Nut)
import Deku.Pursx (makePursx')
import Deku.Pursx (pursx')
import Effect (Effect)
import FRP.Poll (Poll)
import Ocarina.Control (delay_, fan1, gain_, playBuf)
Expand All @@ -12,10 +12,8 @@ import Ocarina.Example.Docs.Types (CancelCurrentAudio, Page, SingleSubgraphEvent
import Ocarina.Example.Docs.Util (audioWrapper)
import Ocarina.Interpret (decodeAudioDataFromUri)
import Ocarina.Run (run2)
import Type.Proxy (Proxy(..))

px =
Proxy :: Proxy """<section>
type Px = """<section>
<h2 id="delay">Delay</h2>
<p><a href="https://developer.mozilla.org/en-US/docs/Web/API/DelayNode">Delay</a>, as its name suggests, delays a signal. Using multiple delay nodes, you can create a decent echo effect.</p>

Expand All @@ -36,7 +34,7 @@ px =
"""
delay :: CancelCurrentAudio -> (Page -> Effect Unit) -> Poll SingleSubgraphEvent -> Nut
delay ccb _ ev = makePursx' (Proxy :: _ "@") px
delay ccb _ ev = pursx' @"@" @Px
{ delay:
( audioWrapper ev ccb (\ctx -> decodeAudioDataFromUri ctx "https://freesound.org/data/previews/339/339822_5121236-lq.mp3")
\ctx buf -> run2 ctx
Expand Down
Loading

0 comments on commit 4fe1618

Please sign in to comment.