Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Audio playback and capture library written in C, in a single source file.

License

NotificationsYou must be signed in to change notification settings

mackron/miniaudio

miniaudio

An audio playback and capture library in a single source file.

discordx

Features -Examples -Building -Documentation -Supported Platforms -Security -License

miniaudio is written in C with no dependencies except the standard library and should compile clean on all majorcompilers without the need to install any additional development packages. All major desktop and mobile platformsare supported.

Features

  • Simple build system with no external dependencies.
  • Simple and flexible API.
  • Low-level API for direct access to raw audio data.
  • High-level API for sound management, mixing, effects and optional 3D spatialization.
  • Flexible node graph system for advanced mixing and effect processing.
  • Resource management for loading sound files.
  • Decoding, with built-in support for WAV, FLAC, and MP3, in addition to being able to plug in custom decoders.
  • Encoding (WAV only).
  • Data conversion.
  • Resampling, including custom resamplers.
  • Channel mapping.
  • Basic generation of waveforms and noise.
  • Basic effects and filters.

Refer to theProgramming Manual for a more complete description ofavailable features in miniaudio.

Examples

This example shows one way to play a sound using the high level API.

#include"miniaudio/miniaudio.h"#include<stdio.h>intmain(){ma_resultresult;ma_engineengine;result=ma_engine_init(NULL,&engine);if (result!=MA_SUCCESS) {return-1;    }ma_engine_play_sound(&engine,"sound.wav",NULL);printf("Press Enter to quit...");getchar();ma_engine_uninit(&engine);return0;}

This example shows how to decode and play a sound using the low level API.

#include"miniaudio/miniaudio.h"#include<stdio.h>voiddata_callback(ma_device*pDevice,void*pOutput,constvoid*pInput,ma_uint32frameCount){ma_decoder*pDecoder= (ma_decoder*)pDevice->pUserData;if (pDecoder==NULL) {return;    }ma_decoder_read_pcm_frames(pDecoder,pOutput,frameCount,NULL);    (void)pInput;}intmain(intargc,char**argv){ma_resultresult;ma_decoderdecoder;ma_device_configdeviceConfig;ma_devicedevice;if (argc<2) {printf("No input file.\n");return-1;    }result=ma_decoder_init_file(argv[1],NULL,&decoder);if (result!=MA_SUCCESS) {return-2;    }deviceConfig=ma_device_config_init(ma_device_type_playback);deviceConfig.playback.format=decoder.outputFormat;deviceConfig.playback.channels=decoder.outputChannels;deviceConfig.sampleRate=decoder.outputSampleRate;deviceConfig.dataCallback=data_callback;deviceConfig.pUserData=&decoder;if (ma_device_init(NULL,&deviceConfig,&device)!=MA_SUCCESS) {printf("Failed to open playback device.\n");ma_decoder_uninit(&decoder);return-3;    }if (ma_device_start(&device)!=MA_SUCCESS) {printf("Failed to start playback device.\n");ma_device_uninit(&device);ma_decoder_uninit(&decoder);return-4;    }printf("Press Enter to quit...");getchar();ma_device_uninit(&device);ma_decoder_uninit(&decoder);return0;}

More examples can be found in theexamples folder or online here:https://miniaud.io/docs/examples/

Building

Just compile miniaudio.c like any other source file and include miniaudio.h like a normal header. There's no needto install any dependencies. On Windows and macOS there's no need to link to anything. On Linux and BSD just linkto-lpthread and-lm. On iOS you need to compile as Objective-C. Link to-ldl if you get errors aboutdlopen(), etc.

If you get errors about undefined references to__sync_val_compare_and_swap_8,__atomic_load_8, etc. youneed to link with-latomic.

ABI compatibility is not guaranteed between versions so take care if compiling as a DLL/SO. The suggested wayto integrate miniaudio is by adding it directly to your source tree.

You can also use CMake if that's your preference.

Documentation

Online documentation can be found here:https://miniaud.io/docs/

Documentation can also be found at the top ofminiaudio.hwhich is always the most up-to-date and authoritative source of information on how to use miniaudio. All otherdocumentation is generated from this in-code documentation.

Supported Platforms

  • Windows
  • macOS, iOS
  • Linux
  • FreeBSD / OpenBSD / NetBSD
  • Android
  • Raspberry Pi
  • Emscripten / HTML5

miniaudio should compile clean on other platforms, but it will not include any support for playback or captureby default. To support that, you would need to implement a custom backend. You can do this without needing tomodify the miniaudio source code. See thecustom_backend example.

Backends

  • WASAPI
  • DirectSound
  • WinMM
  • Core Audio (Apple)
  • ALSA
  • PulseAudio
  • JACK
  • sndio (OpenBSD)
  • audio(4) (NetBSD and OpenBSD)
  • OSS (FreeBSD)
  • AAudio (Android 8.0+)
  • OpenSL|ES (Android only)
  • Web Audio (Emscripten)
  • Null (Silence)
  • Custom

Security

See the miniaudiosecurity policy.

License

Your choice of either public domain orMIT No Attribution.

About

Audio playback and capture library written in C, in a single source file.

Topics

Resources

License

Code of conduct

Contributing

Security policy

Stars

Watchers

Forks

Sponsor this project

 

Contributors82


[8]ページ先頭

©2009-2026 Movatter.jp