large_vocab_adt_dafx2018/percussion_synth.py
def synthesize(self,
                   output_file,
                   **kwargs):
        """
        Synthesize the patterns from self.jam. If self.jam does not exist, pass in the arguments to `generate_jam`.

        Parameters
        ----------
        output_file : str
            The path where the rendered and mixed output signal will be written. If None, no file will be written.
        kwargs : additional keyword arguments
            Additional keyword arguments to pass to `generate_jam` if self.jam is None.

        Returns
        -------
        rhythm_audio : np.array
            The mixed output_signal
        unmixed_rhythm_audio: np.array
            An MxN array where M is the number of rhythm patterns and N is the length of the measure in samples

        See Also
        --------
        generate_jam
        """
        if self.jam is None or len(kwargs) > 0:
            self.generate_jam(**kwargs)

        onset_anns = [ann for ann in self.jam.search(namespace='onset') if not ann.sandbox.base_pattern]

        unmixed_rhythm_audio = np.zeros([len(self.perc_voice_set), int(np.ceil(self.duration * self.sample_rate))])

        for k, onset_ann in enumerate(onset_anns):
            # load audio file
            sample, _ = read_audio(self.audio_files[k], self.sample_rate, mono=True)
            sample_length = sample.shape[0]

            # render samples at onsets
            for j in range(len(onset_ann.data.index)):
                start_idx = int(np.round(onset_ann.data.ix[j, 'time'].total_seconds() * self.sample_rate))
                start_idx = min(start_idx, unmixed_rhythm_audio.shape[1]-1)
                stop_idx = start_idx + sample_length
                stop_idx = min(stop_idx, unmixed_rhythm_audio.shape[1]-1)
                unmixed_rhythm_audio[k, start_idx:stop_idx] = onset_ann.data.ix[j, 'value'] * sample[:(stop_idx -
                                                                                                       start_idx)]

        rhythm_audio = np.dot(self.mixing_coeffs, unmixed_rhythm_audio)

        if output_file is not None:
            _write_audio(output_file, rhythm_audio, int(self.sample_rate))

        return rhythm_audio, unmixed_rhythm_audio

        Synthesize the patterns from self.jam. If self.jam does not exist, pass in the arguments to `generate_jam`.

        Parameters
        ----------
        output_file : str
            The path where the rendered and mixed output signal will be written. If None, no file will be written.
        kwargs : additional keyword arguments
            Additional keyword arguments to pass to `generate_jam` if self.jam is None.

        Returns
        -------
        rhythm_audio : np.array
            The mixed output_signal
        unmixed_rhythm_audio: np.array
            An MxN array where M is the number of rhythm patterns and N is the length of the measure in samples

        See Also
        --------
        generate_jam
        
Synthesize the patterns from self.jam. If self.jam does not exist, pass in the arguments to `generate_jam`.
Parameters

output_file : str
The path where the rendered and mixed output signal will be written. If None, no file will be written.
kwargs : additional keyword arguments
Additional keyword arguments to pass to `generate_jam` if self.jam is None.

Returns

rhythm_audio : np.array
The mixed output_signal
unmixed_rhythm_audio: np.array
An MxN array where M is the number of rhythm patterns and N is the length of the measure in samples

See Also


Synthesize the patterns from self . jam . If self . jam does not exist pass in the arguments to ` generate_jam ` . Parameters output_file : str The path where the rendered and mixed output signal will be written . If None no file will be written . kwargs : additional keyword arguments Additional keyword arguments to pass to ` generate_jam ` if self . jam is None . Returns rhythm_audio : np . array The mixed output_signal unmixed_rhythm_audio : np . array An MxN array where M is the number of rhythm patterns and N is the length of the measure in samples See Also
def synthesize(self,
                   output_file,
                   **kwargs):
        if self.jam is None or len(kwargs) > 0:
            self.generate_jam(**kwargs)
        onset_anns = [ann for ann in self.jam.search(namespace='onset') if not ann.sandbox.base_pattern]
        unmixed_rhythm_audio = np.zeros([len(self.perc_voice_set), int(np.ceil(self.duration * self.sample_rate))])
        for k, onset_ann in enumerate(onset_anns):
            sample, _ = read_audio(self.audio_files[k], self.sample_rate, mono=True)
            sample_length = sample.shape[0]
            for j in range(len(onset_ann.data.index)):
                start_idx = int(np.round(onset_ann.data.ix[j, 'time'].total_seconds() * self.sample_rate))
                start_idx = min(start_idx, unmixed_rhythm_audio.shape[1]-1)
                stop_idx = start_idx + sample_length
                stop_idx = min(stop_idx, unmixed_rhythm_audio.shape[1]-1)
                unmixed_rhythm_audio[k, start_idx:stop_idx] = onset_ann.data.ix[j, 'value'] * sample[:(stop_idx -
                                                                                                       start_idx)]
        rhythm_audio = np.dot(self.mixing_coeffs, unmixed_rhythm_audio)
        if output_file is not None:
            _write_audio(output_file, rhythm_audio, int(self.sample_rate))
        return rhythm_audio, unmixed_rhythm_audio
def synthesize ( self , output_file , ** kwargs ) : if self . jam is None or len ( kwargs ) > 0 : self . generate_jam ( ** kwargs ) onset_anns = [ ann for ann in self . jam . search ( namespace = 'onset' ) if not ann . sandbox . base_pattern ] unmixed_rhythm_audio = np . zeros ( [ len ( self . perc_voice_set ) , int ( np . ceil ( self . duration * self . sample_rate ) ) ] ) for k , onset_ann in enumerate ( onset_anns ) : sample , _ = read_audio ( self . audio_files [ k ] , self . sample_rate , mono = True ) sample_length = sample . shape [ 0 ] for j in range ( len ( onset_ann . data . index ) ) : start_idx = int ( np . round ( onset_ann . data . ix [ j , 'time' ] . total_seconds ( ) * self . sample_rate ) ) start_idx = min ( start_idx , unmixed_rhythm_audio . shape [ 1 ] - 1 ) stop_idx = start_idx + sample_length stop_idx = min ( stop_idx , unmixed_rhythm_audio . shape [ 1 ] - 1 ) unmixed_rhythm_audio [ k , start_idx : stop_idx ] = onset_ann . data . ix [ j , 'value' ] * sample [ : ( stop_idx - start_idx ) ] rhythm_audio = np . dot ( self . mixing_coeffs , unmixed_rhythm_audio ) if output_file is not None : _write_audio ( output_file , rhythm_audio , int ( self . sample_rate ) ) return rhythm_audio , unmixed_rhythm_audio
Synthesize the patterns from self.jam.
Synthesize the patterns from self . jam .
"""
        Synthesize the patterns from self.jam. If self.jam does not exist, pass in the arguments to `generate_jam`.

        Parameters
        ----------
        output_file : str
            The path where the rendered and mixed output signal will be written. If None, no file will be written.
        kwargs : additional keyword arguments
            Additional keyword arguments to pass to `generate_jam` if self.jam is None.

        Returns
        -------
        rhythm_audio : np.array
            The mixed output_signal
        unmixed_rhythm_audio: np.array
            An MxN array where M is the number of rhythm patterns and N is the length of the measure in samples

        See Also
        --------
        generate_jam
        """ # load audio file # render samples at onsets
self
output_file