MCPcopy Create free account
hub / github.com/FlaxEngine/FlaxEngine / ExportAudioClip

Method ExportAudioClip

Source/Engine/ContentExporters/ExportAudio.cpp:12–47  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

10#include "Engine/Tools/AudioTool/OggVorbisEncoder.h"
11
12ExportAssetResult 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

Callers

nothing calls this directly

Calls 5

LockSafeMethod · 0.80
ExtractDataRawMethod · 0.80
GetMethod · 0.45
ConvertMethod · 0.45
LengthMethod · 0.45

Tested by

no test coverage detected