alto provides idiomatic Rust bindings for OpenAL 1.1 and extensions (including EFX).

Overview

alto

alto provides idiomatic Rust bindings for OpenAL 1.1 and extensions (including EFX).

WARNING

Because Alto interacts with global C state via dynamic linking, having multiple versions of Alto in one project could lead to unsafety. Please make sure only one version of Alto is in your dependency tree at any given time.

API Usage

let alto = Alto::load_default()?;

for s in alto.enumerate_outputs() {
    println!("Found device: {}", s.to_str()?);
}

let device = alto.open(None)?; // Opens the default audio device
let context = device.new_context(None)?; // Creates a default context

// Configure listener
context.set_position([1.0, 4.0, 5.0]);
context.set_velocity([2.5, 0.0, 0.0]);
context.set_orientation(([0.0, 0.0, 1.0], [0.0, 1.0, 0.0]));

let source = context.new_static_source()?;

// Now you can load your samples and store them in a buffer with
// `context.new_buffer(samples, frequency)`;
Comments
  • Building alto on Emscripten

    Building alto on Emscripten

    I recently tried to build a dummy project listing alto as one of its dependencies, targeting Emscripten with --target asmjs-unknown-emscripten, and it failed because libloading does not (yet) support Emscripten.
    I had reported this, but in the meantime, al-sys actually does not need the libloading dependency when target Emscripten, because there, "out-of-the-box" support for OpenAL is claimed (see this issue).

    My suggestion : When the target is Emscripten, fall back to simply declaring the FFI bindings, and disable the libloading dependency so that it builds successfully.

    opened by yoanlcq 15
  • Need alcGetCurrentContext() and alcGetContextsDevice() for library I'm writing.

    Need alcGetCurrentContext() and alcGetContextsDevice() for library I'm writing.

    Hello!

    I need those two methods in order to properly implement the destructor for my Rust library. Is there a way that they can be added, please?

    Thank you!

    opened by sunnystormy 12
  • Compiling for MinGW-W64

    Compiling for MinGW-W64

    I’ve been trying to compile the crate on mingw-w64 for hours. I haven’t found a way to make it through with the crates.io crate, so I downloaded openal-rs, add a local override to my project and changed the link target from #[link(name = "openal32")] to #[link(name = "openal")], because that’s what pkg-config expects if you pass it --libs openal.

    After our talk on IRC, you uploaded an upper-case version that will work for the native Windows installation but not for MinGW. What can we do about that?

    opened by phaazon 10
  • Add

    Add "alut" to this package?

    ALUT adds some helper methods for initializing audio files and creating/binding a buffer. Is there a way you can get that added inside of this package so users don't have to resort to the boilerplate "alc" conventions?

    opened by sunnystormy 6
  • add a dynamic feature flag, allowing static linking if desired

    add a dynamic feature flag, allowing static linking if desired

    On platforms like android, openalsoft can be linked to statically or dynamically. This feature flag allows deciding between the "emscripten" style static linking, or dynamic linking (default). Static linking can save a lot of space in the final APK, so android users will likely prefer it.

    Currently it is up to the client to figure out how to link statically to the openal implementation. This PR makes no attempt to build openal for android. Though, I may try to add that in the future (once I've worked out the kinks).

    opened by mtak- 5
  • Support for rustc nightly 2014-06-29

    Support for rustc nightly 2014-06-29

    • Changed * to *const
    • Changed enum repr to i32 to fix type mismatch errors
    • Also an unrelated change that fixes Source::unqueue_buffer and Source::unqueue_buffers so they handle errors and return results instead of filling buffers
    opened by samyatchmenoff 5
  • Alto::open_loopback(None) returns Invalid Device Error

    Alto::open_loopback(None) returns Invalid Device Error

    i get thread 'main' panicked at 'calledResult::unwrap()on anErrvalue: InvalidDevice', libcore/result.rs:945:5 in the third line.

    fn main () {
        let alto =  Alto::load_default().unwrap();
        let mut loopback: LoopbackDevice<Stereo<i16>> = alto.open_loopback(None).unwrap()
    }
    

    when i call alcLoopbackOpenDeviceSOFT(NULL); in openal-soft directly, it works. Is the rust code equivalent to the c code or did i miss something?

    opened by sebastianpfluegelmeier 3
  • error[E0283]: type annotations required: cannot resolve `_: audio::alto::SampleFrame`

    error[E0283]: type annotations required: cannot resolve `_: audio::alto::SampleFrame`

    Sorry, this is probably a silly error on my part, but I can't figure this one out.

    I'm trying to load samples from an array of Vorbis bytes. I currently have this naive start:

        pub fn new_buffer(&self, bytes: &[u8]) -> Result<Buffer, Error> {
            let reader = OggStreamReader::new(Cursor::new(bytes))
                .map_err(|e| err_msg("Failed to create stream reader"))?;
            let sample_rate = reader.ident_hdr.audio_sample_rate as i32;
            let audio_channels = reader.ident_hdr.audio_channels;
            let decoded: Vec<i16> = Vec::new();
            /*while let Some(samples) = reader.read_dec_packet_itl()? {
                decoded.append(&mut samples);
            }*/
            self.0.new_buffer(decoded, sample_rate)
                .map_err(|e| err_msg("Error creating buffer"))
        }
    

    That case doesn't work. Neither does the case where the block is uncommented and, in theory, I'm appending decoded samples to a larger byte vec I'll ultimately pass to the buffer creation call. If I do:

        pub fn new_buffer(&self, bytes: &[u8]) -> Result<Buffer, Error> {
            let reader = OggStreamReader::new(Cursor::new(bytes))
                .map_err(|e| err_msg("Failed to create stream reader"))?;
            let sample_rate = reader.ident_hdr.audio_sample_rate as i32;
            let audio_channels = reader.ident_hdr.audio_channels;
            let decoded: Vec<i16> = Vec::new();
            while let Some(samples) = reader.read_dec_packet_itl()? {
                //decoded.append(&mut samples);
                self.0.new_buffer(samples, sample_rate);
            }
            self.0.new_buffer(decoded, sample_rate)
                .map_err(|e| err_msg("Error creating buffer"))
        }
    

    That seems to work, in so far as it creates a buffer with the freshly-loaded samples in the loop, but the last buffer creation call with decoded still fails.

    If I scatter around println! calls, I'm told that the samples are Vec<i16>. That's what my decoded buffer is as well, so I don't know what I'm getting wrong. I've tried a few type annotation combinations, but I can't get a match. What am I missing here?

    P.s. I know I'll likely ultimately want to switch to streaming, but I'm just working with short samples now, and am trying to build up complexity over time. Thanks for any help!

    opened by ndarilek 3
  • Link against openal-soft (libopenal.dylib) on OSX (instead of framework version)

    Link against openal-soft (libopenal.dylib) on OSX (instead of framework version)

    This may be kind of a pain for you, but I wonder if there is any way to give the option without needing have a whole other package. The problem is that openal-soft compiles as a dylib typically in /usr/local/lib but the openal link is specified as framework in this package so I just had to modify that one line in a local project to get it working.

    opened by venetanji 3
  • Relicense under dual MIT/Apache-2.0

    Relicense under dual MIT/Apache-2.0

    This issue was automatically generated. Feel free to close without ceremony if you do not agree with re-licensing or if it is not possible for other reasons. Respond to @cmr with any questions or concerns, or pop over to #rust-offtopic on IRC to discuss.

    You're receiving this because someone (perhaps the project maintainer) published a crates.io package with the license as "MIT" xor "Apache-2.0" and the repository field pointing here.

    TL;DR the Rust ecosystem is largely Apache-2.0. Being available under that license is good for interoperation. The MIT license as an add-on can be nice for GPLv2 projects to use your code.

    Why?

    The MIT license requires reproducing countless copies of the same copyright header with different names in the copyright field, for every MIT library in use. The Apache license does not have this drawback. However, this is not the primary motivation for me creating these issues. The Apache license also has protections from patent trolls and an explicit contribution licensing clause. However, the Apache license is incompatible with GPLv2. This is why Rust is dual-licensed as MIT/Apache (the "primary" license being Apache, MIT only for GPLv2 compat), and doing so would be wise for this project. This also makes this crate suitable for inclusion and unrestricted sharing in the Rust standard distribution and other projects using dual MIT/Apache, such as my personal ulterior motive, the Robigalia project.

    Some ask, "Does this really apply to binary redistributions? Does MIT really require reproducing the whole thing?" I'm not a lawyer, and I can't give legal advice, but some Google Android apps include open source attributions using this interpretation. Others also agree with it. But, again, the copyright notice redistribution is not the primary motivation for the dual-licensing. It's stronger protections to licensees and better interoperation with the wider Rust ecosystem.

    How?

    To do this, get explicit approval from each contributor of copyrightable work (as not all contributions qualify for copyright, due to not being a "creative work", e.g. a typo fix) and then add the following to your README:

    ## License
    
    Licensed under either of
    
     * Apache License, Version 2.0 ([LICENSE-APACHE](LICENSE-APACHE) or http://www.apache.org/licenses/LICENSE-2.0)
     * MIT license ([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT)
    
    at your option.
    
    ### Contribution
    
    Unless you explicitly state otherwise, any contribution intentionally submitted
    for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any
    additional terms or conditions.
    

    and in your license headers, if you have them, use the following boilerplate (based on that used in Rust):

    // Copyright 2016 openal-rs developers
    //
    // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
    // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
    // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
    // option. This file may not be copied, modified, or distributed
    // except according to those terms.
    

    It's commonly asked whether license headers are required. I'm not comfortable making an official recommendation either way, but the Apache license recommends it in their appendix on how to use the license.

    Be sure to add the relevant LICENSE-{MIT,APACHE} files. You can copy these from the Rust repo for a plain-text version.

    And don't forget to update the license metadata in your Cargo.toml to:

    license = "MIT/Apache-2.0"
    

    I'll be going through projects which agree to be relicensed and have approval by the necessary contributors and doing this changes, so feel free to leave the heavy lifting to me!

    Contributor checkoff

    To agree to relicensing, comment with :

    I license past and future contributions under the dual MIT/Apache-2.0 license, allowing licensees to chose either at their option.
    

    Or, if you're a contributor, you can check the box in this repo next to your name. My scripts will pick this exact phrase up and check your checkbox, but I'll come through and manually review this issue later as well.

    • [ ] @bjz
    • [ ] @jpernst
    • [x] @samyatchmenoff
    • [ ] @MarkJr94
    • [ ] @benw
    • [ ] @kvark
    • [x] @suhr
    opened by emberian 3
  • Nightly fixes; remove feature gates

    Nightly fixes; remove feature gates

    This fixes the use of a few deprecated methods and removes all gated functionality in preparation for beta1 and crates.io.

    On a related note, I saw over on the cgmath board that you've got a lot on your plate. I'd be happy to assume maintenance of openal-rs if you'd rather focus on your other projects; just let me know.

    opened by jpernst 3
Owner
null
Rust-idiomatic, compliant, flexible and performant BIP21 crate

Rust implementation of BIP21 Rust-idiomatic, compliant, flexible and performant BIP21 crate. About Important: while lot of work went into polishing th

Martin Habovštiak 6 Dec 15, 2022
A peer-reviewed collection of articles/talks/repos which teach concise, idiomatic Rust.

This repository collects resources for writing clean, idiomatic Rust code. Please bring your own. ?? Idiomatic coding means following the conventions

Matthias 4.2k Dec 30, 2022
Idiomatic Rust implementations for various Windows string types (like UNICODE_STRING)

nt-string by Colin Finck <[email protected]> Provides idiomatic Rust implementations for various Windows string types: NtUnicodeString (with NtUnicode

Colin Finck 5 Jun 4, 2023
Efficiently store Rust idiomatic bytes related types in Avro encoding.

Serde Avro Bytes Avro is a binary encoding format which provides a "bytes" type optimized to store &[u8] data like. Unfortunately the apache_avro enco

Akanoa 3 Mar 30, 2024
An API for getting questions from http://either.io implemented fully in Rust, using reqwest and some regex magic. Provides asynchronous and blocking clients respectively.

eithers_rust An API for getting questions from http://either.io implemented fully in Rust, using reqwest and some regex magic. Provides asynchronous a

null 2 Oct 24, 2021
This blog provides detailed status updates and useful information about Theseus OS and its development

The Theseus OS Blog This blog provides detailed status updates and useful information about Theseus OS and its development. Attribution This blog was

Theseus OS 1 Apr 14, 2022
A rust library that provides pseudo-reflection for structs and enums

Treeflection treeflection_derive Treeflection runs a command stored as a string on a tree of structs, collections and primitive types. Commands A comm

Lucas Kent 21 Nov 17, 2022
A radix tree implementation for router, and provides CRUD operations.

radixtree A radix tree implementation for router, and provides CRUD operations. Radixtree is part of treemux, on top of which updates and removes are

Zhenwei Guo 2 Dec 19, 2022
This is the Rust course used by the Android team at Google. It provides you the material to quickly teach Rust to everyone.

Comprehensive Rust ?? This repository has the source code for Comprehensive Rust ?? , a four day Rust course developed by the Android team. The course

Google 5.2k Jan 3, 2023
Crabzilla provides a simple interface for running JavaScript modules alongside Rust code.

Crabzilla Crabzilla provides a simple interface for running JavaScript modules alongside Rust code. Example use crabzilla::*; use std::io::stdin; #[i

Andy 14 Feb 19, 2022
Rust library provides a standalone implementation of the ROS (Robot Operating System) core

ROS-core implementation in Rust This Rust library provides a standalone implementation of the ROS (Robot Operating System) core. It allows you to run

Patrick Wieschollek 3 Apr 26, 2023
Safe, efficient, and ergonomic bindings to Wolfram LibraryLink and the Wolfram Language

wolfram-library-link Bindings to the Wolfram LibraryLink interface, making it possible to call Rust code from the Wolfram Language. This library is us

Wolfram Research, Inc. 28 Dec 6, 2022
Rust bindings to the Wolfram Symbolic Transport Protocol (WSTP)

wstp Bindings to the Wolfram Symbolic Transfer Protocol (WSTP) library. This crate provides a set of safe and ergonomic bindings to the WSTP library,

Wolfram Research, Inc. 10 Nov 1, 2022
Safe Rust bindings to the DynamoRIO dynamic binary instrumentation framework.

Introduction The dynamorio-rs crate provides safe Rust bindings to the DynamoRIO dynamic binary instrumentation framework, essentially allowing you to

S.J.R. van Schaik 17 Nov 21, 2022
Rust bindings to the dos-like framework

dos-like for Rust   This project provides access to Mattias Gustavsson's dos-like framework, so as to write DOS-like applications in Rust. How to use

Eduardo Pinho 9 Aug 25, 2022
Complete bindings to the raspicam C++ library

raspicam-rs Rust bindings to the amazing C++ raspicam library (with optional OpenCV utilities)! This is a followup to a Rust-based robotics project I

blusk 8 Oct 17, 2022
In this repository you can find modules with code and comments that explain rust syntax and all about Rust lang.

Learn Rust What is this? In this repository you can find modules with code and comments that explain rust syntax and all about Rust lang. This is usef

Domagoj Ratko 5 Nov 5, 2022
A comprehensive and FREE Online Rust hacking tutorial utilizing the x64, ARM64 and ARM32 architectures going step-by-step into the world of reverse engineering Rust from scratch.

FREE Reverse Engineering Self-Study Course HERE Hacking Rust A comprehensive and FREE Online Rust hacking tutorial utilizing the x64, ARM64 and ARM32

Kevin Thomas 98 Jun 21, 2023