def init_sounds(sph, tone=True, noise=True): # TODO: remove creation of card objec when checks are implemented if sph.SOFT_SOUND is None: msg = f""" ########################################## SOUND BOARD NOT FOUND ON SYSTEM!!", PLEASE GO TO: iblrig_params/IBL/tasks/{sph.PYBPOD_PROTOCOL}/task_settings.py and set SOFT_SOUND = 'sysdefault' or 'xonar' ##########################################""" card = SoundCardModule() if not card.connected: log.error(msg) raise (NameError) chans = 'stereo' else: chans = 'L+TTL' if tone: sph.GO_TONE = make_sound(rate=sph.SOUND_SAMPLE_FREQ, frequency=sph.GO_TONE_FREQUENCY, duration=sph.GO_TONE_DURATION, amplitude=sph.GO_TONE_AMPLITUDE, fade=0.01, chans=chans) if noise: sph.WHITE_NOISE = make_sound(rate=sph.SOUND_SAMPLE_FREQ, frequency=-1, duration=sph.WHITE_NOISE_DURATION, amplitude=sph.WHITE_NOISE_AMPLITUDE, fade=0.01, chans=chans) return sph
def init_sounds(sph_obj, tone=True, noise=True): if not sph_obj.SOFT_SOUND: msg = f""" ########################################## SOUND BOARD NOT FOUND ON SYSTEM!!", PLEASE GO TO: iblrig_params/IBL/tasks/{sph_obj.PYBPOD_PROTOCOL}/task_settings.py and set SOFT_SOUND = 'sysdefault' or 'xonar' ##########################################""" card = SoundCardModule() if card._port is None and card._serial_port is None: log.error(msg) raise(NameError) if tone: sph_obj.GO_TONE = make_sound( rate=sph_obj.SOUND_SAMPLE_FREQ, frequency=sph_obj.GO_TONE_FREQUENCY, duration=sph_obj.GO_TONE_DURATION, amplitude=sph_obj.GO_TONE_AMPLITUDE, fade=0.01, chans='L+TTL') if noise: sph_obj.WHITE_NOISE = make_sound( rate=sph_obj.SOUND_SAMPLE_FREQ, frequency=-1, duration=sph_obj.WHITE_NOISE_DURATION, amplitude=sph_obj.WHITE_NOISE_AMPLITUDE, fade=0.01, chans='L+TTL') return sph_obj
def harp_sound_card_ok() -> bool: # Check HarpSoundCard if on ephys rig ephys_rig = "ephys" in _grep_param_dict("NAME") harp_sc_name = "Harp Sound Card" nscs = len(_list_pc_devices(harp_sc_name)) if nscs > 1: log.warning("Multiple Harp Sound Card devices found") return False if nscs and ephys_rig: scard = SoundCardModule() out = scard.connected scard.close() elif not nscs and ephys_rig: out = False elif nscs and not ephys_rig: log.warning("Harp Sound Card detected: UNUSED, this is a traing rig!") out = True elif not nscs and not ephys_rig: # no sound card no ephys_rig, no problem out = True return out
def trigger_sc_sound(sound_idx, card=None): if card is None: card = SoundCardModule() close_card = True # [MessageType] [Length] [Address] [Port] [PayloadType] [Payload] [Checksum] # write=2 LEN=6 addr=32 port=255 payloadType=2 payload=[index 0]U16 checksum=43 # 2 6 32 255 2 [2 0] 43 --> play tone # 2 6 32 255 2 [3 0] 44 --> play noise # 2 LEN=5 33 255 1 [index]U8 checksum def _calc_checksum(data): return sum(data) & 0xFF sound_idx = int(sound_idx) message = [2, 6, 32, 255, 2, sound_idx, 0] message.append(_calc_checksum(message)) message = bytes(np.array(message, dtype=np.int8)) # usb.write(port, message, timeout) card._dev.write(1, message, 200) if close_card: card.close()
def configure_sound_card(sounds=[], indexes=[], sample_rate=96): card = SoundCardModule() if sample_rate == 192 or sample_rate == 192000: sample_rate = SampleRate._192000HZ elif sample_rate == 96 or sample_rate == 96000: sample_rate = SampleRate._96000HZ else: log.error(f"Sound sample rate {sample_rate} should be 96 or 192 (KHz)") raise (ValueError) if len(sounds) != len(indexes): log.error("Wrong number of sounds and indexes") raise (ValueError) sounds = [format_sound(s, flat=True) for s in sounds] for sound, index in zip(sounds, indexes): card.send_sound(sound, index, sample_rate, DataType.INT32) card.close() return
# sd = configure_sounddevice(output=device, samplerate=samplerate) # sd.stop() # rig_tone = make_sound(rate=samplerate, frequency=5000, # duration=10, amplitude=0.1) # rig_noise = make_sound(rate=samplerate, frequency=- # 1, duration=10, amplitude=0.1) # N_TTL = make_sound(chans='L+TTL', amplitude=-1) # import matplotlib.pyplot as plt # # sd.play(rig_tone, samplerate, mapping=[1, 2]) # l = 0.5 # c = make_chirp(f0=80, f1=160, length=l, amp=0.1, fade=0.05, sf=192000) # plt.plot(np.linspace(0, l, 192000), c[:, 0]) # plt.show() # TEST SOUNDCARD MODULE card = SoundCardModule() SOFT_SOUND = None SOUND_SAMPLE_FREQ = sound_sample_freq(SOFT_SOUND) SOUND_BOARD_BPOD_PORT = "Serial3" WHITE_NOISE_DURATION = float(0.5) WHITE_NOISE_AMPLITUDE = float(0.05) GO_TONE_DURATION = float(0.1) GO_TONE_FREQUENCY = int(5000) GO_TONE_AMPLITUDE = float( 0.0151) # 0.0151 for 70.0 dB SPL CCU | 0.0272 for 70.0 dB SPL Xonar GO_TONE = make_sound( rate=SOUND_SAMPLE_FREQ, frequency=GO_TONE_FREQUENCY, duration=GO_TONE_DURATION, amplitude=GO_TONE_AMPLITUDE, fade=0.01,