Commit fdaa1de2 authored by Your Name's avatar Your Name
Browse files

.

parent 03977b0a
gw.clang-format
\ No newline at end of file
......@@ -4,3 +4,6 @@
[submodule "labstreaminglayer"]
path = labstreaminglayer
url = https://github.com/sccn/labstreaminglayer.git
[submodule "libevdev"]
path = libevdev
url = https://gitlab.freedesktop.org/libevdev/libevdev.git
clang-format -i <file.cc>
......@@ -2,7 +2,7 @@
LSL_BUILD_DIR=labstreaminglayer/build/install
LSL_INSTALL_DIR=/usr/local
SUBDIRS=ledbox lslder lsldert zmqmqbroker
SUBDIRS=ledbox lslder lsldert zmqmqbroker lslhidev
INSTALL=install -v
......@@ -14,7 +14,7 @@ $(SUBDIRS):
$(MAKE) -C $@ $(MAKECMDGOALS)
libs: labstreaminglayer azmq
libs: labstreaminglayer azmq libevdev
labstreaminglayer:
......@@ -30,6 +30,11 @@ azmq:
cd build && \
$(MAKE)
libevdev:
cd libevdev && \
./autogen.sh && \
$(MAKE)
# workaround to install LSL in system directories
libs/install/lsl:
$(INSTALL) $(LSL_BUILD_DIR)/lib/liblsl*.so.* /usr/local/lib/
......@@ -40,6 +45,9 @@ libs/install/lsl:
libs/install/azmq:
$(MAKE) -C azmq/build install
libs/install/libevdev:
$(MAKE) -C libevdev install
.PHONY: labstreaminglayer azmq $(SUBDIRS)
.PHONY: labstreaminglayer azmq libevdev $(SUBDIRS)
......@@ -69,7 +69,9 @@ Reboot and login again.
$ sudo apt-get update
$ sudo apt-get install git libboost-all-dev cmake wiringpi pigpio libzmq3-dev
$ sudo apt install libasound2 libasound2-data libasound2-dev
$ sudo apt install portaudio19-dev portaudio19-doc
$
$ cd
$ git clone --recurse-submodules https://gitlab.science.ru.nl/biophysics-labs/firmware.git
......
---
Language: Cpp
# BasedOnStyle: LLVM
# Edited by Gunter Windau
AccessModifierOffset: -2
AlignAfterOpenBracket: Align
AlignConsecutiveAssignments: false
AlignConsecutiveDeclarations: false
AlignEscapedNewlines: Right
AlignOperands: true
AlignTrailingComments: true
AllowAllParametersOfDeclarationOnNextLine: true
AllowShortBlocksOnASingleLine: false
AllowShortCaseLabelsOnASingleLine: false
AllowShortFunctionsOnASingleLine: All
AllowShortIfStatementsOnASingleLine: false
AllowShortLoopsOnASingleLine: false
AlwaysBreakAfterDefinitionReturnType: None
AlwaysBreakAfterReturnType: None
AlwaysBreakBeforeMultilineStrings: false
AlwaysBreakTemplateDeclarations: MultiLine
BinPackArguments: true
BinPackParameters: true
BraceWrapping:
AfterClass: false
AfterControlStatement: false
AfterEnum: false
AfterFunction: false
AfterNamespace: false
AfterObjCDeclaration: false
AfterStruct: false
AfterUnion: false
AfterExternBlock: false
# BeforeCatch: false
BeforeCatch: true
# BeforeElse: false
BeforeElse: true
IndentBraces: false
SplitEmptyFunction: true
SplitEmptyRecord: true
SplitEmptyNamespace: true
BreakBeforeBinaryOperators: None
# BreakBeforeBraces: Attach
BreakBeforeBraces: Custom
BreakBeforeInheritanceComma: false
BreakInheritanceList: BeforeColon
BreakBeforeTernaryOperators: true
BreakConstructorInitializersBeforeComma: false
BreakConstructorInitializers: BeforeColon
BreakAfterJavaFieldAnnotations: false
BreakStringLiterals: true
ColumnLimit: 80
CommentPragmas: '^ IWYU pragma:'
CompactNamespaces: false
ConstructorInitializerAllOnOneLineOrOnePerLine: false
ConstructorInitializerIndentWidth: 4
ContinuationIndentWidth: 4
Cpp11BracedListStyle: true
DerivePointerAlignment: false
DisableFormat: false
ExperimentalAutoDetectBinPacking: false
FixNamespaceComments: true
ForEachMacros:
- foreach
- Q_FOREACH
- BOOST_FOREACH
IncludeBlocks: Preserve
IncludeCategories:
- Regex: '^"(llvm|llvm-c|clang|clang-c)/'
Priority: 2
- Regex: '^(<|"(gtest|gmock|isl|json)/)'
Priority: 3
- Regex: '.*'
Priority: 1
IncludeIsMainRegex: '(Test)?$'
IndentCaseLabels: false
IndentPPDirectives: None
# IndentWidth: 2
IndentWidth: 4
IndentWrappedFunctionNames: false
JavaScriptQuotes: Leave
JavaScriptWrapImports: true
KeepEmptyLinesAtTheStartOfBlocks: true
MacroBlockBegin: ''
MacroBlockEnd: ''
MaxEmptyLinesToKeep: 1
NamespaceIndentation: None
ObjCBinPackProtocolList: Auto
ObjCBlockIndentWidth: 2
ObjCSpaceAfterProperty: false
ObjCSpaceBeforeProtocolList: true
PenaltyBreakAssignment: 2
PenaltyBreakBeforeFirstCallParameter: 19
PenaltyBreakComment: 300
PenaltyBreakFirstLessLess: 120
PenaltyBreakString: 1000
PenaltyBreakTemplateDeclaration: 10
PenaltyExcessCharacter: 1000000
PenaltyReturnTypeOnItsOwnLine: 60
PointerAlignment: Right
ReflowComments: true
SortIncludes: true
SortUsingDeclarations: true
SpaceAfterCStyleCast: false
SpaceAfterTemplateKeyword: true
SpaceBeforeAssignmentOperators: true
SpaceBeforeCpp11BracedList: false
SpaceBeforeCtorInitializerColon: true
SpaceBeforeInheritanceColon: true
SpaceBeforeParens: ControlStatements
SpaceBeforeRangeBasedForLoopColon: true
SpaceInEmptyParentheses: false
SpacesBeforeTrailingComments: 1
SpacesInAngles: false
SpacesInContainerLiterals: true
SpacesInCStyleCastParentheses: false
SpacesInParentheses: false
SpacesInSquareBrackets: false
Standard: Cpp11
TabWidth: 8
UseTab: Never
...
libevdev @ f9302c18
Subproject commit f9302c18b7c01be629d3b6b64f02bc7c5384f8e0
......@@ -23,3 +23,7 @@ playtone: playtone.cc
zmq_trigger: zmq_trigger.cc
msgqueue_pubsub: msgqueue_pubsub.cc
zmq_trigger_subscriber: zmq_trigger_subscriber.cc
paex_sine: paex_sine.c
paex_sine: LDLIBS+=-lm -lportaudio
sine: sine.cc
sine: LDLIBS+=-lportaudio -lportaudiocpp
Setting the default device
Find your desired card with:
cat /proc/asound/cards
and then create /etc/asound.conf with following:
defaults.pcm.card 1
defaults.ctl.card 1
Replace "1" with number of your card determined above.
void lsldert_sound_cmd(sound_cmd, sound_arg, msg, nmsg);
/** @file paex_sine.c
@ingroup examples_src
@brief Play a sine wave for several seconds.
@author Ross Bencina <rossb@audiomulch.com>
@author Phil Burk <philburk@softsynth.com>
*/
/*
* $Id$
*
* This program uses the PortAudio Portable Audio Library.
* For more information see: http://www.portaudio.com/
* Copyright (c) 1999-2000 Ross Bencina and Phil Burk
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files
* (the "Software"), to deal in the Software without restriction,
* including without limitation the rights to use, copy, modify, merge,
* publish, distribute, sublicense, and/or sell copies of the Software,
* and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR
* ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
/*
* The text above constitutes the entire PortAudio license; however,
* the PortAudio community also makes the following non-binding requests:
*
* Any person wishing to distribute modifications to the Software is
* requested to send the modifications to the original developer so that
* they can be incorporated into the canonical version. It is also
* requested that these non-binding requests be included along with the
* license above.
*/
#include <stdio.h>
#include <math.h>
#include "portaudio.h"
#define NUM_SECONDS (5)
#define SAMPLE_RATE (44100)
#define FRAMES_PER_BUFFER (64)
#ifndef M_PI
#define M_PI (3.14159265)
#endif
#define TABLE_SIZE (200)
typedef struct
{
float sine[TABLE_SIZE];
int left_phase;
int right_phase;
char message[20];
}
paTestData;
/* This routine will be called by the PortAudio engine when audio is needed.
** It may called at interrupt level on some machines so don't do anything
** that could mess up the system like calling malloc() or free().
*/
static int patestCallback( const void *inputBuffer, void *outputBuffer,
unsigned long framesPerBuffer,
const PaStreamCallbackTimeInfo* timeInfo,
PaStreamCallbackFlags statusFlags,
void *userData )
{
paTestData *data = (paTestData*)userData;
float *out = (float*)outputBuffer;
unsigned long i;
(void) timeInfo; /* Prevent unused variable warnings. */
(void) statusFlags;
(void) inputBuffer;
for( i=0; i<framesPerBuffer; i++ )
{
*out++ = data->sine[data->left_phase]; /* left */
*out++ = data->sine[data->right_phase]; /* right */
data->left_phase += 1;
if( data->left_phase >= TABLE_SIZE ) data->left_phase -= TABLE_SIZE;
data->right_phase += 3; /* higher pitch so we can distinguish left and right. */
if( data->right_phase >= TABLE_SIZE ) data->right_phase -= TABLE_SIZE;
}
return paContinue;
}
/*
* This routine is called by portaudio when playback is done.
*/
static void StreamFinished( void* userData )
{
paTestData *data = (paTestData *) userData;
printf( "Stream Completed: %s\n", data->message );
}
/*******************************************************************/
int main(void);
int main(void)
{
PaStreamParameters outputParameters;
PaStream *stream;
PaError err;
paTestData data;
int i;
printf("PortAudio Test: output sine wave. SR = %d, BufSize = %d\n", SAMPLE_RATE, FRAMES_PER_BUFFER);
/* initialise sinusoidal wavetable */
for( i=0; i<TABLE_SIZE; i++ )
{
data.sine[i] = (float) sin( ((double)i/(double)TABLE_SIZE) * M_PI * 2. );
}
data.left_phase = data.right_phase = 0;
err = Pa_Initialize();
if( err != paNoError ) goto error;
outputParameters.device = Pa_GetDefaultOutputDevice(); /* default output device */
if (outputParameters.device == paNoDevice) {
fprintf(stderr,"Error: No default output device.\n");
goto error;
}
outputParameters.channelCount = 2; /* stereo output */
outputParameters.sampleFormat = paFloat32; /* 32 bit floating point output */
outputParameters.suggestedLatency = Pa_GetDeviceInfo( outputParameters.device )->defaultLowOutputLatency;
outputParameters.hostApiSpecificStreamInfo = NULL;
err = Pa_OpenStream(
&stream,
NULL, /* no input */
&outputParameters,
SAMPLE_RATE,
FRAMES_PER_BUFFER,
paClipOff, /* we won't output out of range samples so don't bother clipping them */
patestCallback,
&data );
if( err != paNoError ) goto error;
sprintf( data.message, "No Message" );
err = Pa_SetStreamFinishedCallback( stream, &StreamFinished );
if( err != paNoError ) goto error;
err = Pa_StartStream( stream );
if( err != paNoError ) goto error;
printf("Play for %d seconds.\n", NUM_SECONDS );
Pa_Sleep( NUM_SECONDS * 1000 );
err = Pa_StopStream( stream );
if( err != paNoError ) goto error;
err = Pa_CloseStream( stream );
if( err != paNoError ) goto error;
Pa_Terminate();
printf("Test finished.\n");
return err;
error:
Pa_Terminate();
fprintf( stderr, "An error occured while using the portaudio stream\n" );
fprintf( stderr, "Error number: %d\n", err );
fprintf( stderr, "Error message: %s\n", Pa_GetErrorText( err ) );
return err;
}
......@@ -2,43 +2,38 @@
* This extra small demo sends a random samples to your speakers.
*/
#include <alsa/asoundlib.h>
static char *device = "default"; /* playback device */
static char *device = "default"; /* playback device */
snd_output_t *output = NULL;
unsigned char buffer[16*1024]; /* some random data */
int main(void)
{
int err;
unsigned int i;
snd_pcm_t *handle;
snd_pcm_sframes_t frames;
for (i = 0; i < sizeof(buffer); i++)
buffer[i] = random() & 0xff;
unsigned char buffer[16 * 1024]; /* some random data */
int main(void) {
int err;
unsigned int i;
snd_pcm_t *handle;
snd_pcm_sframes_t frames;
for (i = 0; i < sizeof(buffer); i++)
buffer[i] = random() & 0xff;
if ((err = snd_pcm_open(&handle, device, SND_PCM_STREAM_PLAYBACK, 0)) < 0) {
printf("Playback open error: %s\n", snd_strerror(err));
exit(EXIT_FAILURE);
}
if ((err = snd_pcm_set_params(handle,
SND_PCM_FORMAT_U8,
SND_PCM_ACCESS_RW_INTERLEAVED,
1,
48000,
1,
500000)) < 0) { /* 0.5sec */
if ((err = snd_pcm_set_params(handle, SND_PCM_FORMAT_U8,
SND_PCM_ACCESS_RW_INTERLEAVED, 1, 48000, 1,
500000)) < 0) { /* 0.5sec */
printf("Playback open error: %s\n", snd_strerror(err));
exit(EXIT_FAILURE);
}
for (i = 0; i < 16; i++) {
frames = snd_pcm_writei(handle, buffer, sizeof(buffer));
if (frames < 0)
frames = snd_pcm_recover(handle, frames, 0);
if (frames < 0) {
printf("snd_pcm_writei failed: %s\n", snd_strerror(frames));
break;
}
if (frames > 0 && frames < (long)sizeof(buffer))
printf("Short write (expected %li, wrote %li)\n", (long)sizeof(buffer), frames);
for (i = 0; i < 16; i++) {
frames = snd_pcm_writei(handle, buffer, sizeof(buffer));
if (frames < 0)
frames = snd_pcm_recover(handle, frames, 0);
if (frames < 0) {
printf("snd_pcm_writei failed: %s\n", snd_strerror(frames));
break;
}
if (frames > 0 && frames < (long)sizeof(buffer))
printf("Short write (expected %li, wrote %li)\n",
(long)sizeof(buffer), frames);
}
snd_pcm_close(handle);
return 0;
}
This diff is collapsed.
File added
// ---------------------------------------------------------------------------------------
#include "portaudiocpp/PortAudioCpp.hxx"
#include <cassert>
#include <cmath>
#include <cstddef>
#include <iostream>
// ---------------------------------------------------------------------------------------
// Some constants:
const int NUM_SECONDS = 5;
const double SAMPLE_RATE = 44100.0;
const int FRAMES_PER_BUFFER = 64;
const int TABLE_SIZE = 200;
// ---------------------------------------------------------------------------------------
// SineGenerator class:
class SineGenerator {
public:
SineGenerator(int tableSize)
: tableSize_(tableSize), leftPhase_(0), rightPhase_(0) {
const double PI = 3.14159265;
table_ = new float[tableSize];
for (int i = 0; i < tableSize; ++i) {
table_[i] =
0.125f * (float)sin(((double)i / (double)tableSize) * PI * 2.);
}
}
~SineGenerator() { delete[] table_; }
int generate(const void *inputBuffer, void *outputBuffer,
unsigned long framesPerBuffer,
const PaStreamCallbackTimeInfo *timeInfo,
PaStreamCallbackFlags statusFlags) {
assert(outputBuffer != NULL);
float **out = static_cast<float **>(outputBuffer);
for (unsigned int i = 0; i < framesPerBuffer; ++i) {
out[0][i] = table_[leftPhase_];
out[1][i] = table_[rightPhase_];
leftPhase_ += 1;
if (leftPhase_ >= tableSize_)
leftPhase_ -= tableSize_;
rightPhase_ += 3;
if (rightPhase_ >= tableSize_)
rightPhase_ -= tableSize_;
}
return paContinue;
}
private:
float *table_;
int tableSize_;
int leftPhase_;
int rightPhase_;
};
// ---------------------------------------------------------------------------------------
// main:
int main(int, char *[]);
int main(int, char *[]) {
try {
// Create a SineGenerator object:
SineGenerator sineGenerator(TABLE_SIZE);
std::cout << "Setting up PortAudio..." << std::endl;
// Set up the System:
portaudio::AutoSystem autoSys;
portaudio::System &sys = portaudio::System::instance();
// Set up the parameters required to open a (Callback)Stream:
portaudio::DirectionSpecificStreamParameters outParams(
sys.defaultOutputDevice(), 2, portaudio::FLOAT32, false,
sys.defaultOutputDevice().defaultLowOutputLatency(), NULL);
portaudio::StreamParameters params(
portaudio::DirectionSpecificStreamParameters::null(), outParams,
SAMPLE_RATE, FRAMES_PER_BUFFER, paClipOff);
std::cout << "Opening stereo output stream..." << std::endl;
// Create (and open) a new Stream, using the SineGenerator::generate
// function as a callback:
portaudio::MemFunCallbackStream<SineGenerator> stream(
params, sineGenerator, &SineGenerator::generate);
std::cout << "Starting playback for " << NUM_SECONDS << " seconds."
<< std::endl;
// Start the Stream (audio playback starts):
stream.start();
// Wait for 5 seconds:
sys.sleep(NUM_SECONDS * 1000);
std::cout << "Closing stream..." << std::endl;
// Stop the Stream (not strictly needed as termintating the System will
// also stop all open Streams):
stream.stop();
// Close the Stream (not strictly needed as terminating the System will
// also close all open Streams):
stream.close();
// Terminate the System (not strictly needed as the AutoSystem will also
// take care of this when it goes out of scope):
sys.terminate();
std::cout << "Test finished." << std::endl;
}
catch (const portaudio::PaException &e) {
std::cout << "A PortAudio error occured: " << e.paErrorText()
<< std::endl;
}
catch (const portaudio::PaCppException &e) {
std::cout << "A PortAudioCpp error occured: " << e.what() << std::endl;
}
catch (const std::exception &e) {
std::cout << "A generic exception occured: " << e.what() << std::endl;
}
catch (...) {
std::cout << "An unknown exception occured." << std::endl;
}
return 0;
}
This diff is collapsed.
CC=gcc
CFLAGS+=-Wall -I../libevdev
LDLIBS+=-levdev
LDFLAGS+=-static
all: libevdev-events
This diff is collapsed.
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment