Re: [Audacity-devel] typo fixes / file-format thoughts
A free multi-track audio editor and recorder
Brought to you by:
aosiniao
From: Dominic M. <do...@mi...> - 2001-11-06 08:25:13
|
Matt, I'm sorry, that's partially my fault - I finished new importing code and stopped halfway through writing the new exporting code. We switched to a totally new library (libsndfile) for sound file I/O, which is why things are still in flux. What you see in ExportPCM.cpp is all old code, and the prefs dialog is all new. The new importing code should work fine, aside from the typo you found (fixed in my copy, I'll commit it soon). > I found these while working on a much larger bug in the export file-format > code. The format strings stored by the prefs dialog (e.g. "Windows Wave") > don't match the ones expected by Export() (e.g. "WAV"). This mismatch > causes export to fail with a "cannot export this format" message. > > Overall, the treatment of export formats is messy and should be changed > significantly. Passing around wxStrings complicates the code and leads to > problems like above; named constants would be much better. I can start > coding this -- with your input of course -- if no one else is doing it. Great, that would be a big help. I actually just emailed Erik de Castro Lopo, the author of libsndfile, recently, with a proposal to add this API function to libsndfile: /* in the header file */ typedef struct { unsigned int format; const char *name; const char *extension; } SF_STD_FORMAT_INFO; int sf_get_num_std_formats(); SF_STD_FORMAT_INFO *sf_get_std_format(int i); /* in the C file */ #define SF_NUM_STD_FORMATS 6 /* these should be kept alphabetical */ SF_STD_FORMAT_INFO sf_std_format_array[SF_NUM_STD_FORMATS] = { {SF_FORMAT_AIFF | SF_FORMAT_AIFF | SF_FORMAT_PCM_BE, "AIFF (Apple/SGI Audio Interchange File Format)", "aiff"}, {SF_FORMAT_AU | SF_FORMAT_ULAW, "AU (Sun/NeXT, u-law)", "au"}, {SF_FORMAT_AU | SF_FORMAT_ALAW, "AU (Sun/NeXT, a-law)", "au"}, {SF_FORMAT_LE | SF_FORMAT_ULAW, "AU (DEC, u-law)", "au"}, {SF_FORMAT_WAV | SF_FORMAT_PCM | SF_FORMAT_PCM_LE, "Wave (Microsoft Wave)", "wav"}, {SF_FORMAT_WAV | SF_FORMAT_PCM | SF_FORMAT_PCM_LE, "Wave (Microsoft ADPCM)", "wav"}}; int sf_get_num_std_formats() { return SF_NUM_STD_FORMATS; } SF_STD_FORMAT_INFO *sf_get_std_format(int i) { if (i>=0 && i<SF_NUM_STD_FORMATS) return &sf_std_format_array[i]; else { /* set error? */ return 0; } } Erik is happy with this API and hopefully he is going to fill in the rest of the formats for us. Note that there isn't a bijection between formats and filetypes, because some filetypes (i.e. WAV) have multiple valid formats (i.e. PCM vs. ADPCM (which is slightly compressed)). So if you'd like to work on this, I'd suggest: * stick the code, above, into libsndfile and check it in. We can throw out this change when Erik releases the next version of libsndfile (which will have a complete implementation). * modify the Preferences dialog to get the list of export formats from this list. Store the name (or the index in the list) of the format they want in the preferences. * If you want, add a button to the prefs dialog called something like "format options..." which pops up a dialog where they can specify details like Little/Big Endian, 8-bit/16-bit/more, etc. * Modify ExportPCM.cpp to use libsndfile - this is a lot more work, you don't have to finish this part, though you should have all of the information you need between ExportPCM.cpp, ImportPCM.cpp, and the libsndfile headers. > Also, the detection of input format by filename extensions seems fragile. > It could be augmented by filesystem metadata where available (mac) and/or > "magic number" methods like file(1). I'm not proposing to do this now, > but it's a thought for the future. Luckily libsndfile already does exactly this! That's one great thing about this library. So the only things we try to detect based on the file extension right now are MP3 and MIDI files. It's actually nontrivial to detect an MP3 file, with ID3 tags and all, so I think that going for the file extension is actually best for those. I'm assuming that you are "mbrubeck" at Sourceforge. I just added you as a developer, so you should now be able to commit files to CVS rather than sending patches. Feel free to go crazy with the importing/exporting code. The CVS trunk is fair game for any new features right now. I'm going to be working on some substantial changes over the next few weeks (multiple channels, multiple sample formats) and the code will be unstable for a while. BTW, you may want to keep a copy of Audacity 0.97 around. If something worked fine in 0.97 and doesn't anymore, then it's something one of us is in the middle of working on. - Dominic |