audio_sample.h
1 /*
2  * Player - One Hell of a Robot Server
3  * Copyright (C) 2003
4  * Brian Gerkey
5  *
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20  *
21  */
22 
23 // Sample type
24 typedef uint8_t SampleType;
25 // No type - no wave data loaded
26 const SampleType SAMPLE_TYPE_NONE = 0;
27 // File samples must be opened, and the data comes from/goes to the file on demand
28 const SampleType SAMPLE_TYPE_FILE = 1;
29 // Memory samples are stored as data in memory, eg a sample received via the player server
30 const SampleType SAMPLE_TYPE_MEM = 2;
31 
33 {
34  public:
35  AudioSample (void);
36  AudioSample (const player_audio_wav_t *source);
37  AudioSample (const uint8_t *source, uint32_t length, uint16_t channels, uint32_t sr, uint16_t bps);
38  ~AudioSample (void);
39 
40  // Data management functions
41  void SetDataPosition (uint32_t newPosition); // Set current position in the data (in frames, not bytes)
42  uint32_t GetDataPosition (void) const; // Get current position in the data (in frames, not bytes)
43  uint32_t GetDataLength (void) const; // Get length of data (in frames, not bytes)
44  int GetData (int frameCount, uint8_t *buffer); // Get a block of data from current position
45  void ClearSample (void); // Clear the entire sample (including format), making this a SAMPLE_TYPE_NONE
46  bool FillSilence (uint32_t time); // Fill the sample with silence
47 
48  // Data conversion functions
49  bool ToPlayer (player_audio_wav_t *dest); // Convert to player wave structure
50  bool FromPlayer (const player_audio_wav_t *source); // Convert from player wave structure
51 
52  // File management functions
53  bool LoadFile (const char *fileName); // Load wave data from a file
54  void CloseFile (void); // Close the opened file
55  const char* GetFilePath (void) const { return filePath; }
56 
57  // Wave format functions
58  SampleType GetType (void) const { return type; }
59  void SetType (SampleType val) { type = val; }
60  uint16_t GetNumChannels (void) const { return numChannels; }
61  void SetNumChannels (uint16_t val) { numChannels = val; }
62  uint32_t GetSampleRate (void) const { return sampleRate; }
63  void SetSampleRate (uint32_t val) { sampleRate = val; byteRate = blockAlign * sampleRate; }
64  uint32_t GetByteRate (void) const { return byteRate; }
65  uint16_t GetBlockAlign (void) const { return blockAlign; }
66  void SetBlockAlign (uint16_t val) { blockAlign = val; byteRate = blockAlign * sampleRate; }
67  uint16_t GetBitsPerSample (void) const { return bitsPerSample; }
68  void SetBitsPerSample (uint16_t val) { bitsPerSample = val; }
69  uint32_t GetNumFrames (void) const { return numFrames; }
70  bool SameFormat (const AudioSample *rhs);
71  void CopyFormat (const AudioSample *rhs);
72 
73  // Other useful functions
74  void PrintWaveInfo (void); // Print out the wave information
75 
76  private:
77  SampleType type; // Sample type
78 
79  // Information about the wave this sample stores
80  uint16_t numChannels; // Number of channels in the data
81  uint32_t sampleRate; // Number of samples per second
82  uint32_t byteRate; // Number of bytes per second
83  uint16_t blockAlign; // Number of bytes for one sample over all channels (i.e. frame size)
84  uint16_t bitsPerSample; // Number of bits per sample (eg 8, 16, 24, ...)
85  uint32_t numFrames; // Number of frames (divide by sampleRate to get time)
86 
87  // Current position in the wave data (in bytes)
88  uint32_t position;
89 
90  // If this is a file sample, this is the file info
91  FILE *waveFile; // File pointer
92  char *filePath; // Path to the file on disc
93  uint32_t headerSize; // Size of the wave format header in the file (i.e. start of actual data in the file)
94 
95  // If this is a memory sample, the data is stored here
96  uint32_t dataLength; // Length of data in bytes
97  uint8_t *data; // Array on the heap containing the data
98 };
float position
The position to move to.
Definition: player_interfaces.h:3877
Command: Multiple Joint position control (PLAYER_ACTARRAY_CMD_MULTI_POS)
Definition: player_interfaces.h:3883
#define PLAYER_WARN1(msg, a)
Error message macros.
Definition: error.h:89
#define PLAYER_ACTARRAY_ACTSTATE_STALLED
Stalled state code.
Definition: player_interfaces.h:3784
uint32_t blobs_count
The number of blobs.
Definition: player_interfaces.h:1103
#define PLAYER_ACTARRAY_DATA_STATE
Idle state code.
Definition: player_interfaces.h:3774
Data: detected blobs (PLAYER_BLOBFINDER_DATA_BLOBS)
Definition: player_interfaces.h:1096
uint8_t motor_state
power state
Definition: player_interfaces.h:3817
uint32_t color
A descriptive color for the blob (useful for gui's).
Definition: player_interfaces.h:1074
float centre
The range of motion of the actuator, in m or rad depending on the type.
Definition: player_interfaces.h:3839
Definition: pf_vector.h:40
double py
Y [m].
Definition: player.h:198
static bool MatchMessage(player_msghdr_t *hdr, int type, int subtype, player_devaddr_t addr)
Helper for message processing.
Definition: message.h:158
float pan
Pan [rad].
Definition: player_interfaces.h:1231
player_actarray_actuatorgeom_t * actuators
The geometry information for each actuator in the array.
Definition: player_interfaces.h:3859
float accel
Acceleration setting in m/s^2 or rad/s^2.
Definition: player_interfaces.h:3991
uint32_t right
Bounding box for the blob [pixels].
Definition: player_interfaces.h:1084
#define PLAYER_ACTARRAY_CMD_SPEED
Idle state code.
Definition: player_interfaces.h:3759
double ReadFloat(int section, const char *name, double value)
Read a floating point (double) value.
#define PLAYER_PTZ_DATA_STATE
Data subtype: state.
Definition: player_interfaces.h:1208
#define PLAYER_ACTARRAY_CMD_MULTI_POS
Idle state code.
Definition: player_interfaces.h:3756
Request/reply: Acceleration.
Definition: player_interfaces.h:3986
#define PLAYER_WIFI_DATA_STATE
Data subtype: state.
Definition: player_interfaces.h:2188
float speed
Speed setting in m/s or rad/s.
Definition: player_interfaces.h:3978
float max
The range of motion of the actuator, in m or rad depending on the type.
Definition: player_interfaces.h:3841
Data: ranges (PLAYER_SONAR_DATA_RANGES)
Definition: player_interfaces.h:771
#define PLAYER_AUDIO_BITS
Data subtype: wav_rec_data, recorded data block.
Definition: player_interfaces.h:1428
uint32_t data_count
length of raw data
Definition: player_interfaces.h:1466
float tilt
Tilt [rad].
Definition: player_interfaces.h:1233
Data AND Request/reply: geometry.
Definition: player_interfaces.h:785
#define PLAYER_AUDIO_24BIT
24 bit
Definition: player_interfaces.h:1434
float home
The range of motion of the actuator, in m or rad depending on the type.
Definition: player_interfaces.h:3843
uint32_t height
The image dimensions.
Definition: player_interfaces.h:1101
An angle in 3D space.
Definition: player.h:205
uint32_t left
Bounding box for the blob [pixels].
Definition: player_interfaces.h:1082
double ppitch
pitch [rad]
Definition: player.h:210
Generic message header.
Definition: player.h:160
uint32_t positions_count
The number of actuators in the array.
Definition: player_interfaces.h:3886
virtual int MainSetup(void)
Sets up the resources needed by the driver thread.
Definition: driver.h:657
uint8_t state
The current state of the actuator.
Definition: player_interfaces.h:3804
Request/reply: get geometry.
Definition: player_interfaces.h:3854
virtual void MainQuit(void)
Cleanup method for driver thread (called when main exits)
Definition: driver.h:663
Data: state (PLAYER_PTZ_DATA_STATE)
Definition: player_interfaces.h:1228
#define PLAYER_CAMERA_FORMAT_RGB888
Image format : 24-bit color (8 bits R, 8 bits G, 8 bits B).
Definition: player_interfaces.h:2942
int32_t joint
The joint/actuator to command.
Definition: player_interfaces.h:3875
#define PLAYER_AUDIO_FREQ_48k
Data subtype: wav_rec_data, recorded data block.
Definition: player_interfaces.h:1444
uint8_t type
Message type; must be one of PLAYER_MSGTYPE_*.
Definition: player.h:165
float tilt
Desired tilt angle [rad].
Definition: player_interfaces.h:1253
Command: state (PLAYER_PTZ_CMD_STATE)
Definition: player_interfaces.h:1248
uint32_t bottom
Bounding box for the blob [pixels].
Definition: player_interfaces.h:1088
const char * ReadString(int section, const char *name, const char *value)
Read a string value.
int32_t joint
Joint to set acceleration for.
Definition: player_interfaces.h:3989
int32_t joint
The joint/actuator to command - set to -1 to command all.
Definition: player_interfaces.h:3928
float zoom
Desired field of view [rad].
Definition: player_interfaces.h:1255
#define PLAYER_ACTARRAY_ACTSTATE_BRAKED
Braked state code.
Definition: player_interfaces.h:3782
player_point_3d_t base_pos
The position of the base of the actarray.
Definition: player_interfaces.h:3862
#define PLAYER_BLOBFINDER_DATA_BLOBS
Structure describing a single blob.
Definition: player_interfaces.h:1055
#define PLAYER_PTZ_POSITION_CONTROL
Control mode, for use with PLAYER_PTZ_REQ_CONTROL_MODE.
Definition: player_interfaces.h:1221
#define PLAYER_ACTARRAY_REQ_BRAKES
Idle state code.
Definition: player_interfaces.h:3741
float zoom
Field of view [rad].
Definition: player_interfaces.h:1235
#define PLAYER_ACTARRAY_ACTSTATE_IDLE
Idle state code.
Definition: player_interfaces.h:3778
A point in 3D space.
Definition: player.h:193
virtual void Main(void)=0
Main method for driver thread.
float speed
The speed of the actuator in m/s or rad/s depending on the type.
Definition: player_interfaces.h:3798
double ReadAngle(int section, const char *name, double value)
Read an angle (includes unit conversion).
#define PLAYER_AUDIO_FREQ_22k
Data subtype: wav_rec_data, recorded data block.
Definition: player_interfaces.h:1443
int32_t joint
Joint to set speed for.
Definition: player_interfaces.h:3976
const char * ReadTupleString(int section, const char *name, int index, const char *value)
Read a string from a tuple field.
Command: Joint position control (PLAYER_ACTARRAY_CMD_POS)
Definition: player_interfaces.h:3872
#define PLAYER_MAX_MESSAGE_SIZE
The largest possible message.
Definition: player.h:67
Structure containing a single actuator's information.
Definition: player_interfaces.h:3793
int ReadInt(int section, const char *name, int value)
Read an integer value.
#define PLAYER_ACTARRAY_REQ_POWER
Idle state code.
Definition: player_interfaces.h:3738
#define PLAYER_ACTARRAY_CMD_MULTI_SPEED
Idle state code.
Definition: player_interfaces.h:3762
uint32_t speeds_count
The number of actuators in the array.
Definition: player_interfaces.h:3908
float * positions
The positions for each joint/actuator.
Definition: player_interfaces.h:3888
Command: Multiple Joint speed control (PLAYER_ACTARRAY_CMD_MULTI_SPEED)
Definition: player_interfaces.h:3905
uint32_t y
The blob centroid [pixels].
Definition: player_interfaces.h:1080
#define PLAYER_MSGTYPE_DATA
A data message.
Definition: player.h:94
#define PLAYER_ERROR2(msg, a, b)
Error message macros.
Definition: error.h:82
virtual void Update()
Update non-threaded drivers.
Definition: driver.h:422
uint32_t area
The blob area [pixels].
Definition: player_interfaces.h:1076
#define PLAYER_ACTARRAY_REQ_SPEED
Idle state code.
Definition: player_interfaces.h:3747
#define PLAYER_MSGTYPE_RESP_ACK
A positive response message.
Definition: player.h:111
uint8_t type
The type of the actuator - linear or rotary.
Definition: player_interfaces.h:3824
double px
X [m].
Definition: player.h:196
#define PLAYER_ACTARRAY_TYPE_ROTARY
Rotary type code.
Definition: player_interfaces.h:3789
float * speeds
The speed to move with.
Definition: player_interfaces.h:3910
#define PLAYER_ACTARRAY_CMD_HOME
Idle state code.
Definition: player_interfaces.h:3765
#define PLAYER_AUDIO_FORMAT_BITS
AUDIO format.
Definition: player_interfaces.h:1447
player_point_3d_t axis
The axis of rotation for this actuator if it is rotary, or axis along which it moves if it is linear.
Definition: player_interfaces.h:3835
Definition: audio_sample.h:32
float acceleration
The acceleration of the actuator in m/s^2 or rad/s^2 depending on the type.
Definition: player_interfaces.h:3800
#define PLAYER_ACTARRAY_REQ_ACCEL
Idle state code.
Definition: player_interfaces.h:3750
float current
The current of the actuator in A.
Definition: player_interfaces.h:3802
uint32_t id
Blob id.
Definition: player_interfaces.h:1071
Command: Joint current control (PLAYER_ACTARRAY_CMD_CURRENT)
Definition: player_interfaces.h:3925
virtual int ProcessMessage(QueuePointer &resp_queue, player_msghdr *hdr, void *data)
Message handler.
player_orientation_3d_t base_orientation
The orientation of the base of the actarray.
Definition: player_interfaces.h:3865
#define PLAYER_AUDIO_16BIT
16 bit
Definition: player_interfaces.h:1432
#define PLAYER_AUDIO_FORMAT_RAW
Data subtype: wav_rec_data, recorded data block.
Definition: player_interfaces.h:1450
#define PLAYER_ACTARRAY_CMD_MULTI_CURRENT
Idle state code.
Definition: player_interfaces.h:3771
#define PLAYER_AUDIO_FREQ_11k
Data subtype: wav_rec_data, recorded data block.
Definition: player_interfaces.h:1442
#define PLAYER_MSGTYPE_REQ
A request message.
Definition: player.h:105
float tiltspeed
Current tilt velocity [rad/s].
Definition: player_interfaces.h:1239
uint32_t mode
Mode to use: must be either PLAYER_PTZ_VELOCITY_CONTROL or PLAYER_PTZ_POSITION_CONTROL.
Definition: player_interfaces.h:1305
#define PLAYER_MSGTYPE_RESP_NACK
A negative response message.
Definition: player.h:124
float speed
The speed to move with.
Definition: player_interfaces.h:3899
Request/reply: Control mode.
Definition: player_interfaces.h:1301
uint32_t actuators_count
The number of actuators in the array.
Definition: player_interfaces.h:3857
int32_t joint
The joint/actuator to command - set to -1 to command all.
Definition: player_interfaces.h:3919
#define PLAYER_AUDIO_FREQ
Frequency.
Definition: player_interfaces.h:1440
#define PLAYER_AUDIO_8BIT
8 bit
Definition: player_interfaces.h:1430
Definition: imagebase.h:61
float panspeed
Current pan velocity [rad/s].
Definition: player_interfaces.h:1237
uint32_t currents_count
The number of actuators in the array.
Definition: player_interfaces.h:3939
double proll
roll [rad]
Definition: player.h:208
#define PLAYER_ACTARRAY_ACTSTATE_MOVING
Moving state code.
Definition: player_interfaces.h:3780
float * currents
The current for the motors of the whole array.
Definition: player_interfaces.h:3941
uint32_t top
Bounding box for the blob [pixels].
Definition: player_interfaces.h:1086
#define PLAYER_AUDIO_FREQ_44k
Data subtype: wav_rec_data, recorded data block.
Definition: player_interfaces.h:1441
float pan
Desired pan angle [rad].
Definition: player_interfaces.h:1251
#define PLAYER_ACTARRAY_TYPE_LINEAR
Linear type code.
Definition: player_interfaces.h:3787
player_actarray_actuator_t * actuators
The actuator data.
Definition: player_interfaces.h:3815
float current
The current to move with.
Definition: player_interfaces.h:3930
#define PLAYER_SONAR_REQ_GET_GEOM
Request/reply subtype: get geometry.
Definition: player_interfaces.h:755
Class for loading configuration file information.
Definition: configfile.h:195
virtual int Setup()
Initialize the driver.
Definition: driver.h:385
double pz
Z [m].
Definition: player.h:200
An autopointer for the message queue.
Definition: message.h:72
#define PLAYER_ACTARRAY_CMD_CURRENT
Idle state code.
Definition: player_interfaces.h:3768
#define PLAYER_PTZ_VELOCITY_CONTROL
Control mode, for use with PLAYER_PTZ_REQ_CONTROL_MODE.
Definition: player_interfaces.h:1219
#define PLAYER_ACTARRAY_CMD_POS
Idle state code.
Definition: player_interfaces.h:3753
#define PLAYER_ERROR1(msg, a)
Error message macros.
Definition: error.h:81
float config_speed
The configured speed setting of the actuator - different from current speed.
Definition: player_interfaces.h:3845
player_orientation_3d_t orientation
The orientation of this actuator when it is in its rest position.
Definition: player_interfaces.h:3832
uint32_t width
The image dimensions.
Definition: player_interfaces.h:1099
#define PLAYER_CAMERA_COMPRESS_RAW
Compression method: raw.
Definition: player_interfaces.h:2945
#define PLAYER_ERROR(msg)
Error message macros.
Definition: error.h:80
Base class for drivers which oeprate with a thread.
Definition: driver.h:551
uint32_t actuators_count
The number of actuators in the array.
Definition: player_interfaces.h:3813
#define PLAYER_PTZ_CMD_STATE
Command subtype: state.
Definition: player_interfaces.h:1214
#define PLAYER_ACTARRAY_REQ_GET_GEOM
Idle state code.
Definition: player_interfaces.h:3744
uint32_t format
Raw data format.
Definition: player_interfaces.h:1470
#define PLAYER_CAMERA_FORMAT_MONO8
Image format : 8-bit monochrome.
Definition: player_interfaces.h:2936
Data: state (PLAYER_WIFI_DATA_STATE)
Definition: player_interfaces.h:2247
player_blobfinder_blob_t * blobs
The list of blobs.
Definition: player_interfaces.h:1105
float min
The range of motion of the actuator, in m or rad depending on the type.
Definition: player_interfaces.h:3837
player_pose3d_t * poses
Pose of each sonar, in robot cs.
Definition: player_interfaces.h:790
uint32_t size
Size in bytes of the payload to follow.
Definition: player.h:173
Request/reply: Speed.
Definition: player_interfaces.h:3973
Actuator geometry.
Definition: player_interfaces.h:3821
int32_t joint
The joint/actuator to command.
Definition: player_interfaces.h:3897
#define PLAYER_AUDIO_STEREO
Stereo.
Definition: player_interfaces.h:1438
#define PLAYER_WARN(msg)
Warning message macros.
Definition: error.h:88
#define PLAYER_MSGTYPE_CMD
A command message.
Definition: player.h:98
Definition: localization/amcl/map/map.h:50
virtual int Shutdown()
Finalize the driver.
Definition: driver.h:392
double pyaw
yaw [rad]
Definition: player.h:212
Command: Joint home (PLAYER_ACTARRAY_CMD_HOME)
Definition: player_interfaces.h:3916
float position
The position of the actuator in m or rad depending on the type.
Definition: player_interfaces.h:3796
Base class for all drivers.
Definition: driver.h:107
Structure describing a single blob.
Definition: player_interfaces.h:1068
Command: Joint speed control (PLAYER_ACTARRAY_CMD_SPEED)
Definition: player_interfaces.h:3894
Command: Multiple Joint current control (PLAYER_ACTARRAY_CMD_MULTI_CURRENT)
Definition: player_interfaces.h:3936
uint32_t x
The blob centroid [pixels].
Definition: player_interfaces.h:1078
uint8_t * data
raw data
Definition: player_interfaces.h:1468
float length
The length of this actuator's link to the next actuator.
Definition: player_interfaces.h:3827
uint8_t hasbrakes
If the actuator has brakes or not.
Definition: player_interfaces.h:3847
Data: state (PLAYER_ACTARRAY_DATA_STATE)
Definition: player_interfaces.h:3810
#define PLAYER_PTZ_REQ_CONTROL_MODE
Request/reply subtype: control mode.
Definition: player_interfaces.h:1199
#define PLAYER_MSGQUEUE_DEFAULT_MAXLEN
Default maximum length for a message queue.
Definition: player.h:75
Data: Raw audio data.
Definition: player_interfaces.h:1463