[Cs-dev] Request for clue on utilities
Date | 2005-06-12 13:34 |
From | jpff@codemist.co.uk |
Subject | [Cs-dev] Request for clue on utilities |
There use to be a table of the utilities (I know because I wrote it) but this seems to have changed for some other scheme. How does one add a utility? I have followed the code of pvanal and in SConstruct but the utility is not recognised. What else is needed? ==John ffitch ------------------------------------------------------- This SF.Net email is sponsored by: NEC IT Guy Games. How far can you shotput a projector? How fast can you ride your desk chair down the office luge track? If you want to score the big prize, get to know the little guy. Play to win an NEC 61" plasma display: http://www.necitguy.com/?r=20 _______________________________________________ Csound-devel mailing list Csound-devel@lists.sourceforge.net |
Date | 2005-06-12 14:01 |
From | Istvan Varga |
Subject | Re: [Cs-dev] Request for clue on utilities |
jpff@codemist.co.uk wrote: > There use to be a table of the utilities (I know because I wrote it) > but this seems to have changed for some other scheme. How does one > add a utility? I have followed the code of pvanal and in SConstruct > but the utility is not recognised. What else is needed? The following code in util/scale.c is correct: PUBLIC int csoundModuleCreate(void *csound) { int retval = ((ENVIRON*) csound)->AddUtility(csound, "scale", scale); if (!retval) { retval = ((ENVIRON*) csound)->SetUtilityDescription(csound, "scale", "Report and/or adjusts maximum gain"); } return retval; } The reason why the utility does not work is that there are undefined symbols (that is, attempts to use functions other than those in ENVIRON). This should be obvious if you look at the messages printed: ./scale Localisation of messages is disabled, using default language. time resolution is 0.757 ns Error './libscale.so: undefined symbol: csoundPreCompile' in dlopen(./libscale.so). WARNING: could not open library 'libscale.so' PortAudio real-time audio module for Csound JACK real-time audio module for Csound by Istvan Varga ALSA real-time audio module for Csound by Istvan Varga PortMIDI real time MIDI plugin for Csound Error: utility 'scale' not found The available utilities are: cvanal Soundfile analysis for convolve dnoise Removes noise from a sound file hetro Soundfile analysis for adsyn lpanal Linear predictive analysis for lpread pvanal Soundfile analysis for pvoc pvlook Prints information about PVOC analysis files sndinfo Prints information about sound files srconv Sample rate conversion In this particular case, you can safely remove the calls to init_getstring(), csoundPreCompile(), and dbfs_init() because these are no longer needed for plugin utilities. The following functions need to be replaced: mmalloc => csound->Malloc mcalloc => csound->Calloc mrealloc => csound->ReAlloc mfree => csound->Free csoundDie => csound->Die There may be more, these are the most common. Also replace uses of exit() with csound->Die() (it is even better if the main function of the utility returns with a non-zero status instead on error, but csound->Die() should be OK). On success, the main function (that you have registered with csound->AddUtility()) should return zero, and not call exit(). Files opened with any of the following functions should not be closed (because they are registered for being closed by csoundReset()) with close(), fclose(), or sf_close(): csound->FileOpen() csound->sndgetset() csound->SAsndgetset() ------------------------------------------------------- This SF.Net email is sponsored by: NEC IT Guy Games. How far can you shotput a projector? How fast can you ride your desk chair down the office luge track? If you want to score the big prize, get to know the little guy. Play to win an NEC 61" plasma display: http://www.necitguy.com/?r=20 _______________________________________________ Csound-devel mailing list Csound-devel@lists.sourceforge.net |
Date | 2005-06-12 16:15 |
From | jpff@codemist.co.uk |
Subject | Re: [Cs-dev] Request for clue on utilities |
Those are not the error message I got. I got libscale.so not found, and nothing about missing references. ==John ffitch ------------------------------------------------------- This SF.Net email is sponsored by: NEC IT Guy Games. How far can you shotput a projector? How fast can you ride your desk chair down the office luge track? If you want to score the big prize, get to know the little guy. Play to win an NEC 61" plasma display: http://www.necitguy.com/?r=20 _______________________________________________ Csound-devel mailing list Csound-devel@lists.sourceforge.net |
Date | 2005-06-12 16:18 |
From | jpff@codemist.co.uk |
Subject | Re: [Cs-dev] Request for clue on utilities |
If files opened with csound->FileOpen should not be closed, what does one do about the differences between sf_close and fclose ? I have two files opened as FILE* and then given SNDFILE* status with sf_open_fd This does not seem to fit your changes. ==John ffitch ------------------------------------------------------- This SF.Net email is sponsored by: NEC IT Guy Games. How far can you shotput a projector? How fast can you ride your desk chair down the office luge track? If you want to score the big prize, get to know the little guy. Play to win an NEC 61" plasma display: http://www.necitguy.com/?r=20 _______________________________________________ Csound-devel mailing list Csound-devel@lists.sourceforge.net |
Date | 2005-06-12 16:47 |
From | Istvan Varga |
Subject | Re: [Cs-dev] Request for clue on utilities |
jpff@codemist.co.uk wrote: > If files opened with csound->FileOpen should not be closed, what does > one do about the differences between sf_close and fclose ? I have two > files opened as FILE* and then given SNDFILE* status with sf_open_fd > This does not seem to fit your changes. Files opened with csoundFileOpen can be closed, but with csoundFileClose and not close/fclose/sf_close. Here are some examples for opening files: /* --------------------------------------------------------------- */ SF_INFO sfinfo; SNDFILE *sf; void *fd; char *filename, *fullName; /* sound file open for read */ memset(&sfinfo, 0, sizeof(SF_INFO)); /* set default format for raw file here: */ ... /* this opens the file: */ fd = csound->FileOpen(csound, &sf, CSFILE_SND_R, filename, &sfinfo, "SFDIR;SSDIR"); if (fd == NULL) error(); /* fail in some way */ /* if full path file name is needed: */ fullName = csound->GetFileName(fd); /* close the file (if not done, csoundReset() will close it): */ csound->FileClose(csound, fd); /* sound file open for write: */ ... fd = csound->FileOpen(csound, &sf, CSFILE_SND_W, filename, &sfinfo, "SFDIR"); ... /* --------------------------------------------------------------- */ If you have opened a file with SAsndgetset() or sndgetset(), the void* handle for use with csound->FileClose() and csound->GetFileName() is stored in the SOUNDIN structure as 'fd'. An existing sound file, opened with sf_open_fd, can be associated with a handle that is compatible with csound->FileOpen() by using csound->CreateFileHandle(). In this case, sf_open_fd() should be called with the close_desc flag set to TRUE, unless the file is stdin/stdout (which, however, is really the only reason to use sf_open_fd()). /* 'sf' is an already opened SNDFILE* */ /* 'fullName' is the file name that will be returned */ /* by csound->GetFileName(). */ /* read */ fd = csound->CreateFileHandle(csound, &sf, CSFILE_SND_R, fullName); /* write */ fd = csound->CreateFileHandle(csound, &sf, CSFILE_SND_W, fullName); ------------------------------------------------------- This SF.Net email is sponsored by: NEC IT Guy Games. How far can you shotput a projector? How fast can you ride your desk chair down the office luge track? If you want to score the big prize, get to know the little guy. Play to win an NEC 61" plasma display: http://www.necitguy.com/?r=20 _______________________________________________ Csound-devel mailing list Csound-devel@lists.sourceforge.net |
Date | 2005-06-12 17:22 |
From | jpff@codemist.co.uk |
Subject | Re: [Cs-dev] Request for clue on utilities |
I need to open a file, and then tell libsndfile about it. I cannot see how this can be closed in you examples. Unless it is a myth that sf_close differs from fclose (which is hard to believe). I suspect that my problem is that the function csound->FileOpen is not one I have heard of and so do not know what it can do. The previous code used openout to get access to the search paths, and then sf_open_fd so it could be used with libsndfile. With the lack of documentation, how is this supposed to be done? ==John ffitch ------------------------------------------------------- This SF.Net email is sponsored by: NEC IT Guy Games. How far can you shotput a projector? How fast can you ride your desk chair down the office luge track? If you want to score the big prize, get to know the little guy. Play to win an NEC 61" plasma display: http://www.necitguy.com/?r=20 _______________________________________________ Csound-devel mailing list Csound-devel@lists.sourceforge.net |
Date | 2005-06-12 17:42 |
From | Istvan Varga |
Subject | Re: [Cs-dev] Request for clue on utilities |
jpff@codemist.co.uk wrote: > I need to open a file, and then tell libsndfile about it. I cannot > see how this can be closed in you examples. Unless it is a myth that > sf_close differs from fclose (which is hard to believe). > > I suspect that my problem is that the function csound->FileOpen is > not one I have heard of and so do not know what it can do. The > previous code used openout to get access to the search paths, and then > sf_open_fd so it could be used with libsndfile. With the lack of > documentation, how is this supposed to be done? The documentation for the various file related functions (from header files H/csound.h and H/envvar.h) is included below. For opening sound files, you can use csound->FileOpen directly, as shown by the examples in the previous message, without having to open a file descriptor first. The only exception to this is stdin/stdout, in which case you already have an integer file descriptor: SF_INFO sfinfo; SNDFILE *sf; void *fd; /* open stdin for input */ memset(&sfinfo, 0, sizeof(SF_INFO)); sf = sf_open_fd(0, SFM_READ, &sfinfo, 0); if (sf == NULL) error(); fd = csound->CreateFileHandle(csound, &sf, CSFILE_SND_R, "stdin"); ... csound->FileClose(csound, fd); /* optional, csoundReset() does it anyway */ /* open stdout for output */ memset(&sfinfo, 0, sizeof(SF_INFO)); /* set format parameters here: */ ... sf = sf_open_fd(1, SFM_WRITE, &sfinfo, 0); if (sf == NULL) error(); fd = csound->CreateFileHandle(csound, &sf, CSFILE_SND_W, "stdout"); ... csound->FileClose(csound, fd); /* optional, csoundReset() does it anyway */ /* -------------------------------------------------------------- */ #define CSFILE_FD_R 1 #define CSFILE_FD_W 2 #define CSFILE_STD 3 #define CSFILE_SND_R 4 #define CSFILE_SND_W 5 /** * Open a file and return handle. * * void *csound: * Csound instance pointer * void *fd: * pointer a variable of type int, FILE*, or SNDFILE*, depending on 'type', * for storing handle to be passed to file read/write functions * int type: * file type, one of the following: * CSFILE_FD_R: read file using low level interface (open()) * CSFILE_FD_W: write file using low level interface (open()) * CSFILE_STD: use ANSI C interface (fopen()) * CSFILE_SND_R: read sound file * CSFILE_SND_W: write sound file * const char *name: * file name * void *param: * parameters, depending on type: * CSFILE_FD_R: unused (should be NULL) * CSFILE_FD_W: unused (should be NULL) * CSFILE_STD: mode parameter (of type char*) to be passed to fopen() * CSFILE_SND_R: SF_INFO* parameter for sf_open(), with defaults for * raw file; the actual format paramaters of the opened * file will be stored in this structure * CSFILE_SND_W: SF_INFO* parameter for sf_open(), output file format * const char *env: * list of environment variables for search path (see csoundFindInputFile() * for details); if NULL, the specified name is used as it is, without any * conversion or search. * return value: * opaque handle to the opened file, for use with csoundGetFileName() or * csoundFileClose(), or storing in FDCH.fd. * On failure, NULL is returned. */ PUBLIC void *csoundFileOpen(void *csound, void *fd, int type, const char *name, void *param, const char *env); /** * Allocate a file handle for an existing file already opened with open(), * fopen(), or sf_open(), for later use with csoundFileClose() or * csoundGetFileName(), or storing in an FDCH structure. * Files registered this way (or opened with csoundFileOpen()) are also * automatically closed by csoundReset(). * Parameters and return value are similar to csoundFileOpen(), except * fullName is the name that will be returned by a later call to * csoundGetFileName(). */ PUBLIC void *csoundCreateFileHandle(void *csound, void *fd, int type, const char *fullName); /** * Get the full name of a file previously opened with csoundFileOpen(). */ PUBLIC char *csoundGetFileName(void *fd); /** * Close a file previously opened with csoundFileOpen(). */ PUBLIC int csoundFileClose(void *csound, void *fd); /** * Search for input file 'filename'. * If the file name specifies full path (it begins with '.', the pathname * delimiter character, or a drive letter and ':' on Windows), that exact * file name is tried without searching. * Otherwise, the file is searched relative to the current directory first, * and if it is still not found, a pathname list that is created the * following way is searched: * 1. if envList is NULL or empty, no directories are searched * 2. envList is parsed as a ';' separated list of environment variable * names, and all environment variables are expanded and expected to * contain a ';' separated list of directory names * 2. all directories in the resulting pathname list are searched, starting * from the last and towards the first one, and the directory where the * file is found first will be used * The function returns a pointer to the full name of the file if it is * found, and NULL if the file could not be found in any of the search paths, * or an error has occured. The caller is responsible for freeing the memory * pointed to by the return value, by calling mfree(). */ PUBLIC char *csoundFindInputFile(void *csound, const char *filename, const char *envList); /** * Search for a location to write file 'filename'. * If the file name specifies full path (it begins with '.', the pathname * delimiter character, or a drive letter and ':' on Windows), that exact * file name is tried without searching. * Otherwise, a pathname list that is created the following way is searched: * 1. if envList is NULL or empty, no directories are searched * 2. envList is parsed as a ';' separated list of environment variable * names, and all environment variables are expanded and expected to * contain a ';' separated list of directory names * 2. all directories in the resulting pathname list are searched, starting * from the last and towards the first one, and the directory that is * found first where the file can be written to will be used * Finally, if the file cannot be written to any of the directories in the * search paths, writing relative to the current directory is tried. * The function returns a pointer to the full name of the file if a location * suitable for writing the file is found, and NULL if the file cannot not be * written anywhere in the search paths, or an error has occured. * The caller is responsible for freeing the memory pointed to by the return * value, by calling mfree(). */ PUBLIC char *csoundFindOutputFile(void *csound, const char *filename, const char *envList); ------------------------------------------------------- This SF.Net email is sponsored by: NEC IT Guy Games. How far can you shotput a projector? How fast can you ride your desk chair down the office luge track? If you want to score the big prize, get to know the little guy. Play to win an NEC 61" plasma display: http://www.necitguy.com/?r=20 _______________________________________________ Csound-devel mailing list Csound-devel@lists.sourceforge.net |
Date | 2005-06-12 21:44 |
From | jpff@codemist.co.uk |
Subject | Re: [Cs-dev] Request for clue on utilities |
I am still struggling with this. Are you saying that FileOpen is NOT a replacement for openout which took account of teh environment variables. What does it do beyond fopen? ==John ffitch ------------------------------------------------------- This SF.Net email is sponsored by: NEC IT Guy Games. How far can you shotput a projector? How fast can you ride your desk chair down the office luge track? If you want to score the big prize, get to know the little guy. Play to win an NEC 61" plasma display: http://www.necitguy.com/?r=20 _______________________________________________ Csound-devel mailing list Csound-devel@lists.sourceforge.net |
Date | 2005-06-12 22:23 |
From | Istvan Varga |
Subject | Re: [Cs-dev] Request for clue on utilities |
jpff@codemist.co.uk wrote: > I am still struggling with this. Are you saying that FileOpen is NOT > a replacement for openout which took account of teh environment > variables. What does it do beyond fopen? It can do everything that openin/openout used to do, but also more: * opens files using any of the open(), fopen(), and sf_open() interfaces, to get int, FILE*, and SNDFILE* file handles, respectively. * if the char *env argument is not NULL, converts '/' and '\\' to native pathname delimiters and does file search in the path list defined by the specified environment variable(s). For example, the following will look for "foo.wav" in the current directory first, then SSDIR, and finally in SFDIR: SNDFILE *sf; void *fd; SF_INFO sfinfo; ... fd = csound->FileOpen(csound, &sf, CSFILE_SND_R, "foo.wav", &sfinfo, "SFDIR;SSDIR"); note that the environment variables themselves can be ';' separated lists of directories, in which the last one has the highest precedence. * remembers the files opened, and, if not closed with csound->FileClose(), all files will be closed when csoundReset() or csoundDestroy() is called This line does the same as openout() (assuming that you want to use SFDIR): char *filename; int ofd; ... fd = csound->FileOpen(csound, &ofd, CSFILE_FD_W, filename, NULL, "SFDIR"); however, the files should be closed this way (or just left open, and have csoundReset() close it eventually): csound->CloseFile(csound, fd); this is a bug: close(ofd); You can also get the full path file name with: char *fullName = csound->GetFileName(fd); It should be noted again, that it is not needed to open an unix-style integer file descriptor first to open a sound file unless you want to use stdin/stdout. Here is a more complete example for opening sound files (not tested, hope that does not have editing errors): SF_INFO sfinfo; char *filename, *fullName; SNDFILE *sf; void *fd = NULL; memset(&sfinfo, 0, sizeof(SF_INFO)); /* open file for read */ if (strcmp(filename, "stdin") == 0 || strcmp(filename, "-" == 0)) { sf = sf_open_fd(0, SFM_READ, &sfinfo, 0); if (sf != NULL) { fd = csound->CreateFileHandle(csound, &sf, CSFILE_SND_R, "stdin"); if (fd == NULL) { sf_close(sf); csound->Die(csound, Str("Memory allocation failure")); } } } else { /* set default format for raw file, change as needed */ sfinfo.samplerate = 44100; sfinfo.format = TYPE2SF(TYP_RAW) | FORMAT2SF(AE_SHORT); sfinfo.channels = 1; fd = csound->FileOpen(csound, &sf, CSFILE_SND_R, filename, &sfinfo, "SFDIR;SSDIR"); } if (fd == NULL) csound->Die(csound, Str("failed to open file %s"), filename); csound->Message(csound, Str("Opened file %s\n"), csound->GetFileName(fd)); /* read file */ /* ... */ csound->FileClose(csound, fd); /* optional */ /* ------------------------------------------------------------------------ */ /* open file for write */ sfinfo.samplerate = 44100; /* change format as needed */ sfinfo.format = TYPE2SF(TYP_RAW) | FORMAT2SF(AE_SHORT); sfinfo.channels = 1; if (strcmp(filename, "stdout") == 0 || strcmp(filename, "-" == 0)) { sf = sf_open_fd(1, SFM_WRITE, &sfinfo, 0); if (sf != NULL) { fd = csound->CreateFileHandle(csound, &sf, CSFILE_SND_W, "stdout"); if (fd == NULL) { sf_close(sf); csound->Die(csound, Str("Memory allocation failure")); } } } else { fd = csound->FileOpen(csound, &sf, CSFILE_SND_W, filename, &sfinfo, "SFDIR"); } if (fd == NULL) csound->Die(csound, Str("failed to open file %s"), filename); csound->Message(csound, Str("Opened file %s\n"), csound->GetFileName(fd)); /* write file */ /* ... */ csound->FileClose(csound, fd); /* optional */ /* ------------------------------------------------------------------------ */ SOUNDIN p; /* ... set parameters in p ... */ sf = csound->sndgetset(csound, &p); /* ... */ csound->FileClose(csound, p.fd); /* optional */ ------------------------------------------------------- This SF.Net email is sponsored by: NEC IT Guy Games. How far can you shotput a projector? How fast can you ride your desk chair down the office luge track? If you want to score the big prize, get to know the little guy. Play to win an NEC 61" plasma display: http://www.necitguy.com/?r=20 _______________________________________________ Csound-devel mailing list Csound-devel@lists.sourceforge.net |
Date | 2005-06-13 11:44 |
From | Istvan Varga |
Subject | Re: [Cs-dev] Request for clue on utilities |
I have changed util/xtrct.c to correctly use the interface (and also fixed a few bugs related to confusion about samples, sample frames, and bytes); it may be of some help to better understand csoundFileOpen(). ------------------------------------------------------- This SF.Net email is sponsored by: NEC IT Guy Games. How far can you shotput a projector? How fast can you ride your desk chair down the office luge track? If you want to score the big prize, get to know the little guy. Play to win an NEC 61" plasma display: http://www.necitguy.com/?r=20 _______________________________________________ Csound-devel mailing list Csound-devel@lists.sourceforge.net |