| 33 | constexpr size_t kDefaultBytesPerTick = 1378; |
| 34 | |
| 35 | void MusicObject::Load() |
| 36 | { |
| 37 | GetStringTable().Sort(); |
| 38 | NameStringId = LanguageAllocateObjectString(GetName()); |
| 39 | |
| 40 | // Start with base images |
| 41 | _loadedSampleTable.LoadFrom(_sampleTable, 0, _sampleTable.GetCount()); |
| 42 | |
| 43 | // Override samples from asset packs |
| 44 | auto context = GetContext(); |
| 45 | auto assetManager = context->GetAssetPackManager(); |
| 46 | if (assetManager != nullptr) |
| 47 | { |
| 48 | assetManager->LoadSamplesForObject(GetIdentifier(), _loadedSampleTable); |
| 49 | } |
| 50 | |
| 51 | // Load metadata of samples |
| 52 | auto& audioContext = GetContext()->GetAudioContext(); |
| 53 | for (auto& track : _tracks) |
| 54 | { |
| 55 | auto stream = track.Asset.GetStream(); |
| 56 | if (stream != nullptr) |
| 57 | { |
| 58 | auto source = audioContext.CreateStreamFromWAV(std::move(stream)); |
| 59 | if (source != nullptr) |
| 60 | { |
| 61 | track.BytesPerTick = source->GetBytesPerSecond() / 40; |
| 62 | track.Size = source->GetLength(); |
| 63 | source->Release(); |
| 64 | } |
| 65 | else |
| 66 | { |
| 67 | track.BytesPerTick = kDefaultBytesPerTick; |
| 68 | track.Size = track.Asset.GetSize(); |
| 69 | } |
| 70 | } |
| 71 | else |
| 72 | { |
| 73 | track.BytesPerTick = kDefaultBytesPerTick; |
| 74 | track.Size = track.Asset.GetSize(); |
| 75 | } |
| 76 | } |
| 77 | |
| 78 | _hasPreview = !!GetImageTable().GetCount(); |
| 79 | _previewImageId = LoadImages(); |
| 80 | } |
| 81 | |
| 82 | void MusicObject::Unload() |
| 83 | { |
nothing calls this directly
no test coverage detected