CEBL  2.1
MindsetStream.cpp
Go to the documentation of this file.
1 
9 #include "../CEBLModel.hpp"
10 #include "DeviceConfig.hpp"
11 #include "Mindset24.hpp"
12 #include "MindsetStream.hpp"
13 #include <cppR/cppR.hpp>
14 
15 #include <iostream>
16 using namespace std;
17 //----------------------------------------------------------------------
18 // CONSTRUCTORS / DESTRUCTORS
19 
21 {
22  this->model = model;
23 }
25 {}
26 
27 
28 //----------------------------------------------------------------------
29 
30 void MindsetStream::updater()
31 {
32 
34  if(!mindset.Ready())
35  {
36  throw DeviceException("Lost connection to mindset during recording.");
37  }
38 
39  ublas::matrix<double> data;
40  try
41  {
42  data = mindset.GetAllData();
43  }
44  catch(const char *m)
45  {
46  throw DeviceException("Exception caught when trying to read data from mindset: " + string(m));
47  }
48  {
49  boost::mutex::scoped_lock lock(thread_lock);
50  buffer.append(data);
51 
52  }
53 
54 }
55 
56 void MindsetStream::onStart()
57 {
58  // make sure device is ready
59  if(!model->getDeviceConfig()->isReady())
60  {
61  throw DeviceException("Mindset is not ready.");
62  }
63  // open up the device
64  mindset.Open(model->getDeviceConfig()->getLocation().c_str());
65 
66  // start it
67  int bs = model->getDeviceConfig()->getBlockSize();
68  int sr = model->getDeviceConfig()->getSampleRate();
69  BlockSize block_size;
70  switch(bs)
71  {
72  case 1:
73  block_size = BLOCKSIZE96;
74  break;
75  case 2:
76  block_size = BLOCKSIZE192;
77  break;
78  case 3:
79  block_size = BLOCKSIZE384;
80  break;
81  case 4:
82  block_size = BLOCKSIZE768;
83  break;
84  default:
85  block_size = BLOCKSIZE192;
86  }
87  SampleRate sample_rate;
88  switch(sr)
89  {
90  case 0:
91  sample_rate = SAMPLERATE0;
92  break;
93  case 1:
94  sample_rate = SAMPLERATE1024;
95  break;
96  case 2:
97  sample_rate = SAMPLERATE512;
98  break;
99  case 3:
100  sample_rate = SAMPLERATE256;
101  break;
102  case 4:
103  sample_rate = SAMPLERATE128;
104  break;
105  case 5:
106  sample_rate = SAMPLERATE64;
107  break;
108  default:
109  sample_rate = SAMPLERATE256;
110  }
111 
112 
113  mindset.SetBlockSize(block_size);
114  mindset.SetSampleRate(sample_rate);
115 }
116 
117 void MindsetStream::onStop()
118 {
119  mindset.Close();
120 }
121 
122 
123 
124