Skip to content

Tutorial 1. Getting started with LSL single stream

Chadwick Boulay edited this page Dec 23, 2019 · 2 revisions

In this tutorial you get to know the basic building blocks of LSL. You will open an LSL stream of the microphone of your computer, save it to as a .xdf file using the LabRecorder and load the resulting file data into MATLAB.

For this tutorial you need

Make sure that you have connected a microphone to your computer and that it is selected as the "default recording device" (you should be able to set this in your Control Panel).


  • Start AudioCapture binary (AudioCapture.exe)

https://github.com/labstreaminglayer/App-AudioCapture/raw/master/audiocapturewin.png

  • Click the "Link" button to link the app to the lab network. If successful, the button turns into "Unlink". If a firewall complains, allow the app to connect to the network.

    • You should now have a stream on your local network that has type "Audio" and name "AudioCaptureWin". Note that you cannot close the app while it is linked.

    • You just created your first LSL stream that captures the microphone input of your PC.

  • To visualize the incoming data stream, start MATLAB (we use here Version 12) and change to the directory of the MATLAB viewer

    • Run the vis_stream.m script: type ‘vis_stream’
    • Select the AudioCaptureWin stream, press ‘OK’
    • You now see two lines for the incoming microphone input. The arrow keys allow you the change the figure’s Y -axis (i.e. amplitude, up arrow, down arrow) and the X-axis (i.e. time, left arrow right arrow)

  • Start LabRecorder.exe. The LabRecorder stores all data streams into a single .xdf file.
    • Click update, you now should see your AudioCaptureWin stream

https://github.com/labstreaminglayer/App-LabRecorder/raw/master/doc/labrecorder-default.png

  • Select the AudioCaptureWin stream by checking the check box next to it.
  • The entry in "Storage Location" shows you the file name (or file name template) where your recording will be stored. You can change this by clicking the browse button.
  • If this string contains any occurrence of %n, it will be replaced by the value in the "Experiment Number“ field. When you start the recorder or load a configuration file, this field will be set automatically to the lowest number for which no directory exists yet. Here you can find more details on the config file.
  • If the string contains any occurrence of %b, it will be substituted by the selected string under "Current experiment block".
  • If the respective directory does not yet exist, it will be created automatically. If the file that you are trying to record to already exists, the existing file will be renamed (the string _oldX will be appended where X is the lowest number that is not yet occupied by another existing file). This way, it is impossible to accidentally overwrite data.
  • Record data for some seconds while you are speaking into the microphone
  • Click "Stop" to end the recording.

  • In MATLAB change to the directory of the MATLAB Importer
    • To load the xdf file type data=load_xdf(‘C:\Recordings\CurrentStudy\exp18\untitled.xdf’)

    • Familiarize yourself with the data structure. The structure holds all recorded LSL streams (in this case only one)

      • .info contains all meta information about the stream
      • .time_stamps contains the timing information
      • .time_series contains the data
    • To see the metadata of the stream type data{1}.info

which will look like this:

           name: 'AudioCaptureWin'
           type: 'Audio'
  channel_count: '2'
  nominal_srate: '44100'
 channel_format: 'float32'
      source_id: 'laptop-st5'
        version: '1'
     created_at: '664014.051553344'
            uid: '823b227b-737c-46f5-9d9c-cd52baafbe9a'
     session_id: 'default'
       hostname: 'neuro-st5'
      v4address: [1x1 struct]
    v4data_port: '16572'
 v4service_port: '16572'
      v6address: [1x1 struct]
    v6data_port: '16572'
 v6service_port: '16572'
           desc: [1x1 struct]
  clock_offsets: [1x1 struct]
first_timestamp: '-1'
 last_timestamp: '0'
   sample_count: '0'

Visualize the data  

  • To visualize the results in MATLAB, type:
figure;
plot(data{1}.time_stamps, data{1}.time_series)


You have completed your first LSL recording. In tutorial 2 you will learn to record from multiple streams.