mirror of https://github.com/probonopd/MiniDexed
commit
ecbae30c03
@ -0,0 +1,88 @@ |
|||||||
|
#include "arm_float_to_q23.h" |
||||||
|
|
||||||
|
#if defined(ARM_MATH_NEON_EXPERIMENTAL) |
||||||
|
void arm_float_to_q23(const float32_t * pSrc, q23_t * pDst, uint32_t blockSize) |
||||||
|
{ |
||||||
|
const float32_t *pIn = pSrc; /* Src pointer */ |
||||||
|
uint32_t blkCnt; /* loop counter */ |
||||||
|
|
||||||
|
float32x4_t inV; |
||||||
|
|
||||||
|
int32x4_t cvt; |
||||||
|
|
||||||
|
blkCnt = blockSize >> 2U; |
||||||
|
|
||||||
|
/* Compute 4 outputs at a time.
|
||||||
|
** a second loop below computes the remaining 1 to 3 samples. */ |
||||||
|
while (blkCnt > 0U) |
||||||
|
{ |
||||||
|
/* C = A * 8388608 */ |
||||||
|
/* Convert from float to q23 and then store the results in the destination buffer */ |
||||||
|
inV = vld1q_f32(pIn); |
||||||
|
|
||||||
|
cvt = vcvtq_n_s32_f32(inV, 23); |
||||||
|
|
||||||
|
/* saturate */ |
||||||
|
cvt = vminq_s32(cvt, vdupq_n_s32(0x007fffff)); |
||||||
|
cvt = vmaxq_s32(cvt, vdupq_n_s32(0xff800000)); |
||||||
|
|
||||||
|
vst1q_s32(pDst, cvt); |
||||||
|
pDst += 4; |
||||||
|
pIn += 4; |
||||||
|
|
||||||
|
/* Decrement the loop counter */ |
||||||
|
blkCnt--; |
||||||
|
} |
||||||
|
|
||||||
|
/* If the blockSize is not a multiple of 4, compute any remaining output samples here.
|
||||||
|
** No loop unrolling is used. */ |
||||||
|
blkCnt = blockSize & 3; |
||||||
|
|
||||||
|
while (blkCnt > 0U) |
||||||
|
{ |
||||||
|
/* C = A * 8388608 */ |
||||||
|
/* Convert from float to q23 and then store the results in the destination buffer */ |
||||||
|
*pDst++ = (q23_t) __SSAT((q31_t) (*pIn++ * 8388608.0f), 24); |
||||||
|
|
||||||
|
/* Decrement the loop counter */ |
||||||
|
blkCnt--; |
||||||
|
} |
||||||
|
} |
||||||
|
#else |
||||||
|
void arm_float_to_q23(const float32_t * pSrc, q23_t * pDst, uint32_t blockSize) |
||||||
|
{ |
||||||
|
uint32_t blkCnt; /* Loop counter */ |
||||||
|
const float32_t *pIn = pSrc; /* Source pointer */ |
||||||
|
|
||||||
|
/* Loop unrolling: Compute 4 outputs at a time */ |
||||||
|
blkCnt = blockSize >> 2U; |
||||||
|
|
||||||
|
while (blkCnt > 0U) |
||||||
|
{ |
||||||
|
/* C = A * 8388608 */ |
||||||
|
/* convert from float to Q23 and store result in destination buffer */ |
||||||
|
|
||||||
|
*pDst++ = (q23_t) __SSAT((q31_t) (*pIn++ * 8388608.0f), 24); |
||||||
|
*pDst++ = (q23_t) __SSAT((q31_t) (*pIn++ * 8388608.0f), 24); |
||||||
|
*pDst++ = (q23_t) __SSAT((q31_t) (*pIn++ * 8388608.0f), 24); |
||||||
|
*pDst++ = (q23_t) __SSAT((q31_t) (*pIn++ * 8388608.0f), 24); |
||||||
|
|
||||||
|
/* Decrement loop counter */ |
||||||
|
blkCnt--; |
||||||
|
} |
||||||
|
|
||||||
|
/* Loop unrolling: Compute remaining outputs */ |
||||||
|
blkCnt = blockSize % 0x4U; |
||||||
|
|
||||||
|
while (blkCnt > 0U) |
||||||
|
{ |
||||||
|
/* C = A * 8388608 */ |
||||||
|
/* Convert from float to q23 and then store the results in the destination buffer */ |
||||||
|
*pDst++ = (q23_t) __SSAT((q31_t) (*pIn++ * 8388608.0f), 24); |
||||||
|
|
||||||
|
/* Decrement loop counter */ |
||||||
|
blkCnt--; |
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
|
#endif /* #if defined(ARM_MATH_NEON_EXPERIMENTAL) */ |
@ -0,0 +1,22 @@ |
|||||||
|
#pragma once |
||||||
|
|
||||||
|
#include "arm_math_types.h" |
||||||
|
|
||||||
|
typedef int32_t q23_t; |
||||||
|
|
||||||
|
#ifdef __cplusplus |
||||||
|
extern "C" |
||||||
|
{ |
||||||
|
#endif |
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Converts the elements of the floating-point vector to Q23 vector. |
||||||
|
* @param[in] pSrc points to the floating-point input vector |
||||||
|
* @param[out] pDst points to the Q23 output vector |
||||||
|
* @param[in] blockSize length of the input vector |
||||||
|
*/ |
||||||
|
void arm_float_to_q23(const float32_t * pSrc, q23_t * pDst, uint32_t blockSize); |
||||||
|
|
||||||
|
#ifdef __cplusplus |
||||||
|
} |
||||||
|
#endif |
@ -0,0 +1,57 @@ |
|||||||
|
#!/usr/bin/env python3 |
||||||
|
# -*- coding: utf-8 -*- |
||||||
|
|
||||||
|
""" |
||||||
|
Syslog server to receive and display syslog messages from MiniDexed. |
||||||
|
""" |
||||||
|
|
||||||
|
import socket |
||||||
|
import time |
||||||
|
import threading |
||||||
|
|
||||||
|
class SyslogServer: |
||||||
|
def __init__(self, host='0.0.0.0', port=8514): |
||||||
|
self.host = host |
||||||
|
self.port = port |
||||||
|
self.server = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) |
||||||
|
self.server.bind((self.host, self.port)) |
||||||
|
self.start_time = None |
||||||
|
self.running = True |
||||||
|
|
||||||
|
def start(self): |
||||||
|
ip_address = socket.gethostbyname(socket.gethostname()) |
||||||
|
print(f"Syslog server listening on {ip_address}:{self.port}") |
||||||
|
input_thread = threading.Thread(target=self.wait_for_input) |
||||||
|
input_thread.daemon = True |
||||||
|
input_thread.start() |
||||||
|
while self.running: |
||||||
|
try: |
||||||
|
data, address = self.server.recvfrom(1024) |
||||||
|
self.handle_message(data) |
||||||
|
except KeyboardInterrupt: |
||||||
|
self.running = False |
||||||
|
|
||||||
|
def handle_message(self, data): |
||||||
|
message = data[2:].decode('utf-8').strip() |
||||||
|
|
||||||
|
if self.start_time is None: |
||||||
|
self.start_time = time.time() |
||||||
|
relative_time = "0:00:00.000" |
||||||
|
else: |
||||||
|
elapsed_time = time.time() - self.start_time |
||||||
|
hours = int(elapsed_time // 3600) |
||||||
|
minutes = int((elapsed_time % 3600) // 60) |
||||||
|
seconds = int(elapsed_time % 60) |
||||||
|
milliseconds = int((elapsed_time % 1) * 1000) |
||||||
|
relative_time = f"{hours:02d}:{minutes:02d}:{seconds:02d}.{milliseconds:03d}" |
||||||
|
|
||||||
|
print(f"{relative_time} {message}") |
||||||
|
|
||||||
|
def wait_for_input(self): |
||||||
|
input("Press any key to exit...") |
||||||
|
self.running = False |
||||||
|
|
||||||
|
if __name__ == "__main__": |
||||||
|
server = SyslogServer() |
||||||
|
server.start() |
||||||
|
print("Syslog server stopped.") |
Loading…
Reference in new issue