Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

ALSA: emu10k1: fix sample rates for E-MU cards at 44.1 kHz word clock

Now that we know the actual word clock, we can:
- Put the resulting rate into the hardware info
- At 44.1 kHz word clock shift the rate for the pitch calculations,
which presume a 48 kHz word clock

Signed-off-by: Oswald Buddenhagen <oswald.buddenhagen@gmx.de>
Link: https://lore.kernel.org/r/20230612191325.1315854-5-oswald.buddenhagen@gmx.de
Signed-off-by: Takashi Iwai <tiwai@suse.de>

authored by

Oswald Buddenhagen and committed by
Takashi Iwai
19b89d15 e73b597e

+56 -57
+1
include/sound/emu10k1.h
··· 1495 1495 unsigned short first_ptr; 1496 1496 snd_pcm_uframes_t resume_pos; 1497 1497 struct snd_util_memblk *memblk; 1498 + unsigned int pitch_target; 1498 1499 unsigned int start_addr; 1499 1500 unsigned int ccca_start_addr; 1500 1501 unsigned int capture_ipr; /* interrupt acknowledge mask */
+55 -57
sound/pci/emu10k1/emupcm.c
··· 195 195 } 196 196 } 197 197 198 + static void snd_emu10k1_constrain_capture_rates(struct snd_emu10k1 *emu, 199 + struct snd_pcm_runtime *runtime) 200 + { 201 + if (emu->card_capabilities->emu_model && 202 + emu->emu1010.word_clock == 44100) { 203 + // This also sets the rate constraint by deleting SNDRV_PCM_RATE_KNOT 204 + runtime->hw.rates = SNDRV_PCM_RATE_11025 | \ 205 + SNDRV_PCM_RATE_22050 | \ 206 + SNDRV_PCM_RATE_44100; 207 + runtime->hw.rate_min = 11025; 208 + runtime->hw.rate_max = 44100; 209 + return; 210 + } 211 + snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_RATE, 212 + &hw_constraints_capture_rates); 213 + } 214 + 215 + static void snd_emu1010_constrain_efx_rate(struct snd_emu10k1 *emu, 216 + struct snd_pcm_runtime *runtime) 217 + { 218 + int rate; 219 + 220 + rate = emu->emu1010.word_clock; 221 + runtime->hw.rate_min = runtime->hw.rate_max = rate; 222 + runtime->hw.rates = snd_pcm_rate_to_rate_bit(rate); 223 + } 224 + 198 225 static unsigned int emu10k1_calc_pitch_target(unsigned int rate) 199 226 { 200 227 unsigned int pitch_target; ··· 278 251 const unsigned char *send_routing, 279 252 const unsigned char *send_amount) 280 253 { 281 - struct snd_pcm_substream *substream = evoice->epcm->substream; 282 - struct snd_pcm_runtime *runtime = substream->runtime; 283 254 unsigned int silent_page; 284 255 int voice; 285 - unsigned int pitch_target; 286 256 287 257 voice = evoice->number; 288 258 289 - if (emu->card_capabilities->emu_model) 290 - pitch_target = PITCH_48000; /* Disable interpolators on emu1010 card */ 291 - else 292 - pitch_target = emu10k1_calc_pitch_target(runtime->rate); 293 259 silent_page = ((unsigned int)emu->silent_page.addr << emu->address_mode) | 294 260 (emu->address_mode ? MAP_PTI_MASK1 : MAP_PTI_MASK0); 295 261 snd_emu10k1_ptr_write_multiple(emu, voice, ··· 293 273 // Stereo slaves don't need to have the addresses set, but it doesn't hurt 294 274 DSL, end_addr | (send_amount[3] << 24), 295 275 PSST, start_addr | (send_amount[2] << 24), 296 - CCCA, emu10k1_select_interprom(pitch_target) | 276 + CCCA, emu10k1_select_interprom(evoice->epcm->pitch_target) | 297 277 (w_16 ? 0 : CCCA_8BITSELECT), 298 278 // Clear filter delay memory 299 279 Z1, 0, ··· 439 419 bool w_16 = snd_pcm_format_width(runtime->format) == 16; 440 420 bool stereo = runtime->channels == 2; 441 421 unsigned int start_addr, end_addr; 422 + unsigned int rate; 423 + 424 + rate = runtime->rate; 425 + if (emu->card_capabilities->emu_model && 426 + emu->emu1010.word_clock == 44100) 427 + rate = rate * 480 / 441; 428 + epcm->pitch_target = emu10k1_calc_pitch_target(rate); 442 429 443 430 start_addr = epcm->start_addr >> w_16; 444 431 end_addr = start_addr + runtime->period_size; ··· 469 442 unsigned int start_addr; 470 443 unsigned int extra_size, channel_size; 471 444 unsigned int i; 445 + 446 + epcm->pitch_target = PITCH_48000; 472 447 473 448 start_addr = epcm->start_addr >> 1; // 16-bit voices 474 449 ··· 555 526 epcm->capture_bs_val++; 556 527 } 557 528 if (epcm->type == CAPTURE_AC97ADC) { 529 + unsigned rate = runtime->rate; 530 + if (!(runtime->hw.rates & SNDRV_PCM_RATE_48000)) 531 + rate = rate * 480 / 441; 532 + 558 533 epcm->capture_cr_val = emu->audigy ? A_ADCCR_LCHANENABLE : ADCCR_LCHANENABLE; 559 534 if (runtime->channels > 1) 560 535 epcm->capture_cr_val |= emu->audigy ? A_ADCCR_RCHANENABLE : ADCCR_RCHANENABLE; 561 536 epcm->capture_cr_val |= emu->audigy ? 562 - snd_emu10k1_audigy_capture_rate_reg(runtime->rate) : 563 - snd_emu10k1_capture_rate_reg(runtime->rate); 537 + snd_emu10k1_audigy_capture_rate_reg(rate) : 538 + snd_emu10k1_capture_rate_reg(rate); 564 539 } 565 540 return 0; 566 541 } ··· 703 670 static void snd_emu10k1_playback_trigger_voice(struct snd_emu10k1 *emu, 704 671 struct snd_emu10k1_voice *evoice) 705 672 { 706 - struct snd_pcm_substream *substream; 707 - struct snd_pcm_runtime *runtime; 708 - unsigned int voice, pitch_target; 673 + unsigned int voice; 709 674 710 - substream = evoice->epcm->substream; 711 - runtime = substream->runtime; 712 675 voice = evoice->number; 713 - 714 - if (emu->card_capabilities->emu_model) 715 - pitch_target = PITCH_48000; /* Disable interpolators on emu1010 card */ 716 - else 717 - pitch_target = emu10k1_calc_pitch_target(runtime->rate); 718 - snd_emu10k1_playback_commit_pitch(emu, voice, pitch_target << 16); 676 + snd_emu10k1_playback_commit_pitch(emu, voice, evoice->epcm->pitch_target << 16); 719 677 } 720 678 721 679 static void snd_emu10k1_playback_stop_voice(struct snd_emu10k1 *emu, ··· 1067 1043 SNDRV_PCM_INFO_RESUME | 1068 1044 SNDRV_PCM_INFO_MMAP_VALID), 1069 1045 .formats = SNDRV_PCM_FMTBIT_S16_LE, 1070 - .rates = SNDRV_PCM_RATE_44100 | SNDRV_PCM_RATE_48000 | 1071 - SNDRV_PCM_RATE_88200 | SNDRV_PCM_RATE_96000 | 1072 - SNDRV_PCM_RATE_176400 | SNDRV_PCM_RATE_192000, 1073 - .rate_min = 44100, 1074 - .rate_max = 192000, 1046 + .rates = SNDRV_PCM_RATE_48000, 1047 + .rate_min = 48000, 1048 + .rate_max = 48000, 1075 1049 .channels_min = 1, 1076 1050 .channels_max = 16, 1077 1051 .buffer_bytes_max = (64*1024), ··· 1166 1144 runtime->private_data = epcm; 1167 1145 runtime->private_free = snd_emu10k1_pcm_free_substream; 1168 1146 runtime->hw = snd_emu10k1_efx_playback; 1147 + if (emu->card_capabilities->emu_model) 1148 + snd_emu1010_constrain_efx_rate(emu, runtime); 1169 1149 err = snd_emu10k1_playback_set_constraints(runtime); 1170 1150 if (err < 0) { 1171 1151 kfree(epcm); ··· 1209 1185 kfree(epcm); 1210 1186 return err; 1211 1187 } 1212 - if (emu->card_capabilities->emu_model && emu->emu1010.clock_source == 0) 1213 - sample_rate = 44100; 1188 + if (emu->card_capabilities->emu_model) 1189 + sample_rate = emu->emu1010.word_clock; 1214 1190 else 1215 1191 sample_rate = 48000; 1216 1192 err = snd_pcm_hw_rule_noresample(runtime, sample_rate); ··· 1260 1236 runtime->private_data = epcm; 1261 1237 runtime->private_free = snd_emu10k1_pcm_free_substream; 1262 1238 runtime->hw = snd_emu10k1_capture; 1239 + snd_emu10k1_constrain_capture_rates(emu, runtime); 1263 1240 snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_BUFFER_BYTES, 1264 1241 &hw_constraints_capture_buffer_sizes); 1265 1242 emu->capture_interrupt = snd_emu10k1_pcm_ac97adc_interrupt; 1266 1243 emu->pcm_capture_substream = substream; 1267 - snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_RATE, &hw_constraints_capture_rates); 1268 1244 return 0; 1269 1245 } 1270 1246 ··· 1337 1313 substream->runtime->private_data = epcm; 1338 1314 substream->runtime->private_free = snd_emu10k1_pcm_free_substream; 1339 1315 runtime->hw = snd_emu10k1_capture_efx; 1340 - runtime->hw.rates = SNDRV_PCM_RATE_48000; 1341 - runtime->hw.rate_min = runtime->hw.rate_max = 48000; 1342 1316 if (emu->card_capabilities->emu_model) { 1343 - /* TODO 1344 - * SNDRV_PCM_RATE_44100 | SNDRV_PCM_RATE_48000 | 1345 - * SNDRV_PCM_RATE_88200 | SNDRV_PCM_RATE_96000 | 1346 - * SNDRV_PCM_RATE_176400 | SNDRV_PCM_RATE_192000 1347 - * rate_min = 44100, 1348 - * rate_max = 192000, 1349 - * Need to add mixer control to fix sample rate 1350 - * 1317 + snd_emu1010_constrain_efx_rate(emu, runtime); 1318 + /* 1351 1319 * There are 32 mono channels of 16bits each. 1352 1320 * 24bit Audio uses 2x channels over 16bit, 1353 1321 * 96kHz uses 2x channels over 48kHz, ··· 1350 1334 * 1010rev2 and 1616(m) cards have double that, 1351 1335 * but we don't exceed 16 channels anyway. 1352 1336 */ 1353 - #if 1 1354 - switch (emu->emu1010.clock_source) { 1355 - case 0: 1356 - /* For 44.1kHz */ 1357 - runtime->hw.rates = SNDRV_PCM_RATE_44100; 1358 - runtime->hw.rate_min = runtime->hw.rate_max = 44100; 1359 - break; 1360 - case 1: 1361 - /* For 48kHz */ 1362 - runtime->hw.rates = SNDRV_PCM_RATE_48000; 1363 - runtime->hw.rate_min = runtime->hw.rate_max = 48000; 1364 - break; 1365 - } 1366 - #endif 1367 1337 #if 0 1368 1338 /* For 96kHz */ 1369 - runtime->hw.rates = SNDRV_PCM_RATE_96000; 1370 - runtime->hw.rate_min = runtime->hw.rate_max = 96000; 1371 1339 runtime->hw.channels_min = runtime->hw.channels_max = 4; 1372 1340 #endif 1373 1341 #if 0 1374 1342 /* For 192kHz */ 1375 - runtime->hw.rates = SNDRV_PCM_RATE_192000; 1376 - runtime->hw.rate_min = runtime->hw.rate_max = 192000; 1377 1343 runtime->hw.channels_min = runtime->hw.channels_max = 2; 1378 1344 #endif 1379 1345 runtime->hw.formats = SNDRV_PCM_FMTBIT_S32_LE;