Source code for audioOut


from pypixxlib._libdpx import DPxUpdateRegCache, DPxSetAudCodecOutLeftVolume, \
    DPxSetAudCodecOutVolume, \
    DPxGetAudCodecOutLeftVolume, DPxGetAudCodecOutRightVolume, \
    DPxSetAudCodecSpeakerLeftVolume, DPxSetAudCodecSpeakerRightVolume, \
    DPxSetAudCodecSpeakerVolume, DPxGetAudCodecSpeakerLeftVolume, \
    DPxGetAudCodecSpeakerRightVolume, DPxSetAudLRMode, DPxGetAudLRMode, \
    DPxSetAudBuffBaseAddr, DPxGetAudBuffBaseAddr, DPxSetAudBuffReadAddr, \
    DPxGetAudBuffReadAddr, DPxSetAudBuffSize, DPxGetAudBuffSize, \
    DPxSetAudSchedOnset, DPxGetAudSchedOnset, DPxSetAudSchedRate, \
    DPxGetAudSchedRate, DPxSetAudSchedCount, DPxGetAudSchedCount, \
    DPxEnableAudSchedCountdown, DPxDisableAudSchedCountdown, \
    DPxIsAudSchedCountdown, DPxStartAudSched, DPxStopAudSched, \
    DPxIsAudSchedRunning, DPxSetAuxBuffBaseAddr, DPxGetAuxBuffBaseAddr, \
    DPxSetAuxBuffReadAddr, DPxGetAuxBuffReadAddr, DPxSetAuxBuffSize, \
    DPxGetAuxBuffSize, DPxSetAuxSchedOnset, DPxGetAuxSchedOnset, \
    DPxSetAuxSchedRate, DPxGetAuxSchedRate, DPxSetAuxSchedCount, \
    DPxGetAuxSchedCount, DPxEnableAuxSchedCountdown, DPxDisableAuxSchedCountdown, \
    DPxIsAuxSchedCountdown, DPxStartAuxSched, DPxStopAuxSched, \
    DPxIsAuxSchedRunning, DPxGetAudGroupDelay, DPxGetAudCodecSpeakerVolume, \
    DPxGetAudCodecOutVolume, DPxInitAudCodec, DPxSetAudBuff, \
    DPxSetAudRightVolume, DPxSetAudLeftVolume, \
    DPxSetAudVolume, DPxGetAudRightVolume, DPxGetAudLeftVolume, DPxGetAudVolume, \
    DPxSetAudSched, DPxWriteRam, DPxWriteAudioBuffer, DPxSetAudioSchedule, \
    DPxOpen, DPxGetTime, DPxSetAudCodecOutRightVolume
from abc import ABCMeta
import math
from pypixxlib.schedule import Schedule
from pypixxlib.dpxDevice import DpxExceptionDecorate
import sys
import numpy as np

[docs]class AudioOut(Schedule, metaclass=ABCMeta): """Class which implements the AUDIO features. Any device which has Audio OUT should implement this class. It contains all the necessary methods to use the audio outputs of a VPIxx device. """
[docs] @DpxExceptionDecorate def initializeCodec(self): """This needs to be called once to configure initial audio CODEC state. """ return DPxInitAudCodec()
[docs] @DpxExceptionDecorate def setAudioBuffer(self, buff_addr, buff_size): """ Sets base address, reads address and buffer size for AUD schedules. This function is a shortcut which assigns Size/BaseAddr/ReadAddr Args: buff_addr (int): Base addresss. buff_size (int): Buffer size. """ return DPxSetAudBuff(buff_addr, buff_size)
[docs] @DpxExceptionDecorate def setCodecVolumeRight(self, volume, unit): """Sets the codec volume of the right channel. Args: volume (float): Range 0-1 or dB. unit (float): 0 for linear or 1 for dB. See Also: :class:`getVolumeRight`, :class:`getVolumeLeft`, :class:`setVolumeRight`, :class:`setVolumeLeft`, :class:`setVolume`, :class:`setCodecVolume`, :class:`setCodecVolumeLeft`, :class:`getCodecVolumeRight`, :class:`getCodecVolume`, :class:`getCodecVolumeLeft` """ DPxSetAudCodecOutRightVolume(volume, unit)
[docs] @DpxExceptionDecorate def setCodecVolumeLeft(self, volume, unit): """Sets the codec volume of the left channel. Args: volume (float): Range 0-1 or dB. unit (float): 0 for linear or 1 for dB. See Also: :class:`getVolumeRight`, :class:`getVolumeLeft`, :class:`setVolumeRight`, :class:`setVolumeLeft`, :class:`setVolume`, :class:`setCodecVolume`, :class:`getCodecVolumeLeft`, :class:`setCodecVolumeRight`, :class:`getCodecVolume`, :class:`getCodecVolumeLeft`, :class:`getCodecVolumeRight` """ DPxSetAudCodecOutLeftVolume(volume, unit)
[docs] @DpxExceptionDecorate def setCodecVolume(self, volume, unit): """Sets the codec volume of for both left and right channels. Args: volume (float): Range 0-1 or dB. unit (float): 0 for linear or 1 for dB. See Also: :class:`getVolumeRight`, :class:`getVolumeLeft`, :class:`setVolumeRight`, :class:`setVolumeLeft`, :class:`setVolume`, :class:`setCodecVolume`, :class:`setCodecVolumeLeft`, :class:`setCodecVolumeRight`, :class:`getCodecVolume`, :class:`getCodecVolumeLeft`, :class:`getCodecVolumeRight` """ DPxSetAudCodecOutVolume(volume, unit)
[docs] @DpxExceptionDecorate def getCodecVolumeLeft(self, unit=0): """Gets the current codec volume of the left channel. Args: unit (int): Set non-zero to return the gain in dB. Defaults to 0. Returns: float: Range 0 to 1. """ return DPxGetAudCodecOutLeftVolume(unit)
[docs] @DpxExceptionDecorate def getCodecVolumeRight(self, unit=0): """Gets the current codec volume of the right channel. Args: unit (int): Set non-zero to return the gain in dB. Defaults to 0. Returns: float: Range 0 to 1. """ return DPxGetAudCodecOutRightVolume(unit)
[docs] @DpxExceptionDecorate def getCodecVolume(self, unit=0): """Gets the current codec volume of the right channel. Args: unit (int): Set non-zero to return the gain in dB. Defaults to 0. Returns: float: Range 0 to 1. """ return DPxGetAudCodecOutVolume(unit)
[docs] @DpxExceptionDecorate def setCodecSpeakerRightVolume(self, volume, unit): """Sets the speaker volume of the right channel. Args: volume (float): Range 0-1 or dB. unit (float): 0 for linear or 1 for dB. See Also: :class:`getCodecSpeakerLeftVolume`, :class:`getCodecSpeakerVolume`, :class:`getCodecSpeakerRightVolume`, :class:`setCodecSpeakerLeftVolume`, :class:`setCodecSpeakerVolume` """ DPxSetAudCodecSpeakerRightVolume(volume, unit)
[docs] @DpxExceptionDecorate def setCodecSpeakerLeftVolume(self, volume, unit=0): """Sets the speaker volume of the left channel. Args: volume (float): Range 0-1 or dB. unit (float): 0 for linear or 1 for dB. See Also: :class:`getCodecSpeakerRightVolume`, :class:`getCodecSpeakerVolume`, :class:`getCodecSpeakerRightVolume`, :class:`setCodecSpeakerLeftVolume`, :class:`setCodecSpeakerVolume` """ DPxSetAudCodecSpeakerLeftVolume(volume, unit)
[docs] @DpxExceptionDecorate def setCodecSpeakerVolume(self, volume, unit=0): """Sets the speaker volume of both Left and right channels. Args: volume (float): Range 0-1 or dB. unit (float): 0 for linear or 1 for dB. See Also: :class:`getCodecSpeakerLeftVolume`, :class:`getCodecSpeakerRightVolume`, :class:`getCodecSpeakerRightVolume`, :class:`setCodecSpeakerLeftVolume`, :class:`setCodecSpeakerVolume` """ DPxSetAudCodecSpeakerVolume(volume, unit)
[docs] @DpxExceptionDecorate def getCodecSpeakerRightVolume(self, unit=0): """Gets the current speaker volume of the right channel. Args: unit (float): 0 for linear or 1 for dB. Returns: float: Range 0 to 1. """ return DPxGetAudCodecSpeakerRightVolume(unit)
[docs] @DpxExceptionDecorate def getCodecSpeakerLeftVolume(self, unit): """Gets the current speaker volume of the left channel. Args: unit (float): 0 for linear or 1 for dB. Returns: float: Range 0 to 1. """ return DPxGetAudCodecSpeakerLeftVolume(unit)
[docs] @DpxExceptionDecorate def getCodecSpeakerVolume(self, unit): """Gets the current speaker volume of the right and left channel. Args: unit (float): 0 for linear or 1 for dB. Returns: A tuple containing floats: [left Speaker Volume, Right speaker Volume] """ return DPxGetAudCodecSpeakerVolume(unit)
[docs] @DpxExceptionDecorate def setVolumeRight(self, volume): """ Sets volume for the Right audio channels, range 0-1 Args: volume (float): Value for the desired volume, between 0 and 1. """ return DPxSetAudRightVolume(volume)
[docs] @DpxExceptionDecorate def setVolumeLeft(self, volume): """ Sets volume for the Left audio channels, range 0-1 Args: volume (float): Value for the desired volume, between 0 and 1. """ return DPxSetAudLeftVolume(volume)
[docs] @DpxExceptionDecorate def setVolume(self, volume): """ Sets volume for the Left and Right audio channels, range 0-1 Args: volume (float): Value for the desired volume, between 0 and 1. """ return DPxSetAudVolume(volume)
[docs] @DpxExceptionDecorate def getVolumeRight(self): """Get volume for the Right audio output channel, range 0-1 """ return DPxGetAudRightVolume()
[docs] @DpxExceptionDecorate def getVolumeLeft(self): """Get volume for the Left audio output channel, range 0-1 """ return DPxGetAudLeftVolume()
[docs] @DpxExceptionDecorate def getVolume(self): """Gets volume for both Left/Right audio channels Returns: A tuple containing floats: [left Speaker Volume, Right speaker Volume] """ return DPxGetAudVolume()
[docs] @DpxExceptionDecorate def setLeftRightMode(self, mode): """Sets how audio data is updated by schedules. Args: mode (str): Any of the following predefined constants.\n - **mono** : Left schedule data goes to left and right channels. - **left** : Each schedule data goes to left channel only. - **right** : Each schedule data goes to right channel only. - **stereo1** : Pairs of Left data are copied to left/right channels. - **stereo2** : Left data goes to left channel, Right data goes to right. See Also: :class:`getLeftRightMode` """ DPxSetAudLRMode(mode)
[docs] @DpxExceptionDecorate def getLeftRightMode(self): """Gets the audio schedule update mode. Returns: String: Any of the following predefined constants.\n - **mono** : Left schedule data goes to left and right channels. - **left** : Each schedule data goes to left channel only. - **right** : Each schedule data goes to right channel only. - **stereo1** : Pairs of Left data are copied to left/right channels. - **stereo2** : Left data goes to left channel, Right data goes to right. See Also: :class:`setScheduleBufferMode` """ return DPxGetAudLRMode()
[docs] @DpxExceptionDecorate def setBaseAddress(self, value): """Sets the Ram buffer start address. This method allows the user to set the RAM buffer start address used in schedules. The given address must be an even value. Args: address (int): Any value in a range of 0 up to the RAM size. """ DPxSetAudBuffBaseAddr(value)
[docs] @DpxExceptionDecorate def getBaseAddress(self): """Gets the Ram buffer start address. This method allows the user to get the RAM buffer start address used in schedules. It should only be used if the user wants the schedules to wrap when it has reached its maximum size. When schedules are expected to wrap, the user should also use setBufferSize() Returns: int: Any value in a range of 0 up to the RAM size. """ return DPxGetAudBuffBaseAddr()
[docs] @DpxExceptionDecorate def setReadAddress(self, address): """Sets the Ram buffer read address. This method allows the user to set the RAM buffer read address used in schedules. This address is used by the schedule to know where the data should be first read from. The schedule will then read the following data to the address following the RAM buffer read address. The given address must be an even value. Args: address (int): Any value in a range of 0 up to the RAM size. """ DPxSetAudBuffReadAddr(address)
[docs] @DpxExceptionDecorate def getReadAddress(self): """Gets the Ram buffer read address. This method allows the user to get the RAM buffer read address used in schedules. Returns: int: Any value in a range of 0 up to the RAM size. """ return DPxGetAudBuffReadAddr()
[docs] @DpxExceptionDecorate def setBufferSize(self, buffer_size): """Sets the Ram buffer size. This method allows the user to set the RAM buffer size used in schedules. It should only be used if the user wants the schedules to wrap when it has reached its maximum size. When schedules are expected to wrap, the user should also use setBaseAddress() The given size is in bytes and must be an even value. Args: buffer_size (int): Any value in a range of 0 up to the RAM size. """ DPxSetAudBuffSize(buffer_size)
[docs] @DpxExceptionDecorate def getBufferSize(self): """Gets the Ram buffer size. This method allows the user to get the RAM buffer size used in schedules. Returns: int: Any value in a range of 0 up to the RAM size. """ return DPxGetAudBuffSize()
[docs] @DpxExceptionDecorate def setAudSched(self, onset, rateValue, rateUnits, count): """Sets AUD schedule onset, count and rate. This function is a shortcut which assigns Onset/Rate/Count. If Count > 0, enables Countdown mode. Args: onset (int): Schedule onset. rateValue (int): Rate value. rateUnits (string): Usually ``hz``. Can also be ``video`` to update every ``rateValue`` video frames or ``nano`` to update every ``rateValue`` nanoseconds. count (int): Schedule count. """ return DPxSetAudSched(onset, rateValue, rateUnits, count)
[docs] @DpxExceptionDecorate def startSchedule(self): """Starts the active schedule for a given subsystem. Depending on how the schedules are configured, it may not be necessary to call this method. When a schedule is using a countdown, it is not required to stop the schedule. """ DPxStartAudSched()
[docs] @DpxExceptionDecorate def stopSchedule(self): """Stops the active schedule for a given subsystem. Depending on how the schedules are configured, it may not be necessary to call this method. When a schedule is using a countdown, it is not required to stop the schedule. """ DPxStopAudSched()
[docs] @DpxExceptionDecorate def setScheduleOnset(self, onset): """Sets the schedule onset value. This method allows the user to set the nanosecond delay between schedule start and first sample. If no delay is required, this method does not need to be used. Default value is 0. Args: onset (int): Any positive value equal or greater to 0. """ DPxSetAudSchedOnset(onset)
[docs] @DpxExceptionDecorate def getScheduleOnset(self): """Gets the schedule onset value. This method allows the user to get the schedule onset value used in schedules. The onset represents a nanosecond delay between schedule start and first sample. Returns: int: Any positive value equal or greater to 0. """ return DPxGetAudSchedOnset()
[docs] @DpxExceptionDecorate def setScheduleRate(self, rate, unit='hz'): """Sets the schedule rate. This method allows the user to set the schedule rate. Since the rate can be given with different units, the method also needs to have a unit associated with the rate. If no delay is required, this method does not need to be used. Default value is 0. Args: rate (int): Any positive value equal or greater to 0. unit (str): hz : samples per second, maximum 96 kHz. \n video : samples per video frame, maximum 96 kHz. nano : sample period in nanoseconds, minimum 10417 ns. """ DPxSetAudSchedRate(rate, unit)
[docs] @DpxExceptionDecorate def getScheduleRate(self): """Gets the schedule rate value. This method allows the user to get the schedule rate value used in schedules. The rate represents the speed at which the schedule updates. Returns: int: Any positive value equal or greater to 0. """ schedule_rate = DPxGetAudSchedRate() return schedule_rate[0]
[docs] @DpxExceptionDecorate def getScheduleUnit(self): """Gets the schedule unit value. This method allows the user to get the schedule unit value used in schedules. Returns: int: Any positive value equal or greater to 0. See Also: :class:`getScheduleRate`, :class:`setScheduleRate` """ schedule_unit = DPxGetAudSchedRate() return schedule_unit[1]
[docs] @DpxExceptionDecorate def setScheduleCount(self, count): """Sets the schedule count. This method allows the user to set the schedule count for a schedule with a fixed number of samples. In which case, the schedule will decrement at a given rate and stop when the count reaches 0. Args: count (int): Any positive value greater than 0. See Also: :class:`getScheduleUnit`, :class:`setScheduleCountDown` """ DPxSetAudSchedCount(count)
[docs] @DpxExceptionDecorate def getScheduleCount(self): """Gets the schedule count value. This method allows the user to get the current count for a schedule. Returns: int: Any positive value equal or greater to 0. See Also: :class:`setScheduleCount`, :class:`setScheduleCountDown` """ return DPxGetAudSchedCount()
[docs] @DpxExceptionDecorate def setScheduleCountDown(self, enable): """Sets the schedule countdown mode. This method allows the user to enable or disable the countdown on a schedule. When enabled, the schedule decrements at the given rate and stops automatically when the count hits 0. When disabled, the schedule increments at the given rate and is stopped by calling stopSchedule(). Args: enable (Bool): True if countdown is enabled, False otherwise. See Also: :class:`setScheduleCount`, :class:`stopSchedule`, :class:`isCountDownEnabled` """ if enable == True: DPxEnableAudSchedCountdown() else: DPxDisableAudSchedCountdown()
[docs] @DpxExceptionDecorate def isCountDownEnabled(self): """Verifies the schedule countdown mode. Returns: enable (Bool): True if the schedule is decrementing at every sample, False otherwise. See Also: :class:`setScheduleCount`, :class:`stopSchedule`, :class:`setScheduleCountDown` """ if DPxIsAudSchedCountdown() !=0: enable = True else: enable = False return enable
[docs] @DpxExceptionDecorate def isScheduleRunning(self): """Verifies if a schedule is currently running on the subsystem. Returns: schedule_running (Bool): True if a schedule is currently running, False otherwise. See Also: :class:`startSchedule`, :class:`stopSchedule`, :class:`getScheduleRunningState` """ if DPxIsAudSchedRunning() == 0: schedule_running = False else: schedule_running = True return schedule_running
[docs] @DpxExceptionDecorate def getScheduleRunningState(self): """Gets the schedule state for the subsystem. Returns: schedule_state (str): "running" if a schedule is currently running, "stopped" otherwise. See Also: :class:`startSchedule`, :class:`stopSchedule`, :class:`isScheduleRunning` """ if DPxIsAudSchedRunning() == 0: self.schedule_state = "stopped" else: self.schedule_state = "running" return self.schedule_state
[docs] @DpxExceptionDecorate def getBaseAddressAux(self): """Gets the Ram buffer start address. This method allows the user to get the RAM buffer start address used in schedules. It should only be used if the user wants the schedules to wrap when it has reached its maximum size. When schedules are expected to wrap, the user should also use setBufferSize(). Returns: int: Any value in a range of 0 up to the RAM size. """ return DPxGetAuxBuffBaseAddr()
[docs] @DpxExceptionDecorate def setReadAddressRight(self, address): """Sets the Ram buffer read address. This method allows the user to set the RAM buffer read address used in schedules. This address is used by the schedule to know where the data should be first read from. The schedule will then read the following data to the address following the RAM buffer read address. The given address must be an even value. Args: address (int): Any value in a range of 0 up to the RAM size. """ DPxSetAuxBuffReadAddr(address)
[docs] @DpxExceptionDecorate def getReadAddressAux(self): """Gets the Ram buffer read address. This method allows the user to get the RAM buffer read address used in schedules. Returns: int: Any value in a range of 0 up to the RAM size. """ return DPxGetAuxBuffReadAddr()
[docs] @DpxExceptionDecorate def setBufferSizeAux(self, buffer_size): """Sets the Ram buffer size. This method allows the user to set the RAM buffer size used in schedules. It should only be used if the user wants the schedules to wrap when it has reached its maximum size. When schedules are expected to wrap, the user should also use setBaseAddress() The given size is in byte and must be an even value. Args: buffer_size (int): Any value in a range of 0 up to the RAM size. """ return DPxSetAuxBuffSize(buffer_size)
[docs] @DpxExceptionDecorate def getBufferSizeAux(self): """Gets the Ram buffer size. This method allows the user to get the RAM buffer size used in schedules. Returns: int: Any value in a range of 0 up to the RAM size. """ return DPxGetAuxBuffSize()
[docs] @DpxExceptionDecorate def setScheduleOnsetAux(self, onset): """Sets the schedule onset value. This method allows the user to set the nanosecond delay between schedule start and first sample. If no delay is required, this method does not need to be used. Default value is 0. Args: onset (int): Any positive value equal or greater to 0. """ DPxSetAuxSchedOnset(onset)
[docs] @DpxExceptionDecorate def getScheduleOnsetAux(self): """Gets the schedule onset value. This method allows the user to get the schedule onset value used in schedules. The onset represents a nanosecond delay between schedule start and first sample. Returns: int: Any positive value equal or greater to 0. """ return DPxGetAuxSchedOnset()
[docs] @DpxExceptionDecorate def setScheduleRateAux(self, rate, unit='hz'): """Sets the schedule rate. This method allows the user to set the schedule rate. Since the rate can be given with different units, the method also needs to have a unit associated with the rate. If no delay is required, this method does not need to be used. Default value is 0. Args: rate (int): Any positive value equal or greater to 0. unit (str): hz : samples per second, maximum 96 kHz. \n video : samples per video frame, maximum 96 kHz. nano : sample period in nanoseconds, minimum 10417 ns. """ return DPxSetAuxSchedRate(rate, unit)
[docs] @DpxExceptionDecorate def getScheduleRateAux(self): """Gets the schedule rate value. This method allows the user to get the schedule rate value used in schedules. The rate represents the speed at which the schedule updates. Returns: int: Any positive value equal or greater to 0. """ schedule_rate = DPxGetAuxSchedRate() return schedule_rate[0]
[docs] @DpxExceptionDecorate def getScheduleUnitAux(self): """Gets the schedule unit value. This method allows the user to get the schedule unit value used in schedules. Returns: int: Any positive value equal or greater to 0. See Also: :class:`getScheduleRateAux`, :class:`setScheduleRateAux` """ schedule_unit = DPxGetAuxSchedRate() return schedule_unit[1]
[docs] @DpxExceptionDecorate def setScheduleCountAux(self, count): """Sets the schedule count. This method allows the user to set the schedule count for a schedule with a fixed number of samples. In which case, the schedule will decrement at a given rate and stop when the count reaches 0. Args: count (int): Any positive value greater than 0. See Also: :class:`getScheduleCountAux`, :class:`setScheduleCountDownAux` """ DPxSetAuxSchedCount(count)
[docs] @DpxExceptionDecorate def getScheduleCountAux(self): """Gets the schedule count value. This method allows the user to get the current count for a schedule. Returns: int: Any positive value equal or greater to 0. See Also: :class:`setScheduleCountAux`, :class:`setScheduleCountDownAux` """ return DPxGetAuxSchedCount()
[docs] @DpxExceptionDecorate def setScheduleCountDownAux(self, enable): """Sets the schedule countdown mode. This method allows the user to enable or disable the countdown on a schedule. When enabled, the schedule decrements at the given rate and stops automatically when the count hits 0. When disabled, the schedule increments at the given rate and is stopped by calling stopSchedule(). Args: enable (Bool): True if countdown is enabled, False otherwise. See Also: :class:`setScheduleCountAux`, :class:`stopScheduleAux`, :class:`isCountDownEnabledAux` """ if enable == True: DPxEnableAuxSchedCountdown() else: DPxDisableAuxSchedCountdown()
[docs] @DpxExceptionDecorate def isCountDownEnabledAux(self): """Verifies the schedule countdown mode. Returns: enable (Bool): True if the schedule is decrementing at every sample, False otherwise. See Also: :class:`setScheduleCountAux`, :class:`stopScheduleAux`, :class:`setScheduleCountDownAux` """ if DPxIsAuxSchedCountdown() !=0: enable = True else: enable = False return enable
[docs] @DpxExceptionDecorate def startScheduleAux(self): """Starts a schedule. Schedules may be configured in different ways, affecting their behavior. Before a schedule is started, the user should make sure that it is properly set in the Aux mode. See Also: :class:`stopScheduleAux`, :class:`setReadAddressAux`, :class:`setBaseAddressAux`, :class:`setScheduleOnsetAux`, :class:`setScheduleRateAux`, :class:`setScheduleCountDownAux`, :class:`setScheduleCountAux` """ DPxStartAuxSched()
[docs] @DpxExceptionDecorate def stopScheduleAux(self): """Stops the active schedule for a given subsystem. Depending on how the schedules are configured, it may not be necessary to call this method. When a schedule is using a countdown, it is not required to stop the schedule. See Also: :class:`startScheduleAux`, :class:`setReadAddressAux`, :class:`setBaseAddressAux`, :class:`setScheduleOnsetAux`, :class:`setScheduleRateAux`, :class:`setScheduleCountDownAux`, :class:`setScheduleCountAux` """ DPxStopAuxSched()
[docs] @DpxExceptionDecorate def isScheduleRunningAux(self): """Verifies if a schedule is currently running on the subsystem. Returns: schedule_running (Bool): True if a schedule is currently running, False otherwise. See Also: :class:`startScheduleAux`, :class:`stopScheduleAux`, :class:`getScheduleRunningStateAux` """ if DPxIsAuxSchedRunning() == 0: schedule_running = False else: schedule_running = True return schedule_running
[docs] @DpxExceptionDecorate def getScheduleRunningStateAux(self): """Gets the schedule state for the subsystem. Returns: schedule_state (str): "running" if a schedule is currently running, "stopped" otherwise. See Also: :class:`startScheduleAux`, :class:`stopScheduleAux`, :class:`isScheduleRunningAux` """ if DPxIsAuxSchedRunning() == 0: self.schedule_state = "stopped" else: self.schedule_state = "running" return self.schedule_state
[docs] @DpxExceptionDecorate def getGroupDelay(self, sample_rate): """Gets the CODEC Audio OUT group delay in seconds. Returns: float: delay in seconds. """ return DPxGetAudGroupDelay(sample_rate)
[docs] @DpxExceptionDecorate def beep(self, volume=0.5, time=1, frequency=40000): """Beep bop beep bop bop beep beep beep. Args: volume (float): Value between 0 and 1 of the desired volume. time (int): Time factor for the beep duration. """ DPxInitAudCodec() audioVolume = int(32767/2) SinVal = 0.19634954 #(2*3.14159265)/32 sound_buffer = [] for i in range(32): sound_buffer.append(int(audioVolume * math.sin(i * SinVal))) # Configure how audio Left/Right channels are updated by schedule data DPxWriteRam(DPxGetAudBuffBaseAddr(), sound_buffer) DPxSetAudVolume(volume) DPxSetAudBuff(DPxGetAudBuffBaseAddr(), 64) DPxSetAudSched(0, frequency, 'hz', int(frequency*time)) DPxStartAudSched() DPxUpdateRegCache()
[docs] @DpxExceptionDecorate def writeAudioBuffer(self, bufferData,bufferAddress=int(16e6)): """ Writes the audio waveform data in 'bufferData' to the DATAPixx RAM at memory address 'bufferAddress'. Mimics the behavior of Datapixx('WriteAudioBuffer') in MATLAB, but with more flexibility in the data format. 'bufferData' can be in any format really, while in MATLAB, it must be scaled between (0,1). Args: bufferData (list/array): can be a list or a NumPy array. If a list, must be castable to NumPy ndarray of type float bufferAddress (int): memory location in DATAPixx RAM. default=0 Exceptions: 1) bufferData cannot be casted into a NumPy array of type float. 2) bufferData is empty 3) bufferData has more than 2 dimensions 4) bufferData has more than 2 rows 5) bufferAddress is not of type int or is less than 0 or is odd """ return DPxWriteAudioBuffer(bufferData,bufferAddress=int(16e6))
[docs] @DpxExceptionDecorate def setAudioSchedule(self, scheduleOnset, scheduleRate, maxScheduleFrames, lrMode='mono', bufferAddress=int(16e6), numBufferFrames=None): """ Implements an audio schedule in a DATAPixx. Mimics the behavior of Datapixx('SetAudioSchedule') in MATLAB, but with more flexibility in the 'lrMode' format. 'lrMode' can be passed as an integer (as in MATLAB), or as a string. Args: scheduleOnset (float): the audio schedule delay in seconds scheduleRate (int): the audio codec sampling rate in Hz maxScheduleFrames (int): the number of samples after which the audio codec stops sampling. if maxScheduleFrames > numBufferFrames, the audio codec loops back to sample data at the start address of the audio buffer. lrMode (int/string): the audio stereo mode. acceptable inputs are in the 'int' and 'string' columns: int string description 0 'mono' same output to left and right speakers 1 'left' output to left speaker only 2 'right' output to right speaker only 3 'stereo1' 1st row of 'bufferData' to left speaker. 2nd row of 'bufferData' to right speaker. 4 'stereo2' vice-versa of stereo1 mode default='mono' bufferAddress (int): memory location in DATAPixx RAM default=0 numBufferFrames (int): number of audio samples written into DATAPixx RAM. NOTE: these are specified in bytes, while the data format is int16. therefore, numBufferFrames = maxScheduleFrames*2 default = maxScheduleFrames*2 Exceptions: 1) scheduleOnset is not of type float or is less than 0 2) scheduleOnset * 10**9 is greater than 0xffffffff 3) scheduleRate is not of type int. warning when scheduleRate is not in the interval (8000,96000) 4) maxScheduleFrames is not of type int or is less than 0 5) lrMode is not equal to any acceptable values. acceptable values given in error message 6) bufferAddress is not of type int or is less than 0 or is odd 7) numBufferFrames is not of type int or is less than 0 """ return DPxSetAudioSchedule(scheduleOnset, scheduleRate, maxScheduleFrames, lrMode='mono', bufferAddress=int(16e6), numBufferFrames=None)
[docs] @DpxExceptionDecorate def playAudio(self, bufferData, bufferAddress=0, numBufferFrames=None, volume=.2, scheduleOnset=0.0, lrMode='mono', scheduleRate=48000, maxScheduleFrames=None): """ Encapsulates all necessary lipdpx functinality required to play an audio stimulus with a single function call, while offering more argument flexibility than Datapixx.mex: -bufferData can be any data type, so long as it can be casted to a NumPy (dtype=float) ndarray of shape (N,), (1,N), or (2,N) -maxSchedule is optional. default behavior is a single playthrough -lrMode can be either an integer or string (see below) NOTE: this function invokes _libdpx.DPxUpdateRegCache() This function does not perform argument integrity checks (except for 'volume'), as these checks are performed in functions DPxWriteAudioBuffer() and DPxSetAudioSchedule() called by DPxPlayAudio() Args: bufferData (list/array): can be a list or a NumPy array. If a list, must be castable to NumPy ndarray of type float bufferAddress (int): memory location in DATAPixx RAM. default=0 numBufferFrames (int): number of audio samples written into DATAPixx RAM. NOTE: these are specified in bytes, while the data format is int16. therefore, numBufferFrames = len(bufferData)*2 default=len(bufferData)*2 volume (float/int): the audio output volume, between 0 (no output) and 1 (full volume) scheduleOnset (float): the audio schedule delay in seconds lrMode (int/string): the audio stereo mode. acceptable inputs are in the 'int' and 'string' columns: int string description 0 'mono' same output to left and right speakers 1 'left' output to left speaker only 2 'right' output to right speaker only 3 'stereo1' 1st row of 'bufferData' to left speaker. 2nd row of 'bufferData' to right speaker. 4 'stereo2' vice-versa of stereo1 mode default='mono' scheduleRate (int): the audio codec sampling rate in Hz default = 48000 (CD standard) maxScheduleFrames (int): the number of samples after which the audio codec stops sampling. if maxScheduleFrames > numBufferFrames, the audio codec loops back to sample data at the start address of the audio buffer. default = len(bufferData)*2 Exceptions: 1) volume is not of type float or type int. warning when volume is not in the interval (0,1) """ ######################### check inputs # volume if type(volume) is not float and type(volume) is not int: raise Exception("ERROR in %s\n'volume' must be of type float or int" % sys.argv[0]) elif volume < 0 or volume > 1: print("\nWARNING in %s\n'volume' value of '%f' will be defaulted to %d. 'volume' values must be between 0 and 1.\n" % (sys.argv[0],volume,volume>1) ) volume = float(volume>1) # play audio ############################### # handshake with hardware DPxOpen() DPxInitAudCodec() # clear schedules DPxDisableAudSchedCountdown() DPxUpdateRegCache() # write the audio DPxWriteAudioBuffer(bufferData,bufferAddress) # set volume DPxSetAudLeftVolume(volume) DPxSetAudRightVolume(volume) # play audio if maxScheduleFrames is None: maxScheduleFrames = np.array(bufferData).size DPxSetAudioSchedule(scheduleOnset, scheduleRate, maxScheduleFrames, lrMode, bufferAddress, numBufferFrames) DPxStartAudSched() DPxUpdateRegCache()
[docs] @DpxExceptionDecorate def waitForAudio(self, timeOut=np.inf): """ Basic blocking function to halt code execution until the current audio schedule finishes. Useful for preventing contiguous audio schedules from interfering with one another Args: timeOut (float): maximum duration of blocking in seconds. default=np.inf (forever) Returns: total blocking time in seconds Exceptions: 1) timeOut is not of type float and not of type int or is less than 0 """ if type(timeOut) is not float and type(timeOut) is not int or timeOut <= 0: raise Exception("ERROR in %s\n'timeOut' must be of type float or int and greater than 0" % sys.argv[0]) startTime = DPxGetTime() currentTime = startTime while DPxIsAudSchedRunning() and (currentTime-startTime)<timeOut: DPxUpdateRegCache() currentTime = DPxGetTime() return currentTime-startTime