DirectorConference::DirectorConference(int id, int livingcast) : Conference(id) { filter_tee_ = ms_filter_new(MS_TEE_ID); filter_sink_ = ms_filter_new_from_name("ZonekeyVoidSink"); log("%s: ... id=%d \n", __FUNCTION__, id); #if 1 audio_mixer_ = ms_filter_new_from_name("ZonekeyAudioMixer"); int rate = 16000; ms_filter_call_method(audio_mixer_, MS_FILTER_SET_SAMPLE_RATE, &rate); #else audio_mixer_ = ms_filter_new(MS_AUDIO_MIXER_ID); int tmp = 1, rate = 16000; ms_filter_call_method(audio_mixer_, MS_AUDIO_MIXER_ENABLE_CONFERENCE_MODE, &tmp); ms_filter_call_method(audio_mixer_, MS_FILTER_SET_SAMPLE_RATE, &rate); #endif video_mixer_ = ms_filter_new_from_name("ZonekeyVideoMixer"); audio_publisher_ = ms_filter_new_from_name("ZonekeyPublisher"); video_publisher_ = ms_filter_new_from_name("ZonekeyPublisher"); audio_resample_ = ms_filter_new(MS_RESAMPLE_ID); audio_encoder_ = ms_filter_new_from_name("MSIlbcEnc"); video_tee_ = ms_filter_new(MS_TEE_ID); // 是否启用 video mixer ms_filter_call_method(video_mixer_, ZONEKEY_METHOD_VIDEO_MIXER_ENABLE, (void*)livingcast); audio_ticker_ = ms_ticker_new(); video_ticker_ = ms_ticker_new(); /// 总是将 audio mixer 的 preview 使用 iLBC 输出 int in_sample = 16000, in_ch = 1; int out_sample = 8000, out_ch = 1; ms_filter_call_method(audio_resample_, MS_FILTER_SET_SAMPLE_RATE, &in_sample); ms_filter_call_method(audio_resample_, MS_FILTER_SET_NCHANNELS, &in_ch); ms_filter_call_method(audio_resample_, MS_FILTER_SET_OUTPUT_SAMPLE_RATE, &out_sample); ms_filter_call_method(audio_resample_, MS_FILTER_SET_OUTPUT_NCHANNELS, &out_ch); // simple link ms_filter_link(audio_mixer_, ZONEKEY_AUDIO_MIXER_PREVIEW_PIN, audio_resample_, 0); ms_filter_link(audio_resample_, 0, audio_encoder_, 0); ms_filter_link(audio_encoder_, 0, audio_publisher_, 0); ms_filter_link(video_mixer_, 1, video_tee_, 0); ms_filter_link(video_tee_, MAX_STREAMS, video_publisher_, 0); audio_stream_cnt_ = 0; video_stream_cnt_ = 0; resume_audio(); resume_video(); log("ok\n"); }
void Audio::load_wav(const char* filename) { if (sound_enabled) { clear_wav(); // Load Wav File SDL_AudioSpec wave; uint8_t *data; uint32_t length; pause_audio(); if( SDL_LoadWAV(filename, &wave, &data, &length) == NULL) { wavfile.loaded = 0; resume_audio(); std::cout << "Could not load wav: " << filename << std::endl; return; } SDL_LockAudio(); // Halve Volume Of Wav File uint8_t* data_vol = new uint8_t[length]; SDL_MixAudioFormat(data_vol, data, wave.format, length, SDL_MIX_MAXVOLUME / 2); // WAV File Needs Conversion To Target Format if (wave.format != AUDIO_S16 || wave.channels != 2 || wave.freq != FREQ) { SDL_AudioCVT cvt; SDL_BuildAudioCVT(&cvt, wave.format, wave.channels, wave.freq, AUDIO_S16, CHANNELS, FREQ); cvt.buf = (uint8_t*) malloc(length*cvt.len_mult); memcpy(cvt.buf, data_vol, length); cvt.len = length; SDL_ConvertAudio(&cvt); SDL_FreeWAV(data); delete[] data_vol; wavfile.data = (int16_t*) cvt.buf; wavfile.length = cvt.len_cvt / 2; wavfile.pos = 0; wavfile.loaded = 1; } // No Conversion Needed else { SDL_FreeWAV(data); wavfile.data = (int16_t*) data_vol; wavfile.length = length / 2; wavfile.pos = 0; wavfile.loaded = 2; } resume_audio(); SDL_UnlockAudio(); } }