Skip to content

Commit 1713396

Browse files
committed
Merge tag '1.1.2' into develop
2 parents 98b3c89 + 3d899f5 commit 1713396

File tree

2 files changed

+150
-151
lines changed

2 files changed

+150
-151
lines changed

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#===============================================================================
22
cmake_minimum_required (VERSION 3.12)
33

4-
project ("AudioFile" VERSION 1.1.1
4+
project ("AudioFile" VERSION 1.1.2
55
DESCRIPTION "A simple C++ library for reading and writing audio files."
66
HOMEPAGE_URL "https://github.com/adamstark/AudioFile")
77

README.md

Lines changed: 149 additions & 150 deletions
Original file line numberDiff line numberDiff line change
@@ -1,191 +1,189 @@
11
# AudioFile
22

33
<!-- Version and License Badges -->
4-
![Version](https://img.shields.io/badge/version-1.1.1-green.svg?style=flat-square)
5-
![License](https://img.shields.io/badge/license-MIT-blue.svg?style=flat-square)
6-
![Language](https://img.shields.io/badge/language-C++-yellow.svg?style=flat-square)
74

8-
A simple header-only C++ library for reading and writing audio files.
5+
![Version](https://img.shields.io/badge/version-1.1.2-green.svg?style=flat-square)
6+
![License](https://img.shields.io/badge/license-MIT-blue.svg?style=flat-square)
7+
![Language](https://img.shields.io/badge/language-C++-yellow.svg?style=flat-square)
8+
9+
A simple header-only C++ library for reading and writing audio files.
910

1011
Current supported formats:
1112

12-
* WAV
13-
* AIFF
13+
- WAV
14+
- AIFF
1415

15-
Author
16-
------
16+
## Author
1717

1818
AudioFile is written and maintained by Adam Stark.
1919

2020
[http://www.adamstark.co.uk](http://www.adamstark.co.uk)
2121

22-
Usage
23-
-----
22+
## Usage
2423

2524
### Create an AudioFile object:
2625

27-
#include "AudioFile.h"
26+
#include "AudioFile.h"
27+
28+
AudioFile<double> audioFile;
2829

29-
AudioFile<double> audioFile;
30-
3130
### Load an audio file:
3231

33-
audioFile.load ("/path/to/my/audiofile.wav");
34-
32+
audioFile.load ("/path/to/my/audiofile.wav");
33+
3534
### Get some information about the loaded audio:
3635

37-
int sampleRate = audioFile.getSampleRate();
38-
int bitDepth = audioFile.getBitDepth();
39-
40-
int numSamples = audioFile.getNumSamplesPerChannel();
41-
double lengthInSeconds = audioFile.getLengthInSeconds();
42-
43-
int numChannels = audioFile.getNumChannels();
44-
bool isMono = audioFile.isMono();
45-
bool isStereo = audioFile.isStereo();
46-
47-
// or, just use this quick shortcut to print a summary to the console
48-
audioFile.printSummary();
49-
36+
int sampleRate = audioFile.getSampleRate();
37+
int bitDepth = audioFile.getBitDepth();
38+
39+
int numSamples = audioFile.getNumSamplesPerChannel();
40+
double lengthInSeconds = audioFile.getLengthInSeconds();
41+
42+
int numChannels = audioFile.getNumChannels();
43+
bool isMono = audioFile.isMono();
44+
bool isStereo = audioFile.isStereo();
45+
46+
// or, just use this quick shortcut to print a summary to the console
47+
audioFile.printSummary();
48+
5049
### Access the samples directly:
5150

52-
int channel = 0;
53-
int numSamples = audioFile.getNumSamplesPerChannel();
51+
int channel = 0;
52+
int numSamples = audioFile.getNumSamplesPerChannel();
5453

55-
for (int i = 0; i < numSamples; i++)
56-
{
57-
double currentSample = audioFile.samples[channel][i];
58-
}
54+
for (int i = 0; i < numSamples; i++)
55+
{
56+
double currentSample = audioFile.samples[channel][i];
57+
}
5958

6059
### Replace the AudioFile audio buffer with another
6160

62-
// 1. Create an AudioBuffer
63-
// (BTW, AudioBuffer is just a vector of vectors)
64-
65-
AudioFile<double>::AudioBuffer buffer;
66-
67-
// 2. Set to (e.g.) two channels
68-
buffer.resize (2);
69-
70-
// 3. Set number of samples per channel
71-
buffer[0].resize (100000);
72-
buffer[1].resize (100000);
73-
74-
// 4. do something here to fill the buffer with samples, e.g.
75-
76-
#include <math.h> // somewhere earler (for M_PI and sinf())
77-
78-
// then...
79-
80-
int numChannels = 2;
81-
int numSamplesPerChannel = 100000;
82-
float sampleRate = 44100.f;
83-
float frequency = 440.f;
84-
85-
for (int i = 0; i < numSamplesPerChannel; i++)
86-
{
61+
// 1. Create an AudioBuffer
62+
// (BTW, AudioBuffer is just a vector of vectors)
63+
64+
AudioFile<double>::AudioBuffer buffer;
65+
66+
// 2. Set to (e.g.) two channels
67+
buffer.resize (2);
68+
69+
// 3. Set number of samples per channel
70+
buffer[0].resize (100000);
71+
buffer[1].resize (100000);
72+
73+
// 4. do something here to fill the buffer with samples, e.g.
74+
75+
#include <math.h> // somewhere earler (for M_PI and sinf())
76+
77+
// then...
78+
79+
int numChannels = 2;
80+
int numSamplesPerChannel = 100000;
81+
float sampleRate = 44100.f;
82+
float frequency = 440.f;
83+
84+
for (int i = 0; i < numSamplesPerChannel; i++)
85+
{
8786
float sample = sinf (2. * M_PI * ((float) i / sampleRate) * frequency) ;
88-
87+
8988
for (int channel = 0; channel < numChannels; channel++)
9089
buffer[channel][i] = sample * 0.5;
91-
}
92-
93-
// 5. Put into the AudioFile object
94-
bool ok = audioFile.setAudioBuffer (buffer);
95-
96-
97-
### Resize the audio buffer
98-
99-
// Set both the number of channels and number of samples per channel
100-
audioFile.setAudioBufferSize (numChannels, numSamples);
101-
102-
// Set the number of samples per channel
103-
audioFile.setNumSamplesPerChannel (numSamples);
104-
105-
// Set the number of channels
106-
audioFile.setNumChannels (numChannels);
107-
90+
}
91+
92+
// 5. Put into the AudioFile object
93+
bool ok = audioFile.setAudioBuffer (buffer);
94+
95+
### Resize the audio buffer
96+
97+
// Set both the number of channels and number of samples per channel
98+
audioFile.setAudioBufferSize (numChannels, numSamples);
99+
100+
// Set the number of samples per channel
101+
audioFile.setNumSamplesPerChannel (numSamples);
102+
103+
// Set the number of channels
104+
audioFile.setNumChannels (numChannels);
105+
108106
### Set bit depth and sample rate
109-
110-
audioFile.setBitDepth (24);
111-
audioFile.setSampleRate (44100);
112-
107+
108+
audioFile.setBitDepth (24);
109+
audioFile.setSampleRate (44100);
110+
113111
### Save the audio file to disk
114-
115-
// Wave file (implicit)
116-
audioFile.save ("path/to/desired/audioFile.wav");
117-
118-
// Wave file (explicit)
119-
audioFile.save ("path/to/desired/audioFile.wav", AudioFileFormat::Wave);
120-
121-
// Aiff file
122-
audioFile.save ("path/to/desired/audioFile.aif", AudioFileFormat::Aiff);
123112

113+
// Wave file (implicit)
114+
audioFile.save ("path/to/desired/audioFile.wav");
115+
116+
// Wave file (explicit)
117+
audioFile.save ("path/to/desired/audioFile.wav", AudioFileFormat::Wave);
124118

125-
Examples
126-
-----------------
119+
// Aiff file
120+
audioFile.save ("path/to/desired/audioFile.aif", AudioFileFormat::Aiff);
127121

128-
Please see the `examples` folder for some examples on library usage.
122+
## Examples
129123

124+
Please see the `examples` folder for some examples on library usage.
130125

131-
A Note On Types
132-
-----------------
126+
## A Note On Types
133127

134128
AudioFile is a template class and so it can be instantiated using different types to represent the audio samples.
135129

136130
For example, we can use floating point precision...
137131

138-
AudioFile<float> audioFile;
132+
AudioFile<float> audioFile;
139133

140134
...or double precision...
141135

142-
AudioFile<double> audioFile;
143-
136+
AudioFile<double> audioFile;
137+
144138
...or an integer type:
145139

146-
AudioFile<int> audioFile;
147-
148-
This simply reflects the data type you would like to use to store the underlying audio samples.
140+
AudioFile<int> audioFile;
141+
142+
This simply reflects the data type you would like to use to store the underlying audio samples.
149143

150-
When 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.
144+
When 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.
151145

152146
A couple of notes on integer types:
153147

154-
* 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`).
148+
- 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`).
155149

156-
* 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`.
150+
- 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`.
157151

158-
* 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 sample into an 8-bit integer.
152+
- 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 sample into an 8-bit integer.
159153

160-
* 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.
154+
- 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.
161155

162156
The following table details the sample range for each bit-depth:
163157

164-
| Type | 8-bit Audio | 16-bit Audio | 24-bit Audio | 32-bit Audio |
165-
| ------------- | ------------- | ------------- | ------------- | ------------- |
166-
| `float` | `[-1.0, 1.0]` | `[-1.0, 1.0]` | `[-1.0, 1.0]` | `[-1.0, 1.0]` |
167-
| `double` | `[-1.0, 1.0]` | `[-1.0, 1.0]` | `[-1.0, 1.0]` | `[-1.0, 1.0]` |
168-
| `int8_t` | `[-127, 127]` | :x: (type too small) | :x: (type too small) | :x: (type too small) |
169-
| `uint8_t` | `[1, 255]` | :x: (type too small) | :x: (type too small) | :x: (type too small) |
170-
| `int16_t` | `[-127, 127]` | `[-32767, 32767]` | :x: (type too small) | :x: (type too small) |
171-
| `uint16_t` | `[1, 255]` | `[1, 65535]` | :x: (type too small) | :x: (type too small) |
172-
| `int32_t` | `[-127, 127]` | `[-32767, 32767]` | [`-8388607, 8388607]` | `[-2147483647, 2147483647]` |
173-
| `uint32_t` | `[1, 255]` | `[1, 65535]` | `[1, 16777215]` | `[1, 4294967295]` |
174-
| `int64_t` | `[-127, 127]` | `[-32767, 32767]` | [`-8388607, 8388607]` | `[-2147483647, 2147483647]` |
175-
| `uint64_t` | `[1, 255]` | `[1, 65535]` | `[1, 16777215]` | `[1, 4294967295]` |
158+
| Type | 8-bit Audio | 16-bit Audio | 24-bit Audio | 32-bit Audio |
159+
| ---------- | ------------- | -------------------- | --------------------- | --------------------------- |
160+
| `float` | `[-1.0, 1.0]` | `[-1.0, 1.0]` | `[-1.0, 1.0]` | `[-1.0, 1.0]` |
161+
| `double` | `[-1.0, 1.0]` | `[-1.0, 1.0]` | `[-1.0, 1.0]` | `[-1.0, 1.0]` |
162+
| `int8_t` | `[-127, 127]` | :x: (type too small) | :x: (type too small) | :x: (type too small) |
163+
| `uint8_t` | `[1, 255]` | :x: (type too small) | :x: (type too small) | :x: (type too small) |
164+
| `int16_t` | `[-127, 127]` | `[-32767, 32767]` | :x: (type too small) | :x: (type too small) |
165+
| `uint16_t` | `[1, 255]` | `[1, 65535]` | :x: (type too small) | :x: (type too small) |
166+
| `int32_t` | `[-127, 127]` | `[-32767, 32767]` | [`-8388607, 8388607]` | `[-2147483647, 2147483647]` |
167+
| `uint32_t` | `[1, 255]` | `[1, 65535]` | `[1, 16777215]` | `[1, 4294967295]` |
168+
| `int64_t` | `[-127, 127]` | `[-32767, 32767]` | [`-8388607, 8388607]` | `[-2147483647, 2147483647]` |
169+
| `uint64_t` | `[1, 255]` | `[1, 65535]` | `[1, 16777215]` | `[1, 4294967295]` |
176170

177-
Error Messages
178-
-----------------
171+
## Error Messages
179172

180-
By 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).
173+
By 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).
181174

182175
If you prefer not to see these messages, you can disable this error logging behaviour using:
183176

184-
audioFile.shouldLogErrorsToConsole (false);
177+
audioFile.shouldLogErrorsToConsole (false);
178+
179+
## Versions
185180

181+
##### 1.1.2 - 18th November 2024
186182

187-
Versions
188-
-------
183+
- Improved AIFF sample rate calculations
184+
- Improved CMake support
185+
- Code improvements
186+
- Bug and warning fixes
189187

190188
##### 1.1.1 - 4th April 2023
191189

@@ -219,7 +217,7 @@ Versions
219217
##### 1.0.6 - 29th February 2020
220218

221219
- Made error logging to the console optional
222-
- Fixed lots of compiler warnings
220+
- Fixed lots of compiler warnings
223221

224222
##### 1.0.5 - 14th October 2019
225223

@@ -239,38 +237,39 @@ Versions
239237

240238
- Bug fixes
241239

242-
Contributions
243-
-------
240+
## Contributions
244241

245242
Many thanks to the following people for their contributions to this library:
246243

247-
* [Abhinav1997](https://github.com/Abhinav1997)
248-
* [alxarsenault](https://github.com/alxarsenault)
249-
* [BenjaminHinchliff](https://github.com/BenjaminHinchliff)
250-
* [BesselJ](https://github.com/BesselJ)
251-
* [emiro85](https://github.com/emiro85)
252-
* [heartofrain](https://github.com/heartofrain)
253-
* [helloimmatt](https://github.com/helloimmatt/)
254-
* [leocstone](https://github.com/leocstone)
255-
* [MatthieuHernandez](https://github.com/MatthieuHernandez)
256-
* [mrpossoms](https://github.com/mrpossoms)
257-
* [mynameisjohn](https://github.com/mynameisjohn)
258-
* [Sidelobe](https://github.com/Sidelobe)
259-
* [sschaetz](https://github.com/sschaetz)
260-
* [Yhcrown](https://github.com/Yhcrown)
261-
262-
Want to Contribute?
263-
-------
244+
- [Abhinav1997](https://github.com/Abhinav1997)
245+
- [alxarsenault](https://github.com/alxarsenault)
246+
- [ascii255](https://github.com/ascii255)
247+
- [BenjaminHinchliff](https://github.com/BenjaminHinchliff)
248+
- [BesselJ](https://github.com/BesselJ)
249+
- [cgraf78](https://github.com/cgraf78)
250+
- [emiro85](https://github.com/emiro85)
251+
- [encoded](https://github.com/encoded)
252+
- [heartofrain](https://github.com/heartofrain)
253+
- [helloimmatt](https://github.com/helloimmatt/)
254+
- [leocstone](https://github.com/leocstone)
255+
- [MatthieuHernandez](https://github.com/MatthieuHernandez)
256+
- [Metalsofa](https://github.com/Metalsofa)
257+
- [mrpossoms](https://github.com/mrpossoms)
258+
- [mynameisjohn](https://github.com/mynameisjohn)
259+
- [Sidelobe](https://github.com/Sidelobe)
260+
- [sschaetz](https://github.com/sschaetz)
261+
- [Yhcrown](https://github.com/Yhcrown)
262+
263+
## Want to Contribute?
264264

265265
If you would like to submit a pull request for this library, please do! But kindly follow the following simple guidelines...
266266

267-
* Make the changes as concise as is possible for the change you are proposing
268-
* Avoid unnecessarily changing a large number of lines - e.g. commits changing the number of spaces in indentations on all lines (and so on)
269-
* Keep to the code style of this library which is the [JUCE Coding Standards](https://juce.com/discover/stories/coding-standards)
270-
* Make the changes relative to the develop branch of the library (as this may have advanced beyond the master branch)
267+
- Make the changes as concise as is possible for the change you are proposing
268+
- Avoid unnecessarily changing a large number of lines - e.g. commits changing the number of spaces in indentations on all lines (and so on)
269+
- Keep to the code style of this library which is the [JUCE Coding Standards](https://juce.com/discover/stories/coding-standards)
270+
- Make the changes relative to the develop branch of the library (as this may have advanced beyond the master branch)
271271

272-
License
273-
-------
272+
## License
274273

275274
MIT License
276275

0 commit comments

Comments
 (0)