working sending bt messages to Pd. Confused about SR and nchnls and
data format.
This commit is contained in:
parent
6dd8ab1bec
commit
f34cb75ab1
5 changed files with 96 additions and 19 deletions
|
|
@ -62,6 +62,11 @@ static esp_err_t fifostream_close(audio_element_handle_t self)
|
|||
}
|
||||
|
||||
int phaseinc = 123;
|
||||
#define INCHANS 2
|
||||
#define OUTCHANS 2
|
||||
#define BLKSIZE 64
|
||||
|
||||
float soundin[OUTCHANS * BLKSIZE], soundout[OUTCHANS * BLKSIZE];
|
||||
|
||||
static int fifostream_process(audio_element_handle_t self, char *in_buffer, int in_len)
|
||||
{
|
||||
|
|
@ -78,14 +83,15 @@ static int fifostream_process(audio_element_handle_t self, char *in_buffer, int
|
|||
}
|
||||
fifostream->byte_num += r_size;
|
||||
{
|
||||
int i, nsamps = r_size/sizeof(short);
|
||||
static int phase;
|
||||
int i;
|
||||
for (i = 0; i < r_size/sizeof(short); i++)
|
||||
for (i = 0; i < nsamps; i++)
|
||||
{
|
||||
phase += phaseinc ;
|
||||
fifostream->s_buf[i] = (phase >> 3);
|
||||
}
|
||||
cumsamps += r_size/sizeof(short);
|
||||
|
||||
cumsamps += nsamps;
|
||||
while (cumsamps >= 128)
|
||||
{
|
||||
pdmain_tick();
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@ typedef struct fifostream_cfg {
|
|||
bool stack_in_ext; /*!< Try to allocate stack in external memory */
|
||||
} fifostream_cfg_t;
|
||||
|
||||
#define FIFOSTREAM_TASK_STACK (4 * 1024)
|
||||
#define FIFOSTREAM_TASK_STACK (20000)
|
||||
#define FIFOSTREAM_TASK_CORE (0)
|
||||
#define FIFOSTREAM_TASK_PRIO (5)
|
||||
#define FIFOSTREAM_RINGBUFFER_SIZE (8 * 1024)
|
||||
|
|
|
|||
|
|
@ -28,6 +28,7 @@ canvas 274 279 752 643 12;\n\
|
|||
|
||||
static void trymem(int foo)
|
||||
{
|
||||
#if 0
|
||||
int i;
|
||||
char msg[80];
|
||||
for (i = 1; i < 500; i++)
|
||||
|
|
@ -39,6 +40,34 @@ static void trymem(int foo)
|
|||
}
|
||||
sprintf(msg, "%d max mem %dk", foo, i-1);
|
||||
pdmain_print(msg);
|
||||
#endif
|
||||
}
|
||||
|
||||
/* queue from bluetooth. Need to make this a proper RTOS queue */
|
||||
static char *pd_bt_buf;
|
||||
static int pd_bt_size;
|
||||
|
||||
void pd_dispatch_bt(char *data, size_t size)
|
||||
{
|
||||
if (!pd_bt_buf)
|
||||
pd_bt_buf = getbytes(0);
|
||||
pd_bt_buf = (char *)resizebytes(pd_bt_buf, pd_bt_size, pd_bt_size+size);
|
||||
memcpy(pd_bt_buf + pd_bt_size, data, size);
|
||||
pd_bt_size += size;
|
||||
}
|
||||
|
||||
void pd_poll_bt( void)
|
||||
{
|
||||
static t_binbuf *b;
|
||||
if (!b)
|
||||
b = binbuf_new();
|
||||
if (pd_bt_size)
|
||||
{
|
||||
binbuf_text(b, pd_bt_buf, pd_bt_size);
|
||||
binbuf_eval(b, 0, 0, 0);
|
||||
pd_bt_buf = (char *)resizebytes(pd_bt_buf, pd_bt_size, 0);
|
||||
pd_bt_size = 0;
|
||||
}
|
||||
}
|
||||
|
||||
void pdmain_init( void)
|
||||
|
|
@ -64,15 +93,41 @@ void pdmain_init( void)
|
|||
binbuf_free(b);
|
||||
}
|
||||
|
||||
|
||||
void pdmain_tick( void)
|
||||
{
|
||||
static int initted;
|
||||
if (!initted)
|
||||
{
|
||||
pdmain_init();
|
||||
initted = 1;
|
||||
}
|
||||
pd_poll_bt();
|
||||
sched_tick();
|
||||
}
|
||||
|
||||
/* ----------------- stuff to keep Pd happy -------------------- */
|
||||
|
||||
t_class *glob_pdobject;
|
||||
|
||||
extern int phaseinc;
|
||||
|
||||
static void glob_foo(void *dummy, t_floatarg f)
|
||||
{
|
||||
post("foo %f", f);
|
||||
phaseinc = f;
|
||||
}
|
||||
void glob_dsp(void *dummy, t_symbol *s, int argc, t_atom *argv);
|
||||
|
||||
void glob_init( void)
|
||||
{
|
||||
glob_pdobject = class_new(gensym("pd"), 0, 0, sizeof(t_pd),
|
||||
CLASS_DEFAULT, A_NULL);
|
||||
class_addmethod(glob_pdobject, (t_method)glob_dsp, gensym("dsp"),
|
||||
A_GIMME, 0);
|
||||
class_addmethod(glob_pdobject, (t_method)glob_foo, gensym("foo"),
|
||||
A_DEFFLOAT, 0);
|
||||
pd_bind(&glob_pdobject, gensym("pd"));
|
||||
}
|
||||
|
||||
void g_array_setup(void);
|
||||
|
|
@ -171,7 +226,7 @@ void conf_init(void)
|
|||
/* ------- STUBS that do nothing ------------- */
|
||||
int sys_get_outchannels(void) {return(2); }
|
||||
int sys_get_inchannels(void) {return(2); }
|
||||
float sys_getsr( void) {return (44100);}
|
||||
float sys_getsr( void) {return (48000);}
|
||||
int sys_getblksize(void) { return (DEFDACBLKSIZE); }
|
||||
|
||||
int pd_compatibilitylevel = 100;
|
||||
|
|
|
|||
|
|
@ -19,7 +19,6 @@
|
|||
#include "i2s_stream.h"
|
||||
#include "board.h"
|
||||
#include "fifostream.h"
|
||||
|
||||
#include "esp_bt.h"
|
||||
#include "esp_bt_main.h"
|
||||
#include "esp_gap_bt_api.h"
|
||||
|
|
@ -29,8 +28,6 @@
|
|||
#include "time.h"
|
||||
#include "sys/time.h"
|
||||
|
||||
extern void pdmain_init( void);
|
||||
|
||||
|
||||
#define SPP_TAG "WOMBAT"
|
||||
#define SPP_SERVER_NAME "SPP_SERVER"
|
||||
|
|
@ -65,6 +62,7 @@ static void print_speed(void)
|
|||
}
|
||||
|
||||
extern int phaseinc;
|
||||
void pd_dispatch_bt(char *data, size_t size);
|
||||
|
||||
static void esp_spp_cb(esp_spp_cb_event_t event, esp_spp_cb_param_t *param)
|
||||
{
|
||||
|
|
@ -91,11 +89,15 @@ static void esp_spp_cb(esp_spp_cb_event_t event, esp_spp_cb_param_t *param)
|
|||
ESP_LOGI(SPP_TAG, "ESP_SPP_CL_INIT_EVT");
|
||||
break;
|
||||
case ESP_SPP_DATA_IND_EVT:
|
||||
#if (SPP_SHOW_MODE == SPP_SHOW_DATA)
|
||||
|
||||
ESP_LOGI(SPP_TAG, "ESP_SPP_DATA_IND_EVT len=%d handle=%d",
|
||||
param->data_ind.len, param->data_ind.handle);
|
||||
esp_log_buffer_hex("",param->data_ind.data,param->data_ind.len);
|
||||
{
|
||||
#if 1
|
||||
pd_dispatch_bt((char *)(param->data_ind.data),
|
||||
param->data_ind.len);
|
||||
#else
|
||||
char foo[80];
|
||||
int nfoo = (param->data_ind.len > 78 ? 78 : param->data_ind.len), i;
|
||||
for (i = 0; i < nfoo; i++)
|
||||
|
|
@ -103,14 +105,9 @@ static void esp_spp_cb(esp_spp_cb_event_t event, esp_spp_cb_param_t *param)
|
|||
foo[i] = 0;
|
||||
ESP_LOGI(SPP_TAG, "%s", foo);
|
||||
sscanf(foo, "%d%d", &i, &phaseinc);
|
||||
}
|
||||
#else
|
||||
gettimeofday(&time_new, NULL);
|
||||
data_num += param->data_ind.len;
|
||||
if (time_new.tv_sec - time_old.tv_sec >= 3) {
|
||||
print_speed();
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
break;
|
||||
case ESP_SPP_CONG_EVT:
|
||||
ESP_LOGI(SPP_TAG, "ESP_SPP_CONG_EVT");
|
||||
|
|
@ -333,7 +330,26 @@ void app_main()
|
|||
esp_bt_pin_code_t pin_code;
|
||||
esp_bt_gap_set_pin(pin_type, 0, pin_code);
|
||||
|
||||
pdmain_init();
|
||||
/* pdmain_init(); */
|
||||
audio_main();
|
||||
}
|
||||
|
||||
#if 0 /* this will be more work than I thought */
|
||||
void gettaskinfo(char *where)
|
||||
{
|
||||
TaskStatus_t xTaskDetails;
|
||||
vTaskGetInfo( /* The handle of the task being queried. */
|
||||
0,
|
||||
/* The TaskStatus_t structure to complete with information
|
||||
on xTask. */
|
||||
&xTaskDetails,
|
||||
/* Include the stack high water mark value in the
|
||||
TaskStatus_t structure. */
|
||||
pdTRUE,
|
||||
/* Include the task state in the TaskStatus_t structure. */
|
||||
eInvalid );
|
||||
ESP_LOGE("PROC", "where: proc %s: %d %d", xTaskDetails.pcTaskName,
|
||||
(int)((char *)(&xTaskDetails) - (char *)(pxStackBase)),
|
||||
(int)usStackHighWaterMark);
|
||||
}
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -464,8 +464,8 @@ CONFIG_TRACEMEM_RESERVE_DRAM=0x0
|
|||
CONFIG_FOUR_UNIVERSAL_MAC_ADDRESS=y
|
||||
CONFIG_NUMBER_OF_UNIVERSAL_MAC_ADDRESS=4
|
||||
CONFIG_SYSTEM_EVENT_QUEUE_SIZE=32
|
||||
CONFIG_SYSTEM_EVENT_TASK_STACK_SIZE=2304
|
||||
CONFIG_MAIN_TASK_STACK_SIZE=40000
|
||||
CONFIG_SYSTEM_EVENT_TASK_STACK_SIZE=4000
|
||||
CONFIG_MAIN_TASK_STACK_SIZE=20000
|
||||
CONFIG_IPC_TASK_STACK_SIZE=1024
|
||||
CONFIG_TIMER_TASK_STACK_SIZE=3584
|
||||
CONFIG_NEWLIB_STDOUT_LINE_ENDING_CRLF=y
|
||||
|
|
|
|||
Loading…
Reference in a new issue