Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(support M1 architecture) #14

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ path = "lib.rs"
crate-type = ["cdylib"]

[dependencies]
rodio = "0.12.0"
deno_bindgen = "0.5.0"
rodio = "0.17.1"
deno_bindgen = "0.8.1"
53 changes: 39 additions & 14 deletions bindings/bindings.ts
Original file line number Diff line number Diff line change
@@ -1,37 +1,62 @@
// Auto-generated with deno_bindgen
import { CachePolicy, prepare } from "https://deno.land/x/[email protected]/plug.ts"
function encode(v: string | Uint8Array): Uint8Array {
if (typeof v !== "string") return v
return new TextEncoder().encode(v)
}

function decode(v: Uint8Array): string {
return new TextDecoder().decode(v)
}

// deno-lint-ignore no-explicit-any
function readPointer(v: any): Uint8Array {
const ptr = new Deno.UnsafePointerView(v as Deno.UnsafePointer)
const ptr = new Deno.UnsafePointerView(v)
const lengthBe = new Uint8Array(4)
const view = new DataView(lengthBe.buffer)
ptr.copyInto(lengthBe, 0)
const buf = new Uint8Array(view.getUint32(0))
ptr.copyInto(buf, 4)
return buf
}
const opts = {
name: "deno_audio",
url:
(new URL(
"https://github.com/littledivy/deno_audio/releases/download/0.2.0",
import.meta.url,
)).toString(),
policy: undefined,

const url = new URL("../target/release", import.meta.url)

let uri = url.pathname
if (!uri.endsWith("/")) uri += "/"

// https://docs.microsoft.com/en-us/windows/win32/api/libloaderapi/nf-libloaderapi-loadlibrarya#parameters
if (Deno.build.os === "windows") {
uri = uri.replace(/\//g, "\\")
// Remove leading slash
if (uri.startsWith("\\")) {
uri = uri.slice(1)
}
}
const _lib = await prepare(opts, {
play: { parameters: ["pointer", "usize"], result: "void", nonblocking: true },
})

const { symbols } = Deno.dlopen(
{
darwin: uri + "libdeno_audio.dylib",
windows: uri + "deno_audio.dll",
linux: uri + "libdeno_audio.so",
freebsd: uri + "libdeno_audio.so",
netbsd: uri + "libdeno_audio.so",
aix: uri + "libdeno_audio.so",
solaris: uri + "libdeno_audio.so",
illumos: uri + "libdeno_audio.so",
}[Deno.build.os],
{
play: {
parameters: ["buffer", "usize"],
result: "void",
nonblocking: true,
},
},
)

export function play(a0: string) {
const a0_buf = encode(a0)
let rawResult = _lib.symbols.play(a0_buf, a0_buf.byteLength)

const rawResult = symbols.play(a0_buf, a0_buf.byteLength)
const result = rawResult
return result
}