how to convert sample rate/ bit depth of files

redhexagonal's icon

I am using polybuffer~ to read alot of single shot samples which have different sample rates, either 1 or 2 channels and different bit depths.
I want to make them into a single 16 bit 48kHz mono chain , but because of the different sample rates, when I copy them into a 16bit 48khz mono buffer, the ones that were 96khz get pitched down alot, and the 44.1khz files get pitched up a bit.
Is there a way , within max map, to convert the different kinds of 96khz and 44.1khz samples to 16 bit 48kHz mono before copying them?

redhexagonal's icon

Any ideas?

Roman Thilenius's icon

sfplay~ and record~ will do all you need.
unless i missed something, there is no easy nonrealtime method available.

netherwaves's icon

you might also be able to work around the sampling rate difference between your samples and your audio device by using the [groove~] object playback rate.

say you have a 44.1kHz buffer file converted to 48kHz, playing in a 48kHz audio environment. as you've stated earlier, playing it at 1:1 speed will pitch it up by a pinch, which means you have to lower the playback speed to the pre-copy buffer SR over post-copy buffer SR ratio (44100 / 48000 = 0.91875), in order for it to compensate for the conversion. the [info~] and [dspstate~] objects will help you get the necessary data to do the math. you can then plug that number in the playback rate of a [groove~] object set to the copied buffer, and it should play at the correct speed.

I've had a similar issue with a patch that would auto-crop an incoming audio file into some amount of subparts, where, using [mxj buf.Op] to spread it into a polybuffer, it would get converted from 44.1k to 48k (for example) and play back at a higher pitch through [groove~]. the above fixed the issue for me.

hope this helps!