Compare commits
No commits in common. "master" and "gh-pages" have entirely different histories.
43 changed files with 16195 additions and 2806 deletions
|
@ -1,9 +0,0 @@
|
|||
always_for_in = true
|
||||
whitespace_typedefs = true
|
||||
whitespace_ops_in_indices = true
|
||||
remove_extra_newlines = true
|
||||
import_to_using = true
|
||||
short_to_long_function_def = true
|
||||
format_docstrings = true
|
||||
align_pair_arrow = false
|
||||
conditional_to_if = true
|
22
.github/pull_request_template.md
vendored
22
.github/pull_request_template.md
vendored
|
@ -1,22 +0,0 @@
|
|||
Thanks for contributing a pull request!
|
||||
|
||||
Please be aware that we are a loose team of volunteers so patience is
|
||||
necessary. Assistance handling other issues is very welcome. We value
|
||||
all user contributions, no matter how minor they are. If we are slow to
|
||||
review, either the pull request needs some benchmarking, tinkering,
|
||||
convincing, etc. or more likely the reviewers are simply busy. In either
|
||||
case, we ask for your understanding during the review process.
|
||||
|
||||
Again, thanks for contributing!
|
||||
|
||||
|
||||
#### What does this implement/fix?
|
||||
Explain your changes. Please be as descriptive as possible.
|
||||
|
||||
|
||||
#### Reference issue
|
||||
Example: Fixes #1234.
|
||||
|
||||
|
||||
#### Additional information
|
||||
Any additional information you think is important.
|
25
.github/workflows/CompatHelper.yml
vendored
25
.github/workflows/CompatHelper.yml
vendored
|
@ -1,25 +0,0 @@
|
|||
name: CompatHelper
|
||||
on:
|
||||
schedule:
|
||||
- cron: 0 0 * * *
|
||||
workflow_dispatch:
|
||||
jobs:
|
||||
CompatHelper:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: "Install CompatHelper"
|
||||
run: |
|
||||
import Pkg
|
||||
name = "CompatHelper"
|
||||
uuid = "aa819f21-2bde-4658-8897-bab36330d9b7"
|
||||
version = "2"
|
||||
Pkg.add(; name, uuid, version)
|
||||
shell: julia --color=yes {0}
|
||||
- name: "Run CompatHelper"
|
||||
run: |
|
||||
import CompatHelper
|
||||
CompatHelper.main()
|
||||
shell: julia --color=yes {0}
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
COMPATHELPER_PRIV: ${{ secrets.COMPATHELPER_PRIV }}
|
16
.github/workflows/Documentation.yml
vendored
16
.github/workflows/Documentation.yml
vendored
|
@ -1,16 +0,0 @@
|
|||
name: Build documentation
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- 'master'
|
||||
jobs:
|
||||
document:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- uses: julia-actions/setup-julia@latest
|
||||
with:
|
||||
version: '1.6'
|
||||
- uses: julia-actions/julia-docdeploy@releases/v1
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
15
.github/workflows/TagBot.yml
vendored
15
.github/workflows/TagBot.yml
vendored
|
@ -1,15 +0,0 @@
|
|||
name: TagBot
|
||||
on:
|
||||
issue_comment:
|
||||
types:
|
||||
- created
|
||||
workflow_dispatch:
|
||||
jobs:
|
||||
TagBot:
|
||||
if: github.event_name == 'workflow_dispatch' || github.actor == 'JuliaTagBot'
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: JuliaRegistries/TagBot@v1
|
||||
with:
|
||||
token: ${{ secrets.GITHUB_TOKEN }}
|
||||
ssh: ${{ secrets.COMPATHELPER_PRIV }}
|
41
.github/workflows/Tests.yml
vendored
41
.github/workflows/Tests.yml
vendored
|
@ -1,41 +0,0 @@
|
|||
name: Tests
|
||||
|
||||
on:
|
||||
pull_request:
|
||||
push:
|
||||
branches:
|
||||
- master
|
||||
tags: '*'
|
||||
|
||||
|
||||
jobs:
|
||||
test:
|
||||
timeout-minutes: 30
|
||||
name: ${{ matrix.version }} - ${{ matrix.os }} - ${{ matrix.arch }}
|
||||
runs-on: ${{ matrix.os }}
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
version:
|
||||
- '1.6'
|
||||
- '1'
|
||||
- 'nightly'
|
||||
os:
|
||||
- ubuntu-latest
|
||||
- macOS-latest
|
||||
- windows-latest
|
||||
arch:
|
||||
- x64
|
||||
- x86
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- uses: julia-actions/setup-julia@v1
|
||||
with:
|
||||
version: ${{ matrix.version }}
|
||||
- uses: julia-actions/julia-buildpkg@v1
|
||||
- uses: julia-actions/julia-runtest@v1
|
||||
- uses: julia-actions/julia-processcoverage@v1
|
||||
- uses: codecov/codecov-action@v1
|
||||
with:
|
||||
file: lcov.info
|
12
.gitignore
vendored
12
.gitignore
vendored
|
@ -1,12 +0,0 @@
|
|||
*.swp
|
||||
*.o
|
||||
deps/deps.jl
|
||||
deps/build.log
|
||||
docs/build
|
||||
*.wav
|
||||
*.flac
|
||||
*.cov
|
||||
coverage
|
||||
deps/usr/lib/pa_shim.so
|
||||
deps/usr/lib/pa_shim.dylib
|
||||
deps/usr/lib/pa_shim.dll
|
27
LICENSE
27
LICENSE
|
@ -1,27 +0,0 @@
|
|||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2013 Spencer Russell
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
|
||||
|
||||
suppressor.jl includes code from the Suppressor.jl package, licensed under the
|
||||
MIT "Expat" License:
|
||||
|
||||
Copyright (c) 2016: Ismael Venegas Castelló.
|
26
Project.toml
26
Project.toml
|
@ -1,26 +0,0 @@
|
|||
name = "PortAudio"
|
||||
uuid = "80ea8bcb-4634-5cb3-8ee8-a132660d1d2d"
|
||||
repo = "https://github.com/JuliaAudio/PortAudio.jl.git"
|
||||
version = "1.3.0"
|
||||
|
||||
[deps]
|
||||
alsa_plugins_jll = "5ac2f6bb-493e-5871-9171-112d4c21a6e7"
|
||||
libportaudio_jll = "2d7b7beb-0762-5160-978e-1ab83a1e8a31"
|
||||
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
|
||||
SampledSignals = "bd7594eb-a658-542f-9e75-4c4d8908c167"
|
||||
Suppressor = "fd094767-a336-5f1f-9728-57cf17d0bbfb"
|
||||
|
||||
[compat]
|
||||
julia = "1.6"
|
||||
alsa_plugins_jll = "1.2.2"
|
||||
libportaudio_jll = "19.6.0"
|
||||
SampledSignals = "2.1.1"
|
||||
Suppressor = "0.2"
|
||||
|
||||
[extras]
|
||||
Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4"
|
||||
LibSndFile = "b13ce0c6-77b0-50c6-a2db-140568b8d1a5"
|
||||
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
|
||||
|
||||
[targets]
|
||||
test = ["Documenter", "LibSndFile", "Test"]
|
126
README.md
126
README.md
|
@ -1,126 +0,0 @@
|
|||
PortAudio.jl
|
||||
============
|
||||
|
||||
[![Dev](https://img.shields.io/badge/docs-dev-blue.svg)](https://JuliaAudio.github.io/PortAudio.jl/dev)
|
||||
[![Tests](https://github.com/JuliaAudio/PortAudio.jl/actions/workflows/Tests.yml/badge.svg)](https://github.com/JuliaAudio/PortAudio.jl/actions/workflows/Tests.yml)
|
||||
[![codecov](https://codecov.io/gh/JuliaAudio/PortAudio.jl/branch/master/graph/badge.svg?token=mgDAi8ulPY)](https://codecov.io/gh/JuliaAudio/PortAudio.jl)
|
||||
|
||||
|
||||
PortAudio.jl is a wrapper for [libportaudio](http://www.portaudio.com/), which gives cross-platform access to audio devices. It is compatible with the types defined in [SampledSignals.jl](https://github.com/JuliaAudio/SampledSignals.jl). It provides a `PortAudioStream` type, which can be read from and written to.
|
||||
|
||||
## Opening a stream
|
||||
|
||||
The easiest way to open a source or sink is with the default `PortAudioStream()` constructor,
|
||||
which will open a 2-in, 2-out stream to your system's default device(s).
|
||||
The constructor can also take the input and output channel counts as positional arguments,
|
||||
or a variety of other keyword arguments.
|
||||
If named keyword arguments `latency` or `samplerate` are unspecified, then PortAudio will use device defaults.
|
||||
|
||||
```julia
|
||||
PortAudioStream(inchans=2, outchans=2; eltype=Float32, samplerate=48000, latency=0.1)
|
||||
```
|
||||
|
||||
You can open a specific device by adding it as the first argument, either as a `PortAudioDevice` instance or by name. You can also give separate names or devices if you want different input and output devices
|
||||
|
||||
```julia
|
||||
PortAudioStream(device::PortAudioDevice, args...; kwargs...)
|
||||
PortAudioStream(devname::AbstractString, args...; kwargs...)
|
||||
```
|
||||
|
||||
You can get a list of your system's devices with the `PortAudio.devices()` function:
|
||||
|
||||
```julia
|
||||
julia> PortAudio.devices()
|
||||
14-element Vector{PortAudio.PortAudioDevice}:
|
||||
"sof-hda-dsp: - (hw:0,0)" 2→2
|
||||
"sof-hda-dsp: - (hw:0,3)" 0→2
|
||||
"sof-hda-dsp: - (hw:0,4)" 0→2
|
||||
"sof-hda-dsp: - (hw:0,5)" 0→2
|
||||
⋮
|
||||
"upmix" 8→8
|
||||
"vdownmix" 6→6
|
||||
"dmix" 0→2
|
||||
"default" 32→32
|
||||
```
|
||||
|
||||
## Reading and Writing
|
||||
|
||||
The `PortAudioStream` type has `source` and `sink` fields which are of type `PortAudioSource <: SampleSource` and `PortAudioSink <: SampleSink`, respectively. are subtypes of `SampleSource` and `SampleSink`, respectively (from [SampledSignals.jl](https://github.com/JuliaAudio/SampledSignals.jl)). This means they support all the stream and buffer features defined there. For example, if you load SampledSignals with `using SampledSignals` you can read 5 seconds to a buffer with `buf = read(stream.source, 5s)`, regardless of the sample rate of the device.
|
||||
|
||||
PortAudio.jl also provides convenience wrappers around the `PortAudioStream` type so you can read and write to it directly, e.g. `write(stream, stream)` will set up a loopback that will read from the input and play it back on the output.
|
||||
|
||||
## Debugging
|
||||
|
||||
If you are experiencing issues and wish to view detailed logging and debug information, set
|
||||
|
||||
```
|
||||
ENV["JULIA_DEBUG"] = :PortAudio
|
||||
```
|
||||
|
||||
before using the package.
|
||||
|
||||
## Examples
|
||||
|
||||
### Set up an audio pass-through from microphone to speaker
|
||||
|
||||
```julia
|
||||
stream = PortAudioStream(2, 2)
|
||||
try
|
||||
# cancel with Ctrl-C
|
||||
write(stream, stream)
|
||||
finally
|
||||
close(stream)
|
||||
end
|
||||
```
|
||||
|
||||
### Use `do` syntax to auto-close the stream
|
||||
```julia
|
||||
PortAudioStream(2, 2) do stream
|
||||
write(stream, stream)
|
||||
end
|
||||
```
|
||||
|
||||
### Open your built-in microphone and speaker by name
|
||||
```julia
|
||||
PortAudioStream("default", "default") do stream
|
||||
write(stream, stream)
|
||||
end
|
||||
```
|
||||
|
||||
### Record 10 seconds of audio and save to an ogg file
|
||||
|
||||
```julia
|
||||
julia> import LibSndFile # must be in Manifest for FileIO.save to work
|
||||
|
||||
julia> using PortAudio: PortAudioStream
|
||||
|
||||
julia> using SampledSignals: s
|
||||
|
||||
julia> using FileIO: save
|
||||
|
||||
julia> stream = PortAudioStream(1, 0) # default input (e.g., built-in microphone)
|
||||
PortAudioStream{Float32}
|
||||
Samplerate: 44100.0Hz
|
||||
2 channel source: "default"
|
||||
|
||||
julia> buf = read(stream, 10s)
|
||||
480000-frame, 2-channel SampleBuf{Float32, 2, SIUnits.SIQuantity{Int64,0,0,-1,0,0,0,0,0,0}}
|
||||
10.0 s at 48000 s⁻¹
|
||||
▁▄▂▃▅▃▂▄▃▂▂▁▁▂▂▁▁▄▃▁▁▄▂▁▁▁▄▃▁▁▃▃▁▁▁▁▁▁▁▁▄▄▄▄▄▂▂▂▁▃▃▁▃▄▂▁▁▁▁▃▃▂▁▁▁▁▁▁▃▃▂▂▁▃▃▃▁▁▁▁
|
||||
▁▄▂▃▅▃▂▄▃▂▂▁▁▂▂▁▁▄▃▁▁▄▂▁▁▁▄▃▁▁▃▃▁▁▁▁▁▁▁▁▄▄▄▄▄▂▂▂▁▃▃▁▃▄▂▁▁▁▁▃▃▂▁▁▁▁▁▁▃▃▂▂▁▃▃▃▁▁▁▁
|
||||
|
||||
julia> close(stream)
|
||||
|
||||
julia> save(joinpath(homedir(), "Desktop", "myvoice.ogg"), buf)
|
||||
```
|
||||
|
||||
### Play an audio signal through the default sound output device
|
||||
|
||||
```julia
|
||||
using PortAudio, SampledSignals
|
||||
S = 8192 # sampling rate (samples / second)
|
||||
x = cos.(2pi*(1:2S)*440/S) # A440 tone for 2 seconds
|
||||
PortAudioStream(0, 2; samplerate=S) do stream
|
||||
write(stream, x)
|
||||
end
|
||||
```
|
331
dev/assets/documenter.js
Normal file
331
dev/assets/documenter.js
Normal file
|
@ -0,0 +1,331 @@
|
|||
// Generated by Documenter.jl
|
||||
requirejs.config({
|
||||
paths: {
|
||||
'highlight-julia': 'https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.5.1/languages/julia.min',
|
||||
'headroom': 'https://cdnjs.cloudflare.com/ajax/libs/headroom/0.12.0/headroom.min',
|
||||
'jqueryui': 'https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min',
|
||||
'katex-auto-render': 'https://cdnjs.cloudflare.com/ajax/libs/KaTeX/0.13.24/contrib/auto-render.min',
|
||||
'jquery': 'https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/jquery.min',
|
||||
'headroom-jquery': 'https://cdnjs.cloudflare.com/ajax/libs/headroom/0.12.0/jQuery.headroom.min',
|
||||
'katex': 'https://cdnjs.cloudflare.com/ajax/libs/KaTeX/0.13.24/katex.min',
|
||||
'highlight': 'https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.5.1/highlight.min',
|
||||
'highlight-julia-repl': 'https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.5.1/languages/julia-repl.min',
|
||||
},
|
||||
shim: {
|
||||
"highlight-julia": {
|
||||
"deps": [
|
||||
"highlight"
|
||||
]
|
||||
},
|
||||
"katex-auto-render": {
|
||||
"deps": [
|
||||
"katex"
|
||||
]
|
||||
},
|
||||
"headroom-jquery": {
|
||||
"deps": [
|
||||
"jquery",
|
||||
"headroom"
|
||||
]
|
||||
},
|
||||
"highlight-julia-repl": {
|
||||
"deps": [
|
||||
"highlight"
|
||||
]
|
||||
}
|
||||
}
|
||||
});
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
require(['jquery', 'katex', 'katex-auto-render'], function($, katex, renderMathInElement) {
|
||||
$(document).ready(function() {
|
||||
renderMathInElement(
|
||||
document.body,
|
||||
{
|
||||
"delimiters": [
|
||||
{
|
||||
"left": "$",
|
||||
"right": "$",
|
||||
"display": false
|
||||
},
|
||||
{
|
||||
"left": "$$",
|
||||
"right": "$$",
|
||||
"display": true
|
||||
},
|
||||
{
|
||||
"left": "\\[",
|
||||
"right": "\\]",
|
||||
"display": true
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
);
|
||||
})
|
||||
|
||||
})
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
require(['jquery', 'highlight', 'highlight-julia', 'highlight-julia-repl'], function($) {
|
||||
$(document).ready(function() {
|
||||
hljs.highlightAll();
|
||||
})
|
||||
|
||||
})
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
require([], function() {
|
||||
function addCopyButtonCallbacks() {
|
||||
for (const el of document.getElementsByTagName("pre")) {
|
||||
const button = document.createElement("button");
|
||||
button.classList.add("copy-button", "fas", "fa-copy");
|
||||
el.appendChild(button);
|
||||
|
||||
const success = function () {
|
||||
button.classList.add("success", "fa-check");
|
||||
button.classList.remove("fa-copy");
|
||||
};
|
||||
|
||||
const failure = function () {
|
||||
button.classList.add("error", "fa-times");
|
||||
button.classList.remove("fa-copy");
|
||||
};
|
||||
|
||||
button.addEventListener("click", function () {
|
||||
copyToClipboard(el.innerText).then(success, failure);
|
||||
|
||||
setTimeout(function () {
|
||||
button.classList.add("fa-copy");
|
||||
button.classList.remove("success", "fa-check", "fa-times");
|
||||
}, 5000);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
function copyToClipboard(text) {
|
||||
// clipboard API is only available in secure contexts
|
||||
if (window.navigator && window.navigator.clipboard) {
|
||||
return window.navigator.clipboard.writeText(text);
|
||||
} else {
|
||||
return new Promise(function (resolve, reject) {
|
||||
try {
|
||||
const el = document.createElement("textarea");
|
||||
el.textContent = text;
|
||||
el.style.position = "fixed";
|
||||
el.style.opacity = 0;
|
||||
document.body.appendChild(el);
|
||||
el.select();
|
||||
document.execCommand("copy");
|
||||
|
||||
resolve();
|
||||
} catch (err) {
|
||||
reject(err);
|
||||
} finally {
|
||||
document.body.removeChild(el);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
if (document.readyState === "loading") {
|
||||
document.addEventListener("DOMContentLoaded", addCopyButtonCallbacks);
|
||||
} else {
|
||||
addCopyButtonCallbacks();
|
||||
}
|
||||
|
||||
})
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
require(['jquery', 'headroom', 'headroom-jquery'], function($, Headroom) {
|
||||
|
||||
// Manages the top navigation bar (hides it when the user starts scrolling down on the
|
||||
// mobile).
|
||||
window.Headroom = Headroom; // work around buggy module loading?
|
||||
$(document).ready(function() {
|
||||
$('#documenter .docs-navbar').headroom({
|
||||
"tolerance": {"up": 10, "down": 10},
|
||||
});
|
||||
})
|
||||
|
||||
})
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
require(['jquery'], function($) {
|
||||
|
||||
// Modal settings dialog
|
||||
$(document).ready(function() {
|
||||
var settings = $('#documenter-settings');
|
||||
$('#documenter-settings-button').click(function(){
|
||||
settings.toggleClass('is-active');
|
||||
});
|
||||
// Close the dialog if X is clicked
|
||||
$('#documenter-settings button.delete').click(function(){
|
||||
settings.removeClass('is-active');
|
||||
});
|
||||
// Close dialog if ESC is pressed
|
||||
$(document).keyup(function(e) {
|
||||
if (e.keyCode == 27) settings.removeClass('is-active');
|
||||
});
|
||||
});
|
||||
|
||||
})
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
require(['jquery'], function($) {
|
||||
|
||||
// Manages the showing and hiding of the sidebar.
|
||||
$(document).ready(function() {
|
||||
var sidebar = $("#documenter > .docs-sidebar");
|
||||
var sidebar_button = $("#documenter-sidebar-button")
|
||||
sidebar_button.click(function(ev) {
|
||||
ev.preventDefault();
|
||||
sidebar.toggleClass('visible');
|
||||
if (sidebar.hasClass('visible')) {
|
||||
// Makes sure that the current menu item is visible in the sidebar.
|
||||
$("#documenter .docs-menu a.is-active").focus();
|
||||
}
|
||||
});
|
||||
$("#documenter > .docs-main").bind('click', function(ev) {
|
||||
if ($(ev.target).is(sidebar_button)) {
|
||||
return;
|
||||
}
|
||||
if (sidebar.hasClass('visible')) {
|
||||
sidebar.removeClass('visible');
|
||||
}
|
||||
});
|
||||
})
|
||||
|
||||
// Resizes the package name / sitename in the sidebar if it is too wide.
|
||||
// Inspired by: https://github.com/davatron5000/FitText.js
|
||||
$(document).ready(function() {
|
||||
e = $("#documenter .docs-autofit");
|
||||
function resize() {
|
||||
var L = parseInt(e.css('max-width'), 10);
|
||||
var L0 = e.width();
|
||||
if(L0 > L) {
|
||||
var h0 = parseInt(e.css('font-size'), 10);
|
||||
e.css('font-size', L * h0 / L0);
|
||||
// TODO: make sure it survives resizes?
|
||||
}
|
||||
}
|
||||
// call once and then register events
|
||||
resize();
|
||||
$(window).resize(resize);
|
||||
$(window).on('orientationchange', resize);
|
||||
});
|
||||
|
||||
// Scroll the navigation bar to the currently selected menu item
|
||||
$(document).ready(function() {
|
||||
var sidebar = $("#documenter .docs-menu").get(0);
|
||||
var active = $("#documenter .docs-menu .is-active").get(0);
|
||||
if(typeof active !== 'undefined') {
|
||||
sidebar.scrollTop = active.offsetTop - sidebar.offsetTop - 15;
|
||||
}
|
||||
})
|
||||
|
||||
})
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
require(['jquery'], function($) {
|
||||
|
||||
function set_theme(theme) {
|
||||
var active = null;
|
||||
var disabled = [];
|
||||
for (var i = 0; i < document.styleSheets.length; i++) {
|
||||
var ss = document.styleSheets[i];
|
||||
var themename = ss.ownerNode.getAttribute("data-theme-name");
|
||||
if(themename === null) continue; // ignore non-theme stylesheets
|
||||
// Find the active theme
|
||||
if(themename === theme) active = ss;
|
||||
else disabled.push(ss);
|
||||
}
|
||||
if(active !== null) {
|
||||
active.disabled = false;
|
||||
if(active.ownerNode.getAttribute("data-theme-primary") === null) {
|
||||
document.getElementsByTagName('html')[0].className = "theme--" + theme;
|
||||
} else {
|
||||
document.getElementsByTagName('html')[0].className = "";
|
||||
}
|
||||
disabled.forEach(function(ss){
|
||||
ss.disabled = true;
|
||||
});
|
||||
}
|
||||
|
||||
// Store the theme in localStorage
|
||||
if(typeof(window.localStorage) !== "undefined") {
|
||||
window.localStorage.setItem("documenter-theme", theme);
|
||||
} else {
|
||||
console.error("Browser does not support window.localStorage");
|
||||
}
|
||||
}
|
||||
|
||||
// Theme picker setup
|
||||
$(document).ready(function() {
|
||||
// onchange callback
|
||||
$('#documenter-themepicker').change(function themepick_callback(ev){
|
||||
var themename = $('#documenter-themepicker option:selected').attr('value');
|
||||
set_theme(themename);
|
||||
});
|
||||
|
||||
// Make sure that the themepicker displays the correct theme when the theme is retrieved
|
||||
// from localStorage
|
||||
if(typeof(window.localStorage) !== "undefined") {
|
||||
var theme = window.localStorage.getItem("documenter-theme");
|
||||
if(theme !== null) {
|
||||
$('#documenter-themepicker option').each(function(i,e) {
|
||||
e.selected = (e.value === theme);
|
||||
})
|
||||
} else {
|
||||
$('#documenter-themepicker option').each(function(i,e) {
|
||||
e.selected = $("html").hasClass(`theme--${e.value}`);
|
||||
})
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
})
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
require(['jquery'], function($) {
|
||||
|
||||
// update the version selector with info from the siteinfo.js and ../versions.js files
|
||||
$(document).ready(function() {
|
||||
// If the version selector is disabled with DOCUMENTER_VERSION_SELECTOR_DISABLED in the
|
||||
// siteinfo.js file, we just return immediately and not display the version selector.
|
||||
if (typeof DOCUMENTER_VERSION_SELECTOR_DISABLED === 'boolean' && DOCUMENTER_VERSION_SELECTOR_DISABLED) {
|
||||
return;
|
||||
}
|
||||
|
||||
var version_selector = $("#documenter .docs-version-selector");
|
||||
var version_selector_select = $("#documenter .docs-version-selector select");
|
||||
|
||||
version_selector_select.change(function(x) {
|
||||
target_href = version_selector_select.children("option:selected").get(0).value;
|
||||
window.location.href = target_href;
|
||||
});
|
||||
|
||||
// add the current version to the selector based on siteinfo.js, but only if the selector is empty
|
||||
if (typeof DOCUMENTER_CURRENT_VERSION !== 'undefined' && $('#version-selector > option').length == 0) {
|
||||
var option = $("<option value='#' selected='selected'>" + DOCUMENTER_CURRENT_VERSION + "</option>");
|
||||
version_selector_select.append(option);
|
||||
}
|
||||
|
||||
if (typeof DOC_VERSIONS !== 'undefined') {
|
||||
var existing_versions = version_selector_select.children("option");
|
||||
var existing_versions_texts = existing_versions.map(function(i,x){return x.text});
|
||||
DOC_VERSIONS.forEach(function(each) {
|
||||
var version_url = documenterBaseURL + "/../" + each;
|
||||
var existing_id = $.inArray(each, existing_versions_texts);
|
||||
// if not already in the version selector, add it as a new option,
|
||||
// otherwise update the old option with the URL and enable it
|
||||
if (existing_id == -1) {
|
||||
var option = $("<option value='" + version_url + "'>" + each + "</option>");
|
||||
version_selector_select.append(option);
|
||||
} else {
|
||||
var option = existing_versions[existing_id];
|
||||
option.value = version_url;
|
||||
option.disabled = false;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// only show the version selector if the selector has been populated
|
||||
if (version_selector_select.children("option").length > 0) {
|
||||
version_selector.toggleClass("visible");
|
||||
}
|
||||
})
|
||||
|
||||
})
|
267
dev/assets/search.js
Normal file
267
dev/assets/search.js
Normal file
|
@ -0,0 +1,267 @@
|
|||
// Generated by Documenter.jl
|
||||
requirejs.config({
|
||||
paths: {
|
||||
'lunr': 'https://cdnjs.cloudflare.com/ajax/libs/lunr.js/2.3.9/lunr.min',
|
||||
'lodash': 'https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.21/lodash.min',
|
||||
'jquery': 'https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/jquery.min',
|
||||
}
|
||||
});
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
require(['jquery', 'lunr', 'lodash'], function($, lunr, _) {
|
||||
|
||||
$(document).ready(function() {
|
||||
// parseUri 1.2.2
|
||||
// (c) Steven Levithan <stevenlevithan.com>
|
||||
// MIT License
|
||||
function parseUri (str) {
|
||||
var o = parseUri.options,
|
||||
m = o.parser[o.strictMode ? "strict" : "loose"].exec(str),
|
||||
uri = {},
|
||||
i = 14;
|
||||
|
||||
while (i--) uri[o.key[i]] = m[i] || "";
|
||||
|
||||
uri[o.q.name] = {};
|
||||
uri[o.key[12]].replace(o.q.parser, function ($0, $1, $2) {
|
||||
if ($1) uri[o.q.name][$1] = $2;
|
||||
});
|
||||
|
||||
return uri;
|
||||
};
|
||||
parseUri.options = {
|
||||
strictMode: false,
|
||||
key: ["source","protocol","authority","userInfo","user","password","host","port","relative","path","directory","file","query","anchor"],
|
||||
q: {
|
||||
name: "queryKey",
|
||||
parser: /(?:^|&)([^&=]*)=?([^&]*)/g
|
||||
},
|
||||
parser: {
|
||||
strict: /^(?:([^:\/?#]+):)?(?:\/\/((?:(([^:@]*)(?::([^:@]*))?)?@)?([^:\/?#]*)(?::(\d*))?))?((((?:[^?#\/]*\/)*)([^?#]*))(?:\?([^#]*))?(?:#(.*))?)/,
|
||||
loose: /^(?:(?![^:@]+:[^:@\/]*@)([^:\/?#.]+):)?(?:\/\/)?((?:(([^:@]*)(?::([^:@]*))?)?@)?([^:\/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/
|
||||
}
|
||||
};
|
||||
|
||||
$("#search-form").submit(function(e) {
|
||||
e.preventDefault()
|
||||
})
|
||||
|
||||
// list below is the lunr 2.1.3 list minus the intersect with names(Base)
|
||||
// (all, any, get, in, is, only, which) and (do, else, for, let, where, while, with)
|
||||
// ideally we'd just filter the original list but it's not available as a variable
|
||||
lunr.stopWordFilter = lunr.generateStopWordFilter([
|
||||
'a',
|
||||
'able',
|
||||
'about',
|
||||
'across',
|
||||
'after',
|
||||
'almost',
|
||||
'also',
|
||||
'am',
|
||||
'among',
|
||||
'an',
|
||||
'and',
|
||||
'are',
|
||||
'as',
|
||||
'at',
|
||||
'be',
|
||||
'because',
|
||||
'been',
|
||||
'but',
|
||||
'by',
|
||||
'can',
|
||||
'cannot',
|
||||
'could',
|
||||
'dear',
|
||||
'did',
|
||||
'does',
|
||||
'either',
|
||||
'ever',
|
||||
'every',
|
||||
'from',
|
||||
'got',
|
||||
'had',
|
||||
'has',
|
||||
'have',
|
||||
'he',
|
||||
'her',
|
||||
'hers',
|
||||
'him',
|
||||
'his',
|
||||
'how',
|
||||
'however',
|
||||
'i',
|
||||
'if',
|
||||
'into',
|
||||
'it',
|
||||
'its',
|
||||
'just',
|
||||
'least',
|
||||
'like',
|
||||
'likely',
|
||||
'may',
|
||||
'me',
|
||||
'might',
|
||||
'most',
|
||||
'must',
|
||||
'my',
|
||||
'neither',
|
||||
'no',
|
||||
'nor',
|
||||
'not',
|
||||
'of',
|
||||
'off',
|
||||
'often',
|
||||
'on',
|
||||
'or',
|
||||
'other',
|
||||
'our',
|
||||
'own',
|
||||
'rather',
|
||||
'said',
|
||||
'say',
|
||||
'says',
|
||||
'she',
|
||||
'should',
|
||||
'since',
|
||||
'so',
|
||||
'some',
|
||||
'than',
|
||||
'that',
|
||||
'the',
|
||||
'their',
|
||||
'them',
|
||||
'then',
|
||||
'there',
|
||||
'these',
|
||||
'they',
|
||||
'this',
|
||||
'tis',
|
||||
'to',
|
||||
'too',
|
||||
'twas',
|
||||
'us',
|
||||
'wants',
|
||||
'was',
|
||||
'we',
|
||||
'were',
|
||||
'what',
|
||||
'when',
|
||||
'who',
|
||||
'whom',
|
||||
'why',
|
||||
'will',
|
||||
'would',
|
||||
'yet',
|
||||
'you',
|
||||
'your'
|
||||
])
|
||||
|
||||
// add . as a separator, because otherwise "title": "Documenter.Anchors.add!"
|
||||
// would not find anything if searching for "add!", only for the entire qualification
|
||||
lunr.tokenizer.separator = /[\s\-\.]+/
|
||||
|
||||
// custom trimmer that doesn't strip @ and !, which are used in julia macro and function names
|
||||
lunr.trimmer = function (token) {
|
||||
return token.update(function (s) {
|
||||
return s.replace(/^[^a-zA-Z0-9@!]+/, '').replace(/[^a-zA-Z0-9@!]+$/, '')
|
||||
})
|
||||
}
|
||||
|
||||
lunr.Pipeline.registerFunction(lunr.stopWordFilter, 'juliaStopWordFilter')
|
||||
lunr.Pipeline.registerFunction(lunr.trimmer, 'juliaTrimmer')
|
||||
|
||||
var index = lunr(function () {
|
||||
this.ref('location')
|
||||
this.field('title',{boost: 100})
|
||||
this.field('text')
|
||||
documenterSearchIndex['docs'].forEach(function(e) {
|
||||
this.add(e)
|
||||
}, this)
|
||||
})
|
||||
var store = {}
|
||||
|
||||
documenterSearchIndex['docs'].forEach(function(e) {
|
||||
store[e.location] = {title: e.title, category: e.category, page: e.page}
|
||||
})
|
||||
|
||||
$(function(){
|
||||
searchresults = $('#documenter-search-results');
|
||||
searchinfo = $('#documenter-search-info');
|
||||
searchbox = $('#documenter-search-query');
|
||||
searchform = $('.docs-search');
|
||||
sidebar = $('.docs-sidebar');
|
||||
function update_search(querystring) {
|
||||
tokens = lunr.tokenizer(querystring)
|
||||
results = index.query(function (q) {
|
||||
tokens.forEach(function (t) {
|
||||
q.term(t.toString(), {
|
||||
fields: ["title"],
|
||||
boost: 100,
|
||||
usePipeline: true,
|
||||
editDistance: 0,
|
||||
wildcard: lunr.Query.wildcard.NONE
|
||||
})
|
||||
q.term(t.toString(), {
|
||||
fields: ["title"],
|
||||
boost: 10,
|
||||
usePipeline: true,
|
||||
editDistance: 2,
|
||||
wildcard: lunr.Query.wildcard.NONE
|
||||
})
|
||||
q.term(t.toString(), {
|
||||
fields: ["text"],
|
||||
boost: 1,
|
||||
usePipeline: true,
|
||||
editDistance: 0,
|
||||
wildcard: lunr.Query.wildcard.NONE
|
||||
})
|
||||
})
|
||||
})
|
||||
searchinfo.text("Number of results: " + results.length)
|
||||
searchresults.empty()
|
||||
results.forEach(function(result) {
|
||||
data = store[result.ref]
|
||||
link = $('<a class="docs-label">'+data.title+'</a>')
|
||||
link.attr('href', documenterBaseURL+'/'+result.ref)
|
||||
if (data.category != "page"){
|
||||
cat = $('<span class="docs-category">('+data.category+', '+data.page+')</span>')
|
||||
} else {
|
||||
cat = $('<span class="docs-category">('+data.category+')</span>')
|
||||
}
|
||||
li = $('<li>').append(link).append(" ").append(cat)
|
||||
searchresults.append(li)
|
||||
})
|
||||
}
|
||||
|
||||
function update_search_box() {
|
||||
querystring = searchbox.val()
|
||||
update_search(querystring)
|
||||
}
|
||||
|
||||
searchbox.keyup(_.debounce(update_search_box, 250))
|
||||
searchbox.change(update_search_box)
|
||||
|
||||
// Disable enter-key form submission for the searchbox on the search page
|
||||
// and just re-run search rather than refresh the whole page.
|
||||
searchform.keypress(
|
||||
function(event){
|
||||
if (event.which == '13') {
|
||||
if (sidebar.hasClass('visible')) {
|
||||
sidebar.removeClass('visible');
|
||||
}
|
||||
update_search_box();
|
||||
event.preventDefault();
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
search_query_uri = parseUri(window.location).queryKey["q"]
|
||||
if(search_query_uri !== undefined) {
|
||||
search_query = decodeURIComponent(search_query_uri.replace(/\+/g, '%20'))
|
||||
searchbox.val(search_query)
|
||||
}
|
||||
update_search_box();
|
||||
})
|
||||
})
|
||||
|
||||
})
|
7702
dev/assets/themes/documenter-dark.css
Normal file
7702
dev/assets/themes/documenter-dark.css
Normal file
File diff suppressed because it is too large
Load diff
7738
dev/assets/themes/documenter-light.css
Normal file
7738
dev/assets/themes/documenter-light.css
Normal file
File diff suppressed because it is too large
Load diff
66
dev/assets/themeswap.js
Normal file
66
dev/assets/themeswap.js
Normal file
|
@ -0,0 +1,66 @@
|
|||
// Small function to quickly swap out themes. Gets put into the <head> tag..
|
||||
function set_theme_from_local_storage() {
|
||||
// Intialize the theme to null, which means default
|
||||
var theme = null;
|
||||
// If the browser supports the localstorage and is not disabled then try to get the
|
||||
// documenter theme
|
||||
if(window.localStorage != null) {
|
||||
// Get the user-picked theme from localStorage. May be `null`, which means the default
|
||||
// theme.
|
||||
theme = window.localStorage.getItem("documenter-theme");
|
||||
}
|
||||
// Check if the browser supports user color preference
|
||||
var darkPreference = false;
|
||||
// Check if the users preference is for dark color scheme
|
||||
if(window.matchMedia('(prefers-color-scheme: dark)').matches === true) {
|
||||
darkPreference = true;
|
||||
}
|
||||
// Initialize a few variables for the loop:
|
||||
//
|
||||
// - active: will contain the index of the theme that should be active. Note that there
|
||||
// is no guarantee that localStorage contains sane values. If `active` stays `null`
|
||||
// we either could not find the theme or it is the default (primary) theme anyway.
|
||||
// Either way, we then need to stick to the primary theme.
|
||||
//
|
||||
// - disabled: style sheets that should be disabled (i.e. all the theme style sheets
|
||||
// that are not the currently active theme)
|
||||
var active = null; var disabled = []; var darkTheme = null;
|
||||
for (var i = 0; i < document.styleSheets.length; i++) {
|
||||
var ss = document.styleSheets[i];
|
||||
// The <link> tag of each style sheet is expected to have a data-theme-name attribute
|
||||
// which must contain the name of the theme. The names in localStorage much match this.
|
||||
var themename = ss.ownerNode.getAttribute("data-theme-name");
|
||||
// attribute not set => non-theme stylesheet => ignore
|
||||
if(themename === null) continue;
|
||||
// To distinguish the default (primary) theme, it needs to have the data-theme-primary
|
||||
// attribute set.
|
||||
var isprimary = (ss.ownerNode.getAttribute("data-theme-primary") !== null);
|
||||
// Check if the theme is primary dark theme
|
||||
var isDarkTheme = (ss.ownerNode.getAttribute("data-theme-primary-dark") !== null);
|
||||
// If ss is for dark theme then set the value of darkTheme to the name of the theme
|
||||
if(isDarkTheme) darkTheme = themename;
|
||||
// If we find a matching theme (and it's not the default), we'll set active to non-null
|
||||
if(themename === theme) active = i;
|
||||
// Store the style sheets of inactive themes so that we could disable them
|
||||
if(themename !== theme) disabled.push(ss);
|
||||
}
|
||||
if(active !== null) {
|
||||
// If we did find an active theme, we'll (1) add the theme--$(theme) class to <html>
|
||||
document.getElementsByTagName('html')[0].className = "theme--" + theme;
|
||||
// and (2) disable all the other theme stylesheets
|
||||
disabled.forEach(function(ss){
|
||||
ss.disabled = true;
|
||||
});
|
||||
}
|
||||
else if(darkTheme !== null && darkPreference === true) {
|
||||
// If we did find an active theme, we'll (1) add the theme--$(theme) class to <html>
|
||||
document.getElementsByTagName('html')[0].className = "theme--" + darkTheme;
|
||||
// and (2) disable all the other theme stylesheets
|
||||
disabled.forEach(function(ss){
|
||||
if (ss.ownerNode.getAttribute("data-theme-name") !== darkTheme) {
|
||||
ss.disabled = true;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
set_theme_from_local_storage();
|
49
dev/assets/warner.js
Normal file
49
dev/assets/warner.js
Normal file
|
@ -0,0 +1,49 @@
|
|||
function maybeAddWarning () {
|
||||
// DOCUMENTER_NEWEST is defined in versions.js, DOCUMENTER_CURRENT_VERSION and DOCUMENTER_STABLE
|
||||
// in siteinfo.js.
|
||||
// If either of these are undefined something went horribly wrong, so we abort.
|
||||
if (
|
||||
window.DOCUMENTER_NEWEST === undefined ||
|
||||
window.DOCUMENTER_CURRENT_VERSION === undefined ||
|
||||
window.DOCUMENTER_STABLE === undefined
|
||||
) {
|
||||
return
|
||||
};
|
||||
|
||||
// Current version is not a version number, so we can't tell if it's the newest version. Abort.
|
||||
if (!/v(\d+\.)*\d+/.test(window.DOCUMENTER_CURRENT_VERSION)) {
|
||||
return
|
||||
};
|
||||
|
||||
// Current version is newest version, so no need to add a warning.
|
||||
if (window.DOCUMENTER_NEWEST === window.DOCUMENTER_CURRENT_VERSION) {
|
||||
return
|
||||
};
|
||||
|
||||
// Add a noindex meta tag (unless one exists) so that search engines don't index this version of the docs.
|
||||
if (document.body.querySelector('meta[name="robots"]') === null) {
|
||||
const meta = document.createElement('meta');
|
||||
meta.name = 'robots';
|
||||
meta.content = 'noindex';
|
||||
|
||||
document.getElementsByTagName('head')[0].appendChild(meta);
|
||||
};
|
||||
|
||||
const div = document.createElement('div');
|
||||
div.classList.add('outdated-warning-overlay');
|
||||
const closer = document.createElement('button');
|
||||
closer.classList.add('outdated-warning-closer', 'delete');
|
||||
closer.addEventListener('click', function () {
|
||||
document.body.removeChild(div);
|
||||
});
|
||||
const href = window.documenterBaseURL + '/../' + window.DOCUMENTER_STABLE;
|
||||
div.innerHTML = 'This documentation is not for the latest stable release, but for either the development version or an older release.<br><a href="' + href + '">Click here to go to the documentation for the latest stable release.</a>';
|
||||
div.appendChild(closer);
|
||||
document.body.appendChild(div);
|
||||
};
|
||||
|
||||
if (document.readyState === 'loading') {
|
||||
document.addEventListener('DOMContentLoaded', maybeAddWarning);
|
||||
} else {
|
||||
maybeAddWarning();
|
||||
};
|
27
dev/index.html
Normal file
27
dev/index.html
Normal file
|
@ -0,0 +1,27 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en"><head><meta charset="UTF-8"/><meta name="viewport" content="width=device-width, initial-scale=1.0"/><title>Public interface · PortAudio.jl</title><script data-outdated-warner src="assets/warner.js"></script><link href="https://cdnjs.cloudflare.com/ajax/libs/lato-font/3.0.0/css/lato-font.min.css" rel="stylesheet" type="text/css"/><link href="https://cdnjs.cloudflare.com/ajax/libs/juliamono/0.045/juliamono.min.css" rel="stylesheet" type="text/css"/><link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.4/css/fontawesome.min.css" rel="stylesheet" type="text/css"/><link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.4/css/solid.min.css" rel="stylesheet" type="text/css"/><link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.4/css/brands.min.css" rel="stylesheet" type="text/css"/><link href="https://cdnjs.cloudflare.com/ajax/libs/KaTeX/0.13.24/katex.min.css" rel="stylesheet" type="text/css"/><script>documenterBaseURL="."</script><script src="https://cdnjs.cloudflare.com/ajax/libs/require.js/2.3.6/require.min.js" data-main="assets/documenter.js"></script><script src="siteinfo.js"></script><script src="../versions.js"></script><link class="docs-theme-link" rel="stylesheet" type="text/css" href="assets/themes/documenter-dark.css" data-theme-name="documenter-dark" data-theme-primary-dark/><link class="docs-theme-link" rel="stylesheet" type="text/css" href="assets/themes/documenter-light.css" data-theme-name="documenter-light" data-theme-primary/><script src="assets/themeswap.js"></script></head><body><div id="documenter"><nav class="docs-sidebar"><div class="docs-package-name"><span class="docs-autofit"><a href>PortAudio.jl</a></span></div><form class="docs-search" action="search/"><input class="docs-search-query" id="documenter-search-query" name="q" type="text" placeholder="Search docs"/></form><ul class="docs-menu"><li class="is-active"><a class="tocitem" href>Public interface</a></li><li><a class="tocitem" href="internals/">Internals</a></li></ul><div class="docs-version-selector field has-addons"><div class="control"><span class="docs-label button is-static is-size-7">Version</span></div><div class="docs-selector control is-expanded"><div class="select is-fullwidth is-size-7"><select id="documenter-version-selector"></select></div></div></div></nav><div class="docs-main"><header class="docs-navbar"><nav class="breadcrumb"><ul class="is-hidden-mobile"><li class="is-active"><a href>Public interface</a></li></ul><ul class="is-hidden-tablet"><li class="is-active"><a href>Public interface</a></li></ul></nav><div class="docs-right"><a class="docs-edit-link" href="https://github.com/JuliaAudio/PortAudio.jl/blob/master/docs/src/index.md" title="Edit on GitHub"><span class="docs-icon fab"></span><span class="docs-label is-hidden-touch">Edit on GitHub</span></a><a class="docs-settings-button fas fa-cog" id="documenter-settings-button" href="#" title="Settings"></a><a class="docs-sidebar-button fa fa-bars is-hidden-desktop" id="documenter-sidebar-button" href="#"></a></div></header><article class="content" id="documenter-page"><h1 id="Public-interface"><a class="docs-heading-anchor" href="#Public-interface">Public interface</a><a id="Public-interface-1"></a><a class="docs-heading-anchor-permalink" href="#Public-interface" title="Permalink"></a></h1><ul><li><a href="#PortAudio.PortAudioStream"><code>PortAudio.PortAudioStream</code></a></li><li><a href="#PortAudio.devices-Tuple{}"><code>PortAudio.devices</code></a></li></ul><article class="docstring"><header><a class="docstring-binding" id="PortAudio.PortAudioStream" href="#PortAudio.PortAudioStream"><code>PortAudio.PortAudioStream</code></a> — <span class="docstring-category">Type</span></header><section><div><pre><code class="language-julia hljs">PortAudioStream(input_channels = 2, output_channels = 2; options...)
|
||||
PortAudioStream(duplex_device, input_channels = 2, output_channels = 2; options...)
|
||||
PortAudioStream(input_device, output_device, input_channels = 2, output_channels = 2; options...)</code></pre><p>Audio devices can either be <code>PortAudioDevice</code> instances as returned by <a href="#PortAudio.devices-Tuple{}"><code>devices</code></a>, or strings with the device name as reported by the operating system. Set <code>input_channels</code> to <code>0</code> for an output only stream; set <code>output_channels</code> to <code>0</code> for an input only steam. If you pass the function <code>maximum</code> instead of a number of channels, use the maximum channels allowed by the corresponding device. If a single <code>duplex_device</code> is given, it will be used for both input and output. If no devices are given, the system default devices will be used.</p><p>The <code>PortAudioStream</code> type supports all the stream and buffer features defined <a href="https://github.com/JuliaAudio/SampledSignals.jl">SampledSignals.jl</a> by default. For example, if you load SampledSignals with <code>using SampledSignals</code> you can read 5 seconds to a buffer with <code>buf = read(stream, 5s)</code>, regardless of the sample rate of the device. <code>write(stream, stream)</code> will set up a loopback that will read from the input and play it back on the output.</p><p>Options:</p><ul><li><code>adjust_channels = false</code>: If set to <code>true</code>, if either <code>input_channels</code> or <code>output_channels</code> exceeds the corresponding device maximum, adjust down to the maximum.</li><li><code>call_back = C_NULL</code>: The PortAudio call-back function. Currently, passing anything except <code>C_NULL</code> is unsupported.</li><li><code>eltype = Float32</code>: Sample type of the audio stream</li><li><code>flags = PortAudio.paNoFlag</code>: PortAudio flags</li><li><code>frames_per_buffer = 128</code>: the number of frames per buffer</li><li><code>input_info = C_NULL</code>: host API specific stream info for the input device. Currently, passing anything except <code>C_NULL</code> is unsupported.</li><li><code>latency = nothing</code>: Requested latency. Stream could underrun when too low, consider using the defaults. If left as <code>nothing</code>, use the defaults below:<ul><li>For input/output only streams, use the corresponding device's default high latency.</li><li>For duplex streams, use the max of the default high latency of the input and output devices.</li></ul></li><li><code>output_info = C_NULL</code>: host API specific stream info for the output device. Currently, passing anything except <code>C_NULL</code> is unsupported.</li><li><code>reader = PortAudio.SampledSignalsReader()</code>: the scribe that will read input. Defaults to a <a href="internals/#PortAudio.SampledSignalsReader"><code>PortAudio.SampledSignalsReader</code></a>. Users can pass custom scribes; see <a href="internals/#PortAudio.Scribe"><code>PortAudio.Scribe</code></a>.</li><li><code>samplerate = nothing</code>: Sample rate. If left as <code>nothing</code>, use the defaults below:<ul><li>For input/output only streams, use the corresponding device's default sample rate.</li><li>For duplex streams, use the default sample rate if the default sample rates for the input and output devices match, otherwise throw an error.</li></ul></li><li><code>warn_xruns = true</code>: Display a warning if there is a stream overrun or underrun, which often happens when Julia is compiling, or with a particularly large GC run. Only affects duplex streams.</li><li><code>writer = PortAudio.SampledSignalsWriter()</code>: the scribe that will write output. Defaults to a <a href="internals/#PortAudio.SampledSignalsReader"><code>PortAudio.SampledSignalsReader</code></a>. Users can pass custom scribes; see <a href="internals/#PortAudio.Scribe"><code>PortAudio.Scribe</code></a>.</li></ul><p><strong>Examples:</strong></p><p>Set up an audio pass-through from microphone to speaker</p><pre><code class="language-julia hljs">julia> using PortAudio, SampledSignals
|
||||
|
||||
julia> stream = PortAudioStream(2, 2; warn_xruns = false);
|
||||
|
||||
julia> try
|
||||
# cancel with Ctrl-C
|
||||
write(stream, stream, 2s)
|
||||
finally
|
||||
close(stream)
|
||||
end</code></pre><p>Use <code>do</code> syntax to auto-close the stream</p><pre><code class="language-julia hljs">julia> using PortAudio, SampledSignals
|
||||
|
||||
julia> PortAudioStream(2, 2; warn_xruns = false) do stream
|
||||
write(stream, stream, 2s)
|
||||
end</code></pre><p>Open devices by name</p><pre><code class="language-julia hljs">using PortAudio, SampledSignals
|
||||
PortAudioStream("Built-in Microph", "Built-in Output"; warn_xruns = false) do stream
|
||||
write(stream, stream, 2s)
|
||||
end
|
||||
2 s</code></pre><p>Record 10 seconds of audio and save to an ogg file</p><pre><code class="language-julia hljs">julia> using PortAudio, SampledSignals, LibSndFile
|
||||
|
||||
julia> PortAudioStream(2, 0; warn_xruns = false) do stream
|
||||
buf = read(stream, 10s)
|
||||
save(joinpath(tempname(), ".ogg"), buf)
|
||||
end
|
||||
2 s</code></pre></div><a class="docs-sourcelink" target="_blank" href="https://github.com/JuliaAudio/PortAudio.jl/blob/06c6fd04959975644e308b23138313bfcfde4765/src/PortAudio.jl#L630-L720">source</a></section></article><article class="docstring"><header><a class="docstring-binding" id="PortAudio.devices-Tuple{}" href="#PortAudio.devices-Tuple{}"><code>PortAudio.devices</code></a> — <span class="docstring-category">Method</span></header><section><div><pre><code class="language-julia hljs">devices()</code></pre><p>List the devices available on your system. Devices will be shown with their internal name, and maximum input and output channels.</p></div><a class="docs-sourcelink" target="_blank" href="https://github.com/JuliaAudio/PortAudio.jl/blob/06c6fd04959975644e308b23138313bfcfde4765/src/PortAudio.jl#L232-L237">source</a></section></article></article><nav class="docs-footer"><a class="docs-footer-nextpage" href="internals/">Internals »</a><div class="flexbox-break"></div><p class="footer-message">Powered by <a href="https://github.com/JuliaDocs/Documenter.jl">Documenter.jl</a> and the <a href="https://julialang.org/">Julia Programming Language</a>.</p></nav></div><div class="modal" id="documenter-settings"><div class="modal-background"></div><div class="modal-card"><header class="modal-card-head"><p class="modal-card-title">Settings</p><button class="delete"></button></header><section class="modal-card-body"><p><label class="label">Theme</label><div class="select"><select id="documenter-themepicker"><option value="documenter-light">documenter-light</option><option value="documenter-dark">documenter-dark</option></select></div></p><hr/><p>This document was generated with <a href="https://github.com/JuliaDocs/Documenter.jl">Documenter.jl</a> version 0.27.22 on <span class="colophon-date" title="Sunday 24 July 2022 15:58">Sunday 24 July 2022</span>. Using Julia version 1.6.7.</p></section><footer class="modal-card-foot"></footer></div></div></div></body></html>
|
2
dev/internals/index.html
Normal file
2
dev/internals/index.html
Normal file
File diff suppressed because one or more lines are too long
2
dev/search/index.html
Normal file
2
dev/search/index.html
Normal file
|
@ -0,0 +1,2 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en"><head><meta charset="UTF-8"/><meta name="viewport" content="width=device-width, initial-scale=1.0"/><title>Search · PortAudio.jl</title><script data-outdated-warner src="../assets/warner.js"></script><link href="https://cdnjs.cloudflare.com/ajax/libs/lato-font/3.0.0/css/lato-font.min.css" rel="stylesheet" type="text/css"/><link href="https://cdnjs.cloudflare.com/ajax/libs/juliamono/0.045/juliamono.min.css" rel="stylesheet" type="text/css"/><link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.4/css/fontawesome.min.css" rel="stylesheet" type="text/css"/><link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.4/css/solid.min.css" rel="stylesheet" type="text/css"/><link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.4/css/brands.min.css" rel="stylesheet" type="text/css"/><link href="https://cdnjs.cloudflare.com/ajax/libs/KaTeX/0.13.24/katex.min.css" rel="stylesheet" type="text/css"/><script>documenterBaseURL=".."</script><script src="https://cdnjs.cloudflare.com/ajax/libs/require.js/2.3.6/require.min.js" data-main="../assets/documenter.js"></script><script src="../siteinfo.js"></script><script src="../../versions.js"></script><link class="docs-theme-link" rel="stylesheet" type="text/css" href="../assets/themes/documenter-dark.css" data-theme-name="documenter-dark" data-theme-primary-dark/><link class="docs-theme-link" rel="stylesheet" type="text/css" href="../assets/themes/documenter-light.css" data-theme-name="documenter-light" data-theme-primary/><script src="../assets/themeswap.js"></script></head><body><div id="documenter"><nav class="docs-sidebar"><div class="docs-package-name"><span class="docs-autofit"><a href="../">PortAudio.jl</a></span></div><form class="docs-search" action><input class="docs-search-query" id="documenter-search-query" name="q" type="text" placeholder="Search docs"/></form><ul class="docs-menu"><li><a class="tocitem" href="../">Public interface</a></li><li><a class="tocitem" href="../internals/">Internals</a></li></ul><div class="docs-version-selector field has-addons"><div class="control"><span class="docs-label button is-static is-size-7">Version</span></div><div class="docs-selector control is-expanded"><div class="select is-fullwidth is-size-7"><select id="documenter-version-selector"></select></div></div></div></nav><div class="docs-main"><header class="docs-navbar"><nav class="breadcrumb"><ul class="is-hidden-mobile"><li class="is-active"><a href>Search</a></li></ul><ul class="is-hidden-tablet"><li class="is-active"><a href>Search</a></li></ul></nav><div class="docs-right"><a class="docs-settings-button fas fa-cog" id="documenter-settings-button" href="#" title="Settings"></a><a class="docs-sidebar-button fa fa-bars is-hidden-desktop" id="documenter-sidebar-button" href="#"></a></div></header><article><p id="documenter-search-info">Loading search...</p><ul id="documenter-search-results"></ul></article><nav class="docs-footer"><p class="footer-message">Powered by <a href="https://github.com/JuliaDocs/Documenter.jl">Documenter.jl</a> and the <a href="https://julialang.org/">Julia Programming Language</a>.</p></nav></div><div class="modal" id="documenter-settings"><div class="modal-background"></div><div class="modal-card"><header class="modal-card-head"><p class="modal-card-title">Settings</p><button class="delete"></button></header><section class="modal-card-body"><p><label class="label">Theme</label><div class="select"><select id="documenter-themepicker"><option value="documenter-light">documenter-light</option><option value="documenter-dark">documenter-dark</option></select></div></p><hr/><p>This document was generated with <a href="https://github.com/JuliaDocs/Documenter.jl">Documenter.jl</a> version 0.27.22 on <span class="colophon-date" title="Sunday 24 July 2022 15:58">Sunday 24 July 2022</span>. Using Julia version 1.6.7.</p></section><footer class="modal-card-foot"></footer></div></div></div></body><script src="../search_index.js"></script><script src="../assets/search.js"></script></html>
|
3
dev/search_index.js
Normal file
3
dev/search_index.js
Normal file
File diff suppressed because one or more lines are too long
1
dev/siteinfo.js
Normal file
1
dev/siteinfo.js
Normal file
|
@ -0,0 +1 @@
|
|||
var DOCUMENTER_CURRENT_VERSION = "dev";
|
|
@ -1,2 +0,0 @@
|
|||
[deps]
|
||||
Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4"
|
12
docs/make.jl
12
docs/make.jl
|
@ -1,12 +0,0 @@
|
|||
using PortAudio
|
||||
using Documenter: deploydocs, makedocs
|
||||
|
||||
makedocs(
|
||||
sitename = "PortAudio.jl",
|
||||
modules = [PortAudio],
|
||||
pages = [
|
||||
"Public interface" => "index.md",
|
||||
"Internals" => "internals.md"
|
||||
]
|
||||
)
|
||||
deploydocs(repo = "github.com/JuliaAudio/PortAudio.jl.git")
|
|
@ -1,10 +0,0 @@
|
|||
# Public interface
|
||||
|
||||
```@index
|
||||
Pages = ["index.md"]
|
||||
```
|
||||
|
||||
```@autodocs
|
||||
Modules = [PortAudio]
|
||||
Private = false
|
||||
```
|
|
@ -1,10 +0,0 @@
|
|||
# Internals
|
||||
|
||||
```@index
|
||||
Pages = ["internals.md"]
|
||||
```
|
||||
|
||||
```@autodocs
|
||||
Modules = [PortAudio]
|
||||
Public = false
|
||||
```
|
|
@ -1,55 +0,0 @@
|
|||
using PortAudio
|
||||
|
||||
"""
|
||||
Continuously read from the default audio input and plot an
|
||||
ASCII level/peak meter
|
||||
"""
|
||||
function micmeter(metersize)
|
||||
mic = PortAudioStream(1, 0; latency = 0.1)
|
||||
|
||||
signalmax = zero(eltype(mic))
|
||||
println("Press Ctrl-C to quit")
|
||||
while true
|
||||
block = read(mic, 512)
|
||||
blockmax = maximum(abs.(block)) # find the maximum value in the block
|
||||
signalmax = max(signalmax, blockmax) # keep the maximum value ever
|
||||
print("\r") # reset the cursor to the beginning of the line
|
||||
printmeter(metersize, blockmax, signalmax)
|
||||
end
|
||||
end
|
||||
|
||||
"""
|
||||
Print an ASCII level meter of the given size. Signal and peak
|
||||
levels are assumed to be scaled from 0.0-1.0, with peak >= signal
|
||||
"""
|
||||
function printmeter(metersize, signal, peak)
|
||||
# calculate the positions in terms of characters
|
||||
peakpos = clamp(round(Int, peak * metersize), 0, metersize)
|
||||
meterchars = clamp(round(Int, signal * metersize), 0, peakpos - 1)
|
||||
blankchars = max(0, peakpos - meterchars - 1)
|
||||
|
||||
for position in 1:meterchars
|
||||
printstyled(">", color = barcolor(metersize, position))
|
||||
end
|
||||
|
||||
print(" "^blankchars)
|
||||
printstyled("|", color = barcolor(metersize, peakpos))
|
||||
print(" "^(metersize - peakpos))
|
||||
end
|
||||
|
||||
"""
|
||||
Compute the proper color for a given position in the bar graph. The first
|
||||
half of the bar should be green, then the remainder is yellow except the final
|
||||
character, which is red.
|
||||
"""
|
||||
function barcolor(metersize, position)
|
||||
if position / metersize <= 0.5
|
||||
:green
|
||||
elseif position == metersize
|
||||
:red
|
||||
else
|
||||
:yellow
|
||||
end
|
||||
end
|
||||
|
||||
micmeter(80)
|
|
@ -1,179 +0,0 @@
|
|||
using Distributed, PortAudio
|
||||
|
||||
# Modified from Jiahao Chen's example in the obsolete AudioIO module.
|
||||
# Will use first output device found in system's listing or DEFAULTDEVICE if set below
|
||||
const DEFAULTDEVICE = -1
|
||||
|
||||
function paudio()
|
||||
devs = PortAudio.devices()
|
||||
if DEFAULTDEVICE < 0
|
||||
devnum = findfirst(x -> x.maxoutchans > 0, devs)
|
||||
(devnum == nothing) && error("No output device for audio found")
|
||||
else
|
||||
devnum = DEFAULTDEVICE + 1
|
||||
end
|
||||
return ostream = PortAudioStream(devs[devnum].name, 0, 2)
|
||||
end
|
||||
|
||||
play(ostream, sample::Array{Float64, 1}) = write(ostream, sample)
|
||||
play(ostr, sample::Array{Int64, 1}) = play(ostr, Float64.(sample))
|
||||
|
||||
struct Note{S <: Real, T <: Real}
|
||||
pitch::S
|
||||
duration::T
|
||||
sustained::Bool
|
||||
end
|
||||
|
||||
function play(
|
||||
ostream,
|
||||
A::Note,
|
||||
samplingfreq::Real = 44100,
|
||||
shape::Function = t -> 0.6sin(t) + 0.2sin(2t) + 0.05 * sin(8t),
|
||||
)
|
||||
timesamples = 0:(1 / samplingfreq):(A.duration * (A.sustained ? 0.98 : 0.9))
|
||||
v = Float64[shape(2π * A.pitch * t) for t in timesamples]
|
||||
if !A.sustained
|
||||
decay_length = div(length(timesamples), 5)
|
||||
v[(end - decay_length):(end - 1)] =
|
||||
v[(end - decay_length):(end - 1)] .* LinRange(1, 0, decay_length)
|
||||
end
|
||||
play(ostream, v)
|
||||
sleep(A.duration)
|
||||
end
|
||||
|
||||
function parsevoice(melody::String; tempo = 132, beatunit = 4, lyrics = nothing)
|
||||
ostream = paudio() # initialize audio for output
|
||||
lyrics_syllables = lyrics == nothing ? nothing : split(lyrics)
|
||||
lyrics_syllables != nothing && (lyrics_syllables[end] *= "\n")
|
||||
note_idx = 1
|
||||
oldduration = 4
|
||||
for line in split(melody, '\n')
|
||||
percent_idx = findfirst('%', line) # Trim comment
|
||||
percent_idx == nothing || (line = line[1:(percent_idx - 1)])
|
||||
for token in split(line)
|
||||
pitch, duration, dotted, sustained = parsetoken(token)
|
||||
duration == nothing && (duration = oldduration)
|
||||
oldduration = duration
|
||||
dotted && (duration *= 1.5)
|
||||
if lyrics_syllables != nothing && 1 <= note_idx <= length(lyrics_syllables)
|
||||
# Print the lyrics, omitting hyphens
|
||||
if lyrics_syllables[note_idx][end] == '-'
|
||||
print(join(split(lyrics_syllables[note_idx][:], "")[1:(end - 1)]), "")
|
||||
else
|
||||
print(lyrics_syllables[note_idx], ' ')
|
||||
end
|
||||
end
|
||||
play(ostream, Note(pitch, (beatunit / duration) * (60 / tempo), sustained))
|
||||
note_idx += 1
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function parsetoken(token, Atuning::Real = 220)
|
||||
state = :findpitch
|
||||
pitch = 0.0
|
||||
sustain = dotted = false
|
||||
lengthbuf = Char[]
|
||||
for char in token
|
||||
if state == :findpitch
|
||||
scale_idx =
|
||||
something(findfirst(char, String(collect('a':'g'))), 0) +
|
||||
something(findfirst(char, String(collect('A':'G'))), 0)
|
||||
if scale_idx != 0
|
||||
halfsteps = [12, 14, 3, 5, 7, 8, 10]
|
||||
pitch = Atuning * 2^(halfsteps[scale_idx] / 12)
|
||||
state = :findlength
|
||||
elseif char == 'r'
|
||||
pitch, state = 0, :findlength
|
||||
else
|
||||
error("unknown pitch: $char")
|
||||
end
|
||||
elseif state == :findlength
|
||||
if char == '#'
|
||||
pitch *= 2^(1 / 12) # sharp
|
||||
elseif char == 'b'
|
||||
pitch /= 2^(1 / 12) # flat
|
||||
elseif char == '\''
|
||||
pitch *= 2 # higher octave
|
||||
elseif char == ','
|
||||
pitch /= 2 # lower octave
|
||||
elseif char == '.'
|
||||
dotted = true # dotted note
|
||||
elseif char == '~'
|
||||
sustain = true # tied note
|
||||
else
|
||||
push!(lengthbuf, char)
|
||||
# Check for "is" and "es" suffixes for sharps and flats
|
||||
if length(lengthbuf) >= 2
|
||||
if lengthbuf[(end - 1):end] == "is"
|
||||
pitch *= 2^(1 / 12)
|
||||
lengthbuf = lengthbuf[1:(end - 2)]
|
||||
elseif lengthbuf[(end - 1):end] == "es"
|
||||
pitch /= 2^(1 / 12)
|
||||
lengthbuf = lengthbuf[1:(end - 2)]
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
#finalize length
|
||||
lengthstr = String(lengthbuf)
|
||||
duration = isempty(lengthstr) ? nothing : tryparse(Int, lengthstr)
|
||||
return (pitch, duration, sustain, dotted)
|
||||
end
|
||||
|
||||
parsevoice(
|
||||
"""
|
||||
f# f# g a a g f# e d d e f# f#~ f#8 e e2
|
||||
f#4 f# g a a g f# e d d e f# e~ e8 d d2
|
||||
e4 e f# d e f#8~ g8 f#4 d e f#8~ g f#4 e d e a,
|
||||
f#2 f#4 g a a g f# e d d e f# e~ e8 d8 d2""",
|
||||
lyrics = """
|
||||
Freu- de, schö- ner Göt- ter- fun- ken, Toch- ter aus E- li- - si- um!
|
||||
Wir be- tre- ten feu- er- trun- ken, Himm- li- sche, dein Hei- - lig- thum!
|
||||
Dei- ne Zau- ber bin den - wie- der, was die - Mo- de streng ge- theilt,
|
||||
al- le mensch- en wer- den Brü- der wo dein sanf- ter Flü- - gel weilt.
|
||||
""",
|
||||
)
|
||||
|
||||
# And now with harmony!
|
||||
|
||||
soprano = @spawn parsevoice(
|
||||
"""
|
||||
f'#. f'#. g'. a'. a'. g'. f'#. e'~ e'8 d.'4 d.' e.' f#'. f#'.~ f#' e'8 e'4~ e'2
|
||||
""",
|
||||
lyrics = "Freu- de, schö- ner Göt- ter- fun- ken, Toch- ter aus E- li- - si- um!",
|
||||
)
|
||||
alto = @spawn parsevoice("""
|
||||
a. a. a. a. a. a. a. a~ g8 f#.4 a. a. a. a.~ a a8 a4~ a2
|
||||
""")
|
||||
tenor = @spawn parsevoice("""
|
||||
d. d. e. f#. f#. e. d. d~ e8 f#.4 f#. a,. d. d.~ d c#8 c#4 c#2
|
||||
""")
|
||||
bass = @spawn parsevoice("""
|
||||
d. d. d. d. a,. a,. a,. b,~ c8 d. a., a., a., a., a, a8, a,4 a,2
|
||||
""")
|
||||
wait(soprano)
|
||||
wait(alto)
|
||||
wait(tenor)
|
||||
wait(bass)
|
||||
|
||||
soprano = @spawn parsevoice(
|
||||
"""
|
||||
f'#.4 f'#. g'. a'. a'. g'. f'#. e'. d'. d'. e'. f'#. e'.~ e' d'8 d'4~ d'2
|
||||
""",
|
||||
lyrics = "Wir be- tre- ten feu- er- trun- ken, Himm- li- sche, dein Hei- - lig- thum!",
|
||||
)
|
||||
alto = @spawn parsevoice("""
|
||||
a.4 a. b. c'. c'. b. a. g. f#. f#. g. f#. g.~ g4 f#8 f#~ f#2
|
||||
""")
|
||||
tenor = @spawn parsevoice("""
|
||||
d.4 d. d. d. d. d. d. d. d. d. c#. d. c#.~ c# d8 d d2
|
||||
""")
|
||||
bass = @spawn parsevoice("""
|
||||
d.4 d. d. d. a,. a,. a,. a., a., a., a., a., a.,~ a, a,8 d, d,2
|
||||
""")
|
||||
wait(soprano)
|
||||
wait(alto)
|
||||
wait(tenor)
|
||||
wait(bass)
|
|
@ -1,65 +0,0 @@
|
|||
using PortAudio
|
||||
using DSP
|
||||
|
||||
function create_measure_signal()
|
||||
signal = zeros(Float32, 20000)
|
||||
for i in 1:3
|
||||
signal = vcat(signal, rand(Float32, 100), zeros(Float32, i * 10000))
|
||||
end
|
||||
return signal
|
||||
end
|
||||
|
||||
function measure_latency(in_latency = 0.1, out_latency = 0.1; is_warmup = false)
|
||||
in_stream = PortAudioStream(1, 0; latency = in_latency)
|
||||
out_stream = PortAudioStream(0, 1; latency = out_latency)
|
||||
|
||||
cond = Base.Event()
|
||||
|
||||
writer_start_time = Int64(0)
|
||||
reader_start_time = Int64(0)
|
||||
|
||||
reader = Threads.@spawn begin
|
||||
wait(cond)
|
||||
writer_start_time = time_ns() |> Int64
|
||||
return read(in_stream, 100000)
|
||||
end
|
||||
|
||||
signal = create_measure_signal()
|
||||
writer = Threads.@spawn begin
|
||||
wait(cond)
|
||||
reader_start_time = time_ns() |> Int64
|
||||
write(out_stream, signal)
|
||||
end
|
||||
|
||||
notify(cond)
|
||||
|
||||
wait(reader)
|
||||
wait(writer)
|
||||
|
||||
recorded = collect(reader.result)[:, 1]
|
||||
|
||||
close(in_stream)
|
||||
close(out_stream)
|
||||
|
||||
diff = reader_start_time - writer_start_time |> abs
|
||||
|
||||
diff_in_ms = diff / 10^6 # 1 ms = 10^6 ns
|
||||
|
||||
if !is_warmup && diff_in_ms > 1
|
||||
@warn "Threads start time difference $diff_in_ms ms is bigger than 1 ms"
|
||||
end
|
||||
|
||||
delay = finddelay(recorded, signal) / 48000
|
||||
|
||||
return trunc(Int, delay * 1000)# result in ms
|
||||
end
|
||||
|
||||
measure_latency(0.1, 0.1; is_warmup = true) # warmup
|
||||
|
||||
latencies = [0.1, 0.01, 0.005]
|
||||
for in_latency in latencies
|
||||
for out_latency in latencies
|
||||
measure = measure_latency(in_latency, out_latency)
|
||||
println("$measure ms latency for in_latency=$in_latency, out_latency=$out_latency")
|
||||
end
|
||||
end
|
|
@ -1,89 +0,0 @@
|
|||
#=
|
||||
This code illustrates real-time octave down shift
|
||||
using a crude FFT-based method.
|
||||
It also plots the input and output signals and their spectra.
|
||||
|
||||
This code uses the system defaults for the audio input and output devices.
|
||||
If you use the built-in speakers and built-in microphone,
|
||||
you will likely get undesirable audio feedback.
|
||||
|
||||
It works "best" if you play the audio output through headphones
|
||||
so that the output does not feed back into the input.
|
||||
|
||||
The spectrum plotting came from the example in
|
||||
https://github.com/JuliaAudio/PortAudio.jl/blob/master/examples
|
||||
=#
|
||||
|
||||
using PortAudio: PortAudioStream
|
||||
using SampledSignals: Hz, domain
|
||||
using SampledSignals: (..) # see EllipsisNotation.jl and IntervalSets.jl
|
||||
using FFTW: fft, ifft
|
||||
using Plots: plot, gui, default; default(label="")
|
||||
|
||||
|
||||
function pitch_halver(x) # decrease pitch by one octave via FFT
|
||||
N = length(x)
|
||||
mod(N,2) == 0 || throw("N must be multiple of 2")
|
||||
F = fft(x) # original spectrum
|
||||
Fnew = [F[1:N÷2]; zeros(N+1); F[(N÷2+2):N]]
|
||||
out = 2 * real(ifft(Fnew))[1:N]
|
||||
out.samplerate /= 2 # trick!
|
||||
return out
|
||||
end
|
||||
|
||||
|
||||
# Plot input and output signals and their spectra.
|
||||
# Quantize the vertical axis limits to reduce plot jitter.
|
||||
function plotter(buf, out, N, fmin, fmax, fs; quant::Number = 0.1)
|
||||
bmax = quant * ceil(maximum(abs, buf) / quant)
|
||||
xticks = [1, N]; ylims = (-1,1) .* bmax; yticks = (-1:1)*bmax
|
||||
p1 = plot(buf; xticks, ylims, yticks, title="input")
|
||||
p3 = plot(out; xticks, ylims, yticks, title="output")
|
||||
|
||||
X = (2/N) * abs.(fft(buf)[fmin..fmax]) # spectrum
|
||||
Xmax = quant * ceil(maximum(X) / quant)
|
||||
xlims = (fs[1], fs[end]); ylims = (0, Xmax); yticks = [0,Xmax]
|
||||
p2 = plot(fs, X; xlims, ylims, yticks)
|
||||
|
||||
Y = (2/N) * abs.(fft(out)[fmin..fmax])
|
||||
p4 = plot(fs, Y; xlims, ylims, yticks)
|
||||
|
||||
plot(p1, p2, p3, p4)
|
||||
end
|
||||
|
||||
|
||||
"""
|
||||
octave_shift(seconds; N, ...)
|
||||
|
||||
Shift audio down by one octave.
|
||||
|
||||
# Input
|
||||
* `seconds` : how long to run in seconds; defaults to 300 (5 minutes)
|
||||
|
||||
# Options
|
||||
* `N` : buffer size; default 1024 samples
|
||||
* `fmin`,`fmax` : range of frequencies to display; default 0Hz to 4000Hz
|
||||
"""
|
||||
function octave_shift(
|
||||
seconds::Number = 300;
|
||||
N::Int = 1024,
|
||||
fmin::Number = 0Hz,
|
||||
fmax::Number = 4000Hz,
|
||||
# undocumented options below here that are unlikely to be modified
|
||||
in_stream = PortAudioStream(1, 0), # default input device
|
||||
out_stream = PortAudioStream(0, 1), # default output device
|
||||
buf::AbstractArray = read(in_stream, N), # warm-up
|
||||
fs = Float32[float(f) for f in domain(fft(buf)[fmin..fmax])],
|
||||
Niters::Int = ceil(Int, seconds * in_stream.sample_rate / N),
|
||||
)
|
||||
|
||||
for _ in 1:Niters
|
||||
read!(in_stream, buf)
|
||||
out = pitch_halver(buf) # decrease pitch by one octave
|
||||
write(out_stream, out)
|
||||
plotter(buf, out, N, fmin, fmax, fs); gui()
|
||||
end
|
||||
nothing
|
||||
end
|
||||
|
||||
octave_shift(5)
|
|
@ -1,20 +0,0 @@
|
|||
# plot a real-time spectrogram. This example is adapted from the GR example
|
||||
# at http://gr-framework.org/examples/audio_ex.html
|
||||
|
||||
module SpectrumExample
|
||||
|
||||
using GR, PortAudio, SampledSignals, FFTW
|
||||
|
||||
const N = 1024
|
||||
const stream = PortAudioStream(1, 0)
|
||||
const buf = read(stream, N)
|
||||
const fmin = 0Hz
|
||||
const fmax = 10000Hz
|
||||
const fs = Float32[float(f) for f in domain(fft(buf)[fmin..fmax])]
|
||||
|
||||
while true
|
||||
read!(stream, buf)
|
||||
plot(fs, abs.(fft(buf)[fmin..fmax]), xlim = (fs[1], fs[end]), ylim = (0, 100))
|
||||
end
|
||||
|
||||
end
|
|
@ -1,21 +0,0 @@
|
|||
#=
|
||||
This example illustrates synthesizing a long tone in small pieces
|
||||
and routing it to the default audio output device using `write()`.
|
||||
=#
|
||||
|
||||
using PortAudio: PortAudioStream, write
|
||||
|
||||
stream = PortAudioStream(0, 1; warn_xruns=false)
|
||||
|
||||
function play_tone(stream, freq::Real, duration::Real; buf_size::Int = 1024)
|
||||
S = stream.sample_rate
|
||||
current = 1
|
||||
while current < duration*S
|
||||
x = 0.7 * sin.(2π * (current .+ (1:buf_size)) * freq / S)
|
||||
write(stream, x)
|
||||
current += buf_size
|
||||
end
|
||||
nothing
|
||||
end
|
||||
|
||||
play_tone(stream, 440, 2)
|
|
@ -1,67 +0,0 @@
|
|||
using Makie
|
||||
using PortAudio
|
||||
using DSP
|
||||
|
||||
"""
|
||||
Slide the values in the given matrix to the right by 1.
|
||||
The rightmosts column is discarded and the leftmost column is
|
||||
left alone.
|
||||
"""
|
||||
function shift1!(buf::AbstractMatrix)
|
||||
for col in size(buf, 2):-1:2
|
||||
@. buf[:, col] = buf[:, col - 1]
|
||||
end
|
||||
end
|
||||
|
||||
"""
|
||||
takes a block of audio, FFT it, and write it to the beginning of the buffer
|
||||
"""
|
||||
function processbuf!(readbuf, win, dispbuf, fftbuf, fftplan)
|
||||
readbuf .*= win
|
||||
A_mul_B!(fftbuf, fftplan, readbuf)
|
||||
shift1!(dispbuf)
|
||||
@. dispbuf[end:-1:1, 1] = log(clamp(abs(fftbuf[1:D]), 0.0001, Inf))
|
||||
end
|
||||
|
||||
function processblock!(src, buf, win, dispbufs, fftbuf, fftplan)
|
||||
read!(src, buf)
|
||||
for dispbuf in dispbufs
|
||||
processbuf!(buf, win, dispbuf, fftbuf, fftplan)
|
||||
end
|
||||
end
|
||||
|
||||
N = 1024 # size of audio read
|
||||
N2 = N ÷ 2 + 1 # size of rfft output
|
||||
D = 200 # number of bins to display
|
||||
M = 200 # amount of history to keep
|
||||
src = PortAudioStream(1, 2)
|
||||
buf = Array{Float32}(N) # buffer for reading
|
||||
fftplan = plan_rfft(buf; flags = FFTW.EXHAUSTIVE)
|
||||
fftbuf = Array{Complex{Float32}}(N2) # destination buf for FFT
|
||||
dispbufs = [zeros(Float32, D, M) for i in 1:5, j in 1:5] # STFT bufs
|
||||
win = gaussian(N, 0.125)
|
||||
|
||||
scene = Scene(resolution = (1000, 1000))
|
||||
|
||||
#pre-fill the display buffer so we can do a reasonable colormap
|
||||
for _ in 1:M
|
||||
processblock!(src, buf, win, dispbufs, fftbuf, fftplan)
|
||||
end
|
||||
|
||||
heatmaps = map(enumerate(IndexCartesian(), dispbufs)) do ibuf
|
||||
i = ibuf[1]
|
||||
buf = ibuf[2]
|
||||
|
||||
# some function of the 2D index and the value
|
||||
heatmap(buf, offset = (i[2] * size(buf, 2), i[1] * size(buf, 1)))
|
||||
end
|
||||
|
||||
center!(scene)
|
||||
|
||||
while isopen(scene[:screen])
|
||||
processblock!(src, buf, dispbufs, fftbuf, fftplan)
|
||||
for (hm, db) in zip(heatmaps, dispbufs)
|
||||
hm[:heatmap] = db
|
||||
end
|
||||
render_frame(scene)
|
||||
end
|
|
@ -1,43 +0,0 @@
|
|||
using Makie, GeometryTypes
|
||||
using PortAudio
|
||||
|
||||
N = 1024 # size of audio read
|
||||
N2 = N ÷ 2 + 1 # size of rfft output
|
||||
D = 200 # number of bins to display
|
||||
M = 100 # number of lines to draw
|
||||
S = 0.5 # motion speed of lines
|
||||
src = PortAudioStream(1, 2)
|
||||
buf = Array{Float32}(N)
|
||||
fftbuf = Array{Complex{Float32}}(N2)
|
||||
magbuf = Array{Float32}(N2)
|
||||
fftplan = plan_rfft(buf; flags = FFTW.EXHAUSTIVE)
|
||||
|
||||
scene = Scene(resolution = (500, 500))
|
||||
ax = axis(0:0.1:1, 0:0.1:1, 0:0.1:0.5)
|
||||
center!(scene)
|
||||
|
||||
ls = map(1:M) do _
|
||||
yoffset = to_node(to_value(scene[:time]))
|
||||
offset = lift_node(scene[:time], yoffset) do t, yoff
|
||||
Point3f0(0.0f0, (t - yoff) * S, 0.0f0)
|
||||
end
|
||||
l = lines(
|
||||
linspace(0, 1, D),
|
||||
0.0f0,
|
||||
zeros(Float32, D),
|
||||
offset = offset,
|
||||
color = (:black, 0.1),
|
||||
)
|
||||
(yoffset, l)
|
||||
end
|
||||
|
||||
while isopen(scene[:screen])
|
||||
for (yoffset, line) in ls
|
||||
isopen(scene[:screen]) || break
|
||||
read!(src, buf)
|
||||
A_mul_B!(fftbuf, fftplan, buf)
|
||||
@. magbuf = log(clamp(abs(fftbuf), 0.0001, Inf)) / 10 + 0.5
|
||||
line[:z] = magbuf[1:D]
|
||||
push!(yoffset, to_value(scene[:time]))
|
||||
end
|
||||
end
|
|
@ -1 +0,0 @@
|
|||
The clang generators will automatically generate wrappers for a C library based on its headers. So everything you see in libportaudio.jl is automatically generated from the C library. If a newer version of portaudio adds more features, we won't have to add new wrappers: clang will handle it for us. It is easy to use currently unused features: the wrappers have already been written for us. Even though it does an admirable job, clang doesn't handle errors and set locks. Fortunately, it's very easy to add secondary wrappers, or just do it at point of use.
|
|
@ -1,16 +0,0 @@
|
|||
using Clang.Generators
|
||||
using libportaudio_jll
|
||||
|
||||
cd(@__DIR__)
|
||||
|
||||
include_dir = joinpath(libportaudio_jll.artifact_dir, "include") |> normpath
|
||||
portaudio_h = joinpath(include_dir, "portaudio.h")
|
||||
|
||||
options = load_options(joinpath(@__DIR__, "generator.toml"))
|
||||
|
||||
args = get_default_args()
|
||||
push!(args, "-I$include_dir")
|
||||
|
||||
ctx = create_context(portaudio_h, args, options)
|
||||
|
||||
build!(ctx)
|
|
@ -1,9 +0,0 @@
|
|||
[general]
|
||||
library_name = "libportaudio"
|
||||
output_file_path = "../src/LibPortAudio.jl"
|
||||
module_name = "LibPortAudio"
|
||||
jll_pkg_name = "libportaudio_jll"
|
||||
export_symbol_prefixes = ["Pa", "pa"]
|
||||
|
||||
use_julia_native_enum_type = true
|
||||
auto_mutability = true
|
2
index.html
Normal file
2
index.html
Normal file
|
@ -0,0 +1,2 @@
|
|||
<!--This file is automatically generated by Documenter.jl-->
|
||||
<meta http-equiv="refresh" content="0; url=./dev/"/>
|
1069
src/PortAudio.jl
1069
src/PortAudio.jl
File diff suppressed because it is too large
Load diff
|
@ -1,439 +0,0 @@
|
|||
module LibPortAudio
|
||||
|
||||
using libportaudio_jll
|
||||
export libportaudio_jll
|
||||
|
||||
function Pa_GetVersion()
|
||||
ccall((:Pa_GetVersion, libportaudio), Cint, ())
|
||||
end
|
||||
|
||||
function Pa_GetVersionText()
|
||||
ccall((:Pa_GetVersionText, libportaudio), Ptr{Cchar}, ())
|
||||
end
|
||||
|
||||
mutable struct PaVersionInfo
|
||||
versionMajor::Cint
|
||||
versionMinor::Cint
|
||||
versionSubMinor::Cint
|
||||
versionControlRevision::Ptr{Cchar}
|
||||
versionText::Ptr{Cchar}
|
||||
end
|
||||
|
||||
# no prototype is found for this function at portaudio.h:114:22, please use with caution
|
||||
function Pa_GetVersionInfo()
|
||||
ccall((:Pa_GetVersionInfo, libportaudio), Ptr{PaVersionInfo}, ())
|
||||
end
|
||||
|
||||
const PaError = Cint
|
||||
|
||||
@enum PaErrorCode::Int32 begin
|
||||
paNoError = 0
|
||||
paNotInitialized = -10000
|
||||
paUnanticipatedHostError = -9999
|
||||
paInvalidChannelCount = -9998
|
||||
paInvalidSampleRate = -9997
|
||||
paInvalidDevice = -9996
|
||||
paInvalidFlag = -9995
|
||||
paSampleFormatNotSupported = -9994
|
||||
paBadIODeviceCombination = -9993
|
||||
paInsufficientMemory = -9992
|
||||
paBufferTooBig = -9991
|
||||
paBufferTooSmall = -9990
|
||||
paNullCallback = -9989
|
||||
paBadStreamPtr = -9988
|
||||
paTimedOut = -9987
|
||||
paInternalError = -9986
|
||||
paDeviceUnavailable = -9985
|
||||
paIncompatibleHostApiSpecificStreamInfo = -9984
|
||||
paStreamIsStopped = -9983
|
||||
paStreamIsNotStopped = -9982
|
||||
paInputOverflowed = -9981
|
||||
paOutputUnderflowed = -9980
|
||||
paHostApiNotFound = -9979
|
||||
paInvalidHostApi = -9978
|
||||
paCanNotReadFromACallbackStream = -9977
|
||||
paCanNotWriteToACallbackStream = -9976
|
||||
paCanNotReadFromAnOutputOnlyStream = -9975
|
||||
paCanNotWriteToAnInputOnlyStream = -9974
|
||||
paIncompatibleStreamHostApi = -9973
|
||||
paBadBufferPtr = -9972
|
||||
end
|
||||
|
||||
function Pa_GetErrorText(errorCode)
|
||||
ccall((:Pa_GetErrorText, libportaudio), Ptr{Cchar}, (PaError,), errorCode)
|
||||
end
|
||||
|
||||
function Pa_Initialize()
|
||||
ccall((:Pa_Initialize, libportaudio), PaError, ())
|
||||
end
|
||||
|
||||
function Pa_Terminate()
|
||||
ccall((:Pa_Terminate, libportaudio), PaError, ())
|
||||
end
|
||||
|
||||
const PaDeviceIndex = Cint
|
||||
|
||||
const PaHostApiIndex = Cint
|
||||
|
||||
function Pa_GetHostApiCount()
|
||||
ccall((:Pa_GetHostApiCount, libportaudio), PaHostApiIndex, ())
|
||||
end
|
||||
|
||||
function Pa_GetDefaultHostApi()
|
||||
ccall((:Pa_GetDefaultHostApi, libportaudio), PaHostApiIndex, ())
|
||||
end
|
||||
|
||||
@enum PaHostApiTypeId::UInt32 begin
|
||||
paInDevelopment = 0
|
||||
paDirectSound = 1
|
||||
paMME = 2
|
||||
paASIO = 3
|
||||
paSoundManager = 4
|
||||
paCoreAudio = 5
|
||||
paOSS = 7
|
||||
paALSA = 8
|
||||
paAL = 9
|
||||
paBeOS = 10
|
||||
paWDMKS = 11
|
||||
paJACK = 12
|
||||
paWASAPI = 13
|
||||
paAudioScienceHPI = 14
|
||||
end
|
||||
|
||||
mutable struct PaHostApiInfo
|
||||
structVersion::Cint
|
||||
type::PaHostApiTypeId
|
||||
name::Ptr{Cchar}
|
||||
deviceCount::Cint
|
||||
defaultInputDevice::PaDeviceIndex
|
||||
defaultOutputDevice::PaDeviceIndex
|
||||
end
|
||||
|
||||
function Pa_GetHostApiInfo(hostApi)
|
||||
ccall(
|
||||
(:Pa_GetHostApiInfo, libportaudio),
|
||||
Ptr{PaHostApiInfo},
|
||||
(PaHostApiIndex,),
|
||||
hostApi,
|
||||
)
|
||||
end
|
||||
|
||||
function Pa_HostApiTypeIdToHostApiIndex(type)
|
||||
ccall(
|
||||
(:Pa_HostApiTypeIdToHostApiIndex, libportaudio),
|
||||
PaHostApiIndex,
|
||||
(PaHostApiTypeId,),
|
||||
type,
|
||||
)
|
||||
end
|
||||
|
||||
function Pa_HostApiDeviceIndexToDeviceIndex(hostApi, hostApiDeviceIndex)
|
||||
ccall(
|
||||
(:Pa_HostApiDeviceIndexToDeviceIndex, libportaudio),
|
||||
PaDeviceIndex,
|
||||
(PaHostApiIndex, Cint),
|
||||
hostApi,
|
||||
hostApiDeviceIndex,
|
||||
)
|
||||
end
|
||||
|
||||
mutable struct PaHostErrorInfo
|
||||
hostApiType::PaHostApiTypeId
|
||||
errorCode::Clong
|
||||
errorText::Ptr{Cchar}
|
||||
end
|
||||
|
||||
function Pa_GetLastHostErrorInfo()
|
||||
ccall((:Pa_GetLastHostErrorInfo, libportaudio), Ptr{PaHostErrorInfo}, ())
|
||||
end
|
||||
|
||||
function Pa_GetDeviceCount()
|
||||
ccall((:Pa_GetDeviceCount, libportaudio), PaDeviceIndex, ())
|
||||
end
|
||||
|
||||
function Pa_GetDefaultInputDevice()
|
||||
ccall((:Pa_GetDefaultInputDevice, libportaudio), PaDeviceIndex, ())
|
||||
end
|
||||
|
||||
function Pa_GetDefaultOutputDevice()
|
||||
ccall((:Pa_GetDefaultOutputDevice, libportaudio), PaDeviceIndex, ())
|
||||
end
|
||||
|
||||
const PaTime = Cdouble
|
||||
|
||||
const PaSampleFormat = Culong
|
||||
|
||||
mutable struct PaDeviceInfo
|
||||
structVersion::Cint
|
||||
name::Ptr{Cchar}
|
||||
hostApi::PaHostApiIndex
|
||||
maxInputChannels::Cint
|
||||
maxOutputChannels::Cint
|
||||
defaultLowInputLatency::PaTime
|
||||
defaultLowOutputLatency::PaTime
|
||||
defaultHighInputLatency::PaTime
|
||||
defaultHighOutputLatency::PaTime
|
||||
defaultSampleRate::Cdouble
|
||||
end
|
||||
|
||||
function Pa_GetDeviceInfo(device)
|
||||
ccall((:Pa_GetDeviceInfo, libportaudio), Ptr{PaDeviceInfo}, (PaDeviceIndex,), device)
|
||||
end
|
||||
|
||||
struct PaStreamParameters
|
||||
device::PaDeviceIndex
|
||||
channelCount::Cint
|
||||
sampleFormat::PaSampleFormat
|
||||
suggestedLatency::PaTime
|
||||
hostApiSpecificStreamInfo::Ptr{Cvoid}
|
||||
end
|
||||
|
||||
function Pa_IsFormatSupported(inputParameters, outputParameters, sampleRate)
|
||||
ccall(
|
||||
(:Pa_IsFormatSupported, libportaudio),
|
||||
PaError,
|
||||
(Ptr{PaStreamParameters}, Ptr{PaStreamParameters}, Cdouble),
|
||||
inputParameters,
|
||||
outputParameters,
|
||||
sampleRate,
|
||||
)
|
||||
end
|
||||
|
||||
const PaStream = Cvoid
|
||||
|
||||
const PaStreamFlags = Culong
|
||||
|
||||
mutable struct PaStreamCallbackTimeInfo
|
||||
inputBufferAdcTime::PaTime
|
||||
currentTime::PaTime
|
||||
outputBufferDacTime::PaTime
|
||||
end
|
||||
|
||||
const PaStreamCallbackFlags = Culong
|
||||
|
||||
@enum PaStreamCallbackResult::UInt32 begin
|
||||
paContinue = 0
|
||||
paComplete = 1
|
||||
paAbort = 2
|
||||
end
|
||||
|
||||
# typedef int PaStreamCallback ( const void * input , void * output , unsigned long frameCount , const PaStreamCallbackTimeInfo * timeInfo , PaStreamCallbackFlags statusFlags , void * userData )
|
||||
const PaStreamCallback = Cvoid
|
||||
|
||||
function Pa_OpenStream(
|
||||
stream,
|
||||
inputParameters,
|
||||
outputParameters,
|
||||
sampleRate,
|
||||
framesPerBuffer,
|
||||
streamFlags,
|
||||
streamCallback,
|
||||
userData,
|
||||
)
|
||||
ccall(
|
||||
(:Pa_OpenStream, libportaudio),
|
||||
PaError,
|
||||
(
|
||||
Ptr{Ptr{PaStream}},
|
||||
Ptr{PaStreamParameters},
|
||||
Ptr{PaStreamParameters},
|
||||
Cdouble,
|
||||
Culong,
|
||||
PaStreamFlags,
|
||||
Ptr{Cvoid},
|
||||
Ptr{Cvoid},
|
||||
),
|
||||
stream,
|
||||
inputParameters,
|
||||
outputParameters,
|
||||
sampleRate,
|
||||
framesPerBuffer,
|
||||
streamFlags,
|
||||
streamCallback,
|
||||
userData,
|
||||
)
|
||||
end
|
||||
|
||||
function Pa_OpenDefaultStream(
|
||||
stream,
|
||||
numInputChannels,
|
||||
numOutputChannels,
|
||||
sampleFormat,
|
||||
sampleRate,
|
||||
framesPerBuffer,
|
||||
streamCallback,
|
||||
userData,
|
||||
)
|
||||
ccall(
|
||||
(:Pa_OpenDefaultStream, libportaudio),
|
||||
PaError,
|
||||
(
|
||||
Ptr{Ptr{PaStream}},
|
||||
Cint,
|
||||
Cint,
|
||||
PaSampleFormat,
|
||||
Cdouble,
|
||||
Culong,
|
||||
Ptr{Cvoid},
|
||||
Ptr{Cvoid},
|
||||
),
|
||||
stream,
|
||||
numInputChannels,
|
||||
numOutputChannels,
|
||||
sampleFormat,
|
||||
sampleRate,
|
||||
framesPerBuffer,
|
||||
streamCallback,
|
||||
userData,
|
||||
)
|
||||
end
|
||||
|
||||
function Pa_CloseStream(stream)
|
||||
ccall((:Pa_CloseStream, libportaudio), PaError, (Ptr{PaStream},), stream)
|
||||
end
|
||||
|
||||
# typedef void PaStreamFinishedCallback ( void * userData )
|
||||
const PaStreamFinishedCallback = Cvoid
|
||||
|
||||
function Pa_SetStreamFinishedCallback(stream, streamFinishedCallback)
|
||||
ccall(
|
||||
(:Pa_SetStreamFinishedCallback, libportaudio),
|
||||
PaError,
|
||||
(Ptr{PaStream}, Ptr{Cvoid}),
|
||||
stream,
|
||||
streamFinishedCallback,
|
||||
)
|
||||
end
|
||||
|
||||
function Pa_StartStream(stream)
|
||||
ccall((:Pa_StartStream, libportaudio), PaError, (Ptr{PaStream},), stream)
|
||||
end
|
||||
|
||||
function Pa_StopStream(stream)
|
||||
ccall((:Pa_StopStream, libportaudio), PaError, (Ptr{PaStream},), stream)
|
||||
end
|
||||
|
||||
function Pa_AbortStream(stream)
|
||||
ccall((:Pa_AbortStream, libportaudio), PaError, (Ptr{PaStream},), stream)
|
||||
end
|
||||
|
||||
function Pa_IsStreamStopped(stream)
|
||||
ccall((:Pa_IsStreamStopped, libportaudio), PaError, (Ptr{PaStream},), stream)
|
||||
end
|
||||
|
||||
function Pa_IsStreamActive(stream)
|
||||
ccall((:Pa_IsStreamActive, libportaudio), PaError, (Ptr{PaStream},), stream)
|
||||
end
|
||||
|
||||
mutable struct PaStreamInfo
|
||||
structVersion::Cint
|
||||
inputLatency::PaTime
|
||||
outputLatency::PaTime
|
||||
sampleRate::Cdouble
|
||||
end
|
||||
|
||||
function Pa_GetStreamInfo(stream)
|
||||
ccall((:Pa_GetStreamInfo, libportaudio), Ptr{PaStreamInfo}, (Ptr{PaStream},), stream)
|
||||
end
|
||||
|
||||
function Pa_GetStreamTime(stream)
|
||||
ccall((:Pa_GetStreamTime, libportaudio), PaTime, (Ptr{PaStream},), stream)
|
||||
end
|
||||
|
||||
function Pa_GetStreamCpuLoad(stream)
|
||||
ccall((:Pa_GetStreamCpuLoad, libportaudio), Cdouble, (Ptr{PaStream},), stream)
|
||||
end
|
||||
|
||||
function Pa_ReadStream(stream, buffer, frames)
|
||||
ccall(
|
||||
(:Pa_ReadStream, libportaudio),
|
||||
PaError,
|
||||
(Ptr{PaStream}, Ptr{Cvoid}, Culong),
|
||||
stream,
|
||||
buffer,
|
||||
frames,
|
||||
)
|
||||
end
|
||||
|
||||
function Pa_WriteStream(stream, buffer, frames)
|
||||
ccall(
|
||||
(:Pa_WriteStream, libportaudio),
|
||||
PaError,
|
||||
(Ptr{PaStream}, Ptr{Cvoid}, Culong),
|
||||
stream,
|
||||
buffer,
|
||||
frames,
|
||||
)
|
||||
end
|
||||
|
||||
function Pa_GetStreamReadAvailable(stream)
|
||||
ccall((:Pa_GetStreamReadAvailable, libportaudio), Clong, (Ptr{PaStream},), stream)
|
||||
end
|
||||
|
||||
function Pa_GetStreamWriteAvailable(stream)
|
||||
ccall((:Pa_GetStreamWriteAvailable, libportaudio), Clong, (Ptr{PaStream},), stream)
|
||||
end
|
||||
|
||||
function Pa_GetSampleSize(format)
|
||||
ccall((:Pa_GetSampleSize, libportaudio), PaError, (PaSampleFormat,), format)
|
||||
end
|
||||
|
||||
function Pa_Sleep(msec)
|
||||
ccall((:Pa_Sleep, libportaudio), Cvoid, (Clong,), msec)
|
||||
end
|
||||
|
||||
const paNoDevice = PaDeviceIndex(-1)
|
||||
|
||||
const paUseHostApiSpecificDeviceSpecification = PaDeviceIndex(-2)
|
||||
|
||||
const paFloat32 = PaSampleFormat(0x00000001)
|
||||
|
||||
const paInt32 = PaSampleFormat(0x00000002)
|
||||
|
||||
const paInt24 = PaSampleFormat(0x00000004)
|
||||
|
||||
const paInt16 = PaSampleFormat(0x00000008)
|
||||
|
||||
const paInt8 = PaSampleFormat(0x00000010)
|
||||
|
||||
const paUInt8 = PaSampleFormat(0x00000020)
|
||||
|
||||
const paCustomFormat = PaSampleFormat(0x00010000)
|
||||
|
||||
const paNonInterleaved = PaSampleFormat(0x80000000)
|
||||
|
||||
const paFormatIsSupported = 0
|
||||
|
||||
const paFramesPerBufferUnspecified = 0
|
||||
|
||||
const paNoFlag = PaStreamFlags(0)
|
||||
|
||||
const paClipOff = PaStreamFlags(0x00000001)
|
||||
|
||||
const paDitherOff = PaStreamFlags(0x00000002)
|
||||
|
||||
const paNeverDropInput = PaStreamFlags(0x00000004)
|
||||
|
||||
const paPrimeOutputBuffersUsingStreamCallback = PaStreamFlags(0x00000008)
|
||||
|
||||
const paPlatformSpecificFlags = PaStreamFlags(0xffff0000)
|
||||
|
||||
const paInputUnderflow = PaStreamCallbackFlags(0x00000001)
|
||||
|
||||
const paInputOverflow = PaStreamCallbackFlags(0x00000002)
|
||||
|
||||
const paOutputUnderflow = PaStreamCallbackFlags(0x00000004)
|
||||
|
||||
const paOutputOverflow = PaStreamCallbackFlags(0x00000008)
|
||||
|
||||
const paPrimingOutput = PaStreamCallbackFlags(0x00000010)
|
||||
|
||||
# exports
|
||||
const PREFIXES = ["Pa", "pa"]
|
||||
for name in names(@__MODULE__; all = true), prefix in PREFIXES
|
||||
if startswith(string(name), prefix)
|
||||
@eval export $name
|
||||
end
|
||||
end
|
||||
|
||||
end # module
|
|
@ -1,29 +0,0 @@
|
|||
# precompile some important functions
|
||||
const DEFAULT_SINK_MESSENGER_TYPE = Messenger{Float32, SampledSignalsWriter, Tuple{Matrix{Float32}, Int64, Int64}, Int64}
|
||||
const DEFAULT_SOURCE_MESSENGER_TYPE = Messenger{Float32, SampledSignalsReader, Tuple{Matrix{Float32}, Int64, Int64}, Int64}
|
||||
const DEFAULT_STREAM_TYPE = PortAudioStream{DEFAULT_SINK_MESSENGER_TYPE, DEFAULT_SOURCE_MESSENGER_TYPE}
|
||||
const DEFAULT_SINK_TYPE = PortAudioSink{DEFAULT_SINK_MESSENGER_TYPE, DEFAULT_SOURCE_MESSENGER_TYPE}
|
||||
const DEFAULT_SOURCE_TYPE = PortAudioSource{DEFAULT_SINK_MESSENGER_TYPE, DEFAULT_SOURCE_MESSENGER_TYPE}
|
||||
|
||||
precompile(close, (DEFAULT_STREAM_TYPE,))
|
||||
precompile(devices, ())
|
||||
precompile(__init__, ())
|
||||
precompile(isopen, (DEFAULT_STREAM_TYPE,))
|
||||
precompile(nchannels, (DEFAULT_SINK_TYPE,))
|
||||
precompile(nchannels, (DEFAULT_SOURCE_TYPE,))
|
||||
precompile(PortAudioStream, (Int, Int))
|
||||
precompile(PortAudioStream, (String, Int, Int))
|
||||
precompile(PortAudioStream, (String, String, Int, Int))
|
||||
precompile(samplerate, (DEFAULT_STREAM_TYPE,))
|
||||
precompile(send, (DEFAULT_SINK_MESSENGER_TYPE,))
|
||||
precompile(send, (DEFAULT_SOURCE_MESSENGER_TYPE,))
|
||||
precompile(unsafe_read!, (DEFAULT_SOURCE_TYPE, Vector{Float32}, Int, Int))
|
||||
precompile(unsafe_read!, (DEFAULT_SOURCE_TYPE, Matrix{Float32}, Int, Int))
|
||||
precompile(unsafe_write, (DEFAULT_SINK_TYPE, Vector{Float32}, Int, Int))
|
||||
precompile(unsafe_write, (DEFAULT_SINK_TYPE, Matrix{Float32}, Int, Int))
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
256
test/runtests.jl
256
test/runtests.jl
|
@ -1,256 +0,0 @@
|
|||
#!/usr/bin/env julia
|
||||
using Base.Sys: iswindows
|
||||
using Documenter: doctest
|
||||
using PortAudio:
|
||||
combine_default_sample_rates,
|
||||
devices,
|
||||
get_default_input_index,
|
||||
get_default_output_index,
|
||||
get_device,
|
||||
get_input_type,
|
||||
get_output_type,
|
||||
handle_status,
|
||||
initialize,
|
||||
name,
|
||||
PortAudioException,
|
||||
PortAudio,
|
||||
PortAudioDevice,
|
||||
PortAudioStream,
|
||||
safe_load,
|
||||
seek_alsa_conf,
|
||||
terminate,
|
||||
write_buffer
|
||||
using PortAudio.LibPortAudio:
|
||||
Pa_AbortStream,
|
||||
PaError,
|
||||
PaErrorCode,
|
||||
paFloat32,
|
||||
Pa_GetDefaultHostApi,
|
||||
Pa_GetDeviceInfo,
|
||||
Pa_GetHostApiCount,
|
||||
Pa_GetLastHostErrorInfo,
|
||||
Pa_GetSampleSize,
|
||||
Pa_GetStreamCpuLoad,
|
||||
Pa_GetStreamInfo,
|
||||
Pa_GetStreamReadAvailable,
|
||||
Pa_GetStreamTime,
|
||||
Pa_GetStreamWriteAvailable,
|
||||
Pa_GetVersionInfo,
|
||||
Pa_HostApiDeviceIndexToDeviceIndex,
|
||||
paHostApiNotFound,
|
||||
Pa_HostApiTypeIdToHostApiIndex,
|
||||
PaHostErrorInfo,
|
||||
paInDevelopment,
|
||||
paInvalidDevice,
|
||||
Pa_IsFormatSupported,
|
||||
Pa_IsStreamActive,
|
||||
paNoError,
|
||||
paNoFlag,
|
||||
paNotInitialized,
|
||||
Pa_OpenDefaultStream,
|
||||
paOutputUnderflowed,
|
||||
Pa_SetStreamFinishedCallback,
|
||||
Pa_Sleep,
|
||||
Pa_StopStream,
|
||||
PaStream,
|
||||
PaStreamInfo,
|
||||
PaStreamParameters,
|
||||
PaVersionInfo
|
||||
using SampledSignals: nchannels, s, SampleBuf, samplerate, SinSource
|
||||
using Test: @test, @test_logs, @test_nowarn, @testset, @test_throws
|
||||
|
||||
@testset "Tests without sound" begin
|
||||
@testset "Reports version" begin
|
||||
io = IOBuffer()
|
||||
PortAudio.versioninfo(io)
|
||||
result = split(String(take!((io))), "\n")
|
||||
# make sure this is the same version I tested with
|
||||
@test startswith(result[1], "PortAudio V19")
|
||||
end
|
||||
|
||||
@testset "Can list devices without crashing" begin
|
||||
display(devices())
|
||||
println()
|
||||
end
|
||||
|
||||
@testset "libortaudio without sound" begin
|
||||
@test handle_status(Pa_GetHostApiCount()) >= 0
|
||||
@test handle_status(Pa_GetDefaultHostApi()) >= 0
|
||||
# version info not available on windows?
|
||||
if !Sys.iswindows()
|
||||
@test safe_load(Pa_GetVersionInfo(), ErrorException("no info")) isa
|
||||
PaVersionInfo
|
||||
end
|
||||
@test safe_load(Pa_GetLastHostErrorInfo(), ErrorException("no info")) isa
|
||||
PaHostErrorInfo
|
||||
@test PaErrorCode(Pa_IsFormatSupported(C_NULL, C_NULL, 0.0)) == paInvalidDevice
|
||||
@test PaErrorCode(
|
||||
Pa_OpenDefaultStream(Ref(C_NULL), 0, 0, paFloat32, 0.0, 0, C_NULL, C_NULL),
|
||||
) == paInvalidDevice
|
||||
end
|
||||
|
||||
@testset "Errors without sound" begin
|
||||
@test sprint(showerror, PortAudioException(paNotInitialized)) ==
|
||||
"PortAudioException: PortAudio not initialized"
|
||||
@test_throws KeyError("foobarbaz") get_device("foobarbaz")
|
||||
@test_throws KeyError(-1) get_device(-1)
|
||||
@test_throws ArgumentError("Could not find alsa.conf in ()") seek_alsa_conf(())
|
||||
@test_logs (:warn, "libportaudio: Output underflowed") handle_status(
|
||||
PaError(paOutputUnderflowed),
|
||||
)
|
||||
@test_throws PortAudioException(paNotInitialized) handle_status(
|
||||
PaError(paNotInitialized),
|
||||
)
|
||||
Pa_Sleep(1)
|
||||
@test Pa_GetSampleSize(paFloat32) == 4
|
||||
end
|
||||
|
||||
# make sure we can terminate, then reinitialize
|
||||
terminate()
|
||||
initialize()
|
||||
end
|
||||
|
||||
if isempty(devices())
|
||||
@test_throws ArgumentError("No input device available") get_default_input_index()
|
||||
else
|
||||
@testset "Tests with sound" begin
|
||||
# these default values are specific to local machines
|
||||
input_name = get_device(get_default_input_index()).name
|
||||
output_name = get_device(get_default_output_index()).name
|
||||
|
||||
@testset "Interactive tests" begin
|
||||
println("Recording...")
|
||||
stream = PortAudioStream(input_name, output_name, 2, 0; adjust_channels = true)
|
||||
buffer = read(stream, 5s)
|
||||
@test size(buffer) ==
|
||||
(round(Int, 5 * samplerate(stream)), nchannels(stream.source))
|
||||
close(stream)
|
||||
sleep(1)
|
||||
println("Playing back recording...")
|
||||
PortAudioStream(input_name, output_name, 0, 2; adjust_channels = true) do stream
|
||||
write(stream, buffer)
|
||||
end
|
||||
sleep(1)
|
||||
println("Testing pass-through")
|
||||
stream = PortAudioStream(input_name, output_name, 2, 2; adjust_channels = true)
|
||||
write_buffer(stream.sink_messenger.buffer, acquire_lock = false)
|
||||
sink = stream.sink
|
||||
source = stream.source
|
||||
@test sprint(show, stream) == """
|
||||
PortAudioStream{Float32}
|
||||
Samplerate: 44100Hz
|
||||
2 channel sink: $(repr(output_name))
|
||||
2 channel source: $(repr(input_name))"""
|
||||
@test sprint(show, source) == "2 channel source: $(repr(input_name))"
|
||||
@test sprint(show, sink) == "2 channel sink: $(repr(output_name))"
|
||||
write(stream, stream, 5s)
|
||||
@test PaErrorCode(handle_status(Pa_StopStream(stream.pointer_to))) == paNoError
|
||||
@test isopen(stream)
|
||||
close(stream)
|
||||
sleep(1)
|
||||
@test !isopen(stream)
|
||||
@test !isopen(sink)
|
||||
@test !isopen(source)
|
||||
println("done")
|
||||
end
|
||||
@testset "Samplerate-converting writing" begin
|
||||
PortAudioStream(input_name, output_name, 0, 2; adjust_channels = true) do stream
|
||||
write(
|
||||
stream,
|
||||
SinSource(eltype(stream), samplerate(stream) * 0.8, [220, 330]),
|
||||
3s,
|
||||
)
|
||||
println("expected blip")
|
||||
write(
|
||||
stream,
|
||||
SinSource(eltype(stream), samplerate(stream) * 1.2, [220, 330]),
|
||||
3s,
|
||||
)
|
||||
end
|
||||
end
|
||||
sleep(1)
|
||||
# no way to check that the right data is actually getting read or written here,
|
||||
# but at least it's not crashing.
|
||||
@testset "Queued Writing" begin
|
||||
PortAudioStream(input_name, output_name, 0, 2; adjust_channels = true) do stream
|
||||
buffer = SampleBuf(
|
||||
rand(eltype(stream), 48000, nchannels(stream.sink)) * 0.1,
|
||||
samplerate(stream),
|
||||
)
|
||||
frame_count_1 = @async write(stream, buffer)
|
||||
frame_count_2 = @async write(stream, buffer)
|
||||
@test fetch(frame_count_1) == 48000
|
||||
println("expected blip")
|
||||
@test fetch(frame_count_2) == 48000
|
||||
end
|
||||
sleep(1)
|
||||
end
|
||||
@testset "Queued Reading" begin
|
||||
PortAudioStream(input_name, output_name, 2, 0; adjust_channels = true) do stream
|
||||
buffer = SampleBuf(
|
||||
rand(eltype(stream), 48000, nchannels(stream.source)) * 0.1,
|
||||
samplerate(stream),
|
||||
)
|
||||
frame_count_1 = @async read!(stream, buffer)
|
||||
frame_count_2 = @async read!(stream, buffer)
|
||||
@test fetch(frame_count_1) == 48000
|
||||
@test fetch(frame_count_2) == 48000
|
||||
end
|
||||
sleep(1)
|
||||
end
|
||||
@testset "Constructors" begin
|
||||
PortAudioStream(2, maximum; adjust_channels = true) do stream
|
||||
@test isopen(stream)
|
||||
end
|
||||
PortAudioStream(output_name; adjust_channels = true) do stream
|
||||
@test isopen(stream)
|
||||
end
|
||||
PortAudioStream(input_name, output_name; adjust_channels = true) do stream
|
||||
@test isopen(stream)
|
||||
end
|
||||
end
|
||||
@testset "Errors with sound" begin
|
||||
big = typemax(Int)
|
||||
@test_throws DomainError(
|
||||
typemax(Int),
|
||||
"$big exceeds maximum output channels for $output_name",
|
||||
) PortAudioStream(input_name, output_name, 0, big)
|
||||
@test_throws ArgumentError("Input or output must have at least 1 channel") PortAudioStream(
|
||||
input_name,
|
||||
output_name,
|
||||
0,
|
||||
0;
|
||||
adjust_channels = true,
|
||||
)
|
||||
@test_throws ArgumentError("""
|
||||
Default sample rate 0 for input \"$input_name\" disagrees with
|
||||
default sample rate 1 for output \"$output_name\".
|
||||
Please specify a sample rate.
|
||||
""") combine_default_sample_rates(
|
||||
get_device(input_name),
|
||||
0,
|
||||
get_device(output_name),
|
||||
1,
|
||||
)
|
||||
end
|
||||
@testset "libportaudio with sound" begin
|
||||
@test PaErrorCode(Pa_HostApiTypeIdToHostApiIndex(paInDevelopment)) ==
|
||||
paHostApiNotFound
|
||||
@test Pa_HostApiDeviceIndexToDeviceIndex(paInDevelopment, 0) == 0
|
||||
stream = PortAudioStream(input_name, output_name, 2, 2; adjust_channels = true)
|
||||
pointer_to = stream.pointer_to
|
||||
@test handle_status(Pa_GetStreamReadAvailable(pointer_to)) >= 0
|
||||
@test handle_status(Pa_GetStreamWriteAvailable(pointer_to)) >= 0
|
||||
@test Bool(handle_status(Pa_IsStreamActive(pointer_to)))
|
||||
@test safe_load(Pa_GetStreamInfo(pointer_to), ErrorException("no info")) isa
|
||||
PaStreamInfo
|
||||
@test Pa_GetStreamTime(pointer_to) >= 0
|
||||
@test Pa_GetStreamCpuLoad(pointer_to) >= 0
|
||||
@test PaErrorCode(handle_status(Pa_AbortStream(pointer_to))) == paNoError
|
||||
@test PaErrorCode(
|
||||
handle_status(Pa_SetStreamFinishedCallback(pointer_to, C_NULL)),
|
||||
) == paNoError
|
||||
end
|
||||
end
|
||||
doctest(PortAudio)
|
||||
end
|
|
@ -1,95 +0,0 @@
|
|||
# This file has runs the normal tests and also adds tests that can only be run
|
||||
# locally on a machine with a sound card. It's mostly to put the library through
|
||||
# its paces assuming a human is listening.
|
||||
|
||||
include("runtests.jl")
|
||||
|
||||
# these default values are specific to my machines
|
||||
if Sys.iswindows()
|
||||
default_indev = "Microphone Array (Realtek High "
|
||||
default_outdev = "Speaker/Headphone (Realtek High"
|
||||
elseif Sys.isapple()
|
||||
default_indev = "Built-in Microphone"
|
||||
default_outdev = "Built-in Output"
|
||||
elseif Sys.islinux()
|
||||
default_indev = "default"
|
||||
default_outdev = "default"
|
||||
end
|
||||
|
||||
@testset "Local Tests" begin
|
||||
@testset "Open Default Device" begin
|
||||
println("Recording...")
|
||||
stream = PortAudioStream(2, 0)
|
||||
buf = read(stream, 5s)
|
||||
close(stream)
|
||||
@test size(buf) == (round(Int, 5 * samplerate(stream)), nchannels(stream.source))
|
||||
println("Playing back recording...")
|
||||
stream = PortAudioStream(0, 2)
|
||||
write(stream, buf)
|
||||
println("flushing...")
|
||||
flush(stream)
|
||||
close(stream)
|
||||
println("Testing pass-through")
|
||||
stream = PortAudioStream(2, 2)
|
||||
write(stream, stream, 5s)
|
||||
flush(stream)
|
||||
close(stream)
|
||||
println("done")
|
||||
end
|
||||
@testset "Samplerate-converting writing" begin
|
||||
stream = PortAudioStream(0, 2)
|
||||
write(stream, SinSource(eltype(stream), samplerate(stream) * 0.8, [220, 330]), 3s)
|
||||
write(stream, SinSource(eltype(stream), samplerate(stream) * 1.2, [220, 330]), 3s)
|
||||
flush(stream)
|
||||
close(stream)
|
||||
end
|
||||
@testset "Open Device by name" begin
|
||||
stream = PortAudioStream(default_indev, default_outdev)
|
||||
buf = read(stream, 0.001s)
|
||||
@test size(buf) ==
|
||||
(round(Int, 0.001 * samplerate(stream)), nchannels(stream.source))
|
||||
write(stream, buf)
|
||||
io = IOBuffer()
|
||||
show(io, stream)
|
||||
@test occursin(
|
||||
"""
|
||||
PortAudioStream{Float32}
|
||||
Samplerate: 44100.0Hz
|
||||
Buffer Size: 4096 frames
|
||||
2 channel sink: "$default_outdev"
|
||||
2 channel source: "$default_indev\"""",
|
||||
String(take!(io)),
|
||||
)
|
||||
close(stream)
|
||||
end
|
||||
@testset "Error on wrong name" begin
|
||||
@test_throws ErrorException PortAudioStream("foobarbaz")
|
||||
end
|
||||
# no way to check that the right data is actually getting read or written here,
|
||||
# but at least it's not crashing.
|
||||
@testset "Queued Writing" begin
|
||||
stream = PortAudioStream(0, 2)
|
||||
buf = SampleBuf(
|
||||
rand(eltype(stream), 48000, nchannels(stream.sink)) * 0.1,
|
||||
samplerate(stream),
|
||||
)
|
||||
t1 = @async write(stream, buf)
|
||||
t2 = @async write(stream, buf)
|
||||
@test fetch(t1) == 48000
|
||||
@test fetch(t2) == 48000
|
||||
flush(stream)
|
||||
close(stream)
|
||||
end
|
||||
@testset "Queued Reading" begin
|
||||
stream = PortAudioStream(2, 0)
|
||||
buf = SampleBuf(
|
||||
rand(eltype(stream), 48000, nchannels(stream.source)) * 0.1,
|
||||
samplerate(stream),
|
||||
)
|
||||
t1 = @async read!(stream, buf)
|
||||
t2 = @async read!(stream, buf)
|
||||
@test fetch(t1) == 48000
|
||||
@test fetch(t2) == 48000
|
||||
close(stream)
|
||||
end
|
||||
end
|
5
versions.js
Normal file
5
versions.js
Normal file
|
@ -0,0 +1,5 @@
|
|||
var DOC_VERSIONS = [
|
||||
"dev",
|
||||
];
|
||||
var DOCUMENTER_NEWEST = "dev";
|
||||
var DOCUMENTER_STABLE = "dev";
|
Loading…
Reference in a new issue