コード例 #1
0
    def create_sinusoid_file(self, sample_rate, samples):
        cal = Calibration()
        cal.current_offset[:7] = -3000
        cal.current_gain[:7] = [1e-3, 1e-4, 1e-5, 1e-6, 1e-7, 1e-8, 1e-9]
        cal.voltage_offset[:2] = -3000
        cal.voltage_gain[:2] = [1e-3, 1e-4]
        cal.data = cal.save(bytes([0] * 32))

        fh = io.BytesIO()
        d = DataRecorder(fh, calibration=cal)

        stream_buffer = StreamBuffer(1.0, [100], sample_rate)
        stream_buffer.calibration_set(cal.current_offset, cal.current_gain,
                                      cal.voltage_offset, cal.voltage_gain)
        d.stream_notify(stream_buffer)
        data = self.create_sinusoid_data(sample_rate, samples)

        chunk_size = (sample_rate // 2) * 2
        for i in range(0, 2 * samples, chunk_size):
            stream_buffer.insert_raw(data[i:(i + chunk_size)])
            stream_buffer.process()
            d.stream_notify(stream_buffer)

        d.close()
        fh.seek(0)
        return fh
コード例 #2
0
    def create_sinusoid_file(self, file_duration, input_sample_rate, output_sample_rate,
                             stream_buffer_duration=None, chunk_size=None):
        stream_buffer_duration = 1.0 if stream_buffer_duration is None else float(stream_buffer_duration)
        min_duration = 400000 / output_sample_rate
        stream_buffer_duration = max(stream_buffer_duration, min_duration)
        chunk_size = 1024 if chunk_size is None else int(chunk_size)
        cal = Calibration()
        cal.current_offset[:7] = -3000
        cal.current_gain[:7] = [1e-3, 1e-4, 1e-5, 1e-6, 1e-7, 1e-8, 1e-9]
        cal.voltage_offset[:2] = -3000
        cal.voltage_gain[:2] = [1e-3, 1e-4]
        cal.data = cal.save(bytes([0] * 32))

        fh = io.BytesIO()
        d = DataRecorder(fh, calibration=cal)

        buffer = DownsamplingStreamBuffer(stream_buffer_duration, [100], input_sample_rate, output_sample_rate)
        buffer.calibration_set(cal.current_offset, cal.current_gain, cal.voltage_offset, cal.voltage_gain)
        d.stream_notify(buffer)
        input_samples = int(file_duration * input_sample_rate)
        data = self.create_sinusoid_data(input_sample_rate, input_samples)

        i = 0
        while i < input_samples:
            i_next = min(i + chunk_size, input_samples)
            buffer.insert_raw(data[i:i_next])
            buffer.process()
            d.stream_notify(buffer)
            i = i_next

        d.close()
        fh.seek(0)
        return fh