Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Audio Fundamentals - Basics
Search
Chinmay Pendharkar
May 10, 2013
Technology
0
87
Audio Fundamentals - Basics
Slides for a workshop on audio fundamentals.
Chinmay Pendharkar
May 10, 2013
Tweet
Share
More Decks by Chinmay Pendharkar
See All by Chinmay Pendharkar
Audio Fundamentals - Pd
notthetup
0
72
DNSSEC and Bind
notthetup
1
110
Garageband And Podcasting
notthetup
0
38
Audio Fundamentals - HTML5 Audio
notthetup
0
91
Audio Fundamentals - Oscillators
notthetup
0
47
Robots and Pi
notthetup
2
120
Auralization of road vehicles using spectral modeling synthesis
notthetup
0
150
What I’ve learnt about Environmental Sound Design
notthetup
0
190
Audio Editing with Audacity
notthetup
0
47
Other Decks in Technology
See All in Technology
2025/1/29 BigData-JAWS 勉強会 #28 (re:Invent 2024 re:Cap)/new-feature-preview-q-in-quicksight-scenarios-tried-and-tested
emiki
0
310
信頼性を支えるテレメトリーパイプラインの構築 / Building Telemetry Pipeline with OpenTelemetry
ymotongpoo
9
5k
AIエージェントについてまとめてみた
pharma_x_tech
12
8.6k
消し忘れリソースゼロへ!私のResource Explorer活用法
cuorain
0
140
Microsoft Ignite 2024 最新情報!Microsoft 365 Agents SDK 概要 / Microsoft Ignite 2024 latest news Microsoft 365 Agents SDK overview
karamem0
0
190
SREとしてスタッフエンジニアを目指す / SRE Kaigi 2025
tjun
15
6.5k
HCP TerraformとAzure:イオンスマートテクノロジーのインフラ革新 / HCP Terraform and Azure AEON Smart Technology's Infrastructure Innovation
aeonpeople
3
990
extensionとschema
yahonda
1
100
Site Reliability Engineering on Kubernetes
nwiizo
6
4.4k
エラーバジェット枯渇の原因 - 偽陽性との戦い -
phaya72
1
100
Windows Server 2025 へのアップグレードではまった話
tamaiyutaro
2
260
Tech Blog執筆のモチベート向上作戦
imamura_ko_0314
0
740
Featured
See All Featured
It's Worth the Effort
3n
184
28k
Site-Speed That Sticks
csswizardry
3
310
Writing Fast Ruby
sferik
628
61k
Visualization
eitanlees
146
15k
BBQ
matthewcrist
85
9.4k
Measuring & Analyzing Core Web Vitals
bluesmoon
6
220
Templates, Plugins, & Blocks: Oh My! Creating the theme that thinks of everything
marktimemedia
28
2.2k
Designing Dashboards & Data Visualisations in Web Apps
destraynor
231
52k
YesSQL, Process and Tooling at Scale
rocio
171
14k
Code Reviewing Like a Champion
maltzj
521
39k
The World Runs on Bad Software
bkeepers
PRO
67
11k
Code Review Best Practice
trishagee
65
17k
Transcript
Audio Fundamentals Chinmay Pendharkar, Sonoport, 2013
None
Sound Waves
Analog vs Digital Audio
Analog vs Digital Audio
Digitization
Digitization - Why? • Easier to manipulate digital audio •
Easier to store digital audio • Easier to transport digital audio • Get back perfect original analog audio
Digital Audio Analog Audio Analog - Digital Conversion Digital -
Analog Conversion Digital Audio
Sampling Frequency
Sampling Frequency
Sampling Theorem
Sampling Theorem
Sampling Theorem 2 x (Max Frequency of Content) ≤ Sampling
Frequency for perfect reconstruction of analog signal from digital
Sampling Frequency 2 x (Max Frequency of Content) ≤ Sampling
Frequency. 2 x ( 20000 Hz ) ≤ 44100 Hz . Upper Limit of Human Hearing
Sampling • Sampling Frequency > 44100 : Oversampling • Sampling
Frequency < 44100 : Undersampling • 44100Hz => ◦ 44100 samples per second ◦ 44100 data points per second • Less computation vs Audio Fidelity
Quantization / Bit Depth uint_16
Quantization 0x0000 (0) 0xFFFF (65535) 96dBFS ~ 120dB Human Hearing
Range 65535 65534 65533 65532 0
Digital Audio Discretization of Time - Sampling Discretization of Amplitude
- Quantization
Digital Audio Common Formats: Sampling Rate : 44100 Hz Bit
Depth : 16 bits Sampling Rate : 192000 Hz Bit Depth : 24 bits "CD Audio" "Mastering Quality"
Digital Audio Formats • Uncompressed ◦ AIFF ◦ WAV •
Compressed (Lossless) ◦ FLAC ◦ ALAC • Compressed (Lossy) ◦ MP3 ◦ AAC
Real Time Audio on PC/Mac
Audio Stacks Audio Hardware Drivers Operating System Audio API User
Program/Application
Audio Stack - Windows
Audio Stack - OSX/iOS
Audio Stack - Linux
Audio Stack - Android
Audio Stacks Audio Hardware Drivers Operating System Audio API User
Program/Application
Audio Stack Audio Hardware DAC Digital Analog Converter
Audio Stacks 44.1kHz / 16bits ~= 172 kB per second
DAC Digital Data Buffer "Magic" OS
DAC Schemes DAC Digital Data Buffer #1 OS Digital Data
Buffer #2 "Magic" 1s
Buffer Size - Latency • Time taken = Max time
to fill next buffer • Time taken = Min time to new sound output Stereo = 2 channels
Buffer Size - Latency Ideally we want.... • Fill up
next buffer well before current is fully output. (No clicks/silence) • Have no delay between audio being sent to the OS and output. (No buffering)
Buffer Size - Latency Typical Buffer Sizes • 256 *
2 * 2 = 1024 bytes = 5.8ms latency • 512 *2 * 2 = 2048 byes = 11.6ms latency • 1024 * 2 * 2 = 4096 byes = 23.2ms latency Assuming 2 channel stereo and 16bit depth
Callback vs R/W IO Two common schemes for audio drivers.
• Read-Write • Callback
Read-Write • Direct R/W access to "digital data buffer". •
Blocking • PaError Pa_WriteStream ( PaStream * stream, void * buffer, long frames ) • PaError Pa_ReadStream ( PaStream * stream, void * buffer, long frames )
Callback • Callback when more data is needed. • Non-Blocking
• PaError Pa_OpenStream (PaStream ** stream, ... , double sampleRate, long framesPerBuffer, ... ,PaStreamCallback * streamCallback, void * userData) • typedef int PaStreamCallback(const void *input, void *output, unsigned long frameCount, ... , void *userData)
Read-Write Example - C // From http://portaudio.com/docs/v19-doxydocs/blocking_read_write.html err = Pa_Initialize();
if( err != paNoError ) goto error; /* --SKIPPED-- -- Initalize Variables -- --SKIPPED-- */ /* -- setup stream -- */ err = Pa_OpenStream( &stream, &inputParameters,&outputParameters, SAMPLE_RATE,FRAMES_PER_BUFFER, paClipOff, NULL, /* no callback, use blocking API */ NULL ); /* no callback, so no callback userData */ /* -- start stream -- */ err = Pa_StartStream( stream ); printf("Wire on. Will run one minute.\n"); fflush(stdout);
Read-Write Example - C /* -- Here's the loop where
we pass data from input to output -- */ for( i=0; i<(60*SAMPLE_RATE)/FRAMES_PER_BUFFER; ++i ) { err = Pa_WriteStream( stream, sampleBlock, FRAMES_PER_BUFFER ); err = Pa_ReadStream( stream, sampleBlock, FRAMES_PER_BUFFER ); } /* -- Now we stop the stream -- */ err = Pa_StopStream( stream ); /* -- don't forget to cleanup! -- */ err = Pa_CloseStream( stream ); Pa_Terminate(); return 0; }
Callback Example - C // http://portaudio.com/docs/v19-doxydocs/paex__sine_8c_source.html err = Pa_Initialize(); if(
err != paNoError ) goto error; err = Pa_OpenStream( &stream,NULL,&outputParameters, SAMPLE_RATE, FRAMES_PER_BUFFER, paClipOff, patestCallback, &data ); if( err != paNoError ) goto error; printf("Setup Done\n"); err = Pa_SetStreamFinishedCallback( stream, &StreamFinished ); err = Pa_StartStream( stream ); printf("Play for %d seconds.\n", NUM_SECONDS ); Pa_Sleep( NUM_SECONDS * 1000 ); err = Pa_StopStream( stream ); err = Pa_CloseStream( stream ); Pa_Terminate(); return err;
Callback Example - C static int patestCallback( const void *inputBuffer,
void *outputBuffer, unsigned long framesPerBuffer, const PaStreamCallbackTimeInfo* timeInfo, PaStreamCallbackFlags statusFlags, void *userData ) { for( i=0; i<framesPerBuffer; i++ ){ *out++ = data->sine[data->left_phase]; /* left */ *out++ = data->sine[data->right_phase]; /* right */ data->left_phase += 1; if( data->left_phase >= TABLE_SIZE ) data->left_phase -= TABLE_SIZE; data->right_phase += 3; if( data->right_phase >= TABLE_SIZE ) data->right_phase -= TABLE_SIZE; } return paContinue; }
Callback Example - AS3 var mySound:Sound = new Sound(); function
sineWaveGenerator(event:SampleDataEvent):void { for ( var c:int=0; c<8192; c++ ) { event.data.writeFloat(Math.sin((Number(c+event. position)/Math.PI/2))*0.25); event.data.writeFloat(Math.sin((Number(c+event. position)/Math.PI/2))*0.25); } } mySound.addEventListener(SampleDataEvent.SAMPLE_DATA, sineWaveGenerator); mySound.play();
Hands On