include/SDL_sensor.h
author Sam Lantinga <slouken@libsdl.org>
Tue, 25 Sep 2018 20:08:51 -0700
changeset 12224 0582b4e1fa9f
parent 12180 a3c2b6e89522
child 12242 df7260f149f2
permissions -rw-r--r--
Fixed bug 4268 - Android_JNI_OpenAudioDevice function has error

alittle

where iscapture == 1

1.param set error

(*env)->CallStaticIntMethod(env, mAudioManagerClass, midCaptureOpen, sampleRate, audioBuffer16Bit, audioBufferStereo, desiredBufferFrames)

param:audioBuffer16Bit need change to captureBuffer16Bit

2.logic error

if (is16Bit) {
// ALITTLE Modify the source code
if (iscapture) {
audioBufferFrames = (*env)->GetArrayLength(env, (jshortArray)captureBuffer);
} else {
audioBufferPinned = (*env)->GetShortArrayElements(env, (jshortArray)audioBuffer, &isCopy);
audioBufferFrames = (*env)->GetArrayLength(env, (jshortArray)audioBuffer);
}
// if (!iscapture) {
// audioBufferPinned = (*env)->GetShortArrayElements(env, (jshortArray)audioBuffer, &isCopy);
// }
// audioBufferFrames = (*env)->GetArrayLength(env, (jshortArray)audioBuffer);
} else {
// ALITTLE Modify the source code
if (iscapture) {
audioBufferFrames = (*env)->GetArrayLength(env, (jbyteArray)captureBuffer);
} else {
audioBufferPinned = (*env)->GetByteArrayElements(env, (jbyteArray)audioBuffer, &isCopy);
audioBufferFrames = (*env)->GetArrayLength(env, (jbyteArray)audioBuffer);
}
// if (!iscapture) {
// audioBufferPinned = (*env)->GetByteArrayElements(env, (jbyteArray)audioBuffer, &isCopy);
// }
// audioBufferFrames = (*env)->GetArrayLength(env, (jbyteArray)audioBuffer);
}
slouken@12130
     1
/*
slouken@12130
     2
  Simple DirectMedia Layer
slouken@12130
     3
  Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
slouken@12130
     4
slouken@12130
     5
  This software is provided 'as-is', without any express or implied
slouken@12130
     6
  warranty.  In no event will the authors be held liable for any damages
slouken@12130
     7
  arising from the use of this software.
slouken@12130
     8
slouken@12130
     9
  Permission is granted to anyone to use this software for any purpose,
slouken@12130
    10
  including commercial applications, and to alter it and redistribute it
slouken@12130
    11
  freely, subject to the following restrictions:
slouken@12130
    12
slouken@12130
    13
  1. The origin of this software must not be misrepresented; you must not
slouken@12130
    14
     claim that you wrote the original software. If you use this software
slouken@12130
    15
     in a product, an acknowledgment in the product documentation would be
slouken@12130
    16
     appreciated but is not required.
slouken@12130
    17
  2. Altered source versions must be plainly marked as such, and must not be
slouken@12130
    18
     misrepresented as being the original software.
slouken@12130
    19
  3. This notice may not be removed or altered from any source distribution.
slouken@12130
    20
*/
slouken@12130
    21
slouken@12130
    22
/**
slouken@12130
    23
 *  \file SDL_sensor.h
slouken@12130
    24
 *
slouken@12130
    25
 *  Include file for SDL sensor event handling
slouken@12130
    26
 *
slouken@12130
    27
 */
slouken@12130
    28
slouken@12130
    29
#ifndef _SDL_sensor_h
slouken@12130
    30
#define _SDL_sensor_h
slouken@12130
    31
slouken@12130
    32
#include "SDL_stdinc.h"
slouken@12130
    33
#include "SDL_error.h"
slouken@12130
    34
slouken@12130
    35
#include "begin_code.h"
slouken@12130
    36
/* Set up for C function definitions, even when using C++ */
slouken@12130
    37
#ifdef __cplusplus
slouken@12130
    38
/* *INDENT-OFF* */
slouken@12130
    39
extern "C" {
slouken@12130
    40
/* *INDENT-ON* */
slouken@12130
    41
#endif
slouken@12130
    42
slouken@12130
    43
/**
slouken@12130
    44
 *  \file SDL_sensor.h
slouken@12130
    45
 *
slouken@12130
    46
 *  In order to use these functions, SDL_Init() must have been called
slouken@12130
    47
 *  with the ::SDL_INIT_SENSOR flag.  This causes SDL to scan the system
slouken@12130
    48
 *  for sensors, and load appropriate drivers.
slouken@12130
    49
 */
slouken@12130
    50
slouken@12130
    51
struct _SDL_Sensor;
slouken@12130
    52
typedef struct _SDL_Sensor SDL_Sensor;
slouken@12130
    53
slouken@12130
    54
/**
slouken@12130
    55
 * This is a unique ID for a sensor for the time it is connected to the system,
slouken@12130
    56
 * and is never reused for the lifetime of the application.
slouken@12130
    57
 *
slouken@12130
    58
 * The ID value starts at 0 and increments from there. The value -1 is an invalid ID.
slouken@12130
    59
 */
slouken@12133
    60
typedef Sint32 SDL_SensorID;
slouken@12130
    61
slouken@12148
    62
/* The different sensors defined by SDL
slouken@12148
    63
 *
icculus@12178
    64
 * Additional sensors may be available, using platform dependent semantics.
slouken@12148
    65
 *
slouken@12148
    66
 * Hare are the additional Android sensors:
slouken@12148
    67
 * https://developer.android.com/reference/android/hardware/SensorEvent.html#values
slouken@12148
    68
 */
slouken@12130
    69
typedef enum
slouken@12130
    70
{
slouken@12130
    71
    SDL_SENSOR_INVALID = -1,    /**< Returned for an invalid sensor */
slouken@12130
    72
    SDL_SENSOR_UNKNOWN,         /**< Unknown sensor type */
slouken@12130
    73
    SDL_SENSOR_ACCEL,           /**< Accelerometer */
sezeroz@12180
    74
    SDL_SENSOR_GYRO             /**< Gyroscope */
slouken@12130
    75
} SDL_SensorType;
slouken@12130
    76
slouken@12143
    77
/**
slouken@12143
    78
 * Accelerometer sensor
slouken@12143
    79
 *
slouken@12143
    80
 * The accelerometer returns the current acceleration in SI meters per
slouken@12143
    81
 * second squared. This includes gravity, so a device at rest will have
slouken@12143
    82
 * an acceleration of SDL_STANDARD_GRAVITY straight down.
slouken@12143
    83
 *
slouken@12143
    84
 * values[0]: Acceleration on the x axis
slouken@12143
    85
 * values[1]: Acceleration on the y axis
slouken@12143
    86
 * values[2]: Acceleration on the z axis
slouken@12143
    87
 *
slouken@12143
    88
 * For phones held in portrait mode, the axes are defined as follows:
slouken@12143
    89
 * -X ... +X : left ... right
slouken@12143
    90
 * -Y ... +Y : bottom ... top
slouken@12143
    91
 * -Z ... +Z : farther ... closer
slouken@12143
    92
 * 
slouken@12143
    93
 * The axis data is not changed when the phone is rotated.
slouken@12143
    94
 *
slouken@12143
    95
 * \sa SDL_GetDisplayOrientation()
slouken@12143
    96
 */
slouken@12143
    97
#define SDL_STANDARD_GRAVITY    9.80665f
slouken@12143
    98
slouken@12143
    99
/**
slouken@12143
   100
 * Gyroscope sensor
slouken@12143
   101
 *
slouken@12143
   102
 * The gyroscope returns the current rate of rotation in radians per second.
slouken@12143
   103
 * The rotation is positive in the counter-clockwise direction. That is,
slouken@12143
   104
 * an observer looking from a positive location on one of the axes would
slouken@12143
   105
 * see positive rotation on that axis when it appeared to be rotating
slouken@12143
   106
 * counter-clockwise.
slouken@12143
   107
 *
slouken@12143
   108
 * values[0]: Angular speed around the x axis
slouken@12143
   109
 * values[1]: Angular speed around the y axis
slouken@12143
   110
 * values[2]: Angular speed around the z axis
slouken@12143
   111
 *
slouken@12143
   112
 * For phones held in portrait mode, the axes are defined as follows:
slouken@12143
   113
 * -X ... +X : left ... right
slouken@12143
   114
 * -Y ... +Y : bottom ... top
slouken@12143
   115
 * -Z ... +Z : farther ... closer
slouken@12143
   116
 * 
slouken@12143
   117
 * The axis data is not changed when the phone is rotated.
slouken@12143
   118
 *
slouken@12143
   119
 * \sa SDL_GetDisplayOrientation()
slouken@12143
   120
 */
slouken@12143
   121
slouken@12130
   122
/* Function prototypes */
slouken@12130
   123
slouken@12130
   124
/**
slouken@12130
   125
 *  \brief Count the number of sensors attached to the system right now
slouken@12130
   126
 */
slouken@12130
   127
extern DECLSPEC int SDLCALL SDL_NumSensors(void);
slouken@12130
   128
slouken@12130
   129
/**
slouken@12130
   130
 *  \brief Get the implementation dependent name of a sensor.
slouken@12130
   131
 *
slouken@12130
   132
 *  This can be called before any sensors are opened.
slouken@12130
   133
 * 
slouken@12130
   134
 *  \return The sensor name, or NULL if device_index is out of range.
slouken@12130
   135
 */
slouken@12130
   136
extern DECLSPEC const char *SDLCALL SDL_SensorGetDeviceName(int device_index);
slouken@12130
   137
slouken@12130
   138
/**
slouken@12130
   139
 *  \brief Get the type of a sensor.
slouken@12130
   140
 *
slouken@12130
   141
 *  This can be called before any sensors are opened.
slouken@12130
   142
 *
slouken@12130
   143
 *  \return The sensor type, or SDL_SENSOR_INVALID if device_index is out of range.
slouken@12130
   144
 */
slouken@12130
   145
extern DECLSPEC SDL_SensorType SDLCALL SDL_SensorGetDeviceType(int device_index);
slouken@12130
   146
slouken@12130
   147
/**
slouken@12130
   148
 *  \brief Get the platform dependent type of a sensor.
slouken@12130
   149
 *
slouken@12130
   150
 *  This can be called before any sensors are opened.
slouken@12130
   151
 *
slouken@12130
   152
 *  \return The sensor platform dependent type, or -1 if device_index is out of range.
slouken@12130
   153
 */
slouken@12130
   154
extern DECLSPEC int SDLCALL SDL_SensorGetDeviceNonPortableType(int device_index);
slouken@12130
   155
slouken@12130
   156
/**
slouken@12130
   157
 *  \brief Get the instance ID of a sensor.
slouken@12130
   158
 *
slouken@12130
   159
 *  This can be called before any sensors are opened.
slouken@12130
   160
 *
slouken@12130
   161
 *  \return The sensor instance ID, or -1 if device_index is out of range.
slouken@12130
   162
 */
slouken@12130
   163
extern DECLSPEC SDL_SensorID SDLCALL SDL_SensorGetDeviceInstanceID(int device_index);
slouken@12130
   164
slouken@12130
   165
/**
slouken@12130
   166
 *  \brief Open a sensor for use.
slouken@12130
   167
 *
slouken@12130
   168
 *  The index passed as an argument refers to the N'th sensor on the system.
slouken@12130
   169
 *
slouken@12130
   170
 *  \return A sensor identifier, or NULL if an error occurred.
slouken@12130
   171
 */
slouken@12130
   172
extern DECLSPEC SDL_Sensor *SDLCALL SDL_SensorOpen(int device_index);
slouken@12130
   173
slouken@12130
   174
/**
slouken@12130
   175
 * Return the SDL_Sensor associated with an instance id.
slouken@12130
   176
 */
slouken@12130
   177
extern DECLSPEC SDL_Sensor *SDLCALL SDL_SensorFromInstanceID(SDL_SensorID instance_id);
slouken@12130
   178
slouken@12130
   179
/**
slouken@12130
   180
 *  \brief Get the implementation dependent name of a sensor.
slouken@12130
   181
 *
slouken@12130
   182
 *  \return The sensor name, or NULL if the sensor is NULL.
slouken@12130
   183
 */
slouken@12130
   184
extern DECLSPEC const char *SDLCALL SDL_SensorGetName(SDL_Sensor *sensor);
slouken@12130
   185
slouken@12130
   186
/**
slouken@12130
   187
 *  \brief Get the type of a sensor.
slouken@12130
   188
 *
slouken@12130
   189
 *  This can be called before any sensors are opened.
slouken@12130
   190
 *
slouken@12130
   191
 *  \return The sensor type, or SDL_SENSOR_INVALID if the sensor is NULL.
slouken@12130
   192
 */
slouken@12130
   193
extern DECLSPEC SDL_SensorType SDLCALL SDL_SensorGetType(SDL_Sensor *sensor);
slouken@12130
   194
slouken@12130
   195
/**
slouken@12130
   196
 *  \brief Get the platform dependent type of a sensor.
slouken@12130
   197
 *
slouken@12130
   198
 *  This can be called before any sensors are opened.
slouken@12130
   199
 *
slouken@12130
   200
 *  \return The sensor platform dependent type, or -1 if the sensor is NULL.
slouken@12130
   201
 */
slouken@12130
   202
extern DECLSPEC int SDLCALL SDL_SensorGetNonPortableType(SDL_Sensor *sensor);
slouken@12130
   203
slouken@12130
   204
/**
slouken@12130
   205
 *  \brief Get the instance ID of a sensor.
slouken@12130
   206
 *
slouken@12130
   207
 *  This can be called before any sensors are opened.
slouken@12130
   208
 *
slouken@12130
   209
 *  \return The sensor instance ID, or -1 if the sensor is NULL.
slouken@12130
   210
 */
slouken@12130
   211
extern DECLSPEC SDL_SensorID SDLCALL SDL_SensorGetInstanceID(SDL_Sensor *sensor);
slouken@12130
   212
slouken@12130
   213
/**
slouken@12130
   214
 *  Get the current state of an opened sensor.
slouken@12130
   215
 *
slouken@12130
   216
 *  The number of values and interpretation of the data is sensor dependent.
slouken@12130
   217
 *
slouken@12130
   218
 *  \param sensor The sensor to query
slouken@12130
   219
 *  \param data A pointer filled with the current sensor state
slouken@12130
   220
 *  \param num_values The number of values to write to data
slouken@12130
   221
 *
slouken@12130
   222
 *  \return 0 or -1 if an error occurred.
slouken@12130
   223
 */
slouken@12130
   224
extern DECLSPEC int SDLCALL SDL_SensorGetData(SDL_Sensor * sensor, float *data, int num_values);
slouken@12130
   225
slouken@12130
   226
/**
slouken@12130
   227
 *  Close a sensor previously opened with SDL_SensorOpen()
slouken@12130
   228
 */
slouken@12130
   229
extern DECLSPEC void SDLCALL SDL_SensorClose(SDL_Sensor * sensor);
slouken@12130
   230
slouken@12130
   231
/**
slouken@12130
   232
 *  Update the current state of the open sensors.
slouken@12130
   233
 *
slouken@12130
   234
 *  This is called automatically by the event loop if sensor events are enabled.
slouken@12130
   235
 *
slouken@12130
   236
 *  This needs to be called from the thread that initialized the sensor subsystem.
slouken@12130
   237
 */
slouken@12130
   238
extern DECLSPEC void SDLCALL SDL_SensorUpdate(void);
slouken@12130
   239
slouken@12130
   240
slouken@12130
   241
/* Ends C function definitions when using C++ */
slouken@12130
   242
#ifdef __cplusplus
slouken@12130
   243
/* *INDENT-OFF* */
slouken@12130
   244
}
slouken@12130
   245
/* *INDENT-ON* */
slouken@12130
   246
#endif
slouken@12130
   247
#include "close_code.h"
slouken@12130
   248
slouken@12130
   249
#endif /* _SDL_sensor_h */
slouken@12130
   250
slouken@12130
   251
/* vi: set ts=4 sw=4 expandtab: */