Installing stb_vorbis Library Установка библиотеки stb_vorbis
A step-by-step guide to downloading and configuring the single-file stb_vorbis.c (v1.22) Ogg Vorbis audio decoding library on Windows and Ubuntu.
Пошаговое руководство по скачиванию и настройке однофайловой библиотеки декодирования Ogg Vorbis аудио stb_vorbis.c (v1.22) в Windows и Ubuntu.
Step 1: Download Source Code Шаг 1: Скачивание исходного кода
Download the single-file stb_vorbis.c (version v1.22) directly from the official Sean Barrett (nothings) repository on GitHub:
Скачайте однофайловую библиотеку stb_vorbis.c (версия v1.22) напрямую из официального репозитория Sean Barrett (nothings) на GitHub:
View stb_vorbis.c on GitHub Открыть stb_vorbis.c на GitHub Direct Download stb_vorbis.c Прямое скачивание stb_vorbis.c
For Ubuntu, you can download it directly via wget in the terminal:
В Ubuntu вы можете скачать файл напрямую с помощью wget через терминал:
sudo apt update && sudo apt install -y wget
mkdir -p ~/libs/stb_vorbis-1.22
wget https://raw.githubusercontent.com/nothings/stb/master/stb_vorbis.c -O ~/libs/stb_vorbis-1.22/stb_vorbis.c
Step 2: Place the Library File Шаг 2: Размещение файла библиотеки
Option A: Windows Вариант A: Windows
Save the downloaded stb_vorbis.c file so that it is located in:
Сохраните скачанный файл stb_vorbis.c так, чтобы он находился по пути:
C:\libs\stb_vorbis-1.22\stb_vorbis.c
Option B: Ubuntu Вариант B: Ubuntu
Ensure the file is located in your user's ~/libs directory:
Убедитесь, что файл расположен в папке ~/libs пользователя:
~/libs/stb_vorbis-1.22/stb_vorbis.c
Step 3: Create Project Directory Шаг 3: Создание директории проекта
Create a workspace folder and a new directory for your stb_vorbis test project: Создайте рабочую папку и новую директорию для вашего тестового проекта stb_vorbis:
Windows (Command Prompt / PowerShell)
mkdir C:\projects\stb-vorbis-test
cd C:\projects\stb-vorbis-test
Ubuntu (Terminal)
mkdir -p ~/projects/stb-vorbis-test
cd ~/projects/stb-vorbis-test
Step 4: Create Source Files (main.c & CMakeLists.txt) Шаг 4: Создание исходных файлов (main.c и CMakeLists.txt)
Windows (Terminal / Notepad)
notepad main.c
notepad CMakeLists.txt
Ubuntu (Terminal / Nano)
nano main.c
nano CMakeLists.txt
1. File Contents for main.c 1. Содержимое файла main.c
#include <stdio.h>
#include <stb_vorbis.c>
int main(int argc, char *argv[]) {
printf("stb_vorbis (Ogg Vorbis audio decoder) v1.22 loaded successfully!\n");
// Perform verification test using in-memory decoder API
int error = 0;
stb_vorbis* v = stb_vorbis_open_memory(NULL, 0, &error, NULL);
if (v == NULL && error == VORBIS_need_more_data) {
printf("stb_vorbis decoder test passed (expected VORBIS_need_more_data on empty buffer).\n");
} else {
printf("stb_vorbis audio decoder initialized!\n");
}
return 0;
}
2. File Contents for CMakeLists.txt 2. Содержимое файла CMakeLists.txt
cmake_minimum_required(VERSION 3.21)
project(stb_vorbis_test C)
add_executable(app main.c)
if(WIN32)
target_include_directories(app PRIVATE C:/libs/stb_vorbis-1.22)
else()
# On Linux, find stb_vorbis in ~/libs
target_include_directories(app PRIVATE $ENV{HOME}/libs/stb_vorbis-1.22)
# Link standard math library (-lm) required by stb_vorbis
target_link_libraries(app PRIVATE m)
endif()
Step 5: Create Build & Execution Scripts Шаг 5: Создание скриптов сборки и запуска
Windows (MinGW / Batch Scripts)
config-win.bat
cmake -G Ninja -S . -B dist/win
build-win.bat
cmake --build dist/win
run-win.bat
@echo off
.\dist\win\app.exe
Run the scripts sequentially in Command Prompt or PowerShell: Последовательно запустите скрипты в командной строке или PowerShell:
config-win.bat
build-win.bat
run-win.bat
Ubuntu (Bash Scripts)
config-linux.sh
#!/usr/bin/env bash
set -e
cmake -G Ninja -S . -B dist/linux
build-linux.sh
#!/usr/bin/env bash
set -e
cmake --build dist/linux
run-linux.sh
#!/usr/bin/env bash
set -e
./dist/linux/app
Grant execute permissions on Ubuntu before running: Предоставьте права на выполнение в Ubuntu перед запуском:
chmod +x config-linux.sh build-linux.sh run-linux.sh
./config-linux.sh
./build-linux.sh
./run-linux.sh
Step 6: Expected Output Шаг 6: Ожидаемый результат
When launched, the application compiles the single-file decoder and outputs verification messages to your terminal: При запуске приложение компилирует однофайловый декодер и выводит проверочные сообщения в терминал:
stb_vorbis (Ogg Vorbis audio decoder) v1.22 loaded successfully!
stb_vorbis decoder test passed (expected VORBIS_need_more_data on empty buffer).
Support My Work Поддержать проект
If these tutorials helped you, consider buying me a coffee! Если эти туториалы вам помогли, вы можете поддержать автора.
Sberbank (Russia only) Сбербанк (только для РФ)
Direct transfer via phone number (Russia only) Перевод по номеру телефона (только для РФ)
USDT TRC20
Support via Cryptocurrency Поддержка криптовалютой