logo

English

PCM Volume Control 구현 방법

by digipine posted Apr 13, 2022
?

Shortcut

PrevPrev Article

NextNext Article

Larger Font Smaller Font Up Down Go comment Print
?

Shortcut

PrevPrev Article

NextNext Article

Larger Font Smaller Font Up Down Go comment Print

각 샘플에 승수를 적용하여 PCM 오디오 스트림의 진폭을 조작할 수 있습니다. 각 버퍼(샘플 세트)를 PortAudio에 전달하기 직전에 이 작업을 수행할 수 있습니다. 다음과 같이 간단합니다.

float buffer[SAMPLES_PER_BUFFER];
const float volumeMultiplier = 0.2f;
for(int i = 0; i < SAMPLES_PER_BUFFER; ++i)
{
   buffer[i] *= volumeMultiplier;
}

그러나 비결은 승수를 계산하는 방법에 있습니다. 일반적으로 전체 신호 레벨을 절반으로 줄일 때까지 신호 레벨의 큰 변화를 느끼지 못할 것입니다 volumeMultiplier = 0.5f알다시피 인간의 귀는 볼륨 레벨의 변화를 선형적으로 감지하지 않고 대수적으로 감지합니다. 다음 링크는 이 개념을 설명하는 데 도움이 될 수 있습니다.

이 정보를 사용하면 위의 코드를 다음과 같이 변경할 수 있습니다.

float buffer[SAMPLES_PER_BUFFER];
//volume in dB 0db = unity gain, no attenuation, full amplitude signal
//           -20db = 10x attenuation, significantly more quiet
float volumeLevelDb = -6.f; //cut amplitude in half; same as 0.5 above
const float VOLUME_REFERENCE = 1.f;
const float volumeMultiplier = (VOLUME_REFERENCE * pow(10, (volumeLevelDb / 20.f);
for(int i = 0; i < SAMPLES_PER_BUFFER; ++i)
{
   buffer[i] *= volumeMultiplier;
}

목적상 이것은 중요하지 않을 수 있지만, 슬라이더 위젯과 같은 사용자 인터페이스에 volumeLevelDb 또는 volumeMultiplier 값을 첨부하면 차이가 분명해집니다.

이 알고리즘은 모든 데이터 유형에 적용할 수 있습니다.

TAG •

List of Articles
No. Subject Author Date Views
34 8SVX (8-Bit Sampled Voice) 오디오 파일 형식 lizard2019 2025.02.12 1
33 AMP의 설계 방식 - Class A 방식의 앰프 digipine 2017.11.02 1872
32 Any Pretty Girl - Rebekka Bakken Lyrics digipine 2024.08.21 529
31 De-emphasis 개념 정리 file digipine 2017.11.13 3234
30 DSD 2.8M DSF Sample Test Files digipine 2024.11.24 435
29 DSD 음악 파일에 관한 기술 정보 file digipine 2017.11.02 2235
28 FFMpeg에서 DOP (DSD-over-PCM) 구현 패치 엉뚱도마뱀 2018.12.20 4950
27 IFF (Interchange File Format) 파일 구조 lizard2019 2025.02.12 2
26 LDAC 코덱으로 블루투스 고음질 음원 재생 file digipine 2017.11.02 1486
25 OP AMP 기본 개념과 NE5532 자료 file digipine 2017.11.02 1391
24 OP Amp 타입과 종류 정리 digipine 2017.11.02 3744
23 OP Amp의 음색 정리 자료 1 digipine 2017.11.02 10552
» PCM Volume Control 구현 방법 digipine 2022.04.13 1581
21 Phono Amp DIY kit digipine 2023.10.31 1037
20 Sample mp3 files for test file digipine 2022.11.25 964
19 Semibreve DA10S DAC with XMOS 768kHz Oversampling 5 file lizard2019 2024.05.10 874
18 Summary of Sound Characteristics of Electrolytic Capacitors for Audio Tuning lizard2019 2024.12.05 509
17 Test mp3 music files file digipine 2021.01.24 1513
16 TEST용 동영상 모음 01 file digipine 2020.08.26 761
15 TEST용 동영상 모음 02 file digipine 2020.08.26 698
Board Pagination Prev 1 2 Next
/ 2