Cannot change recording sample rate for OpenSL

Hello,

I am trying to record audio in Unity project, but I am not able to set system sampling frequency to 44100Hz. The code for initialization is this:

// CODE
FMOD.Factory.System_Create(out mSystem);
mSystem.setOutput(FMOD.OUTPUTTYPE.OPENSL);

mSystem.setSoftwareFormat(44100, FMOD.SPEAKERMODE.MONO, 1);

mSystem.init(128, FMOD.INITFLAGS.NORMAL, (System.IntPtr)null)
mSystem.getRecordNumDrivers(out numDrivers, out numConnected)

int rate; FMOD.DRIVER_STATE driverstate; Guid guid, FMOD.SPEAKERMODE speakermode;
mSystem.getRecordDriverInfo(deviceindex, name, 0, out guid, out rate, out speakermode, out channels, out driverstate);
//END CODE

but now the returned parameter rate is 16000. Can you help me with setting the record driver to 44100 Hz ?

Thank You

We use 16000 Hz as the default as it is support by OpenSL on any device.
You don’t have to use this, you can set it to whatever number you like and we will attempt to use that, if for some reason it does not work (isn’t supported by the device) we will default it back to 16000 Hz.

If you take a look at the record example that comes with the LowLevel API, you can see how to set the frequency of the sound you would then record into (using FMOD_CREATESOUNDEXINFO).

Thank You for the answer. But setting sound on some frequency (for example 44100) and having the system frequency at 16000 means, that recorded data will be only interpolated, isn’t it ?
(I am sure that the device supports 44100, because, when I use default Unity Audio system, it is recorded at 44100. But in this project I need to use FMod :slight_smile: )

I will try how it behaves in native OpenSL.

There isn’t a way to get the actual recording frequency from the hardware, but we know that 16000 is supported for certain which is why we default to it.

getRecordDriverInfo() provides the default rate.

As I said previously, you can set the frequency of the sound manually and when you use it for recording, we will attempt to record at that frequency (otherwise fallback to the default).