{"id":13652194,"url":"https://github.com/adamstark/AudioFile","last_synced_at":"2025-04-23T03:30:43.554Z","repository":{"id":37735205,"uuid":"80625394","full_name":"adamstark/AudioFile","owner":"adamstark","description":"A simple C++ library for reading and writing audio files.","archived":false,"fork":false,"pushed_at":"2024-11-18T20:58:12.000Z","size":31046,"stargazers_count":973,"open_issues_count":1,"forks_count":203,"subscribers_count":20,"default_branch":"master","last_synced_at":"2024-12-06T21:05:10.844Z","etag":null,"topics":["aif","audio","audio-files","audio-formats","file-format","read","wav","write"],"latest_commit_sha":null,"homepage":"","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/adamstark.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-02-01T14:02:23.000Z","updated_at":"2024-12-05T18:18:21.000Z","dependencies_parsed_at":"2024-01-31T09:01:11.729Z","dependency_job_id":"50df7ffb-62af-4933-b134-8bf936d6d47c","html_url":"https://github.com/adamstark/AudioFile","commit_stats":null,"previous_names":[],"tags_count":13,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/adamstark%2FAudioFile","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/adamstark%2FAudioFile/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/adamstark%2FAudioFile/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/adamstark%2FAudioFile/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/adamstark","download_url":"https://codeload.github.com/adamstark/AudioFile/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250365241,"owners_count":21418651,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["aif","audio","audio-files","audio-formats","file-format","read","wav","write"],"created_at":"2024-08-02T02:00:56.888Z","updated_at":"2025-04-23T03:30:38.540Z","avatar_url":"https://github.com/adamstark.png","language":"C++","readme":"# AudioFile\n\n\u003c!-- Version and License Badges --\u003e\n![Version](https://img.shields.io/badge/version-1.1.1-green.svg?style=flat-square) \n![License](https://img.shields.io/badge/license-MIT-blue.svg?style=flat-square) \n![Language](https://img.shields.io/badge/language-C++-yellow.svg?style=flat-square) \n\nA simple header-only C++ library for reading and writing audio files. \n\nCurrent supported formats:\n\n* WAV\n* AIFF\n\nAuthor\n------\n\nAudioFile is written and maintained by Adam Stark.\n\n[http://www.adamstark.co.uk](http://www.adamstark.co.uk)\n\nUsage\n-----\n\n### Create an AudioFile object:\n\n\t#include \"AudioFile.h\"\n\n\tAudioFile\u003cdouble\u003e audioFile;\n\t\t\n### Load an audio file:\n\n\taudioFile.load (\"/path/to/my/audiofile.wav\");\n\t\n### Get some information about the loaded audio:\n\n\tint sampleRate = audioFile.getSampleRate();\n\tint bitDepth = audioFile.getBitDepth();\n\t\n\tint numSamples = audioFile.getNumSamplesPerChannel();\n\tdouble lengthInSeconds = audioFile.getLengthInSeconds();\n\t\n\tint numChannels = audioFile.getNumChannels();\n\tbool isMono = audioFile.isMono();\n\tbool isStereo = audioFile.isStereo();\n\t\n\t// or, just use this quick shortcut to print a summary to the console\n\taudioFile.printSummary();\n\t\n### Access the samples directly:\n\n\tint channel = 0;\n\tint numSamples = audioFile.getNumSamplesPerChannel();\n\n\tfor (int i = 0; i \u003c numSamples; i++)\n\t{\n\t\tdouble currentSample = audioFile.samples[channel][i];\n\t}\n\n### Replace the AudioFile audio buffer with another\n\n\t// 1. Create an AudioBuffer \n\t// (BTW, AudioBuffer is just a vector of vectors)\n\t\n\tAudioFile\u003cdouble\u003e::AudioBuffer buffer;\n\t\n\t// 2. Set to (e.g.) two channels\n\tbuffer.resize (2);\n\t\n\t// 3. Set number of samples per channel\n\tbuffer[0].resize (100000);\n\tbuffer[1].resize (100000);\n\t\n\t// 4. do something here to fill the buffer with samples, e.g.\n\t\n\t#include \u003cmath.h\u003e // somewhere earler (for M_PI and sinf())\n\t\n\t// then...\n\t\n\tint numChannels = 2;\n\tint numSamplesPerChannel = 100000;\n\tfloat sampleRate = 44100.f;\n\tfloat frequency = 440.f;\n\n\tfor (int i = 0; i \u003c numSamplesPerChannel; i++)\n\t{\n        float sample = sinf (2. * M_PI * ((float) i / sampleRate) * frequency) ;\n        \n        for (int channel = 0; channel \u003c numChannels; channel++)\n             buffer[channel][i] = sample * 0.5;\n\t}\n\t\n\t// 5. Put into the AudioFile object\n\tbool ok = audioFile.setAudioBuffer (buffer);\n\t\n\t\n### Resize the audio buffer\t\n\n\t// Set both the number of channels and number of samples per channel\n\taudioFile.setAudioBufferSize (numChannels, numSamples);\n\t\n\t// Set the number of samples per channel\n\taudioFile.setNumSamplesPerChannel (numSamples);\n\t\n\t// Set the number of channels\n\taudioFile.setNumChannels (numChannels);\n\t\n### Set bit depth and sample rate\n\t\n\taudioFile.setBitDepth (24);\n\taudioFile.setSampleRate (44100);\n\t\n### Save the audio file to disk\n\t\n\t// Wave file (implicit)\n\taudioFile.save (\"path/to/desired/audioFile.wav\");\n\t\n\t// Wave file (explicit)\n\taudioFile.save (\"path/to/desired/audioFile.wav\", AudioFileFormat::Wave);\n\t\n\t// Aiff file\n\taudioFile.save (\"path/to/desired/audioFile.aif\", AudioFileFormat::Aiff);\n\n\nExamples\n-----------------\n\nPlease see the `examples` folder for some examples on library usage. \n\n\nA Note On Types\n-----------------\n\nAudioFile is a template class and so it can be instantiated using floating point precision:\n\nFor example\n\n\tAudioFile\u003cfloat\u003e audioFile;\n\n...or double precision...\n\n\tAudioFile\u003cdouble\u003e audioFile;\n\t\n...or an integer type:\n\n\tAudioFile\u003cint\u003e audioFile;\t\n\t\nThis simply reflects the data type you would like to use to store the underlying audio samples. \n\nWhen you use an integer type to store the samples (e.g. `int` or `int8_t` or `int16_t` or `uint32_t`), the library will read in the integer sample values directly from the audio file. A couple of notes on integer types:\n\n* The range of samples is designed to be symmetric. This means that for (e.g.) an signed 8-bit integer (`int8_t`) we will use the range `[-127, 127]` for storing samples representing the `[-1., 1.]` range. The value `-128` is possible here given the `int8_t` type, but this is interpreted as a value slightly lower than `-1` (specifically `-1.007874015748`).\n\n* In the case of unsigned types, we obviously can't store samples as negative values. Therefore, we used the equivalent range of the unsigned type in use. E.g. if with a 8-bit signed integer (`int8_t`) the range would be `[-127, 127]`, for an 8-bit unsigned integer we would use the range `[1, 255]`. Note that we don't use `-128` for `int8_t` or `0` in `uint8_t`.\n\n* If you try to read an audio file with a larger bit-depth than the type you are using to store samples, the attempt to read the file will fail. Put more simply, you can't read a 16-bit audio file into an 8-bit integer.\n\n* If you are writing audio samples in integer formats, you should use the correct sample range for both a) the type you are using to store samples; and b) the bit depth of the audio you want to write.\n\nThe following table details the sample range for each bit-depth:\n\n| Type  | 8-bit Audio | 16-bit Audio | 24-bit Audio | 32-bit Audio |\n| ------------- | ------------- | ------------- | ------------- | ------------- |\n| `float` | `[-1.0, 1.0]` | `[-1.0, 1.0]` | `[-1.0, 1.0]` | `[-1.0, 1.0]` |\n| `double` | `[-1.0, 1.0]` | `[-1.0, 1.0]` | `[-1.0, 1.0]` | `[-1.0, 1.0]` |\n| `int8_t` | `[-127, 127]` | :x: (type too small) | :x: (type too small) | :x: (type too small) |\n| `uint8_t` | `[1, 255]` | :x: (type too small) | :x: (type too small) | :x: (type too small) |\n| `int16_t` | `[-127, 127]` | `[-32767, 32767]` | :x: (type too small) | :x: (type too small) |\n| `uint16_t` | `[1, 255]` | `[1, 65535]` | :x: (type too small) | :x: (type too small) |\n| `int32_t` | `[-127, 127]` | `[-32767, 32767]` | [`-8388607, 8388607]`  | `[-2147483647, 2147483647]` |\n| `uint32_t` | `[1, 255]` | `[1, 65535]` | `[1, 16777215]` | `[1, 4294967295]` |\n| `int64_t` | `[-127, 127]` | `[-32767, 32767]` | [`-8388607, 8388607]`  | `[-2147483647, 2147483647]` |\n| `uint64_t` | `[1, 255]` | `[1, 65535]` | `[1, 16777215]` | `[1, 4294967295]` |\n\nError Messages\n-----------------\n\nBy default, the library logs error messages to the console to provide information on what has gone wrong (e.g. a file we tried to load didn't exist). \n\nIf you prefer not to see these messages, you can disable this error logging behaviour using:\n\n\taudioFile.shouldLogErrorsToConsole (false);\n\n\nVersions\n-------\n\n##### 1.1.1 - 4th April 2023\n\n- Support for integer formats\n- Improved unit testing\n- Many bug fixes\n\n##### 1.1.0 - 15th January 2022\n\n- Moved project to MIT licence\n- Added option to load an audio file already in memory\n- CI Workflow improvements and bug fixes\n\n##### 1.0.9 - 23rd January 2021\n\n- Faster loading of audio files\n- Bug fixes\n\n##### 1.0.8 - 18th October 2020\n\n- CMake support\n- Construct instances with a file path\n- Bug fixes\n\n##### 1.0.7 - 3rd July 2020\n\n- Support for 32-bit audio files\n- Support for multi-channel audio files\n- Reading/writing of [iXML data chunks](http://www.ixml.info/)\n\n##### 1.0.6 - 29th February 2020\n\n- Made error logging to the console optional\n- Fixed lots of compiler warnings \n\n##### 1.0.5 - 14th October 2019\n\n- Added include of \u003calgorithm\u003e to better support Visual Studio\n\n##### 1.0.4 - 13th October 2019\n\n- Changed to a header-only library. Now you can just include AudioFile.h\n- Bug fixes\n\n##### 1.0.3 - 28th October 2018\n\n- Bug fixes\n- Documentation updates\n\n##### 1.0.2 - 6th June 2017\n\n- Bug fixes\n\nContributions\n-------\n\nMany thanks to the following people for their contributions to this library:\n\n* [Abhinav1997](https://github.com/Abhinav1997)\n* [alxarsenault](https://github.com/alxarsenault)\n* [BenjaminHinchliff](https://github.com/BenjaminHinchliff)\n* [emiro85](https://github.com/emiro85)\n* [heartofrain](https://github.com/heartofrain)\n* [helloimmatt](https://github.com/helloimmatt/)\n* [MatthieuHernandez](https://github.com/MatthieuHernandez)\n* [mrpossoms](https://github.com/mrpossoms)\n* [mynameisjohn](https://github.com/mynameisjohn)\n* [Sidelobe](https://github.com/Sidelobe)\n* [sschaetz](https://github.com/sschaetz)\n* [Yhcrown](https://github.com/Yhcrown)\n\nWant to Contribute?\n-------\n\nIf you would like to submit a pull request for this library, please do! But kindly follow the following simple guidelines...\n\n* Make the changes as concise as is possible for the change you are proposing\n* Avoid unnecessarily changing a large number of lines - e.g. commits changing the number of spaces in indentations on all lines (and so on)\n* Keep to the code style of this library which is the [JUCE Coding Standards](https://juce.com/discover/stories/coding-standards)\n* Make the changes relative to the develop branch of the library (as this may have advanced beyond the master branch)\n\nLicense\n-------\n\nMIT License\n\nCopyright (c) 2017 Adam Stark\n\nPermission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n","funding_links":[],"categories":["Audio","Uncategorized","C++"],"sub_categories":["Uncategorized"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fadamstark%2FAudioFile","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fadamstark%2FAudioFile","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fadamstark%2FAudioFile/lists"}