コード例 #1
0
ファイル: variablerate.py プロジェクト: maozhiqiang/zounds
 def _prepare_data(self, data):
     output = np.recarray(len(data), dtype=[
         ('start', np.int64),
         ('duration', np.int64),
         ('slicedata', data.slicedata.dtype, data.slicedata.shape[1:])
     ])
     ps = Picoseconds(1)
     output.slicedata[:] = data.slicedata
     output.start[:] = [ts.start / ps for ts in data.slices]
     output.duration[:] = [ts.duration / ps for ts in data.slices]
     return output
コード例 #2
0
ファイル: timeseries.py プロジェクト: maozhiqiang/zounds
    def __init__(self, duration=None, start=None):
        super(TimeSlice, self).__init__()

        if duration is not None and not isinstance(duration, np.timedelta64):
            raise ValueError(
                'duration must be of type {t} but was {t2}'.format(
                    t=np.timedelta64, t2=duration.__class__))

        if start is not None and not isinstance(start, np.timedelta64):
            raise ValueError('start must be of type {t} but was {t2}'.format(
                t=np.timedelta64, t2=start.__class__))

        self.duration = duration
        self.start = start or Picoseconds(0)
コード例 #3
0
ファイル: timeseries.py プロジェクト: maozhiqiang/zounds
 def __and__(self, other):
     delta = max(Picoseconds(0),
                 min(self.end, other.end) - max(self.start, other.start))
     return TimeSlice(delta)
コード例 #4
0
ファイル: timeseries.py プロジェクト: maozhiqiang/zounds
 def end_seconds(self):
     return self.end / Picoseconds(int(1e12))
コード例 #5
0
ファイル: timeseries.py プロジェクト: maozhiqiang/zounds
 def samples_per_second(self):
     return int(Picoseconds(int(1e12)) / self.frequency)
コード例 #6
0
ファイル: timeseries.py プロジェクト: maozhiqiang/zounds
 def duration_in_seconds(self):
     return self.duration / Picoseconds(int(1e12))
コード例 #7
0
ファイル: timeseries.py プロジェクト: maozhiqiang/zounds
 def __str__(self):
     fs = self.frequency / Picoseconds(int(1e12))
     ds = self.duration / Picoseconds(int(1e12))
     return 'TimeDimension(f={fs}, d={ds})'.format(**locals())
コード例 #8
0
ファイル: timeseries.py プロジェクト: maozhiqiang/zounds
 def __hash__(self):
     start = self.start / Picoseconds(1)
     duration = \
         None if self.duration is None else (self.duration / Picoseconds(1))
     return (start, duration).__hash__()
コード例 #9
0
ファイル: samplerate.py プロジェクト: maozhiqiang/zounds
 def __init__(self, window_at_44100=2048, hop_at_44100=1024):
     one_sample_at_44100 = Picoseconds(int(1e12)) / 44100.
     window = one_sample_at_44100 * window_at_44100
     step = one_sample_at_44100 * hop_at_44100
     super(HalfLapped, self).__init__(step, window)
コード例 #10
0
ファイル: samplerate.py プロジェクト: maozhiqiang/zounds
 def __init__(self, samples_per_second, suggested_window, suggested_hop):
     self.suggested_hop = suggested_hop
     self.suggested_window = suggested_window
     self.one_sample = Picoseconds(int(1e12)) // samples_per_second
     super(AudioSampleRate, self).__init__(self.one_sample, self.one_sample)
コード例 #11
0
ファイル: samplerate.py プロジェクト: maozhiqiang/zounds
 def resample(self, ratio):
     orig_freq = Picoseconds(int(self.frequency / Picoseconds(1)))
     orig_duration = Picoseconds(int(self.duration / Picoseconds(1)))
     f = orig_freq * ratio
     d = orig_duration * ratio
     return SampleRate(f, d)
コード例 #12
0
ファイル: variablerate.py プロジェクト: maozhiqiang/zounds
 def _gen(self, raw):
     for r in raw:
         ts = TimeSlice(
                 start=Picoseconds(r.start),
                 duration=Picoseconds(r.duration))
         yield (ts, r.slicedata)
コード例 #13
0
 def test_samplerate_audio(self):
     arr = np.arange(10)
     freq = Picoseconds(int(1e12)) / 44100.
     ts = ArrayWithUnits(arr, [TimeDimension(freq)])
     self.assertEqual(44100, int(ts.dimensions[0].samples_per_second))