| 10 | #include "Engine/Tools/AudioTool/OggVorbisEncoder.h" |
| 11 | |
| 12 | ExportAssetResult AssetExporters::ExportAudioClip(ExportAssetContext& context) |
| 13 | { |
| 14 | #if COMPILE_WITH_OGG_VORBIS |
| 15 | // Prepare |
| 16 | auto asset = (AudioClip*)context.Asset.Get(); |
| 17 | auto lock = asset->Storage->LockSafe(); |
| 18 | auto path = GET_OUTPUT_PATH(context, "ogg"); |
| 19 | |
| 20 | // Get audio data |
| 21 | Array<byte> rawData; |
| 22 | AudioDataInfo rawDataInfo; |
| 23 | if (asset->ExtractDataRaw(rawData, rawDataInfo)) |
| 24 | return ExportAssetResult::CannotLoadData; |
| 25 | |
| 26 | // Encode PCM data |
| 27 | BytesContainer encodedData; |
| 28 | OggVorbisEncoder encoder; |
| 29 | if (encoder.Convert(rawData.Get(), rawDataInfo, encodedData, 1.0f)) |
| 30 | { |
| 31 | LOG(Warning, "Failed to compress audio data"); |
| 32 | return ExportAssetResult::Error; |
| 33 | } |
| 34 | |
| 35 | // Save to file |
| 36 | if (File::WriteAllBytes(path, encodedData.Get(), encodedData.Length())) |
| 37 | { |
| 38 | LOG(Warning, "Failed to save data to file"); |
| 39 | return ExportAssetResult::Error; |
| 40 | } |
| 41 | |
| 42 | return ExportAssetResult::Ok; |
| 43 | #else |
| 44 | LOG(Warning, "OggVorbis support is disabled."); |
| 45 | return ExportAssetResult::Error; |
| 46 | #endif |
| 47 | } |
| 48 | |
| 49 | #endif |
nothing calls this directly
no test coverage detected