Skip to content

Commit

Permalink
add tool to send LSL streams
Browse files Browse the repository at this point in the history
  • Loading branch information
gisogrimm committed Jan 14, 2025
1 parent b7e59bb commit 19ac6a0
Show file tree
Hide file tree
Showing 3 changed files with 106 additions and 11 deletions.
18 changes: 7 additions & 11 deletions apps/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,14 @@ include ../rules.mk
#
# main targets:
#
BINFILES = tascar_cli tascar_showlicenses tascar_validatetsc \
tascar_pdf tascar_osc_jack_transport tascar_jackio tascar_sampler \
BINFILES = tascar_cli tascar_showlicenses tascar_validatetsc \
tascar_pdf tascar_osc_jack_transport tascar_jackio tascar_sampler \
tascar_levelmeter tascar_jackpar tascar_renderfile tascar_renderir \
tascar_gpx2csv tascar_version tascar_test_compare_sndfile \
tascar_test_compare_level_sum tascar_lsjackp tascar_sendosc \
tascar_listsrc tascar_getcalibfor tascar_spk2obj \
tascar_gpx2csv tascar_version tascar_test_compare_sndfile \
tascar_test_compare_level_sum tascar_lsjackp tascar_sendosc \
tascar_listsrc tascar_getcalibfor tascar_spk2obj \
tascar_sceneskeleton tascar_osc2file

ifeq "$(HAS_LSL)" "yes"
BINFILES += tascar_osc2lsl
endif

ifneq ($(OS),Windows_NT)
UNAME_S := $(shell uname -s)
ifeq ($(UNAME_S),Linux)
Expand All @@ -33,7 +29,7 @@ BINFILES += $(TEST_FILES)
BUILD_BINS = $(patsubst %,build/%,$(BINFILES))

ifeq "$(HAS_LSL)" "yes"
BINFILES += tascar_lslsl tascar_lsljacktime
BINFILES += tascar_lslsl tascar_lsljacktime tascar_osc2lsl tascar_genrandlsl
endif

ifeq "ok" "$(shell pkg-config gtkmm-3.0 && echo ok)"
Expand Down Expand Up @@ -75,7 +71,7 @@ build/tascar_hdspmixer build/tascar_hdspmixer.o: EXTERNALS += alsa
build/tascar_pdf build/tascar_pdf.o: EXTERNALS += $(GTKEXT)
build/tascar_pdf build/tascar_pdf.o: LDLIBS += -ltascargui `pkg-config --libs $(EXTERNALS)`
build/tascar_ambdecoder: LDLIBS += `pkg-config --libs gsl`
build/tascar_lslsl build/tascar_lsljacktime build/tascar_osc2lsl: LDLIBS+=-llsl
build/tascar_lslsl build/tascar_lsljacktime build/tascar_osc2lsl build/tascar_genrandlsl: LDLIBS+=-llsl
#build/tascar_renderfile: LDLIBS += -lboost_program_options
#build/tascar_renderir: LDLIBS += -lboost_program_options

Expand Down
98 changes: 98 additions & 0 deletions apps/src/tascar_genrandlsl.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
/*
* This file is part of the TASCAR software, see <http://tascar.org/>
*
* Copyright (c) 2019 Giso Grimm
* Copyright (c) 2020 Giso Grimm
*/
/*
* TASCAR is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published
* by the Free Software Foundation, version 3 of the License.
*
* TASCAR is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHATABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License, version 3 for more details.
*
* You should have received a copy of the GNU General Public License,
* Version 3 along with TASCAR. If not, see <http://www.gnu.org/licenses/>.
*/

#include "cli.h"
#include "coordinates.h"
#include "errorhandling.h"
#include "tictoctimer.h"
#include <chrono>
#include <cstdint>
#include <getopt.h>
#include <iostream>
#include <lsl_cpp.h>
#include <signal.h>
#include <thread>
#include <unistd.h>

static bool b_quit;

static void sighandler(int)
{
b_quit = true;
fclose(stdin);
}

int main(int argc, char** argv)
{
b_quit = false;
signal(SIGABRT, &sighandler);
signal(SIGTERM, &sighandler);
signal(SIGINT, &sighandler);
const char* options = "ha:np:t";
struct option long_options[] = {{"help", 0, 0, 'h'}, {"add", 1, 0, 'a'},
{"noauto", 0, 0, 'n'}, {"port", 1, 0, 'p'},
{"timestamp", 0, 0, 't'}, {0, 0, 0, 0}};
int opt(0);
int option_index(0);
std::string name = "tascar_lsl";
double srate = 100.0f;
uint32_t channels = 1;
while((opt = getopt_long(argc, argv, options, long_options, &option_index)) !=
-1) {
switch(opt) {
case 'h':
TASCAR::app_usage("tascar_genrandlsl", long_options, "", "");
return 0;
case 'n':
name = optarg;
break;
case 'c':
channels = atoi(optarg);
break;
case 'r':
srate = atof(optarg);
break;
}
}
double sampleperiod = 1.0 / srate;
lsl::channel_format_t lslfmt = lsl::cf_float32;
lsl::stream_info info(name, "osc2lsl", channels, srate, lslfmt, name.c_str());
lsl::stream_outlet sop = lsl::stream_outlet(info);
std::vector<float> data;
data.resize(channels);
TASCAR::tictoc_t tm;
double elapsed = 0.0;
tm.tic();
while(!b_quit) {
for(auto& v : data)
v = TASCAR::drand() - 0.5;
elapsed = tm.tictoc();
std::this_thread::sleep_for(
std::chrono::microseconds((int)(1e6 * (sampleperiod - elapsed))));

sop.push_sample(data);
}
}

/*
* Local Variables:
* compile-command: "make -C .."
* End:
*/
1 change: 1 addition & 0 deletions packaging/deb/tascarcli.csv
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"apps/build/tascar_cli","usr/bin/"
"apps/build/tascar_genrandlsl","usr/bin/"
"apps/build/tascar_getcalibfor","usr/bin/"
"apps/build/tascar_gpx2csv","usr/bin/"
"apps/build/tascar_hdspmixer","usr/bin/"
Expand Down

0 comments on commit 19ac6a0

Please sign in to comment.