large_vocab_adt_dafx2018/percussion_synth.py
def generate_jam(self,
                     output_jams_file=None,
                     audio_files=None,
                     audio_directory=None,
                     mixing_coeffs=None,
                     sample_rate=None,
                     min_amplitude=None,
                     duration_sec=None,
                     additional_onset_sandbox_info=None,
                     additional_global_sandbox_info=None):
        """
        Parameters
        ----------
        output_jams_file : str
            If not None, write jams file to `output_jams_file`.
        audio_files : list[str]
            A list of the audio_files to use for rendering the rhythm patterns. These should be ordered according to the
            pattern (e.g., if the patterns were constructed to be from low frequency to high frequency, a bass drum
            might be first in the list). If not None, overwrite self.audio_files. Default is None.
        audio_directory : str
            If audio_files is None, then this must be set. It will randomly sample from subdirectories in PERC_VOICE_SET
            Default is None
        mixing_coeffs : np.array
            The coefficients specifying the mixing levels for the patterns. If not None, overwrite self.mixing_coeffs.
            Default is None.
        sample_rate : float
            Sampling rate of output. If not None, overwrite self.sample_rate. Default is None.
        min_amplitude : float
            The minimum amplitude to render for the softest sound above 0 in log amplitude. If not None, overwrite
            self.min_amplitude. Default is None.
        duration_sec : float
            If not None, extend the rhythm pattern to the target duration. Default is None.
        additional_onset_sandbox_info : list[dict]
            If not None, then save this additional info in the sandbox for the corresponding onset annotation.
            Default is None.
        additional_global_sandbox_info: dict
            If not None, then save this additional info in the top-level sandbox of the JAM. Default is None.

        Returns
        -------
        jam : jams.JAM

        """
        if mixing_coeffs is not None:
            self._mixing_coeffs = mixing_coeffs

        if audio_files is None and audio_directory is None:
            raise Exception("Either `audio_files` or `audio_directory` must be defined.")

        if audio_files is None:
            audio_files = select_audio_files_from_directory(audio_directory)[0]

        self._audio_files = audio_files
        assert (len(self.audio_files) == len(self.perc_voice_set))

        if sample_rate is not None:
            self._sample_rate = sample_rate

        if min_amplitude is not None:
            self._min_amplitude = min_amplitude

        # make JAM structure
        jam = jams.JAMS()
        jam.file_metadata.duration = self.duration
        jam.sandbox.sample_rate = self.sample_rate
        # jam.sandbox.time_signature = (self.ts_num, self.ts_denom)
        jam.sandbox.min_amplitude = self.min_amplitude
        jam.sandbox.has_large_vocab = self.has_large_vocab
        jam.sandbox.perc_voice_set = self.perc_voice_set
        if additional_global_sandbox_info is not None:
            jam.sandbox.update(**additional_global_sandbox_info)

        if self.get_beats() is not None:
            # write beat positions to jams
            base_pattern = False
            beat_ann = jams.Annotation(namespace='beat', time=0, duration=jam.file_metadata.duration)
            beat_ann.sandbox = jams.Sandbox(base_pattern=base_pattern)
            for k, t in enumerate(self.get_beats()):
                beat_ann.append(time=t,
                                duration=0.0,
                                value=k)
            jam.annotations.append(beat_ann)

        # write tempo to jams
        # tempo_ann = jams.Annotation(namespace='tempo', time=0, duration=jam.file_metadata.duration)
        # tempo_ann.append(time=0, duration=jam.file_metadata.duration, value=self.tempo, confidence=1.0)
        # jam.annotations.append(tempo_ann)

        # write onsets for each rhythm pattern
        onsets = self.get_onsets()
        for i in range(len(self.perc_voice_set)):
            base_pattern = False
            onsets_ann = jams.Annotation(namespace='onset', time=0, duration=jam.file_metadata.duration)
            onsets_ann.sandbox = jams.Sandbox(pattern_index=i,
                                              perc_voice=self.perc_voice_set[i],
                                              audio_source=self.audio_files[i],
                                              mixing_coeff=self.mixing_coeffs[i],
                                              base_pattern=base_pattern)
            if additional_onset_sandbox_info is not None:
                onsets_ann.sandbox.update(**additional_onset_sandbox_info[i])

            # write onsets
            for onset in onsets[i][1]:
                onsets_ann.append(time=onset['time'],
                                  value=velocity_to_amp(onset['velocity'], (self.min_amplitude, 0.)),
                                  duration=0)

            jam.annotations.append(onsets_ann)

        self._jam = jam
        if output_jams_file is not None:
            jam.save(output_jams_file)

        return jam

        Parameters
        ----------
        output_jams_file : str
            If not None, write jams file to `output_jams_file`.
        audio_files : list[str]
            A list of the audio_files to use for rendering the rhythm patterns. These should be ordered according to the
            pattern (e.g., if the patterns were constructed to be from low frequency to high frequency, a bass drum
            might be first in the list). If not None, overwrite self.audio_files. Default is None.
        audio_directory : str
            If audio_files is None, then this must be set. It will randomly sample from subdirectories in PERC_VOICE_SET
            Default is None
        mixing_coeffs : np.array
            The coefficients specifying the mixing levels for the patterns. If not None, overwrite self.mixing_coeffs.
            Default is None.
        sample_rate : float
            Sampling rate of output. If not None, overwrite self.sample_rate. Default is None.
        min_amplitude : float
            The minimum amplitude to render for the softest sound above 0 in log amplitude. If not None, overwrite
            self.min_amplitude. Default is None.
        duration_sec : float
            If not None, extend the rhythm pattern to the target duration. Default is None.
        additional_onset_sandbox_info : list[dict]
            If not None, then save this additional info in the sandbox for the corresponding onset annotation.
            Default is None.
        additional_global_sandbox_info: dict
            If not None, then save this additional info in the top-level sandbox of the JAM. Default is None.

        Returns
        -------
        jam : jams.JAM

        
Parameters
output_jams_file : str
If not None, write jams file to `output_jams_file`.
audio_files : list[str]
A list of the audio_files to use for rendering the rhythm patterns. These should be ordered according to the
pattern . If not None, overwrite self.audio_files. Default is None.
audio_directory : str
If audio_files is None, then this must be set. It will randomly sample from subdirectories in PERC_VOICE_SET
Default is None
mixing_coeffs : np.array
The coefficients specifying the mixing levels for the patterns. If not None, overwrite self.mixing_coeffs.
Default is None.
sample_rate : float
Sampling rate of output. If not None, overwrite self.sample_rate. Default is None.
min_amplitude : float
The minimum amplitude to render for the softest sound above 0 in log amplitude. If not None, overwrite
self.min_amplitude. Default is None.
duration_sec : float
If not None, extend the rhythm pattern to the target duration. Default is None.
additional_onset_sandbox_info : list[dict]
If not None, then save this additional info in the sandbox for the corresponding onset annotation.
Default is None.
additional_global_sandbox_info: dict
If not None, then save this additional info in the top-level sandbox of the JAM. Default is None.

Returns


Parameters output_jams_file : str If not None write jams file to ` output_jams_file ` . audio_files : list [ str ] A list of the audio_files to use for rendering the rhythm patterns . These should be ordered according to the pattern . If not None overwrite self . audio_files . Default is None . audio_directory : str If audio_files is None then this must be set . It will randomly sample from subdirectories in PERC_VOICE_SET Default is None mixing_coeffs : np . array The coefficients specifying the mixing levels for the patterns . If not None overwrite self . mixing_coeffs . Default is None . sample_rate : float Sampling rate of output . If not None overwrite self . sample_rate . Default is None . min_amplitude : float The minimum amplitude to render for the softest sound above 0 in log amplitude . If not None overwrite self . min_amplitude . Default is None . duration_sec : float If not None extend the rhythm pattern to the target duration . Default is None . additional_onset_sandbox_info : list [ dict ] If not None then save this additional info in the sandbox for the corresponding onset annotation . Default is None . additional_global_sandbox_info : dict If not None then save this additional info in the top - level sandbox of the JAM . Default is None . Returns
def generate_jam(self,
                     output_jams_file=None,
                     audio_files=None,
                     audio_directory=None,
                     mixing_coeffs=None,
                     sample_rate=None,
                     min_amplitude=None,
                     duration_sec=None,
                     additional_onset_sandbox_info=None,
                     additional_global_sandbox_info=None):
        if mixing_coeffs is not None:
            self._mixing_coeffs = mixing_coeffs
        if audio_files is None and audio_directory is None:
            raise Exception("Either `audio_files` or `audio_directory` must be defined.")
        if audio_files is None:
            audio_files = select_audio_files_from_directory(audio_directory)[0]
        self._audio_files = audio_files
        assert (len(self.audio_files) == len(self.perc_voice_set))
        if sample_rate is not None:
            self._sample_rate = sample_rate
        if min_amplitude is not None:
            self._min_amplitude = min_amplitude
        jam = jams.JAMS()
        jam.file_metadata.duration = self.duration
        jam.sandbox.sample_rate = self.sample_rate
        jam.sandbox.min_amplitude = self.min_amplitude
        jam.sandbox.has_large_vocab = self.has_large_vocab
        jam.sandbox.perc_voice_set = self.perc_voice_set
        if additional_global_sandbox_info is not None:
            jam.sandbox.update(**additional_global_sandbox_info)
        if self.get_beats() is not None:
            base_pattern = False
            beat_ann = jams.Annotation(namespace='beat', time=0, duration=jam.file_metadata.duration)
            beat_ann.sandbox = jams.Sandbox(base_pattern=base_pattern)
            for k, t in enumerate(self.get_beats()):
                beat_ann.append(time=t,
                                duration=0.0,
                                value=k)
            jam.annotations.append(beat_ann)
        onsets = self.get_onsets()
        for i in range(len(self.perc_voice_set)):
            base_pattern = False
            onsets_ann = jams.Annotation(namespace='onset', time=0, duration=jam.file_metadata.duration)
            onsets_ann.sandbox = jams.Sandbox(pattern_index=i,
                                              perc_voice=self.perc_voice_set[i],
                                              audio_source=self.audio_files[i],
                                              mixing_coeff=self.mixing_coeffs[i],
                                              base_pattern=base_pattern)
            if additional_onset_sandbox_info is not None:
                onsets_ann.sandbox.update(**additional_onset_sandbox_info[i])
            for onset in onsets[i][1]:
                onsets_ann.append(time=onset['time'],
                                  value=velocity_to_amp(onset['velocity'], (self.min_amplitude, 0.)),
                                  duration=0)
            jam.annotations.append(onsets_ann)
        self._jam = jam
        if output_jams_file is not None:
            jam.save(output_jams_file)
        return jam
def generate_jam ( self , output_jams_file = None , audio_files = None , audio_directory = None , mixing_coeffs = None , sample_rate = None , min_amplitude = None , duration_sec = None , additional_onset_sandbox_info = None , additional_global_sandbox_info = None ) : if mixing_coeffs is not None : self . _mixing_coeffs = mixing_coeffs if audio_files is None and audio_directory is None : raise Exception ( "Either `audio_files` or `audio_directory` must be defined." ) if audio_files is None : audio_files = select_audio_files_from_directory ( audio_directory ) [ 0 ] self . _audio_files = audio_files assert ( len ( self . audio_files ) == len ( self . perc_voice_set ) ) if sample_rate is not None : self . _sample_rate = sample_rate if min_amplitude is not None : self . _min_amplitude = min_amplitude jam = jams . JAMS ( ) jam . file_metadata . duration = self . duration jam . sandbox . sample_rate = self . sample_rate jam . sandbox . min_amplitude = self . min_amplitude jam . sandbox . has_large_vocab = self . has_large_vocab jam . sandbox . perc_voice_set = self . perc_voice_set if additional_global_sandbox_info is not None : jam . sandbox . update ( ** additional_global_sandbox_info ) if self . get_beats ( ) is not None : base_pattern = False beat_ann = jams . Annotation ( namespace = 'beat' , time = 0 , duration = jam . file_metadata . duration ) beat_ann . sandbox = jams . Sandbox ( base_pattern = base_pattern ) for k , t in enumerate ( self . get_beats ( ) ) : beat_ann . append ( time = t , duration = 0.0 , value = k ) jam . annotations . append ( beat_ann ) onsets = self . get_onsets ( ) for i in range ( len ( self . perc_voice_set ) ) : base_pattern = False onsets_ann = jams . Annotation ( namespace = 'onset' , time = 0 , duration = jam . file_metadata . duration ) onsets_ann . sandbox = jams . Sandbox ( pattern_index = i , perc_voice = self . perc_voice_set [ i ] , audio_source = self . audio_files [ i ] , mixing_coeff = self . mixing_coeffs [ i ] , base_pattern = base_pattern ) if additional_onset_sandbox_info is not None : onsets_ann . sandbox . update ( ** additional_onset_sandbox_info [ i ] ) for onset in onsets [ i ] [ 1 ] : onsets_ann . append ( time = onset [ 'time' ] , value = velocity_to_amp ( onset [ 'velocity' ] , ( self . min_amplitude , 0. ) ) , duration = 0 ) jam . annotations . append ( onsets_ann ) self . _jam = jam if output_jams_file is not None : jam . save ( output_jams_file ) return jam
Parameters
output_jams_file : str
If not None, write jams file to `output_jams_file`.
Parameters output_jams_file : str If not None write jams file to ` output_jams_file ` .
"""
        Parameters
        ----------
        output_jams_file : str
            If not None, write jams file to `output_jams_file`.
        audio_files : list[str]
            A list of the audio_files to use for rendering the rhythm patterns. These should be ordered according to the
            pattern (e.g., if the patterns were constructed to be from low frequency to high frequency, a bass drum
            might be first in the list). If not None, overwrite self.audio_files. Default is None.
        audio_directory : str
            If audio_files is None, then this must be set. It will randomly sample from subdirectories in PERC_VOICE_SET
            Default is None
        mixing_coeffs : np.array
            The coefficients specifying the mixing levels for the patterns. If not None, overwrite self.mixing_coeffs.
            Default is None.
        sample_rate : float
            Sampling rate of output. If not None, overwrite self.sample_rate. Default is None.
        min_amplitude : float
            The minimum amplitude to render for the softest sound above 0 in log amplitude. If not None, overwrite
            self.min_amplitude. Default is None.
        duration_sec : float
            If not None, extend the rhythm pattern to the target duration. Default is None.
        additional_onset_sandbox_info : list[dict]
            If not None, then save this additional info in the sandbox for the corresponding onset annotation.
            Default is None.
        additional_global_sandbox_info: dict
            If not None, then save this additional info in the top-level sandbox of the JAM. Default is None.

        Returns
        -------
        jam : jams.JAM

        """ # make JAM structure # jam.sandbox.time_signature = (self.ts_num, self.ts_denom) # write beat positions to jams # write tempo to jams # tempo_ann = jams.Annotation(namespace='tempo', time=0, duration=jam.file_metadata.duration) # tempo_ann.append(time=0, duration=jam.file_metadata.duration, value=self.tempo, confidence=1.0) # jam.annotations.append(tempo_ann) # write onsets for each rhythm pattern # write onsets
self
output_jams_file
audio_files
audio_directory
mixing_coeffs
sample_rate
min_amplitude
duration_sec
additional_onset_sandbox_info
additional_global_sandbox_info