ese 519 include files
Dependents: PROJECT_3D_AUDIO COG4050_adxl355_tilt COG4050_adxl355_tilt COG4050_adxl355_tilt_4050
WavObject.h@0:5347612e39a3, 2015-04-07 (annotated)
- Committer:
- niv17
- Date:
- Tue Apr 07 21:09:51 2015 +0000
- Revision:
- 0:5347612e39a3
april_7 _ sonic start
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
niv17 | 0:5347612e39a3 | 1 | // |
niv17 | 0:5347612e39a3 | 2 | // WavObject.h |
niv17 | 0:5347612e39a3 | 3 | // Demo |
niv17 | 0:5347612e39a3 | 4 | // |
niv17 | 0:5347612e39a3 | 5 | // Created by Philadelphia Game Lab on 7/7/14. |
niv17 | 0:5347612e39a3 | 6 | // Copyright (c) 2014 Philadelphia Game Lab. All rights reserved. |
niv17 | 0:5347612e39a3 | 7 | // |
niv17 | 0:5347612e39a3 | 8 | |
niv17 | 0:5347612e39a3 | 9 | #ifndef WAVOBJECT_H |
niv17 | 0:5347612e39a3 | 10 | #define WAVOBJECT_H |
niv17 | 0:5347612e39a3 | 11 | |
niv17 | 0:5347612e39a3 | 12 | #include <string> |
niv17 | 0:5347612e39a3 | 13 | #include "complextype.h" |
niv17 | 0:5347612e39a3 | 14 | #include <cmath> |
niv17 | 0:5347612e39a3 | 15 | #include <math.h> |
niv17 | 0:5347612e39a3 | 16 | #include <iostream> |
niv17 | 0:5347612e39a3 | 17 | |
niv17 | 0:5347612e39a3 | 18 | //using std::complex; |
niv17 | 0:5347612e39a3 | 19 | |
niv17 | 0:5347612e39a3 | 20 | class WavObject { |
niv17 | 0:5347612e39a3 | 21 | |
niv17 | 0:5347612e39a3 | 22 | FILE* soundFile; |
niv17 | 0:5347612e39a3 | 23 | struct |
niv17 | 0:5347612e39a3 | 24 | { |
niv17 | 0:5347612e39a3 | 25 | long n; |
niv17 | 0:5347612e39a3 | 26 | int sampleRate; |
niv17 | 0:5347612e39a3 | 27 | int bitDepth; |
niv17 | 0:5347612e39a3 | 28 | int nChannels; |
niv17 | 0:5347612e39a3 | 29 | }wavFileData; |
niv17 | 0:5347612e39a3 | 30 | long startOfWavData; |
niv17 | 0:5347612e39a3 | 31 | long endOfWavData; |
niv17 | 0:5347612e39a3 | 32 | |
niv17 | 0:5347612e39a3 | 33 | public: |
niv17 | 0:5347612e39a3 | 34 | |
niv17 | 0:5347612e39a3 | 35 | //Struct that holds RIFF data of Wave File. |
niv17 | 0:5347612e39a3 | 36 | //RIFF data is meta data info that holds ID, size and format of WAVE file. |
niv17 | 0:5347612e39a3 | 37 | struct RIFF_Header { |
niv17 | 0:5347612e39a3 | 38 | char chunkID[4]; |
niv17 | 0:5347612e39a3 | 39 | unsigned int chunkSize; |
niv17 | 0:5347612e39a3 | 40 | char format[4]; |
niv17 | 0:5347612e39a3 | 41 | }; |
niv17 | 0:5347612e39a3 | 42 | |
niv17 | 0:5347612e39a3 | 43 | //Struct that holds format subchunk data for WAVE file. |
niv17 | 0:5347612e39a3 | 44 | struct WAVE_Format { |
niv17 | 0:5347612e39a3 | 45 | unsigned int subChunkSize; |
niv17 | 0:5347612e39a3 | 46 | short audioFormat; |
niv17 | 0:5347612e39a3 | 47 | short nChannels; |
niv17 | 0:5347612e39a3 | 48 | unsigned int sampleRate; |
niv17 | 0:5347612e39a3 | 49 | unsigned int byteRate; |
niv17 | 0:5347612e39a3 | 50 | short blockAlign; |
niv17 | 0:5347612e39a3 | 51 | short bitsPerSample; |
niv17 | 0:5347612e39a3 | 52 | }; |
niv17 | 0:5347612e39a3 | 53 | |
niv17 | 0:5347612e39a3 | 54 | //Struct that holds data of WAVE file. |
niv17 | 0:5347612e39a3 | 55 | struct WAVE_Data { |
niv17 | 0:5347612e39a3 | 56 | long subChunk2Size; |
niv17 | 0:5347612e39a3 | 57 | }; |
niv17 | 0:5347612e39a3 | 58 | |
niv17 | 0:5347612e39a3 | 59 | //Struct to hold subchunkID |
niv17 | 0:5347612e39a3 | 60 | struct CHUNK_ID { |
niv17 | 0:5347612e39a3 | 61 | char chunkID[4]; |
niv17 | 0:5347612e39a3 | 62 | }; |
niv17 | 0:5347612e39a3 | 63 | |
niv17 | 0:5347612e39a3 | 64 | |
niv17 | 0:5347612e39a3 | 65 | WAVE_Format wave_format; |
niv17 | 0:5347612e39a3 | 66 | RIFF_Header riff_header; |
niv17 | 0:5347612e39a3 | 67 | WAVE_Data wave_data; |
niv17 | 0:5347612e39a3 | 68 | CHUNK_ID chunk_id; |
niv17 | 0:5347612e39a3 | 69 | |
niv17 | 0:5347612e39a3 | 70 | short *shortTempData; |
niv17 | 0:5347612e39a3 | 71 | Complex *complexTempData; |
niv17 | 0:5347612e39a3 | 72 | |
niv17 | 0:5347612e39a3 | 73 | |
niv17 | 0:5347612e39a3 | 74 | WavObject (unsigned int size,const std::string wavFileName) : shortTempData(new short[size]), complexTempData(new Complex[size]) { |
niv17 | 0:5347612e39a3 | 75 | extractWavHeader(wavFileName); |
niv17 | 0:5347612e39a3 | 76 | } |
niv17 | 0:5347612e39a3 | 77 | |
niv17 | 0:5347612e39a3 | 78 | Complex *loadCmpWavData(const std::string fname, long *size, int *smpFreq, int *bitDepth, int *channels); |
niv17 | 0:5347612e39a3 | 79 | void extractWavHeader (const std::string fname); |
niv17 | 0:5347612e39a3 | 80 | |
niv17 | 0:5347612e39a3 | 81 | // returns false if end of file reached and no repeat, true otherwise |
niv17 | 0:5347612e39a3 | 82 | bool loadMoreData(unsigned int size, bool repeat); |
niv17 | 0:5347612e39a3 | 83 | |
niv17 | 0:5347612e39a3 | 84 | void seekToBeginning(); |
niv17 | 0:5347612e39a3 | 85 | |
niv17 | 0:5347612e39a3 | 86 | ~WavObject () { |
niv17 | 0:5347612e39a3 | 87 | delete[] shortTempData; |
niv17 | 0:5347612e39a3 | 88 | delete[] complexTempData; |
niv17 | 0:5347612e39a3 | 89 | if (soundFile) |
niv17 | 0:5347612e39a3 | 90 | fclose(soundFile); |
niv17 | 0:5347612e39a3 | 91 | } |
niv17 | 0:5347612e39a3 | 92 | |
niv17 | 0:5347612e39a3 | 93 | }; |
niv17 | 0:5347612e39a3 | 94 | |
niv17 | 0:5347612e39a3 | 95 | #endif |