Thatās a niftey trick. Nice.
Thanks ! I was wondering about buffering and thatās what was needed. Iām not that familiar with Python which is sometimes a bit confusing but I seem to be picking it up as I go along. So are you writing that code from a Python perspective, or things unique to Audaspace ? Unless Iām missing something the documentation on Audaspace is very poor. For example I donāt think it mentions anything about HAVING to buffer for reverse() which seems to be the case.
Iāve never reversed audio with the python API, and it c omes down to a mix of experience, reading the API, and knowing how things work at a level slightly lower than blender.
First off, if you are confused about the API, I wrote a resource on it several years back. It didnāt mention the aud module, but it may help. WIth the AUD documentation, the classes (Eg handle and factory) are on the same page. What youāll find is that all APIās seem pretty poor until you are fluent with the system being documented (in my experience).
So how did I write that code snippet. I recalled seeing that factories could be reversed, but that a handle could not be, so I decided the best approach was to have one playing forwards and another playing backwards. I then had to figure out how to reverse it. The API says:
reverse()
Plays a factory reversed.
[TABLE=āclass: docutils field-listā]
[TR=āclass: field-odd fieldā]
[TH=āclass: field-nameā]Returns:[/TH]
The created Factory object.
[/TR]
[TR=āclass: field-even fieldā]
[TH=āclass: field-nameā]Return type:[/TH]
Factory
[/TR]
[/TABLE]
Note
The factory has to have a finite length and has to be seekable. Itās recommended to use this only with factories with fast and accurate seeking, which is not true for encoded audio files, such ones should be buffered using buffer() before being played reversed.
Warning
If seeking is not accurate in the underlying factory youāll likely hear skips/jumps/cracks.
Youāll notice that it says that facroties have to be finite length and seekable, and even suggests buffering it.
So then it was simply a case of taking the factory, buffering it and then reversing it.
Now, Iāve found that unless you buffer audio, the first time you play it it will lag slightly, so I also buffered the reversed factory. Technically this shouldnāt be necessary, but for a smooth experience it probably is.
Then it was a case of looking for the seek method (handle.position, which Iāve also never used), and then playing/stopping (which I have used) it when required .
So there you go, that is how I wrote it.
Please note it takes a while to buffer the track so wait a few seconds after starting.
It may be worth creating a loading screen if this takes more than a few seconds, however this is often quite an involved process.
If you add some sort of music selection, this would also be nice. Youāve got me somewhat enthusiastic about this project, and Iāve always wanted to make a file selection screen, so I may do this this weekendā¦
Spining right with right mouse button just gives a ācannot set pitchā error as that part is not setup yet.
There are several issues I can see:
- You areāt using āhandle.keep = trueā so when the track reaches itās end, the handle becomes invalid
- A pitch of zero is invalid (and also wouldnāt be playing anything), so maybe run a check against this and make all pitches of less than, say, 0.001 simply pause the handle.
- Youāre also tarting the reverse track twice. (line 23 and line 35). The reason you start it twice is because you run handle.stop() rather than handle.pause(). handle.stop() completely invalidates the handle.
But yes, it is playing backwards.