1 //---------------------------------------------------------------------------- 2 // Sound Gather class 3 //---------------------------------------------------------------------------- 4 // 5 // Copyright (c) 2008 The EDGE Team. 6 // 7 // This program is free software; you can redistribute it and/or 8 // modify it under the terms of the GNU General Public License 9 // as published by the Free Software Foundation; either version 2 10 // of the License, or (at your option) any later version. 11 // 12 // This program is distributed in the hope that it will be useful, 13 // but WITHOUT ANY WARRANTY; without even the implied warranty of 14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 // GNU General Public License for more details. 16 // 17 //---------------------------------------------------------------------------- 18 19 #ifndef __EPI_SOUND_GATHER_H__ 20 #define __EPI_SOUND_GATHER_H__ 21 22 #include <vector> 23 24 #include "sound_data.h" 25 26 namespace epi 27 { 28 29 // private stuff 30 class gather_chunk_c; 31 32 33 class sound_gather_c 34 { 35 private: 36 std::vector<gather_chunk_c *> chunks; 37 38 int total_samples; 39 40 gather_chunk_c *request; 41 42 public: 43 sound_gather_c(); 44 ~sound_gather_c(); 45 46 s16_t * MakeChunk(int max_samples, bool _stereo); 47 // prepare to add a chunk of sound samples. Returns a buffer 48 // containing the number of samples (* 2 for stereo) which the 49 // user can fill up. 50 51 void CommitChunk(int actual_samples); 52 // add the current chunk to the stored sound data. 53 // The number of samples may be less than the size requested 54 // by the MakeChunk() call. Passing zero for 'actual_samples' 55 // is equivalent to callng the DiscardChunk() method. 56 57 void DiscardChunk(); 58 // get rid of current chunk (because it wasn't needed, e.g. 59 // the sound file you were reading hit EOF). 60 61 bool Finalise(sound_data_c *buf, bool want_stereo); 62 // take all the stored sound data and transfer it to the 63 // sound_data_c object, making it all contiguous, and 64 // converting from/to stereoness where needed. 65 // 66 // Returns false (failure) if total samples was zero, 67 // otherwise returns true (success). 68 69 private: 70 void TransferMono (gather_chunk_c *chunk, sound_data_c *buf, int pos); 71 void TransferStereo(gather_chunk_c *chunk, sound_data_c *buf, int pos); 72 }; 73 74 } // namespace epi 75 76 #endif /* __EPI_SOUND_GATHER_H__ */ 77 78 //--- editor settings --- 79 // vi:ts=4:sw=4:noexpandtab 80