Package: cached-conv
Streamable Neural Audio Synthesis With Non-Causal ConvolutionsDeep learning models are mostly used in an offline inference fashion. However, this strongly limits the use of these models inside audio generation setups, as most creative workflows are based on real-time digital signal processing. Although approaches based on recurrent networks can be naturally adapted to this buffer-based computation, the use of convolutions still poses some serious challenges. To tackle this issue, the use ofcausal streaming convolutionshave been proposed. However, this requires specific complexified training and can impact the resulting audio quality.In this paper, we introduce a new method allowing to producenon-causal streamingmodels. This allows to make any convolutional model compatible with real-time buffer-based processing. As our method is based on a post-training reconfiguration of the model, we show that it is able to transform models trained without causal constraints into a streaming model. We show how our method can be adapted to fit complex architectures with parallel branches. To evaluate our method, we apply it on the recent RAVE model, which provides high-quality real-time audio synthesis. We test our approach on multiple music and speech datasets and show that it is faster than overlap-add methods, while having no impact on the generation quality. Finally, we introduce two open-source implementation of our work as Max/MSP and PureData externals, and as a VST audio plugin. This allows to endow traditional digital audio workstations with real-time neural audio synthesis on any laptop CPU.Streamable RAVE for live audio processingApplying our method on the RAVE model allows its use on realtime audio signals, on a wide range of platforms.RAVE x nn~embedded RAVEBuilding a Streamable Convolutional Neural NetworkLet's define a simple autoencoder modelimporttorchimporttorch.nnasnnimportcached_convasccclassAutoEncoder(nn.Module):def__init__(self):super().__init__()self.encoder=cc.Sequential(cc.Conv1d(1,16,3,stride=2,padding=1),nn.ReLU(),cc.Conv1d(16,16,3,stride=2,padding=1),nn.ReLU(),cc.Conv1d(16,16,3,stride=2,padding=1),)self.decoder=cc.Sequential(cc.ConvTranspose1d(16,16,4,stride=2,padding=1),nn.ReLU(),cc.ConvTranspose1d(16,16,4,stride=2,padding=1),nn.ReLU(),cc.ConvTranspose1d(16,1,4,stride=2,padding=1),)defforward(self,x):returnself.decoder(self.encoder(x))Notice that we use convolutions defined by thecached_convpackage instead oftorch.nn. If we stop here, we get a model that behaves exactly as itstorch.nncounterpart. However, if we enable cached convs and then instanciate the modelimportcached_convascccc.use_cached_conv(True)model=AutoEncoder()we now have a streamable model, i.e that can work on live streams ! We can now export it as a torchscript modelmodel.register_buffer("forward_params",torch.tensor([1,1,1,1]))scripted_model=torch.jit.script(model)torch.jit.save(scripted_model,"exported_model.ts")And load it insidenn~ for max/msp and PureDatafor real-time neural audio processing ! Note that nn~ requires aMETHOD_paramsbuffer in the model for each exported method. It must be a tensor with 4 values:in channel numberin sampling rate divider (1 = audio rate, 100 = audio rate / 100)out channel numberout sampling rate dividerWe can also export the encode method like thisclassAutoEncoder(nn.Module):@torch.jit.exportdefencode(self,x):returnself.encoder(x)...model=AutoEncoder()model.register_buffer("encode_params",torch.tensor([1,1,16,8]))Realtime applicationsnn~Thenn~external for max/msp and PureData allows to interface pre-trained deep learning models in a graphical way, giving full control to the user on the different dimensions of input and output tensors.RAVE vstThe RAVE vst is a VST2/VST3/AU plugin designed to allow the use of theRAVE modelinside regular digital audio workstations such as Ableton Live or Bitwig Studio.