TITLE:: FluidBufAudioTransport SUMMARY:: Interpolate between buffers CATEGORIES:: Libraries>FluidCorpusManipulation RELATED:: Classes/FluidAudioTransport DESCRIPTION:: Interpolates between the spectra of two sounds using the Optimal Transport algorithm See Henderson and Solomonm (2019) AUDIO TRANSPORT: A GENERALIZED PORTAMENTO VIA OPTIMAL TRANSPORT, DaFx CLASSMETHODS:: METHOD:: process, processBlocking Processs the source LINK::Classes/Buffer:: on the LINK::Classes/Server::. CODE::processBlocking:: will execute directly in the server command FIFO, whereas CODE::process:: will delegate to a separate worker thread. The latter is generally only worthwhile for longer-running jobs where you don't wish to tie up the server. ARGUMENT:: server The LINK::Classes/Server:: on which the buffers to be processed are allocated. ARGUMENT:: sourceA The first source buffer ARGUMENT:: startFrameA offset into the first source buffer (samples) STRONG::Constraints:: LIST:: ## Minimum: 0 :: ARGUMENT:: numFramesA number of samples to use from first source buffer ARGUMENT:: startChanA starting channel of first source buffer STRONG::Constraints:: LIST:: ## Minimum: 0 :: ARGUMENT:: numChansA number of channels to process in first source buffer ARGUMENT:: sourceB the second source buffer ARGUMENT:: startFrameB offset into the second source buffer (samples) STRONG::Constraints:: LIST:: ## Minimum: 0 :: ARGUMENT:: numFramesB number of samples to process from second buffer ARGUMENT:: startChanB starting channel for second buffer STRONG::Constraints:: LIST:: ## Minimum: 0 :: ARGUMENT:: numChansB number of channels to process in second buffer ARGUMENT:: destination buffer for interpolated audio ARGUMENT:: interpolation The amount to interpolate between A and B (0-1, 0 = A, 1 = B) STRONG::Constraints:: LIST:: ## Minimum: 0.0 ## Maximum: 1.0 :: ARGUMENT:: windowSize The window size. As spectral differencing relies on spectral frames, we need to decide what precision we give it spectrally and temporally, in line with Gabor Uncertainty principles. LINK::http://www.subsurfwiki.org/wiki/Gabor_uncertainty:: ARGUMENT:: hopSize The window hop size. As sinusoidal estimation relies on spectral frames, we need to move the window forward. It can be any size but low overlap will create audible artefacts. The -1 default value will default to half of windowSize (overlap of 2). ARGUMENT:: fftSize The inner FFT/IFFT size. It should be at least 4 samples long, at least the size of the window, and a power of 2. Making it larger allows an oversampling of the spectral precision. The -1 default value will use the next power of 2 equal or above the highest of windowSize and (bandwidth - 1) * 2. ARGUMENT:: freeWhenDone Free the server instance when processing complete. Default CODE::true:: ARGUMENT:: action A function to be evaluated once the offline process has finished and all Buffer's instance variables have been updated on the client side. The function will be passed CODE::[features]:: as an argument. RETURNS:: An instance of the processor METHOD:: kr Trigger the equivalent behaviour to CODE::processBlocking / process:: from a LINK::Classes/Synth::. Can be useful for expressing a sequence of buffer and data processing jobs to execute. Note that the work still executes on the server command FIFO (not the audio thread), and it is the caller's responsibility to manage the sequencing, using the CODE::done:: status of the various UGens. ARGUMENT:: sourceA The first source buffer ARGUMENT:: startFrameA offset into the first source buffer (samples) STRONG::Constraints:: LIST:: ## Minimum: 0 :: ARGUMENT:: numFramesA number of samples to use from first source buffer ARGUMENT:: startChanA starting channel of first source buffer STRONG::Constraints:: LIST:: ## Minimum: 0 :: ARGUMENT:: numChansA number of channels to process in first source buffer ARGUMENT:: sourceB the second source buffer ARGUMENT:: startFrameB offset into the second source buffer (samples) STRONG::Constraints:: LIST:: ## Minimum: 0 :: ARGUMENT:: numFramesB number of samples to process from second buffer ARGUMENT:: startChanB starting channel for second buffer STRONG::Constraints:: LIST:: ## Minimum: 0 :: ARGUMENT:: numChansB number of channels to process in second buffer ARGUMENT:: destination buffer for interpolated audio ARGUMENT:: interpolation The amount to interpolate between A and B (0-1, 0 = A, 1 = B) STRONG::Constraints:: LIST:: ## Minimum: 0.0 ## Maximum: 1.0 :: ARGUMENT:: windowSize The window size. As spectral differencing relies on spectral frames, we need to decide what precision we give it spectrally and temporally, in line with Gabor Uncertainty principles. LINK::http://www.subsurfwiki.org/wiki/Gabor_uncertainty:: ARGUMENT:: hopSize The window hop size. As sinusoidal estimation relies on spectral frames, we need to move the window forward. It can be any size but low overlap will create audible artefacts. The -1 default value will default to half of windowSize (overlap of 2). ARGUMENT:: fftSize The inner FFT/IFFT size. It should be at least 4 samples long, at least the size of the window, and a power of 2. Making it larger allows an oversampling of the spectral precision. The -1 default value will use the next power of 2 equal or above the highest of windowSize and (bandwidth - 1) * 2. ARGUMENT:: trig A CODE::kr:: signal that will trigger execution ARGUMENT:: blocking Whether to execute this process directly on the server command FIFO or delegate to a worker thread. See CODE::processBlocking/process:: for caveats. INSTANCEMETHODS:: METHOD:: kr Returns a UGen that reports the progress of the running task when executing in a worker thread. Calling code::scope:: with this can be used for a convinient progress monitor METHOD:: cancel Cancels non-blocking processing METHOD:: wait When called in the context of a LINK::Classes/Routine:: (it won't work otherwise), will block execution until the processor has finished. This can be convinient for writing sequences of processes more linearly than using lots of nested actions. EXAMPLES:: code:: //Didactic: //Make 2 sinewave sources to be interpolated ( b = Buffer.loadCollection(s, FloatArray.fill(44100, {|a|(a / pi).sin * 0.1})); c = Buffer.loadCollection(s, FloatArray.fill(44100, {|a|(a / pi / 2).sin * 0.02})); d = Buffer.new ) //make an sound interpolating their spectrum FluidBufAudioTransport.process(s,b,source2:c,destination:d,interpolation:0.5,action:{"Ding".postln}) // listen to the source and the result b.play c.play d.play // note that the process is quantized by the spectral bins. For an example of the pros and cons of these settings on this given process, please see the real-time FluidAudioTransport helpfile. // more interesting sources: two cardboard bowing gestures ( b = Buffer.read(s,FluidFilesPath("Green-Box641.wav")); c = Buffer.read(s,FluidFilesPath("Green-Box639.wav")); d = Buffer.new ) // listen to the source b.play c.play // process and listen FluidBufAudioTransport.process(s,b,source2:c,destination:d,interpolation:0.5,action:{"Ding".postln}) d.play // try various interpolation factors (0.1 and 0.9 are quite good ::