wavelength 1.0.0
Loading...
Searching...
No Matches
AudioIO.h
Go to the documentation of this file.
1#pragma once
2
3#include <vector>
4
5#include "utl/Str.h"
6
13 char mTag[4];
14 int mSize;
15 unsigned short mFormatTag;
16 unsigned short mNumChannels;
19 unsigned short mBlockAlign;
20 unsigned short mBitsPerSample;
21};
22
29class AudioIO {
30public:
37 explicit AudioIO(const String &filename);
38
45
53 bool ReadWavData(std::vector<unsigned char> &data);
54
63 void GetStreamData(std::vector<unsigned char> &data);
64
71 void FindZeroCrossings(std::vector<int> &crossings);
72
81 void GetVagData(std::vector<unsigned char> &vagData, int iLoopStart, int iLoopEnd);
82
89 bool operator!() const {
90 return !mGoodRead;
91 }
92
98 int GetNumChannels() const {
99 return mNumChannels;
100 }
101
107 int GetSampleRate() const {
108 return mSampleRate;
109 }
110
116 int GetBitsPerSample() const {
117 return mBitsPerSample;
118 }
119
126 return mFilename;
127 }
128
134 int GetVagSize() const {
135 return mVagSize;
136 }
137
138private:
139 int mNumChannels;
140 int mSampleRate;
141 int mBitsPerSample;
142 String mFilename;
143 int mVagSize;
144 bool mGoodRead;
145};
int GetSampleRate() const
Report the sample rate.
Definition AudioIO.h:107
bool ReadWavData(std::vector< unsigned char > &data)
Read the file's samples and record its format.
AudioIO(const String &filename)
Read the format of a WAV file.
bool operator!() const
Report whether the last read failed.
Definition AudioIO.h:89
~AudioIO()
Release the reader.
int GetBitsPerSample() const
Report the size of one sample.
Definition AudioIO.h:116
void GetVagData(std::vector< unsigned char > &vagData, int iLoopStart, int iLoopEnd)
Encode the file as VAG data, looping between two samples when the points are valid.
int GetNumChannels() const
Report the number of channels.
Definition AudioIO.h:98
String & GetFilename()
Report the path of the file.
Definition AudioIO.h:125
void FindZeroCrossings(std::vector< int > &crossings)
List the start of every 28-sample block at which the waveform crosses zero.
void GetStreamData(std::vector< unsigned char > &data)
Convert a 48 kHz 16-bit stereo file to the layout of a streamed sample.
int GetVagSize() const
Report the size of the VAG data of the file, before any loop adjustment.
Definition AudioIO.h:134
Growable text buffer that is also a PrnStream.
Definition string.h:19
Format chunk of a RIFF WAVE file, as the reader takes it in one read.
Definition AudioIO.h:12
int mAvgBytesPerSec
Definition AudioIO.h:18
unsigned short mNumChannels
Definition AudioIO.h:16
unsigned short mBlockAlign
Definition AudioIO.h:19
unsigned short mFormatTag
Definition AudioIO.h:15
unsigned short mBitsPerSample
Definition AudioIO.h:20
int mSamplesPerSec
Definition AudioIO.h:17
char mTag[4]
Definition AudioIO.h:13
int mSize
Definition AudioIO.h:14