Re: Setting the sample rate in a WAV file
Joseph Anderson <[email protected]> Thu, 6 May 2021 19:47:09 -0700
| Newsgroups | gmane.comp.audio.supercollider.user |
|---|---|
| Message-ID | <CANZDFknFbTOOAcPmzyFBAxMk=jvEczRsiHskQE=BbqLKh89TLA@mail.gmail.com> |
Ah... yes, that's right. You'll need to pull the contents of the Buffer into an Array. For use w/ SignalBox's write message, the Array will have to be converted to a Signal first. *Dr Joseph Anderson | Research Scientist* DXARTS, Box 353414 University of Washington Seattle, WA 98195-3680 http://www.dxarts.washington.edu Subscribe to our events list <https://dxarts.washington.edu/mailing-list> to receive email updates about lectures, performances, exhibitions and more. On Thu, May 6, 2021 at 6:15 PM <[email protected]> wrote: > On Fri, May 7, 2021 at 3:23 AM <[email protected]> wrote: > > I have a process that creates signals at rates other than the server’s > sample rate, and I want to save these signals using a custom UGen > GatedDiskOut that writes a frame only on a trigger (very useful). But then > I need to get the effective sample rate into the WAV file header, and I > can’t figure out how. I have tried buffer.sampleRate, but buffer.write and > buffer.close both seem to ignore that, writing the server’s samplerate to > the WAV header instead. > > That's right. `buffer.write` uses the server command /b_write to > create the file. This can use the server's sample rate only. There's > no way to override that. > > > sf.sampleRate and sf.asBuffer > > Converting a SoundFile to a buffer would imply reading from a file, > wouldn't it? I can't see how that would help you with writing. > > In any case... if you get the data into the language client > (`loadToFloatArray` or `getToFloatArray`), then you can use SoundFile > to write it with any header information you specify. > > If b is your buffer: > > ( > var path = "..... where to save it..."; > var yourDesiredSampleRate = 1000; // or whatever > > b.loadToFloatArray(action: { |data| > var file = SoundFile(path); > > file.sampleRate_(yourDesiredSampleRate) > .numChannels_(b.numChannels) > .sampleFormat_("int24") // or int16 or float > .headerFormat_("WAV"); > > protect { > if(file.openWrite) { > file.writeData(data); > } { > "% could not be opened for writing".format(path.basename).warn; > }; > } { file.close }; > }); > ) > > The Signal:write method from the SignalBox quark just packages the > writing part of the above example into a single method call. But it > won't get the data from the server for you (as far as I can see). > > hjh > > _______________________________________________ > sc-users mailing list > > info (subscription, etc.): > http://www.birmingham.ac.uk/facilities/ea-studios/research/supercollider/mailinglist.aspx > archive: http://www.listarc.bham.ac.uk/marchives/sc-users/ > search: http://www.listarc.bham.ac.uk/lists/sc-users/search/ >