www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Seeking in arsd.simpleaudio?

reply TheZipCreator <thezipcreator protonmail.com> writes:
I'm currently making a library to do programmatic animation (akin 
to [manim](https://www.manim.community/) but for D and a 
different style) and for audio arsd.simpleaudio seems like the 
only real option (all the others I could find are too low-level 
for my taste) but if I want to skip to a specific section of the 
video, then I'd need to be able to seek the audio to that 
location too, and it appears that arsd.simpleaudio doesn't have a 
seek function. Is there a way to do this via other means? I want 
something like:

```d

import arsd.simpleaudio, arsd.vorbis;

void main() {
   AudioOutputThread aot = AudioOutputThread(true);
   aot.playOgg("myAudio.ogg");
   import std.datetime;
   aot.seek(5.seconds); // or maybe this could be directly in 
.playOgg
}
```

so how would you implement this hypothetical `seek` function? (or 
if you could tell me a different library that already has this 
functionality that'd be great too)
Nov 20 2022
next sibling parent reply Adam D Ruppe <destructionator gmail.com> writes:
On Sunday, 20 November 2022 at 20:23:28 UTC, TheZipCreator wrote:
 so how would you implement this hypothetical `seek` function? 
 (or if you could tell me a different library that already has 
 this functionality that'd be great too)
My underlying vorbis lib has it, but haven't added to the simpleaudio interface yet. (Partly cuz i haven't figured it out for the ogg/mp3/wav combo yet) Give me a half hour lemme see if I can do it right now. I'll actually put it on the interface returned by playOgg...... i'll get back to you in a lil
Nov 20 2022
parent reply Adam D Ruppe <destructionator gmail.com> writes:
On Sunday, 20 November 2022 at 20:34:44 UTC, Adam D Ruppe wrote:
 i'll get back to you in a lil
i went overbudget lol. but yeah the seek function in the underlying lib fails and idk why it is so hard to even trace what error actually happened in these C codebases
Nov 20 2022
parent reply TheZipCreator <thezipcreator protonmail.com> writes:
On Sunday, 20 November 2022 at 21:57:03 UTC, Adam D Ruppe wrote:
 On Sunday, 20 November 2022 at 20:34:44 UTC, Adam D Ruppe wrote:
 i'll get back to you in a lil
i went overbudget lol. but yeah the seek function in the underlying lib fails and idk why it is so hard to even trace what error actually happened in these C codebases
I can imagine, errors in C are extremely annoying. I guess in the meantime I'll just use a python script to cut the audio before execution
Nov 20 2022
parent Adam D Ruppe <destructionator gmail.com> writes:
On Sunday, 20 November 2022 at 22:26:26 UTC, TheZipCreator wrote:
 I guess in the meantime I'll just use a python script to cut 
 the audio before execution
i found the problem the library called seek(-thing) and my seek had a if(x <= 0) return; when it should have been if(x == 0) return. so it wouldn't go backward in the file! i'll add it to the interface and do some more fixes, then i can link you to the new file. should ACTUALLY be closer to 30 mins now but no promises i might still find new bugs yet but it is working in the one test file very well now.
Nov 20 2022
prev sibling parent reply Adam D Ruppe <destructionator gmail.com> writes:
On Sunday, 20 November 2022 at 20:23:28 UTC, TheZipCreator wrote:
 and it appears that arsd.simpleaudio doesn't have a seek 
 function. Is there a way to do this via other means? I want 
 something like:
Here's the patch for ogg, you can download those two files off git master too (i can't tag yet since i have a lot of pending stuff before regression testing but you can copy them into your current dir or replace the dub cache if you're using that directly and it will work) https://github.com/adamdruppe/arsd/commit/1f6ead0a178a8cfbb284d7719fe38863610165e2 It looks like: auto controller = aot.playOgg("myAudio.ogg"); controller.seek(5.0); // a float that is seconds in the file Looking at doing it for mp3 is why I didn't put it in the interface yet... my mp3 code ported to D doesn't have a seek function! But ogg did, it was just buggy.
Nov 20 2022
next sibling parent TheZipCreator <thezipcreator protonmail.com> writes:
On Sunday, 20 November 2022 at 23:03:49 UTC, Adam D Ruppe wrote:
 Here's the patch for ogg, you can download those two files off 
 git master too
works great! thanks
Nov 20 2022
prev sibling parent Adam D Ruppe <destructionator gmail.com> writes:
On Sunday, 20 November 2022 at 23:03:49 UTC, Adam D Ruppe wrote:
 Looking at doing it for mp3 is why I didn't put it in the 
 interface yet... my mp3 code ported to D doesn't have a seek 
 function!
This is fixed on my computer now too, just need to check the rest of the bugs. So mp3 support will be coming before long as well. I'll do .wav too later in the week. Not sure about the emulated midi yet, but I'd love them all to implement the same interface, so I'll try. The next arsd tag is gonna have a lot of cool little things.
Nov 20 2022