real sample rate conversion of buffer~


    Apr 25 2017 | 7:42 am
    Hi,
    I want to up or downsample a buffer~ destructively. There seems to be no native way. I want it to be always 32000 hz. I want to load soundfiles with any sr and always have them converted to 32000hz.
    I don't want to use an external tool like sox. For what I have read, it's applying a steep lowpass at 16000hz and dropping or adding samples. But how to do that in a calculation with the floats of a buffer?
    For example 44,1khz to 32khz. How to drop every 1,378125 th sample?
    Any example is helpful. I can translate that for my needs.
    Thanks,
    O.

    • Apr 25 2017 | 9:33 am
      if you mean what you said then the answer is "no", because a buffer always has the samplingrate of the patcher and runtime it is in.
      changing samplerate within one signal chain will mean to "stretch" the sample. the basi strategy is to upsample something like *10 or *16 and then downsample again and interpolate a bit.
      a lowpassfilter is optional.
      poly~ does it all in realtime since max 6... but as you know, only with multiples of 2. 44.1 to 32 is a bit mor ecomplicated if you want perfect sound. i would not do it in max/msp...
    • Apr 25 2017 | 9:51 am
      Hey Roman,
      I don't want to do that in realtime, more like processing a buffer. I don't think it depends on the environment, it's just a property of the loaded soundfile.
    • Apr 25 2017 | 10:00 am
      a property of the soundfile which is, if i am not mistaken, ignored when loading the file, unless you can convert the samplerate on-the-fly (like you can "import" mp3 to sfplay for example)
      and if you´d change the header of the soundfile - that is of course possible - the audio would change its pitch, which is no what you are looking for ;)
    • Apr 25 2017 | 10:20 am
      buffer~ always adopt the sr of the loaded file, I think the playback objects do the conversion on the fly to fit the environment.
    • Apr 25 2017 | 12:42 pm
      I could convert in java if I could figure out a way to get a proper audio input stream from the float array of the buffer?
    • Apr 25 2017 | 6:41 pm
      java sounds doable, there should be vast libraries for stuff like that, maybe even with antialiasing. but java is not my world and so i am clueless. you can still use sfinfo~ with it to find out if and what conversion is required.
    • Apr 25 2017 | 7:42 pm
      Almost OT, but here is a website with some interesting sample-rate-conversion comparison results of different software from open-source to commercial, including matlab, fscape (which is java-based) and others. You may get some inspiration here.