OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. |
| 4 |
| 5 #ifndef EMBEDDERS_OPENGLUI_COMMON_SAMPLE_H_ |
| 6 #define EMBEDDERS_OPENGLUI_COMMON_SAMPLE_H_ |
| 7 |
| 8 #include "embedders/openglui/common/resource.h" |
| 9 |
| 10 class Sample { |
| 11 public: |
| 12 explicit Sample(const char* path) |
| 13 : resource_(path), |
| 14 buffer_(NULL), |
| 15 length_(0) { |
| 16 } |
| 17 |
| 18 ~Sample() { |
| 19 Unload(); |
| 20 } |
| 21 |
| 22 const char* path() { |
| 23 return resource_.path(); |
| 24 } |
| 25 |
| 26 uint8_t* buffer() { |
| 27 return buffer_; |
| 28 } |
| 29 |
| 30 off_t length() { |
| 31 return length_; |
| 32 } |
| 33 |
| 34 int32_t Load() { |
| 35 int32_t rtn = -1; |
| 36 if (resource_.Open() == 0) { |
| 37 buffer_ = new uint8_t[length_ = resource_.length()]; |
| 38 rtn = resource_.Read(buffer_, length_); |
| 39 resource_.Close(); |
| 40 } |
| 41 return rtn; |
| 42 } |
| 43 |
| 44 void Unload() { |
| 45 if (buffer_ != NULL) { |
| 46 delete[] buffer_; |
| 47 buffer_ = NULL; |
| 48 } |
| 49 length_ = 0; |
| 50 } |
| 51 |
| 52 private: |
| 53 friend class SoundService; |
| 54 Resource resource_; |
| 55 uint8_t* buffer_; |
| 56 off_t length_; |
| 57 }; |
| 58 |
| 59 #endif // EMBEDDERS_OPENGLUI_COMMON_SAMPLE_H_ |
| 60 |
OLD | NEW |