Upsamples an MP3 audio clip from 44.1 KHz to 48 KHz using AVBlocks Transcoder with hardcoded input and output file paths.
This sample demonstrates the basic AVBlocks audio upsampling workflow:
- Initialize the AVBlocks library
- Create a
MediaInfoobject to probe the input file - Create an input
MediaSocketfrom the probed media info - Clone the input socket to start with an identical output configuration
- Set the output sample rate to 48000 Hz on the output audio pin
- Configure a
Transcoderwith the input and output sockets - Run the transcode operation
No command line parsing is used -- the input and output file paths are hardcoded in the source code.
From the repository root:
mkdir -Force -Path build\debug_x64
cd build\debug_x64
cmake -G 'Ninja' -DCMAKE_BUILD_TYPE=debug -DPLATFORM=x64 ../../samples
ninjaThe built executable will be placed in bin\x64\simple_audio_upsample.exe.
-
Download the sample audio, the
kahvi011_kennybeltrey-hydrate.mp3song from the Internet Archive (MPEG Audio Layer 3, 44.1 KHz, Joint Stereo):Invoke-WebRequest -Uri https://archive.org/download/kahvi011/kahvi011_kennybeltrey-hydrate.mp3 -OutFile kahvi011_kennybeltrey-hydrate.mp3
-
Run the sample from the sample directory (the input/output file paths are relative to the working directory):
cd samples\windows\simple_audio_upsample ..\..\..\bin\x64\simple_audio_upsample.exe -
The upsampled output file
kahvi011_kennybeltrey-hydrate_48Khz.mp3will be created in thesamples\windows\simple_audio_upsampledirectory.
- The input file
kahvi011_kennybeltrey-hydrate.mp3and output filekahvi011_kennybeltrey-hydrate_48Khz.mp3paths are hardcoded insimple_audio_upsample.cpp. They are relative to the working directory from which the executable is run. - If
transcoder->open()fails, it may be becausekahvi011_kennybeltrey-hydrate_48Khz.mp3already exists in the directory. Delete the output file and try again. - The output audio stream is resampled from 44.1 KHz to 48 KHz using AVBlocks' polyphase resampling method.