1 #ifndef CLUNK_SAMPLE_H__ 2 #define CLUNK_SAMPLE_H__ 3 4 /* clunk - cross-platform 3D audio API built on top SDL library 5 * Copyright (C) 2007-2014 Netive Media Group 6 * 7 * This library is free software; you can redistribute it and/or 8 * modify it under the terms of the GNU Lesser General Public 9 * License as published by the Free Software Foundation; either 10 * version 2.1 of the License, or (at your option) any later version. 11 12 * This library 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 GNU 15 * Lesser General Public License for more details. 16 * 17 * You should have received a copy of the GNU Lesser General Public 18 * License along with this library; if not, write to the Free Software 19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 20 */ 21 22 23 #include <clunk/export_clunk.h> 24 #include <clunk/buffer.h> 25 #include <clunk/audio_spec.h> 26 27 namespace clunk { 28 class Context; 29 30 //!Holds raw wave data. 31 class CLUNKAPI Sample { 32 public: 33 ///name - for general purpose 34 std::string name; 35 ///gain 36 float gain; 37 ///pitch, 2.0f - pitching up one octave 38 float pitch; 39 40 ~Sample(); 41 42 /*! 43 \brief initializes sample 44 \param[in] data raw audio data 45 \param[in] spec audio format specification 46 */ 47 void init(const clunk::Buffer &data, const AudioSpec &spec); 48 49 /*! 50 \brief generate sine wave with given length (seconds) 51 \param[in] freq frequency 52 \param[in] len of the sample in seconds 53 */ 54 void generateSine(int freq, float len); 55 length()56 float length() const { 57 return 1.0f * _data.get_size() / _spec.sample_rate / _spec.channels / 2; 58 } 59 get_data()60 const clunk::Buffer & get_data() const { return _data; } get_spec()61 const AudioSpec get_spec() const { return _spec; } 62 63 private: 64 friend class Context; 65 66 Sample(Context *context); 67 68 Sample(const Sample &); 69 const Sample& operator=(const Sample &); 70 71 Context * _context; 72 AudioSpec _spec; 73 clunk::Buffer _data; 74 }; 75 } 76 77 #endif 78 79