digego / extempore

A cyber-physical programming environment
1.41k stars 127 forks source link

write_audio_file disappeared? #361

Closed CastixGitHub closed 5 years ago

CastixGitHub commented 5 years ago

Following https://extemporelang.github.io/docs/guides/audio-file-io/ I get Compiler Error cannot find symbol write_audio_data and I cannot find any reference to that function. How can I save audio then?

CastixGitHub commented 5 years ago

https://github.com/digego/extempore/commit/a70deacf81357a38c0d965e39891c9d86a3e49e6 it was deleted in this commit, what is the purpose of that branch? In that branch the function was renamed/removed too, but the docs still use that function. can you please update the docs? Thanks

benswift commented 5 years ago

Hmm, yep, that branch is now gone. In general there's been a move away from using libsndfile for basic wav/aiff reading to use the pure-xtlang AudioBuffer stuff instead, but the file writing support isn't there. There's a chance that the sndfile stuff was deleted by mistake - I'll look into it.

So, I apologise that the docs are out-of-date. I'll update them as soon as I'm back from leave (in a week or so).

In the meantime, you should still be able to use the sndfile API for writing files, and in fact most of that code you mention should still work. Again, I can look into it as soon as I'm back from leave.

Sorry about the confusion.

CastixGitHub commented 5 years ago

I see you updated the doc to remove the "how to write a file" section, Actually I'm not able to read audio from extempore with sndfile at all

sys:load notification sndfile already loaded 
Compiler Error cannot find symbol audiofile_c

And AudioBuffer isn't ever mentioned, it would be great to have an example

benswift commented 5 years ago

Hey @CastixGitHub thanks for bumping me on this - I'll try and put together an example for you. What exactly is it that you're after? Reading & writing a wav file? Or some other workflow?

CastixGitHub commented 5 years ago

Yes, The format of the file isn't so important for me at this time, so both AudioBuffer and libsdnfile are good if they read a file. After some menipulation I would write the audio into a new file (curently i'm saving pulseaudio output to a file, but I think it's the worst solution), if I understand it right this will be possible only with libsndfile. Documentation lacks even for basic IO of text/binary file in xtlang reference (edit: it's the same as scheme: https://www.scheme.com/tspl4/io.html#./io:h0 https://github.com/digego/extempore/blob/master/runtime/init.xtm#L461) Thanks again.

benswift commented 5 years ago

Hey there, sorry about the delay. I've written a blog post which might help you out:

https://benswift.me/blog/2019/10/15/sound-file-io-in-extempore-with-libsndfile/

CastixGitHub commented 5 years ago

Wow, Thank you, I think a link from the documentation is a great addition. saving the output can be implemented even in native AudioBuffer, right? there is any reason for AudioBuffer to support only wawe and aiff files or wav/flac may be supported in the future?

benswift commented 5 years ago

saving the output can be implemented even in native AudioBuffer, right?

For simple (uncompressed) formats like wav, sure - it's just the "reverse" of the file reading function(s).

there is any reason for AudioBuffer to support only wawe and aiff files or wav/flac may be supported in the future?

The idea of AudioBuffer is that it's pure xtlang---and simple. Of course, you could write xtlang code to deal with complicated formats (e.g. ogg/flac) but it'd be a lot of work. So the approach at the moment is to have built-in "pure" xtlang functionality for a small number of formats in AudioBuffer, and for every other format there's libsndfile.