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

Add an example for Magnum Audio #14

Merged
merged 15 commits into from Aug 26, 2015

Conversation

Projects
None yet
2 participants
@Squareys
Contributor

Squareys commented Aug 23, 2015

Hi @mosra !

Just to let you know I am currently working on this, here's an early PR for the magnum-audio example possibly coming in near future (in case it's good enough to pass review ;P ).

This is the first steps for getting the following line added to magnums description: "Audio is not an ugly stepchild either: [...]", we'll see if I can make this happen. I am hoping to implement OpenAL extension support in the future, but I don't know if I'll do more than the HRTF extension.

I hope you're as exited about this as I am ;)

Greetings, Squareys

@mosra

This comment has been minimized.

Owner

mosra commented Aug 23, 2015

Wow, didn't expect this :)

Yeah, audio currently is an ugly stepchild, the original implementation was done in a hurry for some game jam and I hadn't touched it since. I actually have some work-in-progress example in my local copy, but never managed to finish it, mainly because I discovered that the WavAudioImporter is not able to parse real-world files :/

What I planned but didn't have a time to do:

  • adding Playable scene graph feature to Magnum::Audio namespace that would manage Audio::Source and properly update its position, orientation (velocity?) on transformation change, so the user doesn't have to implement this every time from scratch
  • adding AudioSourceRenderer or something like that to Magnum::DebugTools namespace, which would visualize position, orientation, cone angle, gain etc. using some simple line art
  • my example would then be something similar to the bullet one, just displaying the audio sources using the debug renderer, playing them and changing their position based on user input

That's not to say that you should implement these things, just a brain dump in case you are trying to invent something similar :)

@Squareys

This comment has been minimized.

Contributor

Squareys commented Aug 24, 2015

@mosra I am currently trying to use Drawable2D, Flat2D, MatrixTransformation2D and such. I cannot seem to get anything rendered to the screen (grey screen of death? :D ). I must be missing something.

because I discovered that the WavAudioImporter is not able to parse real-world files :/

That doesn't sound too good. I will see what I can do if I discover that aswell.

adding Playable scene graph feature to Magnum::Audio namespace

Yes, and something which manages the listener position.

Adding AudioSourceRenderer or something like that to Magnum::DebugTools namespace

That is a very good idea. Obviously "hearing" if the sound is coming from the right direction wont help too much when debugging :D

my example would then be something similar to the bullet one, just displaying the audio sources using the debug renderer, playing them and changing their position based on user input.

After blowing up the example with image loading and such, I understand what you mean. Since this depends on the future changes/additions to the Audio module, I will implement this as originally planned first, and adapt it to debug renderers once the job in Magnum it self has been done. Is this okay with you?

@mosra

This comment has been minimized.

Owner

mosra commented Aug 25, 2015

WavAudioImporter is not able to parse real-world files becuase I incorrectly assumed that there aren't any additional RIFF chunks -- the code should just skip the unknown ones and read the data. I don't remember the particulars, sorry, long time since I last looked at it, but can certainly help you if you have any questions.

Oh, there's also stb_vorbis which might be easy enough to convert into a plugin for opening OGG files (as compared to MP3/Lame) ... or just used directly in the example if you want to have something quickly up and running :)

Since this depends on the future changes/additions to the Audio module, I will implement this as originally planned first, and adapt it to debug renderers once the job in Magnum it self has been done. Is this okay with you?

Sure! :)

EDIT: ugh, GitHub was DDoSed, I wrote this two hours ago and it failed to send, so here is it again :)

@Squareys Squareys force-pushed the Squareys:audio-example branch from e7771c7 to fd92451 Aug 25, 2015

@Squareys

This comment has been minimized.

Contributor

Squareys commented Aug 25, 2015

@mosra That was alot of fun! I just need to update the readme and then this is ready to merge!

You may want to listen into the wav (which is loaded perfectly fine btw). I got it from freesound.org: http://freesound.org/people/dkmedic/sounds/104457/
In case you find it inappropriate, I will use a different one. If you have a preference, just send me a link ;)

@Squareys Squareys force-pushed the Squareys:audio-example branch from fd92451 to 1c5d011 Aug 25, 2015

configure_file(${CMAKE_CURRENT_SOURCE_DIR}/configure.h.cmake
${CMAKE_CURRENT_BINARY_DIR}/configure.h)
corrade_add_resource(TexturedTriangleData resources.conf)

This comment has been minimized.

@mosra

mosra Aug 25, 2015

Owner

Probably a copypaste bug, if you enable also the textured-triangle example, CMake then complains about two targets with the same name (should be AudioData?)

This comment has been minimized.

@Squareys

Squareys Aug 25, 2015

Contributor

Hah, great :P Yeah, indeed.

if(!(audioManager.load("WavAudioImporter") & PluginManager::LoadState::Loaded))
std::exit(1);
std::unique_ptr<Audio::AbstractImporter> wavImporter = audioManager.instance("WavAudioImporter");

This comment has been minimized.

@mosra

mosra Aug 25, 2015

Owner

You might want to use PluginManager::Manager::loadAndInstantiate(), it's less repetitive if you don't need to do extensive checking.

This comment has been minimized.

@Squareys

Squareys Aug 25, 2015

Contributor

You may want to fix that in TexturedTriangle example too, maybe. I think I used that for reference.

This comment has been minimized.

@mosra

mosra Aug 26, 2015

Owner

...and everywhere else except for Viewer, which somehow has it right :)

Good point, thank you, noted.

@Squareys Squareys force-pushed the Squareys:audio-example branch from 4522997 to cbb1eea Aug 25, 2015

**Left-click**: Set sound source position.

This comment has been minimized.

@mosra

mosra Aug 25, 2015

Owner

Trailing newlines?

@Squareys

This comment has been minimized.

Contributor

Squareys commented Aug 25, 2015

@mosra I declare this PR as ready from my side.

@Squareys Squareys changed the title from [WIP] Add an example for Magnum Audio to Add an example for Magnum Audio Aug 25, 2015

Renderer::enable(Renderer::Feature::Blending);
Renderer::setBlendFunction(Renderer::BlendFunction::SourceAlpha, Renderer::BlendFunction::OneMinusSourceAlpha);
Renderer::setClearColor({0.6, 0.6, 0.6, 1.0});

This comment has been minimized.

@mosra

mosra Aug 25, 2015

Owner

I would maybe prefer that all examples have the same (=default) background color, to make them look similarly on the showcase page.

This comment has been minimized.

@Squareys

Squareys Aug 25, 2015

Contributor

Alright, I can understand that.

@mosra

This comment has been minimized.

Owner

mosra commented Aug 25, 2015

Added a few comments inline, other than that I'm more than happy. Great job again!

I hope it's okay that I added the audio example here myself.

Sure, no problem :)

Squareys added some commits Aug 25, 2015

audio: Add README.md and screenshot.
The future magnum-audio example will grow here.

Signed-off-by: Squareys <Squareys@googlemail.com>
audio: Add TexturedDrawable2D
For later displaying the listener and sound source.

Signed-off-by: Squareys <Squareys@googlemail.com>
audio: Add inital AudioExample skeleton code
Setup for a 2D plane mesh and 2D scene graph.

Signed-off-by: Squareys <Squareys@googlemail.com>
audio: Add option and cmake project files
magnum-audio example will be built with the `WITH_AUDIO` option in cmake.

Signed-off-by: Squareys <Squareys@googlemail.com>
audio: Add image resources
Signed-off-by: Squareys <Squareys@googlemail.com>
audio: Draw listener and source images.
Signed-off-by: Squareys <Squareys@googlemail.com>
audio: Add test wav file
Signed-off-by: Squareys <Squareys@googlemail.com>
audio: Load and play test wav.
Signed-off-by: Squareys <Squareys@googlemail.com>
audio: Set position of sound source
Signed-off-by: Squareys <Squareys@googlemail.com>
audio: Cleanup code and add explanatory comments
Signed-off-by: Squareys <Squareys@googlemail.com>
Credits: Add credits for audio test sound and audio example
Signed-off-by: Squareys <Squareys@googlemail.com>
audio: Fix blending for visualization
The images appeard as white alpha masks instead of the actually colors.
Fixing the blending revealed that the drawing order for the source and
listener wasn't correct after all.

Signed-off-by: Squareys <Squareys@googlemail.com>
audio: Remove custom clear color
The default works just fine and will make showcase consisten.

Signed-off-by: Squareys <Squareys@googlemail.com>

@Squareys Squareys force-pushed the Squareys:audio-example branch from cbb1eea to 0ca25d7 Aug 25, 2015

audio: Use PluginManager::Manager::loadAndInstantiate...
... rather than `PluginManager::Manager::load` and
`PluginManager::Manager::instantiate`. Looks nicer, less repetitive, spare
words.

Signed-off-by: Squareys <Squareys@googlemail.com>
@Squareys

This comment has been minimized.

Contributor

Squareys commented Aug 25, 2015

@mosra All your inline comments have been respected.

audio: Use Source::setPosition(Vector3)
Avoid rounding. I missed before this for some reason.

Signed-off-by: Squareys <Squareys@googlemail.com>

@mosra mosra merged commit 8905c4d into mosra:master Aug 26, 2015

1 check failed

continuous-integration/appveyor AppVeyor build failed
Details
@Squareys

This comment has been minimized.

Contributor

Squareys commented Aug 26, 2015

Thanks! :)

@mosra

This comment has been minimized.

Owner

mosra commented Aug 26, 2015

Me too! :)

@mosra mosra added this to the 2018.02 milestone Feb 16, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment