Giter VIP home page Giter VIP logo

Comments (8)

mbillingr avatar mbillingr commented on August 11, 2024

Hi! It's cool that you want to use ambisonic in an actual game. I never really started writing the game I wanted to use it in, so I hardly know how practical the API is... in other words: any feedback is highly appreciated :)

  1. i16 to f32 is a lossless conversion and should be no problem. There is a subtle scaling issue, though: f32 audio samples are usually in the range -1...1 while the simple cast results in a range of -32768...32767. Since you heard the sound just fine there does not seem to be a problem, though. I agree that this is a pain point in the API that should be improved.

  2. I'm not sure if it is possible to use different versions of Rodio simultaneously and it may be hard to completely decouple ambisonic from Rodio, but there is certainly room for improvement. Can you point me to some specific conflicts you have had?

from ambisonic.

bjadamson avatar bjadamson commented on August 11, 2024
  1. i16 to f32 is a lossless conversion and should be no problem. There is a subtle scaling issue, though: f32 audio samples are usually in the range -1...1 while the simple cast results in a range of -32768...32767. Since you heard the sound just fine there does not seem to be a problem, though. I agree that this is a pain point in the API that should be improved.

Well I don't want to claim the audio sounds correct by any means I only started using ambisonic today. I got it to play and I was obviously excited. Right now I'm still trying to figure out how to adjust the audio level for the sounds. The audio is really loud unless I set the position's z value to something like 50000. So I don't know if I'm using the API incorrect or the casted value is somehow messing with the audio. However after reading your response I printed the i16 values out just to see what they were. After looking at the printed values I tried dividing the sample values by 255 and 128 (thinking I could get them into the range [-1..1]) which significantly reduced the volume, but I'm not sure what actually needs to be done here. I think I'm on the right track, but I don't think directly modifying the sample values is the correct way to adjust the volume.

  1. I'm not sure if it is possible to use different versions of Rodio simultaneously and it may be hard to completely decouple ambisonic from Rodio, but there is certainly room for improvement. Can you point me to some specific conflicts you have had?

Sure thing. My project was already using rodio, and to use ambisonic the example code demonstrates pulling in the ambisonic::rodio module. Invoking the play_at function with a source that implements the 'rodio' instead of the 'ambisonic::rodio' trait (like my wrapper struct) causes a compilation error.

ie:

// changing
impl ambisonic::rodio::Source for Wrapper {

// to this
impl rodio::Source for Wrapper {

image

from ambisonic.

mbillingr avatar mbillingr commented on August 11, 2024
  1. I typically work with sample values in ranges not much larger than -1..1, and place the sources much closer to the center... say 100 or less. I think the correct approach for the conversion is to do |v| v as f32 / i16::MAX as f32. Then you can use a lower value for z (between 1 and 10 should be a good start).

  2. If you are using a recent version of rodio (0.12 or 0.13) this would explain the problem. Ambisonic only supports rodio up to 0.11 at the moment. I'm working on the necessary fixes now, so the next release will work with the most current rodio version.

from ambisonic.

mbillingr avatar mbillingr commented on August 11, 2024
  1. There is actually an easier way to convert audio samples. Rodio sources have a .convert_samples() method for this purpose. The following worked for me:
let file = std::fs::File::open("../../Downloads/Engine_01.wav").unwrap();
let source = rodio::Decoder::new(std::io::BufReader::new(file)).unwrap();
let source = source.repeat_infinite();

let mut sound = scene.play_at(source.convert_samples(), [50.0, 1.0, 0.0]);

from ambisonic.

bjadamson avatar bjadamson commented on August 11, 2024

That's amazing, and it just works. Thanks!

I think the code you posted above would go along way in helping someone else in the future. Would you be interested in a PR that adds your example to the documentation?

from ambisonic.

mbillingr avatar mbillingr commented on August 11, 2024

Sure! Go ahead :)
Maybe you can think of a nice generic replacement for the audio file name? Others obviously won't have that file available...

from ambisonic.

mbillingr avatar mbillingr commented on August 11, 2024

By the way, does version 4.0 correctly work with your rodio?

from ambisonic.

bjadamson avatar bjadamson commented on August 11, 2024

Yes it does I upgraded this morning, and was able to remove all references to ambisonic::rodio and just use rodio, everything worked nicely. Thanks for updating!

from ambisonic.

Related Issues (11)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.