summaryrefslogtreecommitdiff
path: root/apps/plugins/pdbox/PDa/src/d_soundfile.c
diff options
context:
space:
mode:
Diffstat (limited to 'apps/plugins/pdbox/PDa/src/d_soundfile.c')
-rw-r--r--apps/plugins/pdbox/PDa/src/d_soundfile.c82
1 files changed, 82 insertions, 0 deletions
diff --git a/apps/plugins/pdbox/PDa/src/d_soundfile.c b/apps/plugins/pdbox/PDa/src/d_soundfile.c
index 4b89e93fd4..34aa105d28 100644
--- a/apps/plugins/pdbox/PDa/src/d_soundfile.c
+++ b/apps/plugins/pdbox/PDa/src/d_soundfile.c
@@ -11,6 +11,10 @@ readsf~ and writesf~ are defined which confine disk operations to a separate
11thread so that they can be used in real time. The readsf~ and writesf~ 11thread so that they can be used in real time. The readsf~ and writesf~
12objects use Posix-like threads. */ 12objects use Posix-like threads. */
13 13
14#ifdef ROCKBOX
15#include "plugin.h"
16#include "pdbox.h"
17#else /* ROCKBOX */
14#ifdef UNIX 18#ifdef UNIX
15#include <unistd.h> 19#include <unistd.h>
16#include <fcntl.h> 20#include <fcntl.h>
@@ -22,6 +26,7 @@ objects use Posix-like threads. */
22#include <stdio.h> 26#include <stdio.h>
23#include <string.h> 27#include <string.h>
24#include <errno.h> 28#include <errno.h>
29#endif /* ROCKBOX */
25 30
26#include "m_pd.h" 31#include "m_pd.h"
27 32
@@ -198,9 +203,15 @@ int open_soundfile(const char *dirname, const char *filename, int headersize,
198 long skipframes) 203 long skipframes)
199{ 204{
200 char buf[OBUFSIZE], *bufptr; 205 char buf[OBUFSIZE], *bufptr;
206#ifdef ROCKBOX
207 int fd, nchannels, bigendian, bytespersamp, swap, sysrtn;
208#else
201 int fd, format, nchannels, bigendian, bytespersamp, swap, sysrtn; 209 int fd, format, nchannels, bigendian, bytespersamp, swap, sysrtn;
210#endif
202 long bytelimit = 0x7fffffff; 211 long bytelimit = 0x7fffffff;
212#ifndef ROCKBOX
203 errno = 0; 213 errno = 0;
214#endif
204 fd = open_via_path(dirname, filename, 215 fd = open_via_path(dirname, filename,
205 "", buf, &bufptr, MAXPDSTRING, 1); 216 "", buf, &bufptr, MAXPDSTRING, 1);
206 if (fd < 0) 217 if (fd < 0)
@@ -239,7 +250,9 @@ int open_soundfile(const char *dirname, const char *filename, int headersize,
239 swap = (bigendian != garray_ambigendian()); 250 swap = (bigendian != garray_ambigendian());
240 if (format == FORMAT_NEXT) /* nextstep header */ 251 if (format == FORMAT_NEXT) /* nextstep header */
241 { 252 {
253#ifndef ROCKBOX
242 uint32 param; 254 uint32 param;
255#endif
243 if (bytesread < (int)sizeof(t_nextstep)) 256 if (bytesread < (int)sizeof(t_nextstep))
244 goto badheader; 257 goto badheader;
245 nchannels = swap4(((t_nextstep *)buf)->ns_nchans, swap); 258 nchannels = swap4(((t_nextstep *)buf)->ns_nchans, swap);
@@ -381,7 +394,9 @@ int open_soundfile(const char *dirname, const char *filename, int headersize,
381badheader: 394badheader:
382 /* the header wasn't recognized. We're threadable here so let's not 395 /* the header wasn't recognized. We're threadable here so let's not
383 print out the error... */ 396 print out the error... */
397#ifndef ROCKBOX
384 errno = EIO; 398 errno = EIO;
399#endif
385 return (-1); 400 return (-1);
386} 401}
387 402
@@ -705,7 +720,11 @@ static int create_soundfile(t_canvas *canvas, const char *filename,
705 720
706 canvas_makefilename(canvas, filenamebuf, buf2, MAXPDSTRING); 721 canvas_makefilename(canvas, filenamebuf, buf2, MAXPDSTRING);
707 sys_bashfilename(buf2, buf2); 722 sys_bashfilename(buf2, buf2);
723#ifdef ROCKBOX
724 if ((fd = open(buf2, BINCREATE)) < 0)
725#else
708 if ((fd = open(buf2, BINCREATE, 0666)) < 0) 726 if ((fd = open(buf2, BINCREATE, 0666)) < 0)
727#endif
709 return (-1); 728 return (-1);
710 729
711 if (write(fd, headerbuf, headersize) < headersize) 730 if (write(fd, headerbuf, headersize) < headersize)
@@ -771,7 +790,11 @@ static void soundfile_finishwrite(void *obj, char *filename, int fd,
771 } 790 }
772 return; 791 return;
773baddonewrite: 792baddonewrite:
793#ifdef ROCKBOX
794 post("%s: error", filename);
795#else
774 post("%s: %s", filename, strerror(errno)); 796 post("%s: %s", filename, strerror(errno));
797#endif
775} 798}
776 799
777static void soundfile_xferout(int nchannels, t_sample **vecs, 800static void soundfile_xferout(int nchannels, t_sample **vecs,
@@ -920,9 +943,16 @@ static t_soundfiler *soundfiler_new(void)
920static void soundfiler_read(t_soundfiler *x, t_symbol *s, 943static void soundfiler_read(t_soundfiler *x, t_symbol *s,
921 int argc, t_atom *argv) 944 int argc, t_atom *argv)
922{ 945{
946#ifdef ROCKBOX
947 (void) s;
948#endif
923 int headersize = -1, channels = 0, bytespersamp = 0, bigendian = 0, 949 int headersize = -1, channels = 0, bytespersamp = 0, bigendian = 0,
924 resize = 0, i, j; 950 resize = 0, i, j;
951#ifdef ROCKBOX
952 long skipframes = 0, nframes = 0, finalsize = 0,
953#else
925 long skipframes = 0, nframes = 0, finalsize = 0, itemsleft, 954 long skipframes = 0, nframes = 0, finalsize = 0, itemsleft,
955#endif
926 maxsize = DEFMAXSIZE, itemsread = 0, bytelimit = 0x7fffffff; 956 maxsize = DEFMAXSIZE, itemsread = 0, bytelimit = 0x7fffffff;
927 int fd = -1; 957 int fd = -1;
928 char endianness, *filename; 958 char endianness, *filename;
@@ -930,7 +960,11 @@ static void soundfiler_read(t_soundfiler *x, t_symbol *s,
930 t_sample *vecs[MAXSFCHANS]; 960 t_sample *vecs[MAXSFCHANS];
931 char sampbuf[SAMPBUFSIZE]; 961 char sampbuf[SAMPBUFSIZE];
932 int bufframes, nitems; 962 int bufframes, nitems;
963#ifdef ROCKBOX
964 int fp;
965#else
933 FILE *fp; 966 FILE *fp;
967#endif
934 while (argc > 0 && argv->a_type == A_SYMBOL && 968 while (argc > 0 && argv->a_type == A_SYMBOL &&
935 *argv->a_w.w_symbol->s_name == '-') 969 *argv->a_w.w_symbol->s_name == '-')
936 { 970 {
@@ -1019,8 +1053,14 @@ static void soundfiler_read(t_soundfiler *x, t_symbol *s,
1019 1053
1020 if (fd < 0) 1054 if (fd < 0)
1021 { 1055 {
1056#ifdef ROCKBOX
1057 pd_error(x, "soundfiler_read: %s: %s",
1058 filename,
1059 "unknown or bad header format");
1060#else
1022 pd_error(x, "soundfiler_read: %s: %s", filename, (errno == EIO ? 1061 pd_error(x, "soundfiler_read: %s: %s", filename, (errno == EIO ?
1023 "unknown or bad header format" : strerror(errno))); 1062 "unknown or bad header format" : strerror(errno)));
1063#endif
1024 goto done; 1064 goto done;
1025 } 1065 }
1026 1066
@@ -1065,14 +1105,22 @@ static void soundfiler_read(t_soundfiler *x, t_symbol *s,
1065 if (!finalsize) finalsize = 0x7fffffff; 1105 if (!finalsize) finalsize = 0x7fffffff;
1066 if (finalsize > bytelimit / (channels * bytespersamp)) 1106 if (finalsize > bytelimit / (channels * bytespersamp))
1067 finalsize = bytelimit / (channels * bytespersamp); 1107 finalsize = bytelimit / (channels * bytespersamp);
1108#ifdef ROCKBOX
1109 fp = open(filename, O_RDONLY);
1110#else
1068 fp = fdopen(fd, "rb"); 1111 fp = fdopen(fd, "rb");
1112#endif
1069 bufframes = SAMPBUFSIZE / (channels * bytespersamp); 1113 bufframes = SAMPBUFSIZE / (channels * bytespersamp);
1070 1114
1071 for (itemsread = 0; itemsread < finalsize; ) 1115 for (itemsread = 0; itemsread < finalsize; )
1072 { 1116 {
1073 int thisread = finalsize - itemsread; 1117 int thisread = finalsize - itemsread;
1074 thisread = (thisread > bufframes ? bufframes : thisread); 1118 thisread = (thisread > bufframes ? bufframes : thisread);
1119#ifdef ROCKBOX
1120 nitems = read(fp, sampbuf, thisread * bytespersamp * channels);
1121#else
1075 nitems = fread(sampbuf, channels * bytespersamp, thisread, fp); 1122 nitems = fread(sampbuf, channels * bytespersamp, thisread, fp);
1123#endif
1076 if (nitems <= 0) break; 1124 if (nitems <= 0) break;
1077 soundfile_xferin(channels, argc, vecs, itemsread, 1125 soundfile_xferin(channels, argc, vecs, itemsread,
1078 (unsigned char *)sampbuf, nitems, bytespersamp, bigendian); 1126 (unsigned char *)sampbuf, nitems, bytespersamp, bigendian);
@@ -1082,7 +1130,11 @@ static void soundfiler_read(t_soundfiler *x, t_symbol *s,
1082 1130
1083 for (i = 0; i < argc; i++) 1131 for (i = 0; i < argc; i++)
1084 { 1132 {
1133#ifdef ROCKBOX
1134 int vecsize;
1135#else
1085 int nzero, vecsize; 1136 int nzero, vecsize;
1137#endif
1086 garray_getfloatarray(garrays[i], &vecsize, &vecs[i]); 1138 garray_getfloatarray(garrays[i], &vecsize, &vecs[i]);
1087 for (j = itemsread; j < vecsize; j++) 1139 for (j = itemsread; j < vecsize; j++)
1088 vecs[i][j] = 0; 1140 vecs[i][j] = 0;
@@ -1099,7 +1151,11 @@ static void soundfiler_read(t_soundfiler *x, t_symbol *s,
1099 /* do all graphics updates */ 1151 /* do all graphics updates */
1100 for (i = 0; i < argc; i++) 1152 for (i = 0; i < argc; i++)
1101 garray_redraw(garrays[i]); 1153 garray_redraw(garrays[i]);
1154#ifdef ROCKBOX
1155 close(fp);
1156#else
1102 fclose(fp); 1157 fclose(fp);
1158#endif
1103 fd = -1; 1159 fd = -1;
1104 goto done; 1160 goto done;
1105usage: 1161usage:
@@ -1118,14 +1174,25 @@ done:
1118long soundfiler_dowrite(void *obj, t_canvas *canvas, 1174long soundfiler_dowrite(void *obj, t_canvas *canvas,
1119 int argc, t_atom *argv) 1175 int argc, t_atom *argv)
1120{ 1176{
1177#ifdef ROCKBOX
1178 int bytespersamp, bigendian,
1179 swap, filetype, normalize, i, j, nchannels;
1180 long onset, nframes,
1181 itemswritten = 0;
1182#else
1121 int headersize, bytespersamp, bigendian, 1183 int headersize, bytespersamp, bigendian,
1122 endianness, swap, filetype, normalize, i, j, nchannels; 1184 endianness, swap, filetype, normalize, i, j, nchannels;
1123 long onset, nframes, itemsleft, 1185 long onset, nframes, itemsleft,
1124 maxsize = DEFMAXSIZE, itemswritten = 0; 1186 maxsize = DEFMAXSIZE, itemswritten = 0;
1187#endif
1125 t_garray *garrays[MAXSFCHANS]; 1188 t_garray *garrays[MAXSFCHANS];
1126 t_sample *vecs[MAXSFCHANS]; 1189 t_sample *vecs[MAXSFCHANS];
1127 char sampbuf[SAMPBUFSIZE]; 1190 char sampbuf[SAMPBUFSIZE];
1191#ifdef ROCKBOX
1192 int bufframes;
1193#else
1128 int bufframes, nitems; 1194 int bufframes, nitems;
1195#endif
1129 int fd = -1; 1196 int fd = -1;
1130 float normfactor, biggest = 0, samplerate; 1197 float normfactor, biggest = 0, samplerate;
1131 t_symbol *filesym; 1198 t_symbol *filesym;
@@ -1174,7 +1241,11 @@ long soundfiler_dowrite(void *obj, t_canvas *canvas,
1174 nframes, bytespersamp, bigendian, nchannels, 1241 nframes, bytespersamp, bigendian, nchannels,
1175 swap, samplerate)) < 0) 1242 swap, samplerate)) < 0)
1176 { 1243 {
1244#ifdef ROCKBOX
1245 post("%s: %s\n", filesym->s_name, "error");
1246#else
1177 post("%s: %s\n", filesym->s_name, strerror(errno)); 1247 post("%s: %s\n", filesym->s_name, strerror(errno));
1248#endif
1178 goto fail; 1249 goto fail;
1179 } 1250 }
1180 if (!normalize) 1251 if (!normalize)
@@ -1194,14 +1265,22 @@ long soundfiler_dowrite(void *obj, t_canvas *canvas,
1194 1265
1195 for (itemswritten = 0; itemswritten < nframes; ) 1266 for (itemswritten = 0; itemswritten < nframes; )
1196 { 1267 {
1268#ifdef ROCKBOX
1269 int thiswrite = nframes - itemswritten, nbytes;
1270#else
1197 int thiswrite = nframes - itemswritten, nitems, nbytes; 1271 int thiswrite = nframes - itemswritten, nitems, nbytes;
1272#endif
1198 thiswrite = (thiswrite > bufframes ? bufframes : thiswrite); 1273 thiswrite = (thiswrite > bufframes ? bufframes : thiswrite);
1199 soundfile_xferout(argc, vecs, (unsigned char *)sampbuf, thiswrite, 1274 soundfile_xferout(argc, vecs, (unsigned char *)sampbuf, thiswrite,
1200 onset, bytespersamp, bigendian, normfactor); 1275 onset, bytespersamp, bigendian, normfactor);
1201 nbytes = write(fd, sampbuf, nchannels * bytespersamp * thiswrite); 1276 nbytes = write(fd, sampbuf, nchannels * bytespersamp * thiswrite);
1202 if (nbytes < nchannels * bytespersamp * thiswrite) 1277 if (nbytes < nchannels * bytespersamp * thiswrite)
1203 { 1278 {
1279#ifdef ROCKBOX
1280 post("%s: %s", filesym->s_name, "error");
1281#else
1204 post("%s: %s", filesym->s_name, strerror(errno)); 1282 post("%s: %s", filesym->s_name, strerror(errno));
1283#endif
1205 if (nbytes > 0) 1284 if (nbytes > 0)
1206 itemswritten += nbytes / (nchannels * bytespersamp); 1285 itemswritten += nbytes / (nchannels * bytespersamp);
1207 break; 1286 break;
@@ -1230,6 +1309,9 @@ fail:
1230static void soundfiler_write(t_soundfiler *x, t_symbol *s, 1309static void soundfiler_write(t_soundfiler *x, t_symbol *s,
1231 int argc, t_atom *argv) 1310 int argc, t_atom *argv)
1232{ 1311{
1312#ifdef ROCKBOX
1313 (void) s;
1314#endif
1233 long bozo = soundfiler_dowrite(x, x->x_canvas, 1315 long bozo = soundfiler_dowrite(x, x->x_canvas,
1234 argc, argv); 1316 argc, argv);
1235 outlet_float(x->x_obj.ob_outlet, (float)bozo); 1317 outlet_float(x->x_obj.ob_outlet, (float)bozo);