Mercurial > hg > beaglert
changeset 342:860c42b3830e prerelease
Updated basic_libpd, now slightly more efficient with less memory operations. Requires the API change in libpd operated in libpd:99a2be8
author | Giulio Moro <giuliomoro@yahoo.it> |
---|---|
date | Mon, 06 Jun 2016 12:21:38 +0100 |
parents | 7af9c5be3434 |
children | 4823ee13bcac |
files | examples/basic_libpd/render.cpp examples/basic_libpd/z_libpd.h |
diffstat | 2 files changed, 16 insertions(+), 20 deletions(-) [+] |
line wrap: on
line diff
--- a/examples/basic_libpd/render.cpp Mon Jun 06 03:31:22 2016 +0100 +++ b/examples/basic_libpd/render.cpp Mon Jun 06 12:21:38 2016 +0100 @@ -13,6 +13,7 @@ #include <stdio.h> #include "z_libpd.h" #include "z_queued.h" +#include "s_stuff.h" #include <UdpServer.h> #include <Midi.h> @@ -41,8 +42,6 @@ rt_printf("%s", recv); } -UdpServer udpServer; - void libpdReadFilesLoop(){ while(!gShouldStop){ // check for modified sockets/file descriptors @@ -58,6 +57,7 @@ AuxiliaryTask libpdProcessMessageQueueTask; AuxiliaryTask libpdProcessMidiQueueTask; Midi midi; +//UdpServer udpServer; bool setup(BelaContext *context, void *userData) { @@ -69,7 +69,7 @@ midi.enableParser(false); #endif /* PARSE_MIDI */ gChannelsInUse = min((int)(context->analogChannels+context->audioChannels), (int)gChannelsInUse); - udpServer.bindToPort(1234); +// udpServer.bindToPort(1234); gLibpdBlockSize = libpd_blocksize(); // check that we are not running with a blocksize smaller than gLibPdBlockSize @@ -91,16 +91,13 @@ libpd_finish_message("pd", "dsp"); gBufLength = max(gLibpdBlockSize, context->audioFrames); - unsigned int bufferSize = sizeof(float)*gChannelsInUse*gBufLength; - gInBuf = (float*)malloc(bufferSize); - gOutBuf = (float*)malloc(bufferSize); - // no need to memset to zero char file[] = "_main.pd"; char folder[] = "./"; // open patch [; pd open file folder( libpd_openfile(file, folder); - + gInBuf = libpd_get_sys_soundin(); + gOutBuf = libpd_get_sys_soundout(); libpdReadFilesTask = Bela_createAuxiliaryTask(libpdReadFilesLoop, 60, "libpdReadFiles"); Bela_scheduleAuxiliaryTask(libpdReadFilesTask); @@ -195,8 +192,6 @@ } #endif /* PARSE_MIDI */ - unsigned int inW = 0; - unsigned int outR = 0; /* * NOTE: if you are only using audio (or only analogs) and you are using interleaved buffers * and the blocksize of Bela is the same as gLibPdBlockSize, then you probably @@ -205,9 +200,10 @@ */ static unsigned int analogChannelsInUse = min(context->analogChannels, gChannelsInUse - context->audioChannels); static unsigned int numberOfPdBlocksToProcess = gBufLength / gLibpdBlockSize; - // rt_printf("channelsInUse: %d, analogChannels in Use: %d\n", gChannelsInUse, analogChannelsInUse); for(unsigned int j = 0; j < numberOfPdBlocksToProcess; ++j){ - int oldInW = inW; + unsigned int inW = 0; + unsigned int outR = 0; + for(unsigned int n = 0; n < gLibpdBlockSize; ++n){ //pd buffers are interleaved for(unsigned int ch = 0; ch < context->audioChannels; ++ch){ //first two channels are audio gInBuf[inW++] = audioRead(context, n, ch); @@ -228,13 +224,9 @@ } } } - // TODO: see if we can rewrite libpd_process_float so that it takes a buffer - // of interleaved channels of arbitrary length rather than a series of - // stacked buffers of size gLibPdBlockSize as it currently does. - // This would allow to use the buffers as they are rather than having to copy them - libpd_process_float(1, &gInBuf[oldInW], &gOutBuf[oldInW]); + libpd_process_sys(); // process the block for(unsigned int n = 0; n < gLibpdBlockSize; ++n){ //pd buffers are interleaved - unsigned int outAudioFrame = n + j * gLibpdBlockSize; + unsigned int outAudioFrame = 0; for(unsigned int ch = 0; ch < context->audioChannels; ++ch){ audioWrite(context, outAudioFrame, ch, gOutBuf[outR++]); } @@ -272,6 +264,6 @@ void cleanup(BelaContext *context, void *userData) { libpd_queued_release(); - free(gInBuf); - free(gOutBuf); +// free(gInBuf); +// free(gOutBuf); }
--- a/examples/basic_libpd/z_libpd.h Mon Jun 06 03:31:22 2016 +0100 +++ b/examples/basic_libpd/z_libpd.h Mon Jun 06 12:21:38 2016 +0100 @@ -29,6 +29,9 @@ EXTERN int libpd_blocksize(void); EXTERN int libpd_init_audio(int inChans, int outChans, int sampleRate); EXTERN int libpd_process_raw(const float *inBuffer, float *outBuffer); +EXTERN t_sample* libpd_get_sys_soundin(); +EXTERN t_sample* libpd_get_sys_soundout(); +EXTERN int libpd_process_sys(); EXTERN int libpd_process_short(const int ticks, const short *inBuffer, short *outBuffer); EXTERN int libpd_process_float(int ticks, @@ -108,6 +111,7 @@ EXTERN void libpd_set_polyaftertouchhook(const t_libpd_polyaftertouchhook hook); EXTERN void libpd_set_midibytehook(const t_libpd_midibytehook hook); EXTERN void libpd_sys_microsleep(int sleep); + #ifdef __cplusplus } #endif