Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- struct chantype{ enum { normal, mono, stereo }; };
- // Returns the leftmost channel number of the take, 0-based, enum of type is normal, mono, stereo
- int GetTakeChannel(MediaItem_Take* take, int* chanmode, int* type) {
- int chm, t;
- chm = GetMediaItemTakeInfo_Value(take, "I_CHANMODE");
- int ch = chm;
- // Get channel type
- if (chm == 0) t = chantype::normal;
- else if (in_range(chm, 2, 66)) t = chantype::mono;
- else t = chantype::stereo;
- // Get leftmost channel
- if (chm >= 67) ch = chm - 67;
- else if (chm >= 3) ch = chm - 3;
- else if (chm == 2) ch = chm = 0;
- if (chanmode != nullptr) *chanmode = chm;
- if (type != nullptr) *type = t;
- return ch;
- }
- void SetTakeChannel(MediaItem_Take* take, int type, int channel) {
- switch (type) {
- case chantype::normal:
- SetMediaItemTakeInfo_Value(take, "I_CHANMODE", 0);
- break;
- case chantype::mono:
- if (channel < 0) channel = GetTakeChannel(take);
- SetMediaItemTakeInfo_Value(take, "I_CHANMODE", clamp(channel+3, 3, 66));
- break;
- case chantype::stereo:
- if (channel < 0) channel = GetTakeChannel(take);
- SetMediaItemTakeInfo_Value(take, "I_CHANMODE", clamp(channel+67, 67, 129));
- break;
- }
- }
- vector<vector<double>> MultichannelToChannelMode(vector<vector<double>> audio, MediaItem_Take* take) {
- int nch = audio.size();
- vector< vector<double> > v;
- int chanmode;
- size_t frames = 0;
- for (int i = 0; i < audio.size(); ++i) frames = max(frames, audio[i].size());
- size_t ch = GetTakeChannel(take, &chanmode);
- // Stereo
- if (chanmode >= 67) {
- if (nch > ch) v.push_back(audio[ch]); else v.push_back(vector<double>(frames, 0));
- if (nch > ch+1) v.push_back(audio[ch+1]); else v.push_back(vector<double>(frames, 0));
- }
- // Mono
- else if (chanmode >= 3) {
- if (nch > ch) v.push_back(audio[ch]); else v.push_back(vector<double>(frames, 0));
- }
- // Mono Mix (L + R)
- else if (chanmode == 2) {
- vector<double> temp(frames, 0);
- if (nch > 1) for (int c = 0; c < nch; ++c) {
- for (int s = 0; s < audio[c].size(); ++s) temp[s] = audio[0][s] + audio[1][s];
- v.push_back(temp);
- }
- else v.push_back(audio[0]);
- }
- //Reverse Stereo
- else if (chanmode == 1) {
- if (nch > 1) v.push_back(audio[1]);
- v.push_back(audio[0]);
- for (int c = 2; c < nch; ++c) v.push_back(audio[c]);
- }
- //Normal
- else if (chanmode == 0) v = audio;
- return v;
- }
Add Comment
Please, Sign In to add comment