Example #1
0
    def extract_data(self, timestamp, data, offset):
        """Extract the data from the feature's raw data.
        
        Args:
            timestamp (int): Data's timestamp.
            data (str): The data read from the feature.
            offset (int): Offset where to start reading data.
        
        Returns:
            :class:`blue_st_sdk.feature.ExtractedData`: Container of the number
            of bytes read and the extracted data.

        Raises:
            :exc:`blue_st_sdk.utils.blue_st_exceptions.InvalidDataException`
                if the data array has not enough data to read.
        """
        if len(data) - offset < self.DATA_LENGTH_BYTES:
            raise InvalidDataException(
                'There are no %s bytes available to read.' \
                % (self.DATA_LENGTH_BYTES))
        sample = Sample(
            [LittleEndian.bytes_to_int16(data, offset) / self.SCALE_FACTOR,
             LittleEndian.bytes_to_int16(data, offset + 2) / self.SCALE_FACTOR,
             LittleEndian.bytes_to_int16(data, offset + 4) / self.SCALE_FACTOR],
            self.get_fields_description(),
            timestamp)
        return ExtractedData(sample, self.DATA_LENGTH_BYTES)
    def extract_data(self, timestamp, data, offset):
        """Extract the audio sync data from the feature's raw data.
           In this case it reads a short integer (adpcm_index) and an integer
           (adpcm_predsample).

        Args:
            data (bytearray): The data read from the feature (a 6 bytes array).
            offset (int): Offset where to start reading data (0 by default).
        
        Returns:
            :class:`blue_st_sdk.feature.ExtractedData`: Container of the number
            of bytes read (6)  and the extracted data (audio sync info, a short
            and an int).

        Raises:
            :exc:`blue_st_sdk.utils.blue_st_exceptions.InvalidDataException`
                if the data array has not enough data to read.
        """
        if len(data) != self.DATA_LENGTH_BYTES:
            raise InvalidDataException(
                'There are no %d bytes available to read.' \
                % (self.DATA_LENGTH_BYTES))

        sample = Sample([
            LittleEndian.bytes_to_int16(data, 0),
            LittleEndian.bytes_to_int32(data, 2)
        ], self.get_fields_description(), None)
        return ExtractedData(sample, self.DATA_LENGTH_BYTES)
    def get_audio(self, sample):
        """Get the audio data from a sample.

        Args:
            sample (:class:`blue_st_sdk.feature.Sample`): Sample data.
        
        Returns:
            short[]: audio values if the data array is valid, None[]
            otherwise.
        """
        audioPckt = []
        if sample is not None:
            if sample._data:
                if sample._data[0] is not None:
                    length = len(sample._data)
                    audioPckt = [None] * length
                    
                    for i in range(0,length):
                        if sample.data[i] != None:
                            audioPckt[i] = LittleEndian.bytes_to_int16(sample._data[i], (2*i))
                    return audioPckt
        return audioPckt