Changeset b1dfe13 in mainline
- Timestamp:
- 2013-04-10T19:08:09Z (12 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 8a7d78cc
- Parents:
- a8e87da
- Location:
- uspace/lib/pcm
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/pcm/include/pcm/format.h
ra8e87da rb1dfe13 41 41 #include <pcm/sample_format.h> 42 42 43 /** Linear PCM audio parameters */ 43 44 typedef struct { 44 45 unsigned channels; … … 50 51 extern const pcm_format_t AUDIO_FORMAT_ANY; 51 52 53 /** 54 * Frame size helper function. 55 * @param a pointer to a PCM format structure. 56 * @return Size in bytes. 57 */ 52 58 static inline size_t pcm_format_frame_size(const pcm_format_t *a) 53 59 { … … 55 61 } 56 62 63 /** 64 * Convert byte size to frame count. 65 * @param size Byte-size. 66 * @param a pointer to a PCM format structure. 67 * @return Frame count. 68 */ 57 69 static inline size_t pcm_format_size_to_frames(size_t size, 58 70 const pcm_format_t *a) … … 62 74 } 63 75 64 static inline suseconds_t pcm_format_size_to_usec(size_t size, 76 /** 77 * Convert byte size to audio playback time. 78 * @param size Byte-size. 79 * @param a pointer to a PCM format structure. 80 * @return Number of microseconds. 81 */ 82 static inline useconds_t pcm_format_size_to_usec(size_t size, 65 83 const pcm_format_t *a) 66 84 { … … 70 88 71 89 bool pcm_format_same(const pcm_format_t *a, const pcm_format_t* b); 90 91 /** 92 * Helper function, compares with ANY metaformat. 93 * @param f pointer to format structure. 94 * @return True if @p f points to ANY format, false otherwise. 95 */ 72 96 static inline bool pcm_format_is_any(const pcm_format_t *f) 73 97 { -
uspace/lib/pcm/include/pcm/sample_format.h
ra8e87da rb1dfe13 40 40 #include <time.h> 41 41 42 /** Known and supported PCM sample formats */ 42 43 typedef enum { 43 44 PCM_SAMPLE_UINT8, … … 63 64 } pcm_sample_format_t; 64 65 66 /** 67 * Query if the format uses signed values. 68 * @param format PCM sample format. 69 * @return True if the format uses signed values, false otherwise. 70 */ 65 71 static inline bool pcm_sample_format_is_signed(pcm_sample_format_t format) 66 72 { … … 91 97 } 92 98 99 /** 100 * Query byte-size of samples. 101 * @param format PCM sample format. 102 * @return Size in bytes of a single sample. 103 */ 93 104 static inline size_t pcm_sample_format_size(pcm_sample_format_t format) 94 105 { … … 122 133 } 123 134 135 /** 136 * Query sie of the entire frame. 137 * @param channels Number of samples in every frame. 138 * @param format PCM sample format. 139 * @return Size in bytes. 140 */ 124 141 static inline size_t pcm_sample_format_frame_size(unsigned channels, 125 142 pcm_sample_format_t format) … … 128 145 } 129 146 147 /** 148 * Count number of frames that fit into a buffer (even incomplete frames). 149 * @param size Size of the buffer. 150 * @param channels Number of samples in every frame. 151 * @param format PCM sample format. 152 * @return Number of frames (even incomplete). 153 */ 130 154 static inline size_t pcm_sample_format_size_to_frames(size_t size, 131 155 unsigned channels, pcm_sample_format_t format) … … 135 159 } 136 160 161 /** 162 * Convert byte size to time. 163 * @param size Size of the buffer. 164 * @param sample_rate Samples per second. 165 * @param channels Number of samples in every frame. 166 * @param format PCM sample format. 167 * @return Number of useconds of audio data. 168 */ 137 169 static inline useconds_t pcm_sample_format_size_to_usec(size_t size, 138 170 unsigned sample_rate, unsigned channels, pcm_sample_format_t format) 139 171 { 140 const long long frames =172 const unsigned long long frames = 141 173 pcm_sample_format_size_to_frames(size, channels, format); 142 174 return (frames * 1000000ULL) / sample_rate; 143 175 } 144 176 177 /** 178 * Get readable name of a sample format. 179 * @param format PCM sample format. 180 * @return Valid string representation. 181 */ 145 182 static inline const char * pcm_sample_format_str(pcm_sample_format_t format) 146 183 { -
uspace/lib/pcm/src/format.c
ra8e87da rb1dfe13 75 75 #define to(x, type, endian) (float)(host2 ## type ## _ ## endian(x)) 76 76 77 /** Default linear PCM format */ 77 78 const pcm_format_t AUDIO_FORMAT_DEFAULT = { 78 79 .channels = 2, … … 81 82 }; 82 83 84 /** Special ANY PCM format. 85 * This format is used if the real format is no know or important. 86 */ 83 87 const pcm_format_t AUDIO_FORMAT_ANY = { 84 88 .channels = 0,
Note:
See TracChangeset
for help on using the changeset viewer.