-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #57 from michiboo/master
add humanize function to generate pink noise
- Loading branch information
Showing
6 changed files
with
59 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,7 +5,7 @@ os: | |
- osx | ||
|
||
julia: | ||
- 1.2 | ||
- 1 | ||
# - nightly # commented to save energy and time | ||
|
||
before_script: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
export humanize!, humanize | ||
|
||
using ARFIMA, Statistics | ||
const φ0 = ARFIMA.SVector(-0.5, -1.5) | ||
|
||
""" | ||
humanize!(notes, property, σ, noise = :ARFIMA; kwargs...) | ||
Humanize given `notes` by adding noise of standard deviation `σ` to their `property`, | ||
typically either `:position` or `:velocity`. Research[^Datseris2019] suggests that `σ` | ||
should be around 40 (for `:position`) but that depends on the BPM, and around 10 for `:velocity`. | ||
The `noise` argument decides the type of noise: | ||
* `:ARFIMA` uses ARFIMA.jl and attempts to generate a power-law correlated (pink) noise. | ||
Keywords `d = 0.25, φ = SVector(-0.5, -1.5)` are propagated to function `arfima`. | ||
* `:white` plain ol' white noise. | ||
Use `humanize` for a non-modifying version. | ||
[^Datseris2019]: Datseris, G., et al. [Microtiming Deviations and Swing Feel in Jazz. Sci Rep 9, 19824 (2019)](https://doi.org/10.1038/s41598-019-55981-3) | ||
""" | ||
function humanize!(n::Notes, property, σ, noise = :ARFIMA; d=0.25, φ=φ0) | ||
N = length(n) | ||
if noise == :ARFIMA | ||
ξ = arfima(N, 1.0, d, φ) | ||
elseif noise == :white | ||
ξ = randn(N) | ||
else | ||
error("Unrecognized noise type") | ||
end | ||
ξ .*= σ/std(ξ) | ||
for j in 1:N | ||
setproperty!(n[j], property, getproperty(n[j], property) + round(Int, ξ[j])) | ||
end | ||
return n | ||
end | ||
|
||
humanize(notes, args...; kwargs...) = humanize!(copy(notes), args...; kwargs...) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
using MusicManipulations, Test, Statistics | ||
|
||
@testset "humanize" begin | ||
|
||
#test of humanize functionality | ||
notes = randomnotes(100) | ||
for n in notes; n.velocity = 100; end | ||
hnotes = humanize(notes, :velocity, 10) | ||
@test any(i -> notes[i].velocity ≠ hnotes[i].velocity, 1:length(notes)) | ||
σ = std(velocities(hnotes)) | ||
@test 9.5 ≤ σ ≤ 10.5 | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8d734fc
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@JuliaRegistrator register()
8d734fc
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Registration pull request created: JuliaRegistries/General/22000
After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.
This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via: