added: implementation for the bitpanel
This commit is contained in:
parent
fd0c6044d2
commit
ca402f4a2e
2 changed files with 89 additions and 8 deletions
|
@ -31,7 +31,7 @@
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
#define CONNECTINTERVAL 10000000
|
#define CONNECTINTERVAL 1000000
|
||||||
|
|
||||||
CBitVis::CBitVis(int argc, char *argv[])
|
CBitVis::CBitVis(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
|
@ -43,6 +43,7 @@ CBitVis::CBitVis(int argc, char *argv[])
|
||||||
m_displaybuf = NULL;
|
m_displaybuf = NULL;
|
||||||
m_samplecounter = 0;
|
m_samplecounter = 0;
|
||||||
m_nrffts = 0;
|
m_nrffts = 0;
|
||||||
|
m_peakholds = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
CBitVis::~CBitVis()
|
CBitVis::~CBitVis()
|
||||||
|
@ -115,7 +116,7 @@ void CBitVis::SetupSignals()
|
||||||
|
|
||||||
void CBitVis::Process()
|
void CBitVis::Process()
|
||||||
{
|
{
|
||||||
int64_t lastconnect = GetTimeUs() - CONNECTINTERVAL;
|
int64_t lastconnect = GetTimeUs() - CONNECTINTERVAL - 1;
|
||||||
|
|
||||||
while (!m_stop)
|
while (!m_stop)
|
||||||
{
|
{
|
||||||
|
@ -140,11 +141,15 @@ void CBitVis::Process()
|
||||||
|
|
||||||
if (!m_socket.IsOpen() && GetTimeUs() - lastconnect > CONNECTINTERVAL)
|
if (!m_socket.IsOpen() && GetTimeUs() - lastconnect > CONNECTINTERVAL)
|
||||||
{
|
{
|
||||||
if (m_socket.Open("192.168.88.117", 1337) == FAIL)
|
if (m_socket.Open("192.168.88.117", 1337, 60000000) == FAIL)
|
||||||
{
|
{
|
||||||
LogError("Failed to connect: %s", m_socket.GetError().c_str());
|
LogError("Failed to connect: %s", m_socket.GetError().c_str());
|
||||||
m_socket.Close();
|
m_socket.Close();
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Log("Connected");
|
||||||
|
}
|
||||||
didconnect = true;
|
didconnect = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -196,7 +201,7 @@ void CBitVis::ProcessSignalfd()
|
||||||
void CBitVis::ProcessAudio()
|
void CBitVis::ProcessAudio()
|
||||||
{
|
{
|
||||||
const int bins = 1024;
|
const int bins = 1024;
|
||||||
const int lines = 40;
|
const int lines = 120;
|
||||||
const float decay = 0.5;
|
const float decay = 0.5;
|
||||||
int samplerate;
|
int samplerate;
|
||||||
int samples;
|
int samples;
|
||||||
|
@ -265,14 +270,16 @@ void CBitVis::ProcessAudio()
|
||||||
add += increase;
|
add += increase;
|
||||||
}
|
}
|
||||||
|
|
||||||
int64_t sleeptime = audiotime + Round64(1000000.0 / (double)samplerate * (double)i) - GetTimeUs();
|
//int64_t sleeptime = audiotime + Round64(1000000.0 / (double)samplerate * (double)i) - GetTimeUs();
|
||||||
USleep(sleeptime);
|
//SendData(sleeptime);
|
||||||
|
SendData(audiotime + Round64(1000000.0 / (double)samplerate * (double)i));
|
||||||
|
//USleep(sleeptime);
|
||||||
static int64_t prev;
|
static int64_t prev;
|
||||||
int64_t now = GetTimeUs();
|
int64_t now = GetTimeUs();
|
||||||
int64_t interval = now - prev;
|
int64_t interval = now - prev;
|
||||||
prev = now;
|
prev = now;
|
||||||
printf("samples:%i\nsleeptime:%" PRIi64"\ninterval:%" PRIi64 "\nstart\n%send\n", samples, sleeptime, interval, out.c_str());
|
//printf("samples:%i\nsleeptime:%" PRIi64"\ninterval:%" PRIi64 "\nstart\n%send\n", samples, sleeptime, interval, out.c_str());
|
||||||
fflush(stdout);
|
//fflush(stdout);
|
||||||
|
|
||||||
memset(m_fftbuf, 0, bins * sizeof(float));
|
memset(m_fftbuf, 0, bins * sizeof(float));
|
||||||
m_nrffts = 0;
|
m_nrffts = 0;
|
||||||
|
@ -286,6 +293,71 @@ void CBitVis::Cleanup()
|
||||||
m_jackclient.Disconnect();
|
m_jackclient.Disconnect();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CBitVis::SendData(int64_t time)
|
||||||
|
{
|
||||||
|
if (!m_socket.IsOpen())
|
||||||
|
return;
|
||||||
|
|
||||||
|
CTcpData data;
|
||||||
|
data.SetData(":00");
|
||||||
|
|
||||||
|
const int lines = 48;
|
||||||
|
const int columns = 120;
|
||||||
|
|
||||||
|
if (!m_peakholds)
|
||||||
|
{
|
||||||
|
m_peakholds = new peak[columns];
|
||||||
|
memset(m_peakholds, 0, columns * sizeof(peak));
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int y = lines - 1; y >= 0; y--)
|
||||||
|
{
|
||||||
|
uint8_t line[columns / 4];
|
||||||
|
for (int x = 0; x < columns / 4; x++)
|
||||||
|
{
|
||||||
|
uint8_t pixel = 0;
|
||||||
|
for (int i = 0; i < 4; i++)
|
||||||
|
{
|
||||||
|
pixel <<= 2;
|
||||||
|
int value = Round32((log10(m_displaybuf[x * 4 + i]) * 20.0f) + 55.0f) * 1.0f;
|
||||||
|
if (value > y)
|
||||||
|
pixel |= 1;
|
||||||
|
|
||||||
|
peak& currpeak = m_peakholds[x * 4 + i];
|
||||||
|
if (value >= Round32(currpeak.value))
|
||||||
|
{
|
||||||
|
currpeak.value = value;
|
||||||
|
currpeak.time = time;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Round32(currpeak.value) == y)
|
||||||
|
pixel |= 2;
|
||||||
|
|
||||||
|
if (time - currpeak.time > 500000 && Round32(currpeak.value) > 0)
|
||||||
|
currpeak.value -= 0.01f;
|
||||||
|
}
|
||||||
|
line[x] = pixel;
|
||||||
|
}
|
||||||
|
data.SetData(line, sizeof(line), true);
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8_t end[10];
|
||||||
|
memset(end, 0, sizeof(end));
|
||||||
|
data.SetData(end, sizeof(end), true);
|
||||||
|
|
||||||
|
USleep(time - GetTimeUs());
|
||||||
|
|
||||||
|
if (m_socket.Write(data) == FAIL)
|
||||||
|
{
|
||||||
|
LogError("%s", m_socket.GetError().c_str());
|
||||||
|
m_socket.Close();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Log("Data written");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void CBitVis::JackError(const char* jackerror)
|
void CBitVis::JackError(const char* jackerror)
|
||||||
{
|
{
|
||||||
LogDebug("%s", jackerror);
|
LogDebug("%s", jackerror);
|
||||||
|
|
|
@ -45,11 +45,20 @@ class CBitVis
|
||||||
int m_samplecounter;
|
int m_samplecounter;
|
||||||
int m_nrffts;
|
int m_nrffts;
|
||||||
|
|
||||||
|
struct peak
|
||||||
|
{
|
||||||
|
int64_t time;
|
||||||
|
float value;
|
||||||
|
};
|
||||||
|
|
||||||
|
peak* m_peakholds;
|
||||||
|
|
||||||
CTcpClientSocket m_socket;
|
CTcpClientSocket m_socket;
|
||||||
|
|
||||||
void SetupSignals();
|
void SetupSignals();
|
||||||
void ProcessSignalfd();
|
void ProcessSignalfd();
|
||||||
void ProcessAudio();
|
void ProcessAudio();
|
||||||
|
void SendData(int64_t time);
|
||||||
static void JackError(const char* jackerror);
|
static void JackError(const char* jackerror);
|
||||||
static void JackInfo(const char* jackinfo);
|
static void JackInfo(const char* jackinfo);
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue