A modern Music Player Daemon based on Rockbox open source high quality audio player
libadwaita audio rust zig deno mpris rockbox mpd
at master 95 lines 2.0 kB view raw
1/* Copyright (c) 1997-1999 Miller Puckette. 2* For information on usage and redistribution, and for a DISCLAIMER OF ALL 3* WARRANTIES, see the file, "LICENSE.txt," in this distribution. */ 4 5#ifdef ROCKBOX 6#include "plugin.h" 7#include "../../pdbox.h" 8#else /* ROCKBOX */ 9#include <stdlib.h> 10#include <string.h> 11#endif /* ROCKBOX */ 12#include "m_pd.h" 13#include "m_imp.h" 14 15/* #define LOUD */ 16#ifdef LOUD 17#include <stdio.h> 18#endif 19 20/* #define DEBUGMEM */ 21#ifdef DEBUGMEM 22static int totalmem = 0; 23#endif 24 25void *getbytes(size_t nbytes) 26{ 27 void *ret; 28 if (nbytes < 1) nbytes = 1; 29 ret = (void *)calloc(nbytes, 1); 30#ifdef LOUD 31 fprintf(stderr, "new %x %d\n", (int)ret, nbytes); 32#endif /* LOUD */ 33#ifdef DEBUGMEM 34 totalmem += nbytes; 35#endif 36 if (!ret) 37 post("pd: getbytes() failed -- out of memory"); 38 return (ret); 39} 40 41void *getzbytes(size_t nbytes) /* obsolete name */ 42{ 43 return (getbytes(nbytes)); 44} 45 46void *copybytes(void *src, size_t nbytes) 47{ 48 void *ret; 49 ret = getbytes(nbytes); 50 if (nbytes) 51 memcpy(ret, src, nbytes); 52 return (ret); 53} 54 55void *resizebytes(void *old, size_t oldsize, size_t newsize) 56{ 57 void *ret; 58 if (newsize < 1) newsize = 1; 59 if (oldsize < 1) oldsize = 1; 60 ret = (void *)realloc((char *)old, newsize); 61 if (newsize > oldsize && ret) 62 memset(((char *)ret) + oldsize, 0, newsize - oldsize); 63#ifdef LOUD 64 fprintf(stderr, "resize %x %d --> %x %d\n", (int)old, oldsize, (int)ret, newsize); 65#endif /* LOUD */ 66#ifdef DEBUGMEM 67 totalmem += (newsize - oldsize); 68#endif 69 if (!ret) 70 post("pd: resizebytes() failed -- out of memory"); 71 return (ret); 72} 73 74void freebytes(void *fatso, size_t nbytes) 75{ 76 if (nbytes == 0) 77 nbytes = 1; 78#ifdef LOUD 79 fprintf(stderr, "free %x %d\n", (int)fatso, nbytes); 80#endif /* LOUD */ 81#ifdef DEBUGMEM 82 totalmem -= nbytes; 83#endif 84 free(fatso); 85} 86 87#ifdef DEBUGMEM 88#include <stdio.h> 89 90void glob_foo(void *dummy, t_symbol *s, int argc, t_atom *argv) 91{ 92 fprintf(stderr, "total mem %d\n", totalmem); 93} 94#endif 95