MCPcopy Create free account
hub / github.com/ml-explore/mlx-data / apply

Method apply

mlx/data/op/LoadAudio.cpp:86–125  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

84 resamplingQuality_(resampling_quality) {}
85
86Sample LoadAudio::apply(const Sample& sample) const {
87 auto src = sample::check_key(sample, iKey_, ArrayType::Any);
88 auto okey = (oKey_.empty() ? iKey_ : oKey_);
89 auto res = sample;
90
91 std::filesystem::path path;
92 if (!from_memory_) {
93 if (src->type() != ArrayType::Int8) {
94 throw std::runtime_error("LoadAudio: expected filename (int8 array)");
95 }
96 path = prefix_;
97 std::string filename(reinterpret_cast<char*>(src->data()), src->size());
98 path /= filename;
99 }
100
101 std::shared_ptr<Array> info;
102 std::shared_ptr<Array> dst;
103
104 // need to return only info?
105 if (info_ && infoKey_.empty()) {
106 auto audio_info =
107 from_memory_ ? core::audio::info(src) : core::audio::info(path);
108 res[okey] = extract_audio_info(audio_info, infoType_);
109 } else {
110 core::audio::AudioInfo audio_info;
111 auto audio = from_memory_ ? core::audio::load(src, &audio_info)
112 : core::audio::load(path, &audio_info);
113 audio = core::audio::resample(
114 audio,
115 convert_resample_mode(resamplingQuality_),
116 audio_info.sampleRate,
117 sampleRate_);
118
119 if (!infoKey_.empty()) {
120 res[infoKey_] = extract_audio_info(audio_info, infoType_);
121 }
122 res[okey] = audio;
123 }
124 return res;
125}
126
127ResampleAudio::ResampleAudio(
128 const std::string& ikey,

Callers

nothing calls this directly

Calls 9

check_keyFunction · 0.85
extract_audio_infoFunction · 0.85
resampleFunction · 0.85
convert_resample_modeFunction · 0.85
typeMethod · 0.80
infoFunction · 0.50
loadFunction · 0.50
dataMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected