HelenOS sources
This source file includes following definitions.
- pcm_sample_format_is_signed
- pcm_sample_format_size
- pcm_sample_format_frame_size
- pcm_sample_format_size_to_frames
- pcm_sample_format_size_to_usec
- pcm_sample_format_str
#ifndef PCM_SAMPLE_FORMAT_H_
#define PCM_SAMPLE_FORMAT_H_
#include <stdbool.h>
#include <time.h>
typedef enum {
PCM_SAMPLE_UINT8,
PCM_SAMPLE_SINT8,
PCM_SAMPLE_UINT16_LE,
PCM_SAMPLE_UINT16_BE,
PCM_SAMPLE_SINT16_LE,
PCM_SAMPLE_SINT16_BE,
PCM_SAMPLE_UINT24_LE,
PCM_SAMPLE_UINT24_BE,
PCM_SAMPLE_SINT24_LE,
PCM_SAMPLE_SINT24_BE,
PCM_SAMPLE_UINT24_32_LE,
PCM_SAMPLE_UINT24_32_BE,
PCM_SAMPLE_SINT24_32_LE,
PCM_SAMPLE_SINT24_32_BE,
PCM_SAMPLE_UINT32_LE,
PCM_SAMPLE_UINT32_BE,
PCM_SAMPLE_SINT32_LE,
PCM_SAMPLE_SINT32_BE,
PCM_SAMPLE_FLOAT32,
PCM_SAMPLE_FORMAT_LAST = PCM_SAMPLE_FLOAT32,
} pcm_sample_format_t;
static inline bool pcm_sample_format_is_signed(pcm_sample_format_t format)
{
switch (format) {
case PCM_SAMPLE_SINT8:
case PCM_SAMPLE_SINT16_LE:
case PCM_SAMPLE_SINT16_BE:
case PCM_SAMPLE_SINT24_LE:
case PCM_SAMPLE_SINT24_BE:
case PCM_SAMPLE_SINT24_32_LE:
case PCM_SAMPLE_SINT24_32_BE:
case PCM_SAMPLE_SINT32_LE:
case PCM_SAMPLE_SINT32_BE:
return true;
case PCM_SAMPLE_UINT8:
case PCM_SAMPLE_UINT16_LE:
case PCM_SAMPLE_UINT16_BE:
case PCM_SAMPLE_UINT24_LE:
case PCM_SAMPLE_UINT24_BE:
case PCM_SAMPLE_UINT24_32_LE:
case PCM_SAMPLE_UINT24_32_BE:
case PCM_SAMPLE_UINT32_LE:
case PCM_SAMPLE_UINT32_BE:
case PCM_SAMPLE_FLOAT32:
default:
return false;
}
}
static inline size_t pcm_sample_format_size(pcm_sample_format_t format)
{
switch (format) {
case PCM_SAMPLE_UINT8:
case PCM_SAMPLE_SINT8:
return 1;
case PCM_SAMPLE_UINT16_LE:
case PCM_SAMPLE_UINT16_BE:
case PCM_SAMPLE_SINT16_LE:
case PCM_SAMPLE_SINT16_BE:
return 2;
case PCM_SAMPLE_UINT24_LE:
case PCM_SAMPLE_UINT24_BE:
case PCM_SAMPLE_SINT24_LE:
case PCM_SAMPLE_SINT24_BE:
return 3;
case PCM_SAMPLE_UINT24_32_LE:
case PCM_SAMPLE_UINT24_32_BE:
case PCM_SAMPLE_SINT24_32_LE:
case PCM_SAMPLE_SINT24_32_BE:
case PCM_SAMPLE_UINT32_LE:
case PCM_SAMPLE_UINT32_BE:
case PCM_SAMPLE_SINT32_LE:
case PCM_SAMPLE_SINT32_BE:
case PCM_SAMPLE_FLOAT32:
return 4;
default:
return 0;
}
}
static inline size_t pcm_sample_format_frame_size(unsigned channels,
pcm_sample_format_t format)
{
return pcm_sample_format_size(format) * channels;
}
static inline size_t pcm_sample_format_size_to_frames(size_t size,
unsigned channels, pcm_sample_format_t format)
{
const size_t frame_size = pcm_sample_format_frame_size(channels, format);
return (size + frame_size - 1) / frame_size;
}
static inline usec_t pcm_sample_format_size_to_usec(size_t size,
unsigned sample_rate, unsigned channels, pcm_sample_format_t format)
{
const unsigned long long frames =
pcm_sample_format_size_to_frames(size, channels, format);
return (frames * 1000000ULL) / sample_rate;
}
static inline const char *pcm_sample_format_str(pcm_sample_format_t format)
{
switch (format) {
case PCM_SAMPLE_UINT8:
return "8 bit unsigned";
case PCM_SAMPLE_SINT8:
return "8 bit signed";
case PCM_SAMPLE_UINT16_LE:
return "16 bit unsigned(LE)";
case PCM_SAMPLE_SINT16_LE:
return "16 bit signed(LE)";
case PCM_SAMPLE_UINT16_BE:
return "16 bit unsigned(BE)";
case PCM_SAMPLE_SINT16_BE:
return "16 bit signed(BE)";
case PCM_SAMPLE_UINT24_LE:
return "24 bit unsigned(LE)";
case PCM_SAMPLE_SINT24_LE:
return "24 bit signed(LE)";
case PCM_SAMPLE_UINT24_BE:
return "24 bit unsigned(BE)";
case PCM_SAMPLE_SINT24_BE:
return "24 bit signed(BE)";
case PCM_SAMPLE_UINT24_32_LE:
return "24 bit(4byte aligned) unsigned(LE)";
case PCM_SAMPLE_UINT24_32_BE:
return "24 bit(4byte aligned) unsigned(BE)";
case PCM_SAMPLE_SINT24_32_LE:
return "24 bit(4byte aligned) signed(LE)";
case PCM_SAMPLE_SINT24_32_BE:
return "24 bit(4byte aligned) signed(BE)";
case PCM_SAMPLE_UINT32_LE:
return "32 bit unsigned(LE)";
case PCM_SAMPLE_UINT32_BE:
return "32 bit unsigned(BE)";
case PCM_SAMPLE_SINT32_LE:
return "32 bit signed(LE)";
case PCM_SAMPLE_SINT32_BE:
return "32 bit signed(BE)";
case PCM_SAMPLE_FLOAT32:
return "32 bit float";
default:
return "Unknown sample format";
}
}
#endif
HelenOS homepage, sources at GitHub