coding a better audio API

Posted By on July 24, 2019

okay welcome to the second time lapse type of thing that I'm doing I've decided that I want to record at least well not all of it but most of the development of this project is some kind of record other than code and I've decided they're going to make videos not only streams but because I don't have four hours five hours seven hours of a spare time to stream during the weekdays I'm going to make these small time-lapse videos of a two-hour more or less work session and yesterday I did one I put up on YouTube you can find there is not very high production quality or anything that's why I'm doing this now I'm speaking giving an intro and outro anyway so I did this implementation using open layout and SCB verbs which is the most straightforward way of playing a sound I think STP verbs is great up in there open al is quite simple to use to play a simple audio but this is you ad hoc I'd like to abstract this away a little bit so that we don't interact directly with STP verbs or if our open al but with our own API so that if you ever want you not play oh gee gee file for example we won't be using STV verbs or if you whatever I want to play if you are going to change migrate away from open al to F mothers and our own audio playback system I don't want to change the entire code base so I'm going to abstract this away into a subsystem of the engine and I also going to right now we are only playing music we are not playing sounds although there is not much difference there although actually right now we are playing music in the form of a sound because of a sound effect because you're not not streaming the file you're just loading the entire file into a buffer and playing it the ideal way issue for playing a long sound issue long music like that you should buffer from file instead of our foreign byte array or something instead of sending out the dated she did to the buffer and so I started to work on that right now and well hopefully will be a good solid two hours of progress in here I'll get back to you after two hours or so okay so I have the results here it's been one hour 55 minutes and I just about finished I thank for an hour list let me show you how we open the file how we open something and play a play something let me show the results first run the game so you can see here that we can click let me open this we can click to play the sound can pause the sound unpause you can stop the sound which you play from the beginning of and you can change the volume of it and I don't know if that I don't know if the the video will be played in stereo but if I go to my left I should see the sound play on my right if I go to my right I should see the son play on my left if I rotate the camera as you see I should hear the sound playing around me so that's right I'm a right Oh and I can rotate around so that's how good let's see how we load stuff so to load we first load the asset file which is music slash test then we get the asset because we just load you get the ID we created audio source we set out your search to the should be did the asset should be the music asset and we add to our list and that will that will be hot reloading later to plate we go to it just calling play audio one shot this will start to plated the sound unpause you just play from the from the last position play audio just play from the last position pause audio is just pause stop and set here the volume adjusts at the other volume and for the camera if you go to read a table camera where is it you can see here that we just set the listener 3d position and their attention to be the position of the camera and the rotation of the camera and when I rotate or move the camera around I see that I heard the sound moving on the 3ds place on the 3d space is actually the camera that is moving the listener that is moving but the effects the same and the API is quite simple the implementation is also quite simple is maybe 200 300 lines there's a lot to do here like we need to expose and I need to understand all of the max distance fall-off distance stuff like that none of that is exposed and I also don't understand those values but for now I think it's pretty good we don't need anything much more so physically than this should to build the asteroid clone which is the showcase that you're building to create all of the systems that we need to build a 2-d game read grow and those are sounds graphics rendering text rendering and controller support which is the thing that will be adding next I believe but yeah I think that's pretty much it for today I'll be back tomorrow probably our this week for sure and on the weekends I'll be streaming on Twitch ok that's about it thank you thanks for watching see you next time

Posted by Lewis Heart

Leave a Reply

Your email address will not be published. Required fields are marked *