Example #1
0
    def test_create_key(self):
        orientation = Orientation('10', '20', '30')
        position = Position('1', '2', '3')

        pose = Pose(orientation, position)

        self.assertEqual(orientation.pitch, '20')
        self.assertEqual(position.z, '3')

        self.assertEqual(pose.create_key(), "10,20,30,1,2,3,0,0,0")
Example #2
0
    def parse_filter_list(self):
        """
        Generator for filter list lines

        Lines are assumed to have a format like
        0 0 40 1 1 0 brirWav_APA/Ref_A01_1_040.wav

        The headphone filter starts with HPFILTER instead of the positions.

        Lines can be commented with a '#' as first character.

        :return: Iterator of (Pose, filter-path) tuples
        """

        for line in self.filter_list:

            # comment out lines in the list with a '#'
            if line.startswith('#'):
                continue

            line_content = line.split()
            filter_path = line_content[-1]

            if line.startswith('HPFILTER'):
                self.log.info(
                    "Loading headphone filter: {}".format(filter_path))
                self.headphone_filter = Filter(self.load_filter(filter_path),
                                               self.ir_blocks, self.block_size)
                continue

            filter_value_list = tuple(line_content[0:-1])

            pose = Pose.from_filterValueList(filter_value_list)

            yield pose, filter_path
Example #3
0
    def callback(in_data, frame_count, time_info, status):
        # print("pyAudio callback")

        current_soundfile_list = binsim.oscReceiver.get_sound_file_list()
        if current_soundfile_list:
            binsim.soundHandler.request_new_sound_file(current_soundfile_list)

        # Get sound block. At least one convolver should exist
        binsim.block[:binsim.soundHandler.get_sound_channels(
        ), :] = binsim.soundHandler.buffer_read()

        # Update Filters and run each convolver with the current block
        for n in range(binsim.soundHandler.get_sound_channels()):

            # Get new Filter
            if binsim.oscReceiver.is_filter_update_necessary(n):
                filterValueList = binsim.oscReceiver.get_current_values(n)
                filter = binsim.filterStorage.get_filter(
                    Pose.from_filterValueList(filterValueList))
                binsim.convolvers[n].setIR(
                    filter, callback.config.get('enableCrossfading'))

            left, right = binsim.convolvers[n].process(binsim.block[n, :])

            # Sum results from all convolvers
            if n == 0:
                binsim.result[:, 0] = left
                binsim.result[:, 1] = right
            else:
                binsim.result[:, 0] = np.add(binsim.result[:, 0], left)
                binsim.result[:, 1] = np.add(binsim.result[:, 1], right)

        # Finally apply Headphone Filter
        if callback.config.get('useHeadphoneFilter'):
            binsim.result[:, 0], binsim.result[:,
                                               1] = binsim.convolverHP.process(
                                                   binsim.result)

        # Scale data
        binsim.result = np.divide(
            binsim.result, float(
                (binsim.soundHandler.get_sound_channels()) * 2))
        binsim.result = np.multiply(binsim.result,
                                    callback.config.get('loudnessFactor'))

        if np.max(np.abs(binsim.result)) > 1:
            binsim.log.warn('Clipping occurred: Adjust loudnessFactor!')

        # When the last block is small than the blockSize, this is probably the end of the file.
        # Call pyaudio to stop after this frame
        # Should not be the case for current soundhandler implementation
        if binsim.block.size < callback.config.get('blockSize'):
            pyaudio.paContinue = 1

        return (binsim.result[:frame_count].tostring(), pyaudio.paContinue)
Example #4
0
 def test_from_filter_value_invalid(self):
     with self.assertRaises(RuntimeError):
         Pose.from_filterValueList([1, 2, 3])
Example #5
0
    def test_from_filter_value_list_9(self):

        pose = Pose.from_filterValueList([10, 20, 30, 1, 2, 3, 11, 22, 33])
        self.assertTrue(pose.orientation.yaw, 10)
        self.assertTrue(pose.position.x, 1)
        self.assertTrue(pose.custom.b, 22)