Parcourir la source

play with sounds

master
Parent
révision
8f5be1aa99
Signé par: yogsototh ID de la clé GPG: 7B19A4C650D59646
  1. 49
      2020-05-22.tidal
  2. BIN
      output.bin
  3. 90
      raw-sound.hs
  4. 2
      shell.nix

49
2020-05-22.tidal

@ -0,0 +1,49 @@
-- sounds
-- ======
-- # Bass
-- bass2, ht
-- clubkick
-- kicklinn
-- popkick
-- reverbkick
-- rs,sd,sn,stomp,ul,ulgab
-- # aigus
-- co, cp (clap), cr (cimbales), dr, dr2
-- hc, ho
-- # sons
-- control, cosmicg, f, fest, flick, fm, gab (gabbernation), gtr (guitare electrique)
-- hit (futuristique), hoover (techno), if, juno, off, moog, pad, padlong (introductions)
-- rave2, sine, stab
-- # templates
-- hardcore, hardkick
-- Inspiration https://www.youtube.com/watch?v=MbCNdB3hfpc&feature=youtu.be
import qualified Sound.Tidal.Chords as Chords
do
let arp = "[0 1 2 3 4 5 6 7 8 7 6 5 4 3 2 1]*2"
arp2 = "[7 0 2 4]*2"
pat = "<0 2 5 4>"
oct = -2
d1 $ stack [
n (toScale Chords.minor (arp + pat)) # s "superchip" # release 0.05,
n (toScale Chords.minor (arp2 + pat - 4)) # s "superchip" # release 0.8,
n ("0*8" + (slow 2 pat) - 14) # s "superchip" # release 0.3 # cut 2
] # orbit 1 # room 0.1 # size 0.93
d2 $ s "clubkick*4"
# n 1
# speed 0.5
# crunch 2
# orbit 2 # room 0.5
d3 $ s "[~ dr2]*4"
# orbit 2
solo 4
unsolo 4
hush

BIN
output.bin

Fichier binaire non affiché.

90
raw-sound.hs

@ -0,0 +1,90 @@
{-# LANGUAGE NoImplicitPrelude #-}
{-# LANGUAGE OverloadedStrings #-}
{- Inspiration: https://www.youtube.com/watch?v=FYTZkE5BZ-0&app=desktop
-}
import Protolude hiding (note)
import qualified Data.ByteString.Lazy as B
import qualified Data.ByteString.Builder as B
import System.Process
import Text.Printf (printf)
import Data.List (zipWith3)
outputFilePath :: FilePath
outputFilePath = "output.bin"
sampleRate :: Float
sampleRate = 48000
volume :: Float
volume = 0.5
type Duration = Float
type Hz = Float
type Seconds = Float
type Pulse = Float
type Soundwave = [Pulse]
type Beats = Float
bpm :: Beats
bpm = 120
beatDuration :: Seconds
beatDuration = 60.0/bpm
standardFreq :: Hz
standardFreq = 440
f n = standardFreq * ((2 ** (1/12)) ** n)
major = [0,2,4,5,7,9,11,12]
freq :: Hz -> Seconds -> [Float]
freq hz duration = map (* volume) $ zipWith3 (\x y z -> x * y * z) attack release output
where
nbpulse = sampleRate * duration
attackduration = 0.05
attack = map (min 1) [0, (1 / (attackduration * nbpulse)).. ]
release = reverse (take (length output) attack)
output = map (sin . (* step)) [0.0 .. sampleRate * duration]
step = (hz * 2 * pi) / sampleRate
note n l = freq (f n) (beatDuration * l)
maintrack =
[ note 0 0.25
, note 0 0.25
, note 0 0.25
, note 0 0.25
, note 0 0.5
, note 0 0.25
, note 0 0.25
, note 0 0.25
, note 0 0.25
, note 0 0.5
, note 5 0.25
, note 5 0.25
, note 5 0.25
, note 5 0.25
, note 5 0.5
, note 3 0.25
, note 3 0.25
, note 3 0.25
, note 3 0.25
, note 3 0.5
, note (-2) 0.5
]
wave :: Soundwave
wave = concat (maintrack <> maintrack)
save :: FilePath -> IO ()
save fp =
B.writeFile fp $ B.toLazyByteString $ fold $ map B.floatLE wave
play :: IO ()
play = do
save outputFilePath
void $ runCommand $ printf "ffplay -showmode 1 -f f32le -ar %f %s" sampleRate outputFilePath

2
shell.nix

@ -15,6 +15,7 @@ let
base
protolude
tidal
random
];
ghc = hspkgs.ghcWithPackages haskellDeps;
@ -22,6 +23,7 @@ let
nixPackages = [
ghc
pkgs.gdb
pkgs.ffmpeg-full
haskellPackages.cabal-install
];
in

Chargement…
Annuler
Enregistrer