1515#define MAX_ARR_SIZE (4000*4000)
1616
1717int tsdr_loadplugin (tsdr_lib_t * tsdr , char * filepath ) {
18+ tsdr -> running = 0 ;
1819 tsdr -> plugin = malloc (sizeof (pluginsource_t ));
1920 pluginsource_t * plugin = (pluginsource_t * )(tsdr -> plugin );
2021 return tsdrplug_load (plugin , filepath );
@@ -44,6 +45,7 @@ int tsdr_unloadplugin(tsdr_lib_t * tsdr) {
4445
4546int tsdr_stop (tsdr_lib_t * tsdr ) {
4647 pluginsource_t * plugin = (pluginsource_t * )(tsdr -> plugin );
48+ tsdr -> running = 0 ;
4749 return plugin -> tsdrplugin_stop ();
4850}
4951
@@ -53,6 +55,10 @@ int tsdr_setgain(tsdr_lib_t * tsdr, float gain) {
5355}
5456
5557int tsdr_readasync (tsdr_lib_t * tsdr , tsdr_readasync_function cb , void * ctx ) {
58+ if (tsdr -> running )
59+ return TSDR_ALREADY_RUNNING ;
60+ tsdr -> running = 1 ;
61+
5662 const int width = tsdr -> width ;
5763 const int height = tsdr -> height ;
5864 const int size = width * height ;
@@ -62,16 +68,20 @@ int tsdr_readasync(tsdr_lib_t * tsdr, tsdr_readasync_function cb, void *ctx) {
6268
6369 float * buffer = (float * ) malloc (sizeof (float ) * size );
6470
65- int i ;
66- for (i = 0 ; i < size ; i ++ ) {
67- const int x = i % width ;
68- const int y = i / width ;
71+ uint32_t frames = 0 ;
72+ while (tsdr -> running ) {
73+ frames ++ ;
74+ int i ;
75+ for (i = 0 ; i < size ; i ++ ) {
76+ const int x = i % width ;
77+ const int y = ((i / width ) + frames ) % height ;
6978
70- const float rat = (x > width /2 ) ? (y / (float ) height ) : (1.0f - y / (float ) height );
71- buffer [i ] = rat ;
72- }
79+ const float rat = (x > width /2 ) ? (y / (float ) height ) : (1.0f - y / (float ) height );
80+ buffer [i ] = rat ;
81+ }
7382
74- cb (buffer , width , height , ctx );
83+ cb (buffer , width , height , ctx );
84+ }
7585
7686 free (buffer );
7787 return TSDR_OK ;
0 commit comments