PYTHON - Getting CTsound volume strength on current frame
-
Hello! I was trying to create my own variation of the Sound Effector on R19 since the one on my version doesn't fit the purpose of LipSyncing since it doesn't follow Sound Track time offset from the timeline,
I tried several python functions including CTrack.GetValue() but it always return 0
Any way possible that I can get the sound strength value from a sound track (CTsound type) using python? I can make the thing using Sound Node, but once played, it cannot be stopped or controlled by timeline itself.
-
hi,
I've edit your post to add the python tag and set the thread to "ask a question". You can read our guidelines to have more informations about those features.
Sample the value of a sound track isn't possible directly. But you can use the SoundEffectorData to do so.
That's what is used in the sound effector.
You can create probe and define the frequencies and the amplitude of the samples.We also have the C++ manual where you will find some informations.
A basic example :
import c4d from c4d import gui # Welcome to the world of Python # Main function def main(): tracks = op.GetCTracks() for track in tracks: if track.IsInstanceOf(c4d.CTsound): sed = c4d.SoundEffectorData(); sed.SetActiveSoundTrack(track, doc) # we create basic probes at different frequencies probeIndex = sed.CreateProbe(5000,10000, 1, 0, False) probeIndex2 = sed.CreateProbe(10001,25001, 1, 0, False) # initsample before doing any sample sed.InitSampling(doc) samples = sed.Sample(probeIndex,1) print (samples) samples = sed.Sample(probeIndex2,2) print (samples) # don't forget to call freesampling' sed.FreeSampling() # Execute main() if __name__=='__main__': main()
Cheers,
Manuel -
That does its thing, but like the Sound Effector included in MoGraph Effectors, even if I set the offset of the track like ahead like 30 frames, it still reads volume/sample data from the position of the track with high volume on its original position if the track started in 0F
For like...
If my voice starts at 40F and I pick an offset of 30F, it should start reading sample data from 70F and not 40F
By this code, it behaves the same as the Sound Effector, but the data is readable and can be applied to any object.
-
hi,
sorry i just saw that you were using R19. this issue have been fixed in later release.
a working workaround is to change the time of the document sample it and come back to the current time.
With ExecutePasses you will be (kind of) sure that your document will be updated properlly.import c4d from c4d import gui # Welcome to the world of Python # Main function def main(): tracks = op.GetCTracks() for track in tracks: if track.IsInstanceOf(c4d.CTsound): currentTime = doc.GetTime() offset = track[c4d.CID_SOUND_START] newTime = currentTime - offset doc.SetTime(newTime) doc.ExecutePasses(None, True, True, True, 0) sed = c4d.SoundEffectorData(); sed.SetActiveSoundTrack(track, doc) # we create basic probes at different frequencies probeIndex = sed.CreateProbe(5000,10000, 1, 0, False) probeIndex2 = sed.CreateProbe(10001,25001, 1, 0, False) # initsample before doing any sample sed.InitSampling(doc) samples = sed.Sample(probeIndex,1) print (samples) samples = sed.Sample(probeIndex2,2) print (samples) # don't forget to call freesampling' sed.FreeSampling() doc.SetTime(currentTime) doc.ExecutePasses(None, True, True, True, 0) # Execute main() if __name__=='__main__': main()
Cheers,
Manuel -
Hi @SolarPH,
without further questions or feedback, we will consider this thread as solved by Monday and flag it accordingly.
Cheers,
Ferdinand