xaudio2 - support for loop points for sound files. Forum Home > Construct Classic > Construct Classic Discussion |
Post Reply
|
| Author | |
Post Options
Quote Reply
Topic: xaudio2 - support for loop points for sound files.Posted: 06 Oct 2009 at 6:12pm |
|
|
by loop points i mean custom start and end of loop in samples rather than the currently available "play from start to finish" loop type.
once the music/sound effect reaches the start loop point, the "intro" part ends and the "loop" part starts. from that point it goes on until it reaches the position noted in the finish loop point, so once it does it returns to the position set in the start point and continues from there, giving an infinitely looping music/sound fx, like in most modern games. would it be possible to include something like that? i tried to simulate it with a variable that was increasing itself every frame and once it reached certain point the music positon was changed, but that doesn't work right if the framerate isn't perfect 60fps all the time, and all it'd need would be a slight hickup or pause and the faked synchronization would be over. |
|
![]() |
|
Post Options
Quote Reply
Posted: 06 Oct 2009 at 10:56pm |
|
|
System object -> compare -> get position. Then when that = something, set the channel position to something else.
Haven't tried that, but it should work I think. |
|
![]() |
|
Post Options
Quote Reply
Posted: 07 Oct 2009 at 12:40am |
|
|
i'm not sure how, since i don't see a compare option in the system object. do i need some extension?
even then as far as i know it'd be possible only in seconds, which is very inaccurate, when the loop is done in samples or at least miliseconds. i think having the program do it natively would be the best anyway rather than implementing workarounds. |
|
![]() |
|
Post Options
Quote Reply
Posted: 07 Oct 2009 at 1:42am |
|
|
[quote="Serio":2vi7zlx0]i'm not sure how, since i don't see a compare option in the system object. do i need some extension?
even then as far as i know it'd be possible only in seconds, which is very inaccurate, when the loop is done in samples or at least miliseconds. i think having the program do it natively would be the best anyway rather than implementing workarounds.[/quote:2vi7zlx0] go new event -> system, scroll down -> compare it may be in milliseconds (should be since everything else in the program is measured in milisenconds) It's only 1 event feature, not that hard for people to implement (I think, could be wrong) |
|
![]() |
|
Post Options
Quote Reply
Posted: 07 Oct 2009 at 2:24am |
|
|
alright, that worked. thanks.
it's in seconds, but you apparently can use the decimals as some sort of miliseconds i think and get the more less correct position. more less because i had to make the loop end .020 or so earlier than what goldwave shows as the correct place to end the loop (the loop in the ogg file ends at 57.163 seconds, but to get a correct loop i had to set the loop point at 57.142). not sure if it's simply different calculation or something. it still ocassionally goes out of sync though. |
|
![]() |
|
Post Options
Quote Reply
Posted: 07 Oct 2009 at 2:28am |
|
|
maybe you could just seperate the sounds? when the first intro sound finishes, play the other sound that needs to loop?
|
|
![]() |
|
Post Options
Quote Reply
Posted: 07 Oct 2009 at 4:57am |
|
|
i tried that, but the change's too noticable. it's kind of like either a slight silence or static, lasting for few miliseconds or so, but long enough to break the flow.
|
|
![]() |
|
Post Options
Quote Reply
Posted: 07 Oct 2009 at 4:12pm |
|
|
[quote:17kogi31]
i tried to simulate it with a variable that was increasing itself every frame and once it reached certain point the music positon was changed, but that doesn't work right if the framerate isn't perfect 60fps all the time, and all it'd need would be a slight hickup or pause and the faked synchronization would be over. [/quote:17kogi31] Use timedelta for this. Working with timedelta. However, I doubt this is a very accurate method. To make a perfect loop, I always manually cut the file. But first things first, what format are you using? OGG is the best format if you want things to loop (it's also the best format overal). Also, when you want to loop, you want to make sure that the waveform is at the 0dB line at the beginning and the end of the file. This is usually a pretty good guideline to make good loops. I do that with Audacity. Be sure to remove all the silence at the beginning and the ending by zooming in an incredible amount. Also, like I said, make sure that the waveform is at the 0dB line at the beginning and the ending. Then save the file as an OGG file. For me OGG has always looped perfectly, unlike MP3 for some reason. I hope that helps you a bit |
|
![]() |
|
Post Options
Quote Reply
Posted: 16 Oct 2009 at 4:23pm |
|
|
i use ogg only. mp3 format has that nasty problem where it adds silence at the start and end of the file upon encoding, effectively messing up loop points and making the "two pieces loop" trick useless.
but even with ogg the two piece thing didn't work for me. there was a noticable silence while the first file stopped, then it was detected that channel 0 no longer plays music, then the next track, the loop part starts up. |
|
![]() |
|
Post Options
Quote Reply
Posted: 18 Oct 2009 at 9:39pm |
|
|
Looping audio is tough even with a perfect splice.
Have you considered a small fadein/out in each sample? that's what editing software does to avoid jumps. Just start up the new sample a little bit earlier, about 1ms is enough but you could even go for 5 |
|
![]() |
|
Post Reply
|
| Forum Jump | Forum Permissions ![]() You cannot post new topics in this forum You cannot reply to topics in this forum You cannot delete your posts in this forum You cannot edit your posts in this forum You cannot create polls in this forum You cannot vote in polls in this forum |