|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#pragma once |
|
|
|
#include <string> |
|
|
|
#ifndef WAVE_FORMAT_PCM |
|
#define WAVE_FORMAT_PCM 0x0001 |
|
#endif |
|
#define WAVE_FORMAT_IEEE_FLOAT 0x0003 |
|
#define WAVE_FORMAT_ALAW 0x0006 |
|
#define WAVE_FORMAT_MULAW 0x0007 |
|
#define WAVE_FORMAT_EXTENSIBLE 0xFFFE |
|
|
|
#define WAVE_WAVE 0x45564157 |
|
#define WAVE_RIFF 0x46464952 |
|
#define WAVE_FORMAT 0x20746D66 |
|
#define WAVE_DATA 0x61746164 |
|
|
|
#define DEBUG 1 |
|
|
|
#if DEBUG |
|
#define PRINTCONTROL(x) x; |
|
#define WAVE_ZERO_ON_ALLOCATE 1 |
|
#else |
|
#define PRINTCONTROL(x) |
|
#define WAVE_ZERO_ON_ALLOCATE 0 |
|
#endif |
|
|
|
#define MAX_CHANNELS 64 |
|
|
|
typedef struct { |
|
int ckId; |
|
int cksize; |
|
int waveId; |
|
int waveChunks; |
|
} WaveHeader; |
|
|
|
typedef struct { |
|
uint16_t formatTag; |
|
uint16_t nChannels; |
|
unsigned int nSamplesPerSec; |
|
unsigned int nAvgBytesPerSec; |
|
uint16_t nBlockAlign; |
|
} waveFormat_basic_nopcm; |
|
|
|
typedef struct { |
|
uint16_t formatTag; |
|
uint16_t nChannels; |
|
unsigned int nSamplesPerSec; |
|
unsigned int nAvgBytesPerSec; |
|
uint16_t nBlockAlign; |
|
uint16_t wBitsPerSample; |
|
} waveFormat_basic; |
|
|
|
typedef struct { |
|
uint16_t wFormatTag; |
|
uint16_t nChannels; |
|
unsigned int nSamplesPerSec; |
|
unsigned int nAvgBytesPerSec; |
|
uint16_t nBlockAlign; |
|
uint16_t wBitsPerSample; |
|
uint16_t cbSize; |
|
|
|
} waveFormat_ext; |
|
|
|
class Wave { |
|
public: |
|
Wave(); |
|
explicit Wave(std::string filename); |
|
Wave(const Wave & argB); |
|
~Wave(); |
|
|
|
|
|
Wave(unsigned int nSamples, unsigned int nChannels, unsigned int sampleRate, unsigned int bitDepth); |
|
|
|
|
|
Wave(unsigned int nSamples, unsigned int sampleRate, unsigned int bitDepth, float * singleChannel); |
|
|
|
|
|
Wave & operator -=(const Wave & argB); |
|
Wave & operator *=(float scale); |
|
void operator >> (int shiftSamples); |
|
void operator >> (float shiftSeconds); |
|
void operator <<(int shiftSamples); |
|
void operator <<(float shiftSeconds); |
|
|
|
float& operator[](int sampleIndex); |
|
float* getDataPtr(int channelIndex, int sampleIndex); |
|
|
|
Wave extractChannel(int channelIndex); |
|
void setChannel(int channelIndex, Wave* argB); |
|
|
|
unsigned int getNumSamples(); |
|
unsigned int getNumChannels(); |
|
unsigned int getBitDepth(); |
|
unsigned int getSampleRate(); |
|
|
|
void writeFile(std::string filename); |
|
int maxInt(int channelId); |
|
int minInt(int channelId); |
|
float maxFloat(int channelId); |
|
float minFloat(int channelId); |
|
void append(int numChannels, int numAppendedSamples, float ** buffers); |
|
|
|
void normalize(); |
|
|
|
private: |
|
unsigned int m_numChannels; |
|
unsigned int m_sampleRate; |
|
unsigned int m_bitDepth; |
|
unsigned int m_numSamples; |
|
unsigned int m_bufferAllocation; |
|
|
|
int ** m_intData; |
|
float ** m_floatData; |
|
|
|
bool m_PCMIntValid; |
|
bool m_PCMFloatValid; |
|
|
|
bool allocateInt(); |
|
bool allocateFloat(); |
|
void reallocate(); |
|
|
|
void freeInt(); |
|
void freeFloat(); |
|
|
|
void fillFloatFromInt(); |
|
void fillIntFromFloat(); |
|
void validFloat(); |
|
|
|
void readFromFile(std::string filename); |
|
}; |
|
|
|
|