| 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 extern Resource* MakePlatformResource(const char *path); | |
| 11 | |
| 12 class Sample { | |
| 13 public: | |
| 14 explicit Sample(const char* path) | |
| 15 : buffer_(NULL), | |
| 16 length_(0) { | |
| 17 resource_ = MakePlatformResource(path); | |
| 18 } | |
| 19 | |
| 20 ~Sample() { | |
| 21 Unload(); | |
| 22 delete resource_; | |
| 23 } | |
| 24 | |
| 25 const char* path() { | |
| 26 return resource_->path(); | |
| 27 } | |
| 28 | |
| 29 uint8_t* buffer() { | |
| 30 return buffer_; | |
| 31 } | |
| 32 | |
| 33 off_t length() { | |
| 34 return length_; | |
| 35 } | |
| 36 | |
| 37 int32_t Load() { | |
| 38 int32_t rtn = -1; | |
| 39 if (resource_->Open() == 0) { | |
| 40 buffer_ = new uint8_t[length_ = resource_->length()]; | |
| 41 rtn = resource_->Read(buffer_, length_); | |
| 42 resource_->Close(); | |
| 43 } | |
| 44 return rtn; | |
| 45 } | |
| 46 | |
| 47 void Unload() { | |
| 48 if (buffer_ != NULL) { | |
| 49 delete[] buffer_; | |
| 50 buffer_ = NULL; | |
| 51 } | |
| 52 length_ = 0; | |
| 53 } | |
| 54 | |
| 55 private: | |
| 56 friend class SoundService; | |
| 57 Resource* resource_; | |
| 58 uint8_t* buffer_; | |
| 59 off_t length_; | |
| 60 }; | |
| 61 | |
| 62 #endif // EMBEDDERS_OPENGLUI_COMMON_SAMPLE_H_ | |
| 63 | |
| OLD | NEW |