Skip to content

Commit 04e8277

Browse files
committed
Rename "Sampling" to more common "Rate" term
In audio processing software the sampling frequency of recorded audio is mostly named as sample rate or simply "rate". On the other hand the sampling frequency is more scientific term. Since bluez-alsa is audio processing software, the term "rate" should fit better here. Also, it will align with ALSA nomenclature.
1 parent e3c3184 commit 04e8277

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+540
-531
lines changed

NEWS

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@ bluez-alsa v4.3.1 (2024-08-30)
1111
==============================
1212

1313
- fix crash when playing audio with more than 2 channels
14-
- fix AAC configuration selection for low sampling rates
14+
- fix AAC configuration selection for low sample rates
1515

1616
bluez-alsa v4.3.0 (2024-08-13)
1717
==============================
1818

1919
- optional support for Android 13 A2DP Opus codec
20-
- multi channels and sampling rates mode for ALSA PCM plug-in
20+
- multi channels and sample rates mode for ALSA PCM plug-in
2121
- bluealsa-aplay: fix volume synchronization on Raspberry Pi
2222

2323
bluez-alsa v4.2.0 (2024-05-11)

doc/bluealsa-aplay.1.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ OPTIONS
7878
Internally, **bluealsa-aplay** does not perform any audio transformations
7979
nor streams mixing. If multiple Bluetooth devices are connected it simply
8080
opens a new connection to the ALSA PCM device for each stream. Selected
81-
hardware parameters like sampling frequency and number of channels are
81+
hardware parameters like sample rate and number of channels are
8282
taken from the audio profile of a particular Bluetooth connection. Note,
8383
that each connection can have a different setup.
8484

doc/bluealsa-plugins.7.rst

+2-2
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,8 @@ PCM Parameters
7272
For the A2DP profile it is possible to also specify a "configuration" for
7373
the codec by appending the configuration as a hex string separated from the
7474
codec name by a colon. The bits responsible for the number of channels and
75-
the sampling frequency are set by the plugin with the respect to options
76-
provided by the user (channel mode and sampling frequency bits act as a
75+
the sample rate are set by the plugin with the respect to options
76+
provided by the user (channel mode and sample rate bits act as a
7777
mask). For example:
7878

7979
::

doc/bluealsactl.1.rst

+2-2
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ info *PCM_PATH*
9090
The list of available A2DP codecs requires BlueZ SEP support
9191
(BlueZ >= 5.52)
9292

93-
codec [-c NUM] [-s NUM] [--force] *PCM_PATH* [*CODEC*\ [:*CONFIG*]]
93+
codec [-c NUM] [-r NUM] [--force] *PCM_PATH* [*CODEC*\ [:*CONFIG*]]
9494
Get or set the Bluetooth codec used by the given PCM.
9595

9696
If *CODEC* is given, change the codec to be used by the given PCM. This
@@ -223,7 +223,7 @@ open [--hex] *PCM_PATH*
223223
Transfer raw audio frames to or from the given PCM. For sink PCMs
224224
the frames are read from standard input and written to the PCM. For
225225
source PCMs the frames are read from the PCM and written to standard
226-
output. The format, channels and sampling rate must match the properties
226+
output. The format, channels and sample rate must match the properties
227227
of the PCM, as no format conversions are performed by this tool.
228228

229229
With the **--hex** option, the data is read or written as hexadecimal

doc/bluealsad.8.rst

+6-6
Original file line numberDiff line numberDiff line change
@@ -142,9 +142,9 @@ OPTIONS
142142
Force monophonic sound for A2DP profile.
143143

144144
--a2dp-force-audio-cd
145-
Force 44.1 kHz sampling frequency for A2DP profile.
146-
Some Bluetooth devices can handle streams sampled at either 48kHz or
147-
44.1kHz, in which case they normally default to using 48kHz.
145+
Force 44.1 kHz sample rate for A2DP profile.
146+
Some Bluetooth devices can handle streams sampled at either 48 kHz or
147+
44.1kHz, in which case they normally default to using 48 kHz.
148148
With this option, **bluealsad** will request such a device uses only 44.1
149149
kHz sample rate.
150150

@@ -271,9 +271,9 @@ Profiles
271271
**bluealsad** provides support for Bluetooth Advanced Audio Distribution
272272
Profile (A2DP), Hands-Free Profile (HFP), Headset Profile (HSP) and Bluetooth
273273
Low Energy MIDI (BLE-MIDI).
274-
A2DP profile is dedicated for streaming music (i.e., stereo, 48 kHz or more
275-
sampling frequency), while HFP and HSP for two-way voice transmission (mono, 8
276-
kHz or 16 kHz sampling frequency). BLE-MIDI, on the other hand, is used for
274+
A2DP profile is dedicated for streaming music (i.e., stereo, 48 kHz or higher
275+
sample rates), while HFP and HSP for two-way voice transmission (mono, 8
276+
kHz or 16 kHz sample rate). BLE-MIDI, on the other hand, is used for
277277
transmitting MIDI messages over Bluetooth LE.
278278

279279
The Bluetooth audio profiles are not peer-to-peer; they each have a source or

doc/org.bluealsa.PCM1.7.rst

+10-10
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ org.bluealsa.PCM1
66
Bluetooth Audio PCM D-Bus API
77
-----------------------------
88

9-
:Date: August 2024
9+
:Date: September 2024
1010
:Manual section: 7
1111
:Manual group: D-Bus Interface
1212
:Version: $VERSION$
@@ -49,12 +49,12 @@ array{string, dict} GetCodecs()
4949

5050
:array{byte} Capabilities:
5151
A2DP codec capabilities blob.
52-
:array{byte} SupportedChannels:
53-
List of supported number of audio channels.
54-
:array{uint32} SupportedSampling:
55-
List of supported sampling frequency.
52+
:array{byte} Channels:
53+
List of supported channel counts.
5654
:array{array{string}} ChannelMaps:
5755
List of supported channel maps.
56+
:array{uint32} Rates:
57+
List of supported sample rates.
5858

5959
void SelectCodec(string codec, dict props)
6060
Select PCM codec. This call shall be made before PCM stream opening for
@@ -69,9 +69,9 @@ void SelectCodec(string codec, dict props)
6969
property to true.
7070

7171
In case of codecs which support different number of audio channels or
72-
sampling frequencies, client can select the desired configuration by
73-
providing the "Channels" and "Sampling" properties respectively. These
74-
properties take precedence over the provided codec configuration.
72+
sample rates, client can select the desired configuration by providing the
73+
"Channels" and "Rate" properties respectively. These properties take
74+
precedence over the provided codec configuration.
7575

7676
Possible Errors:
7777
::
@@ -150,8 +150,8 @@ byte Channels [readonly]
150150
array{string} ChannelMap [readonly]
151151
Channel map for selected codec.
152152

153-
uint32 Sampling [readonly]
154-
Sampling frequency.
153+
uint32 Rate [readonly]
154+
Sample rate in Hz.
155155

156156
string Codec [readonly]
157157
Bluetooth transport codec. This property is available only when transport

src/a2dp-aac.c

+24-24
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ static const struct a2dp_bit_mapping a2dp_aac_channels[] = {
7070
{ 0 }
7171
};
7272

73-
static const struct a2dp_bit_mapping a2dp_aac_samplings[] = {
73+
static const struct a2dp_bit_mapping a2dp_aac_rates[] = {
7474
{ AAC_SAMPLING_FREQ_8000, { 8000 } },
7575
{ AAC_SAMPLING_FREQ_11025, { 11025 } },
7676
{ AAC_SAMPLING_FREQ_12000, { 12000 } },
@@ -111,15 +111,15 @@ static int a2dp_aac_caps_foreach_channel_mode(
111111
return -1;
112112
}
113113

114-
static int a2dp_aac_caps_foreach_sampling_freq(
114+
static int a2dp_aac_caps_foreach_sample_rate(
115115
const void *capabilities,
116116
enum a2dp_stream stream,
117117
a2dp_bit_mapping_foreach_func func,
118118
void *userdata) {
119119
const a2dp_aac_t *caps = capabilities;
120120
if (stream == A2DP_MAIN) {
121121
const uint16_t sampling_freq = A2DP_AAC_GET_SAMPLING_FREQ(*caps);
122-
return a2dp_bit_mapping_foreach(a2dp_aac_samplings, sampling_freq, func, userdata);
122+
return a2dp_bit_mapping_foreach(a2dp_aac_rates, sampling_freq, func, userdata);
123123
}
124124
return -1;
125125
}
@@ -134,14 +134,14 @@ static void a2dp_aac_caps_select_channel_mode(
134134
caps->channel_mode, channels);
135135
}
136136

137-
static void a2dp_aac_caps_select_sampling_freq(
137+
static void a2dp_aac_caps_select_sample_rate(
138138
void *capabilities,
139139
enum a2dp_stream stream,
140-
unsigned int frequency) {
140+
unsigned int rate) {
141141
a2dp_aac_t *caps = capabilities;
142142
if (stream == A2DP_MAIN) {
143-
const uint16_t sampling_freq = a2dp_bit_mapping_lookup_value(a2dp_aac_samplings,
144-
A2DP_AAC_GET_SAMPLING_FREQ(*caps), frequency);
143+
const uint16_t sampling_freq = a2dp_bit_mapping_lookup_value(a2dp_aac_rates,
144+
A2DP_AAC_GET_SAMPLING_FREQ(*caps), rate);
145145
A2DP_AAC_SET_SAMPLING_FREQ(*caps, sampling_freq);
146146
}
147147
}
@@ -150,9 +150,9 @@ static struct a2dp_caps_helpers a2dp_aac_caps_helpers = {
150150
.intersect = a2dp_aac_caps_intersect,
151151
.has_stream = a2dp_caps_has_main_stream_only,
152152
.foreach_channel_mode = a2dp_aac_caps_foreach_channel_mode,
153-
.foreach_sampling_freq = a2dp_aac_caps_foreach_sampling_freq,
153+
.foreach_sample_rate = a2dp_aac_caps_foreach_sample_rate,
154154
.select_channel_mode = a2dp_aac_caps_select_channel_mode,
155-
.select_sampling_freq = a2dp_aac_caps_select_sampling_freq,
155+
.select_sample_rate = a2dp_aac_caps_select_sample_rate,
156156
};
157157

158158
static unsigned int a2dp_aac_get_fdk_vbr_mode(
@@ -185,7 +185,7 @@ void *a2dp_aac_enc_thread(struct ba_transport_pcm *t_pcm) {
185185
const a2dp_aac_t *configuration = &t->a2dp.configuration.aac;
186186
const unsigned int bitrate = A2DP_AAC_GET_BITRATE(*configuration);
187187
const unsigned int channels = t_pcm->channels;
188-
const unsigned int samplerate = t_pcm->sampling;
188+
const unsigned int rate = t_pcm->rate;
189189

190190
/* create AAC encoder without the Meta Data module */
191191
if ((err = aacEncOpen(&handle, 0x0F, channels)) != AACENC_OK) {
@@ -255,8 +255,8 @@ void *a2dp_aac_enc_thread(struct ba_transport_pcm *t_pcm) {
255255
}
256256
}
257257
#endif
258-
if ((err = aacEncoder_SetParam(handle, AACENC_SAMPLERATE, samplerate)) != AACENC_OK) {
259-
error("Couldn't set sampling rate: %s", aacenc_strerror(err));
258+
if ((err = aacEncoder_SetParam(handle, AACENC_SAMPLERATE, rate)) != AACENC_OK) {
259+
error("Couldn't set sample rate: %s", aacenc_strerror(err));
260260
goto fail_init;
261261
}
262262
if ((err = aacEncoder_SetParam(handle, AACENC_CHANNELMODE, channel_mode)) != AACENC_OK) {
@@ -317,7 +317,7 @@ void *a2dp_aac_enc_thread(struct ba_transport_pcm *t_pcm) {
317317

318318
struct rtp_state rtp = { .synced = false };
319319
/* RTP clock frequency equal to 90kHz */
320-
rtp_state_init(&rtp, samplerate, 90000);
320+
rtp_state_init(&rtp, rate, 90000);
321321

322322
int in_bufferIdentifiers[] = { IN_AUDIO_DATA };
323323
int out_bufferIdentifiers[] = { OUT_BITSTREAM_DATA };
@@ -459,7 +459,7 @@ void *a2dp_aac_dec_thread(struct ba_transport_pcm *t_pcm) {
459459
pthread_cleanup_push(PTHREAD_CLEANUP(aacDecoder_Close), handle);
460460

461461
const unsigned int channels = t_pcm->channels;
462-
const unsigned int samplerate = t_pcm->sampling;
462+
const unsigned int rate = t_pcm->rate;
463463

464464
#ifdef AACDECODER_LIB_VL0
465465
if ((err = aacDecoder_SetParam(handle, AAC_PCM_MIN_OUTPUT_CHANNELS, channels)) != AAC_DEC_OK) {
@@ -493,7 +493,7 @@ void *a2dp_aac_dec_thread(struct ba_transport_pcm *t_pcm) {
493493

494494
struct rtp_state rtp = { .synced = false };
495495
/* RTP clock frequency equal to 90kHz */
496-
rtp_state_init(&rtp, samplerate, 90000);
496+
rtp_state_init(&rtp, rate, 90000);
497497

498498
int markbit_quirk = -3;
499499

@@ -614,11 +614,11 @@ static int a2dp_aac_configuration_select(
614614
}
615615

616616
unsigned int sampling_freq = 0;
617-
if (a2dp_aac_caps_foreach_sampling_freq(caps, A2DP_MAIN,
618-
a2dp_bit_mapping_foreach_get_best_sampling_freq, &sampling_freq) != -1)
617+
if (a2dp_aac_caps_foreach_sample_rate(caps, A2DP_MAIN,
618+
a2dp_bit_mapping_foreach_get_best_sample_rate, &sampling_freq) != -1)
619619
A2DP_AAC_SET_SAMPLING_FREQ(*caps, sampling_freq);
620620
else {
621-
error("AAC: No supported sampling frequencies: %#x", A2DP_AAC_GET_SAMPLING_FREQ(saved));
621+
error("AAC: No supported sample rates: %#x", A2DP_AAC_GET_SAMPLING_FREQ(saved));
622622
return errno = ENOTSUP, -1;
623623
}
624624

@@ -692,9 +692,9 @@ static int a2dp_aac_configuration_check(
692692
}
693693

694694
const uint16_t conf_sampling_freq = A2DP_AAC_GET_SAMPLING_FREQ(conf_v);
695-
if (a2dp_bit_mapping_lookup(a2dp_aac_samplings, conf_sampling_freq) == -1) {
696-
debug("AAC: Invalid sampling frequency: %#x", A2DP_AAC_GET_SAMPLING_FREQ(*conf));
697-
return A2DP_CHECK_ERR_SAMPLING;
695+
if (a2dp_bit_mapping_lookup(a2dp_aac_rates, conf_sampling_freq) == -1) {
696+
debug("AAC: Invalid sample rate: %#x", A2DP_AAC_GET_SAMPLING_FREQ(*conf));
697+
return A2DP_CHECK_ERR_RATE;
698698
}
699699

700700
if (a2dp_bit_mapping_lookup(a2dp_aac_channels, conf_v.channel_mode) == -1) {
@@ -712,14 +712,14 @@ static int a2dp_aac_transport_init(struct ba_transport *t) {
712712
t->a2dp.configuration.aac.channel_mode)) == -1)
713713
return -1;
714714

715-
ssize_t sampling_i;
716-
if ((sampling_i = a2dp_bit_mapping_lookup(a2dp_aac_samplings,
715+
ssize_t rate_i;
716+
if ((rate_i = a2dp_bit_mapping_lookup(a2dp_aac_rates,
717717
A2DP_AAC_GET_SAMPLING_FREQ(t->a2dp.configuration.aac))) == -1)
718718
return -1;
719719

720720
t->a2dp.pcm.format = BA_TRANSPORT_PCM_FORMAT_S16_2LE;
721721
t->a2dp.pcm.channels = a2dp_aac_channels[channels_i].value;
722-
t->a2dp.pcm.sampling = a2dp_aac_samplings[sampling_i].value;
722+
t->a2dp.pcm.rate = a2dp_aac_rates[rate_i].value;
723723

724724
memcpy(t->a2dp.pcm.channel_map, a2dp_aac_channels[channels_i].ch.map,
725725
t->a2dp.pcm.channels * sizeof(*t->a2dp.pcm.channel_map));

0 commit comments

Comments
 (0)