|
From: Martin R. <ru...@us...> - 2004-08-30 15:59:09
|
Update of /cvsroot/foo/foo/elkfoo/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv26424 Modified Files: pointer.m snd.m soundfile.m tell.m types.m Log Message: reordered (foo:make-soundfile) parameters. added comment support again. minor changes in order to avoid warnings Index: snd.m =================================================================== RCS file: /cvsroot/foo/foo/elkfoo/src/snd.m,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** snd.m 13 Aug 2004 21:34:39 -0000 1.3 --- snd.m 30 Aug 2004 15:58:59 -0000 1.4 *************** *** 50,62 **** #define IdOf(snd) (SND_T(snd)->pointer) ! struct symbol sndTypes[] = { {"char", SND_CHAR}, {"short", SND_SHORT}, {"long", SND_LONG}, {"float", SND_FLOAT}, {"double", SND_DOUBLE}, - {"incremental", SND_INCREMENTAL}, {0, 0} }; ! struct symbol sndFileTypes[] = { {"wav", SND_FILETYPE_WAV}, {"aiff", SND_FILETYPE_AIFF}, {"snd", SND_FILETYPE_SND}, --- 50,63 ---- #define IdOf(snd) (SND_T(snd)->pointer) ! struct symbol sndTypes[] = { {"auto", SND_AUTO}, ! {"char", SND_CHAR}, {"short", SND_SHORT}, {"long", SND_LONG}, {"float", SND_FLOAT}, {"double", SND_DOUBLE}, {0, 0} }; ! struct symbol sndFileTypes[] = { {"incremental", SND_FILETYPE_INCREMENTAL}, ! {"wav", SND_FILETYPE_WAV}, {"aiff", SND_FILETYPE_AIFF}, {"snd", SND_FILETYPE_SND}, *************** *** 82,87 **** char *s; - // Alloca_Begin; - Check_Type (sym, T_Symbol); name = SYMBOL (sym)->name; --- 83,86 ---- *************** *** 96,100 **** Primitive_Error ("unrecognized keyword: ~s", sym); } - // Alloca_End; return p->val; --- 95,98 ---- *************** *** 115,120 **** SND_T(snd)->context = Get_Context(); SND_T(snd)->name = Null; - SND_T(snd)->format = Null; SND_T(snd)->filetype = Null; SND_T(snd)->type = Null; GC_Link(snd); --- 113,119 ---- SND_T(snd)->context = Get_Context(); SND_T(snd)->name = Null; SND_T(snd)->filetype = Null; + SND_T(snd)->format = Null; + SND_T(snd)->comment = Null; SND_T(snd)->type = Null; GC_Link(snd); *************** *** 140,146 **** int incr; NSString *filename; GC_Node2; - // Alloca_Begin; if (! Truep(General_File_Operation(n, 1))) --- 139,145 ---- int incr; NSString *filename; + NSString *comment; GC_Node2; if (! Truep(General_File_Operation(n, 1))) *************** *** 184,188 **** SND_T(s)->name = Make_String(STRING(n)->data, STRING(n)->size); ! GC_Unlink; --- 183,188 ---- SND_T(s)->name = Make_String(STRING(n)->data, STRING(n)->size); ! comment = [IdOf(s) getFileComment]; ! SND_T(s)->comment = Make_String([comment cString], [comment length]); GC_Unlink; *************** *** 199,284 **** } ! if (incr == 1) { t = sndTypes[5].name; } else { ! switch ([IdOf(s) getDataFormat]) { ! case SF_FORMAT_PCM_S8: ! t = sndTypes[0].name; break; ! case SF_FORMAT_PCM_16: ! t = sndTypes[1].name; break; ! case SF_FORMAT_PCM_32: ! t = sndTypes[2].name; break; ! case SF_FORMAT_FLOAT: ! t = sndTypes[3].name; break; ! case SF_FORMAT_DOUBLE: ! t = sndTypes[4].name; break; default: ! Primitive_Error("unknown sound file format: ~a", ! ! Make_Integer(([IdOf(s) getDataFormat]))); } } - switch ([IdOf(s) getFileType]) - { - case SF_FORMAT_WAV: - t = sndFileTypes[0].name; - break; - case SF_FORMAT_AIFF: - t = sndFileTypes[1].name; - break; - case SF_FORMAT_AU: - t = sndFileTypes[2].name; - break; - case SF_FORMAT_PAF: - t = sndFileTypes[3].name; - break; - case SF_FORMAT_SVX: - t = sndFileTypes[4].name; - break; - case SF_FORMAT_NIST: - t = sndFileTypes[5].name; - break; - case SF_FORMAT_VOC: - t = sndFileTypes[6].name; - break; - case SF_FORMAT_IRCAM: - t = sndFileTypes[7].name; - break; - case SF_FORMAT_W64: - t = sndFileTypes[8].name; - break; - case SF_FORMAT_MAT4: - t = sndFileTypes[9].name; - break; - case SF_FORMAT_MAT5: - t = sndFileTypes[10].name; - break; - case SF_FORMAT_PVF: - t = sndFileTypes[11].name; - break; - case SF_FORMAT_XI: - t = sndFileTypes[12].name; - break; - default: - Primitive_Error("unknown sound file filetype: ~a", - Make_Integer(([IdOf(s) getFileType]))); - } - SND_T(s)->filetype = Intern(t); - SND_T(s)->offset = 0; SND_T(s)->length = [IdOf(s) size] / SND_T(s)->samplerate; SND_T(s)->reversed = 0; - // Alloca_End; return s; --- 199,281 ---- } ! switch ([IdOf(s) getDataFormat]) { + case SF_FORMAT_PCM_S8: + t = sndTypes[1].name; + break; + case SF_FORMAT_PCM_16: + t = sndTypes[2].name; + break; + case SF_FORMAT_PCM_32: + t = sndTypes[3].name; + break; + case SF_FORMAT_FLOAT: + t = sndTypes[4].name; + break; + case SF_FORMAT_DOUBLE: t = sndTypes[5].name; + break; + default: + Primitive_Error("unknown sound file format: ~a", + Make_Integer(([IdOf(s) getDataFormat]))); + } + + if (incr == 1) + { + t = sndFileTypes[0].name; } else { ! switch ([IdOf(s) getFileType]) { ! case SF_FORMAT_WAV: ! t = sndFileTypes[1].name; break; ! case SF_FORMAT_AIFF: ! t = sndFileTypes[2].name; break; ! case SF_FORMAT_AU: ! t = sndFileTypes[3].name; break; ! case SF_FORMAT_PAF: ! t = sndFileTypes[4].name; break; ! case SF_FORMAT_SVX: ! t = sndFileTypes[5].name; ! break; ! case SF_FORMAT_NIST: ! t = sndFileTypes[6].name; ! break; ! case SF_FORMAT_VOC: ! t = sndFileTypes[7].name; ! break; ! case SF_FORMAT_IRCAM: ! t = sndFileTypes[8].name; ! break; ! case SF_FORMAT_W64: ! t = sndFileTypes[9].name; ! break; ! case SF_FORMAT_MAT4: ! t = sndFileTypes[10].name; ! break; ! case SF_FORMAT_MAT5: ! t = sndFileTypes[11].name; ! break; ! case SF_FORMAT_PVF: ! t = sndFileTypes[12].name; ! break; ! case SF_FORMAT_XI: ! t = sndFileTypes[13].name; break; default: ! Primitive_Error("unknown sound file filetype: ~a", ! Make_Integer(([IdOf(s) getFileType]))); } } SND_T(s)->filetype = Intern(t); SND_T(s)->offset = 0; SND_T(s)->length = [IdOf(s) size] / SND_T(s)->samplerate; SND_T(s)->reversed = 0; return s; *************** *** 354,357 **** --- 351,365 ---- static SchemeObject + P_Snd_Comment (SchemeObject snd) + { + SchemeObject comment; + + Check_Type(snd, T_Snd); + comment = SND_T(snd)->comment; + return Make_String (STRING(comment)->data, STRING(comment)->size); + } + + + static SchemeObject P_Snd_Reversedp (SchemeObject snd) { *************** *** 466,471 **** [IdOf(region) initWithSubstrate:p offset:o size:l rev:NO]; SND_T(region)->name = SND_T(snd)->name; ! SND_T(region)->format = SND_T(snd)->format; SND_T(region)->filetype = SND_T(snd)->filetype; SND_T(region)->channels = SND_T(snd)->channels; SND_T(region)->channel = SND_T(snd)->channel; --- 474,480 ---- [IdOf(region) initWithSubstrate:p offset:o size:l rev:NO]; SND_T(region)->name = SND_T(snd)->name; ! SND_T(region)->comment = SND_T(snd)->comment; SND_T(region)->filetype = SND_T(snd)->filetype; + SND_T(region)->format = SND_T(snd)->format; SND_T(region)->channels = SND_T(snd)->channels; SND_T(region)->channel = SND_T(snd)->channel; *************** *** 496,501 **** [IdOf(region) initWithSubstrate:p offset:0. size:l rev:YES]; SND_T(region)->name = SND_T(snd)->name; ! SND_T(region)->format = SND_T(snd)->format; SND_T(region)->filetype = SND_T(snd)->filetype; SND_T(region)->channels = SND_T(snd)->channels; SND_T(region)->channel = SND_T(snd)->channel; --- 505,511 ---- [IdOf(region) initWithSubstrate:p offset:0. size:l rev:YES]; SND_T(region)->name = SND_T(snd)->name; ! SND_T(region)->comment = SND_T(snd)->comment; SND_T(region)->filetype = SND_T(snd)->filetype; + SND_T(region)->format = SND_T(snd)->format; SND_T(region)->channels = SND_T(snd)->channels; SND_T(region)->channel = SND_T(snd)->channel; *************** *** 533,538 **** [IdOf(region) initWithSubstrate:p channel:c]; SND_T(region)->name = SND_T(snd)->name; ! SND_T(region)->format = SND_T(snd)->format; SND_T(region)->filetype = SND_T(snd)->filetype; SND_T(region)->channels = SND_T(snd)->channels; SND_T(region)->channel = c; --- 543,549 ---- [IdOf(region) initWithSubstrate:p channel:c]; SND_T(region)->name = SND_T(snd)->name; ! SND_T(region)->comment = SND_T(snd)->comment; SND_T(region)->filetype = SND_T(snd)->filetype; + SND_T(region)->format = SND_T(snd)->format; SND_T(region)->channels = SND_T(snd)->channels; SND_T(region)->channel = c; *************** *** 657,662 **** (*f)(&(SND_T(*x)->type)); (*f)(&(SND_T(*x)->name)); ! (*f)(&(SND_T(*x)->format)); (*f)(&(SND_T(*x)->filetype)); return 0; --- 668,674 ---- (*f)(&(SND_T(*x)->type)); (*f)(&(SND_T(*x)->name)); ! (*f)(&(SND_T(*x)->comment)); (*f)(&(SND_T(*x)->filetype)); + (*f)(&(SND_T(*x)->format)); return 0; *************** *** 682,685 **** --- 694,698 ---- DP(P_Snd_Offset, "foo:snd-offset", 1, 1, EVAL); DP(P_Snd_Length, "foo:snd-length", 1, 1, EVAL); + DP(P_Snd_Comment, "foo:snd-comment", 1, 1, EVAL); DP(P_Snd_Reversedp, "foo:snd-reversed?", 1, 1, EVAL); DP(P_Snd_Type, "foo:snd-type", 1, 1, EVAL); Index: pointer.m =================================================================== RCS file: /cvsroot/foo/foo/elkfoo/src/pointer.m,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** pointer.m 13 Aug 2004 21:34:39 -0000 1.9 --- pointer.m 30 Aug 2004 15:58:59 -0000 1.10 *************** *** 43,46 **** --- 43,81 ---- #endif + /* type names */ + static char *elkfoo_type_names[] = + { /* corresponds to enum above */ + "DUMMY", /* 0 */ + "char", /* 1 */ + "short", /* 2 */ + "int", /* 3 */ + "long", /* 4 */ + "uchar", /* 5 */ + "ushort", /* 6 */ + "uint", /* 7 */ + "ulong", /* 8 */ + "float", /* 9 */ + "double", /* 10 */ + "void*", /* 11 */ + "char*", /* 12 */ + "short*", /* 13 */ + "int*", /* 14 */ + "long*", /* 15 */ + "uchar*", /* 16 */ + "ushort*", /* 17 */ + "uint*", /* 18 */ + "ulong*", /* 19 */ + "float*", /* 20 */ + "double*", /* 21 */ + "id", /* 22 */ + "class", /* 23 */ + "sel", /* 24 */ + "struct*", /* 25 */ + "union*", /* 26 */ + "array*", /* 27 */ + "undefined", /* 28 */ + "char**", /* 29 */ + "undefined*", /* 30 */ + }; int T_Pointer; Index: soundfile.m =================================================================== RCS file: /cvsroot/foo/foo/elkfoo/src/soundfile.m,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** soundfile.m 16 Aug 2004 04:36:29 -0000 1.5 --- soundfile.m 30 Aug 2004 15:58:59 -0000 1.6 *************** *** 50,54 **** ! enum { SND_LENGTH, SND_FORMAT, SND_CHANNELS, SND_SRATE, SND_FILETYPE }; --- 50,54 ---- ! enum { SND_LENGTH, SND_FORMAT, SND_CHANNELS, SND_SRATE, SND_FILETYPE, SND_COMMENT, SND_COMMENT_SIZE, SND_SET_COMMENT }; *************** *** 60,75 **** SNDFILE *sfd; SchemeObject name = General_File_Operation(argv[0], 0); char buffer[PATH_MAX + 1], *n; ! int type, fmode = 0644, dmode = 0755; /* fd, l, m; */ struct stat st; // double sr = [GlobalsManager getDefaultSamplingRate]; - // Alloca_Begin; - s.format = 0; // set soundfile filetype ! switch (type = Scheme_To_C_Symbol(argv[4], sndFileTypes)) { case SND_FILETYPE_WAV: s.format |= SF_FORMAT_WAV; --- 60,79 ---- SNDFILE *sfd; SchemeObject name = General_File_Operation(argv[0], 0); + char *comment = NULL; char buffer[PATH_MAX + 1], *n; ! int filetype, sampleformat; ! // int fmode = 0644; // currently not used ! int dmode = 0755; /* fd, l, m; */ struct stat st; // double sr = [GlobalsManager getDefaultSamplingRate]; s.format = 0; // set soundfile filetype ! switch (filetype = Scheme_To_C_Symbol(argv[1], sndFileTypes)) { + case SND_FILETYPE_INCREMENTAL: + s.format |= SF_FORMAT_AU; + break; case SND_FILETYPE_WAV: s.format |= SF_FORMAT_WAV; *************** *** 116,121 **** // set soundfile data format ! switch (type = Scheme_To_C_Symbol(argv[1], sndTypes)) { case SND_CHAR: s.format |= SF_FORMAT_PCM_S8; --- 120,129 ---- // set soundfile data format ! switch (sampleformat = Scheme_To_C_Symbol(argv[2], sndTypes)) { + case SND_AUTO: + s.format |= SF_FORMAT_FLOAT; + s.format |= SF_ENDIAN_CPU; + break; case SND_CHAR: s.format |= SF_FORMAT_PCM_S8; *************** *** 133,139 **** s.format |= SF_FORMAT_DOUBLE; break; - case SND_INCREMENTAL: - s.format |= SF_FORMAT_FLOAT; - break; default: Primitive_Error("soundfile.m: internal inconsistency (format)"); --- 141,144 ---- *************** *** 141,149 **** // set soundfile channels ! s.channels = Get_Integer(argv[2]); if (s.channels <= 0) { ! Primitive_Error("illegal channel count: ~a", argv[2]); } --- 146,154 ---- // set soundfile channels ! s.channels = Get_Integer(argv[4]); if (s.channels <= 0) { ! Primitive_Error("illegal channel count: ~a", argv[4]); } *************** *** 164,168 **** } ! if (type == SND_INCREMENTAL) { if (mkdir(buffer, dmode) == -1) --- 169,173 ---- } ! if (filetype == SND_FILETYPE_INCREMENTAL) { if (mkdir(buffer, dmode) == -1) *************** *** 180,183 **** --- 185,194 ---- } + /* comment string */ + if (argc > 5) + { + comment = Get_String(argv[5]); + } + /* creating a soundfile with header using libsndfile: * simply open a file for write with an appropriate SF_INFO struct *************** *** 188,191 **** --- 199,211 ---- } + /* write comment */ + if (comment) + { + if (sf_set_string(sfd, SF_STR_COMMENT, comment)) + { + [FOOGlobalsManager schemeOutput: @"WARNING: writing the comment failed. maybe not supported by filetype\n"]; + } + } + if (sf_close(sfd)) { *************** *** 193,198 **** } - // Alloca_End; - return True; } --- 213,216 ---- *************** *** 201,205 **** static SchemeObject General_Soundfile_Operation (SchemeObject soundfile, ! int operation) { SchemeObject name = P_Tilde_Expand(Get_File_Name(soundfile)), ret; --- 219,224 ---- static SchemeObject General_Soundfile_Operation (SchemeObject soundfile, ! int operation, ! SchemeObject *params) { SchemeObject name = P_Tilde_Expand(Get_File_Name(soundfile)), ret; *************** *** 210,215 **** NSString *filename; - // Alloca_Begin; - cname = Get_String(name); if (stat(cname, &st) == -1) --- 229,232 ---- *************** *** 259,264 **** break; default: ! Primitive_Error("unsupported format ~a", ! Make_Integer([snd getDataFormat])); } } --- 276,285 ---- break; default: ! { ! int result = [snd getDataFormat]; ! RELEASE(snd); ! Primitive_Error("unsupported format ~a", ! Make_Integer(result)); ! } } } *************** *** 313,325 **** break; default: ! Primitive_Error("unsupported filetype ~a", ! Make_Integer([snd getFileType])); } break; default: ! Primitive_Error("internal inconsistency"); } RELEASE(snd); - // Alloca_End; return ret; --- 334,375 ---- break; default: ! { ! int result = [snd getFileType]; ! RELEASE(snd); ! Primitive_Error("unsupported filetype ~a", ! Make_Integer(result)); ! } } break; + case SND_SET_COMMENT: + { + NSString *comment = [NSString stringWithCString: Get_String(params[0])]; + ret = Make_String([[snd getFileComment] cString], + [[snd getFileComment] length]); + + if ([snd reopenWithMode: SND_WRITE] == NO) + { + RELEASE(snd); + Primitive_Error("reopening sndfile for writing comment failed."); + } + if ([snd setFileCommentFromString: comment]) + { + RELEASE(snd); + Primitive_Error("setting the comment failed. maybe not supported by file format."); + } + } + break; + case SND_COMMENT: + ret = Make_String([[snd getFileComment] cString], + [[snd getFileComment] length]); + break; + case SND_COMMENT_SIZE: + ret = Make_Integer([[snd getFileComment] length]); + break; default: ! RELEASE(snd); ! Primitive_Error("General_Soundfile_Operation: internal inconsistency"); } RELEASE(snd); return ret; *************** *** 327,339 **** ! #define SND_FUNC(name, type) \ ! static SchemeObject name(soundfile) SchemeObject soundfile; { \ ! return General_Soundfile_Operation(soundfile, type); } ! SND_FUNC(P_Soundfile_Srate, SND_SRATE) ! SND_FUNC(P_Soundfile_Format, SND_FORMAT) ! SND_FUNC(P_Soundfile_Length, SND_LENGTH) ! SND_FUNC(P_Soundfile_Channels, SND_CHANNELS) ! SND_FUNC(P_Soundfile_Filetype, SND_FILETYPE) --- 377,401 ---- ! #define SND_FUNC(name, type) \ ! static SchemeObject name(SchemeObject soundfile) \ ! { \ ! return General_Soundfile_Operation(soundfile, type, NULL); \ ! } ! SND_FUNC(P_Soundfile_Srate, SND_SRATE) ! SND_FUNC(P_Soundfile_Filetype, SND_FILETYPE) ! SND_FUNC(P_Soundfile_Format, SND_FORMAT) ! SND_FUNC(P_Soundfile_Length, SND_LENGTH) ! SND_FUNC(P_Soundfile_Channels, SND_CHANNELS) ! SND_FUNC(P_Soundfile_Comment, SND_COMMENT) ! SND_FUNC(P_Soundfile_Comment_Size, SND_COMMENT_SIZE) ! ! ! static SchemeObject ! P_Set_Soundfile_Comment (SchemeObject soundfile, ! SchemeObject comment) ! { ! return General_Soundfile_Operation(soundfile, SND_SET_COMMENT, &comment); ! } *************** *** 456,460 **** elk_init_soundfile () { ! DP(P_Make_Soundfile, "foo:make-soundfile", 3, 5, VARARGS); DP(P_Soundfile_Format, "foo:soundfile-format", 1, 1, EVAL); DP(P_Soundfile_Length, "foo:soundfile-length", 1, 1, EVAL); --- 518,522 ---- elk_init_soundfile () { ! DP(P_Make_Soundfile, "foo:make-soundfile", 5, 6, VARARGS); DP(P_Soundfile_Format, "foo:soundfile-format", 1, 1, EVAL); DP(P_Soundfile_Length, "foo:soundfile-length", 1, 1, EVAL); *************** *** 462,465 **** --- 524,530 ---- DP(P_Soundfile_Channels, "foo:soundfile-channels", 1, 1, EVAL); DP(P_Soundfile_Filetype, "foo:soundfile-filetype", 1, 1, EVAL); + DP(P_Set_Soundfile_Comment, "foo:set-soundfile-comment!", 2, 2, EVAL); + DP(P_Soundfile_Comment, "foo:soundfile-comment", 1, 1, EVAL); + DP(P_Soundfile_Comment_Size,"foo:soundfile-comment-size", 1, 1, EVAL); DP(P_Soundfile_Play, "foo:soundfile-play", 1, 5, VARARGS); Index: tell.m =================================================================== RCS file: /cvsroot/foo/foo/elkfoo/src/tell.m,v retrieving revision 1.16 retrieving revision 1.17 diff -C2 -d -r1.16 -r1.17 *** tell.m 16 Aug 2004 04:42:26 -0000 1.16 --- tell.m 30 Aug 2004 15:58:59 -0000 1.17 *************** *** 283,287 **** NSString *name; SEL sel; - SchemeObject result; switch (TYPE(selector)) --- 283,286 ---- Index: types.m =================================================================== RCS file: /cvsroot/foo/foo/elkfoo/src/types.m,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** types.m 13 Aug 2004 21:34:39 -0000 1.2 --- types.m 30 Aug 2004 15:58:59 -0000 1.3 *************** *** 154,159 **** elkfoo_type_t etype) { - void *ret; - switch (etype) { --- 154,157 ---- |