I used the SensorManager.SENSOR_DELAY_FASTEST to get the phone (Google pixel 6a) accelerometer data and the sampling frequency is 440Hz. However, when I used the Android native code to read the phone accelerometer data, the minimum delay allowed between events is 5000 microseconds, which means the sampling frequency is 200Hz. And I'm not be able to set the sampling frequency higher than 200Hz. Why the fast sampling frequency is lower when using Android native code? How to set the samping frequency as 440Hz using native code?
Updates:
I installed the same app on Motorola G power 2021. The sampling frequency obtained from the SensorManager.SENSOR_DELAY_FASTEST is 500 Hz, and the minimum delay obtained from the Android native code (ASensor_getMinDelay(accelerometerSensor)) is 2000 microseconds. Which means on Motorola G Power, the fastest samping frequency obtained from the Android API and Android NDK are the same. It is at 500 Hz.
So my question is: why is the sampling frequency consistent on the Motorola G Power 2021 but not consistent on the Google Pixel 6a?
The Android native code:
ASensorRef accelerometerSensor = ASensorManager_getDefaultSensor(sensorManager,ASENSOR_TYPE_ACCELEROMETER);
LOGI("accelerometerSensor: %s, vendor: %s", ASensor_getName(accelerometerSensor), ASensor_getVendor(accelerometerSensor));
int a = ASensor_getMinDelay(accelerometerSensor);
queue = ASensorManager_createEventQueue(sensorManager, looper, LOOPER_ID, get_sensor_events, sensor_data);
ASensorEventQueue_enableSensor(queue, accelerometerSensor);
ASensorEventQueue_setEventRate(queue, accelerometerSensor, a);
static int get_sensor_events(int fd, int events, void *data) {
ASensorEvent event;
//ASensorEventQueue* sensorEventQueue;
while (ASensorEventQueue_getEvents(queue, &event, 1) > 0) {
if(event.type == ASENSOR_TYPE_ACCELEROMETER) {
//LOGI("accl(x,y,z,t): %f %f %f %lld", event.acceleration.x, event.acceleration.y, event.acceleration.z, event.timestamp);
if(accCounter == 1000)
{
LOGI("Acc-Time: %lld (%f)", event.timestamp,((double)(event.timestamp-lastAccTime))/1000000000.0);
lastAccTime = event.timestamp;
accCounter = 0;
}
accCounter++;
// LOGI("aaaaaaa accelerometer X = %f y = %f z=%f ", event.acceleration.x, event.acceleration.y, event.acceleration.z);
}
else{
LOGI("Other event ");
}
}
//should return 1 to continue receiving callbacks, or 0 to unregister
return 1;
}