libbladeRF: Added samples <-> bytes conversion routines
These will become the preferred method of performing such conversions in upcoming commits, where additional formats will be added.
This commit is contained in:
parent
7c0969a44d
commit
0f736c7625
2 changed files with 30 additions and 0 deletions
|
|
@ -58,6 +58,10 @@ struct bladerf_stream {
|
|||
void *backend_data;
|
||||
};
|
||||
|
||||
/* Get the number of bytes per stream buffer */
|
||||
static inline size_t async_stream_buf_bytes(struct bladerf_stream *s) {
|
||||
return samples_to_bytes(s->format, s->samples_per_buffer);
|
||||
}
|
||||
|
||||
int async_init_stream(struct bladerf_stream **stream,
|
||||
struct bladerf *dev,
|
||||
|
|
|
|||
|
|
@ -143,6 +143,32 @@ static inline size_t sc16q11_to_bytes(size_t n_samples)
|
|||
return n_samples * sample_size;
|
||||
}
|
||||
|
||||
/* Covert samples to bytes based upon the provided format */
|
||||
static inline size_t samples_to_bytes(bladerf_format format, size_t n)
|
||||
{
|
||||
switch (format) {
|
||||
case BLADERF_FORMAT_SC16_Q11:
|
||||
return sc16q11_to_bytes(n);
|
||||
|
||||
default:
|
||||
assert(!"Invalid format");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/* Convert bytes to samples based upon the provided format */
|
||||
static inline size_t bytes_to_samples(bladerf_format format, size_t n)
|
||||
{
|
||||
switch (format) {
|
||||
case BLADERF_FORMAT_SC16_Q11:
|
||||
return bytes_to_sc16q11(n);
|
||||
|
||||
default:
|
||||
assert(!"Invalid format");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize device registers - required after power-up, but safe
|
||||
* to call multiple times after power-up (e.g., multiple close and reopens)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue