How to use the psychtoolbox.audio function in psychtoolbox

To help you get started, we’ve selected a few psychtoolbox examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github kleinerm / Psychtoolbox-3 / PsychPython / demos / ppatest_pythonic.py View on Github external
recording.get_audio_data(10)  # PsychPortAudio('GetAudioData', pahandle, 10);

    # Start audio capture immediately and wait for the capture to start.
    # We set the number of 'repetitions' to zero,
    # i.e. record until recording is manually stopped.
    recording.start(repetitions=0, stop_time=None)  # PsychPortAudio('Start', pahandle, 0, 0, 1);

    # fetch just under 10s from that buffer
    # PsychPortAudio('GetAudioData', pahandle, None, 9.9, None);
    audiodata, a, b, c = recording.get_audio_data(in_secs=9.9)
    print('Type', type(audiodata), 'Shape', audiodata.shape, 'Datatype',
          audiodata.dtype);

    recording.close()  # PsychPortAudio('Close', pahandle);

    playback = audio.Stream(freq=Fs, channels=2);
    playback.volume = 1.0  # PsychPortAudio('Volume', pahandle, 1);

    # Fill in audio matrix for playback:
    playback.fill_buffer(audiodata)  # PsychPortAudio('FillBuffer', pahandle, audiodata);

    # Start playback for one repetition (1), 5 seconds from now, wait for sound onset:
    playback.start(1, GetSecs() + 1, 1)  #  PsychPortAudio('Start', pahandle, 1, GetSecs() + 1, 1)

    # Go into a loop that prints playback status once a second, as long as playback
    # is active:
    keyboard = hid.Keyboard()
    info = playback.status  # PsychPortAudio('GetStatus', pahandle);
    print(info, ' Spec ', info['Active']);
    while playback.status['Active'] and not Keyboard.check()[0]:
        WaitSecs('YieldSecs', 1);
github psychopy / psychopy / psychopy / sound / backend_ptb.py View on Github external
raise exceptions.SoundFormatError(
                "Tried to create audio stream {} but {} already exists "
                "and {} doesn't support multiple portaudio streams"
                    .format(label, list(self.keys())[0], sys.platform)
            )
        else:
            # create new stream
            self[label] = _MasterStream(sampleRate, channels, blockSize,
                                       device=defaultOutput)
        return label, self[label]


streams = _StreamsDict()


class _MasterStream(audio.Stream):
    def __init__(self, sampleRate, channels, blockSize,
                 device=None, duplex=False, mode=1,
                 audioLatencyClass=None):
        # initialise thread
        if audioLatencyClass is None:
            audioLatencyClass = defaultLatencyClass
        self.streamLabel = None
        self.streams = []
        self.list = []
        # sound stream info
        self.sampleRate = sampleRate
        self.channels = 2
        self.duplex = duplex
        self.blockSize = blockSize
        self.label = getStreamLabel(sampleRate, channels, blockSize)
        if device == 'default':