Ticket #6975: new_audio.diff
File new_audio.diff, 105.1 KB (added by , 15 years ago) |
---|
-
mythplugins/mythmusic/mythmusic/playbackbox.cpp
365 365 changeSpeed(true); 366 366 else if (action == "MUTE") 367 367 toggleMute(); 368 else if (action == "TOGGLEUPMIX") 369 toggleUpmix(); 368 370 else if (action == "MENU" && visualizer_status != 2) 369 371 { 370 372 menufilters = false; … … 1202 1204 } 1203 1205 } 1204 1206 1207 void PlaybackBoxMusic::toggleUpmix() 1208 { 1209 if (gPlayer->getOutput()) 1210 gPlayer->getOutput()->ToggleUpmix(); 1211 } 1212 1213 1205 1214 void PlaybackBoxMusic::showProgressBar() 1206 1215 { 1207 1216 if (progress_bar && visualizer_status != 2) -
mythplugins/mythmusic/mythmusic/globalsettings.cpp
67 67 return gc; 68 68 }; 69 69 70 static HostCheckBox *MusicUpmixer() 71 { 72 HostCheckBox *gc = new HostCheckBox("MusicDefaultUpmix"); 73 gc->setLabel(QObject::tr("Upconvert stereo to 5.1 surround")); 74 gc->setValue(false); 75 gc->setHelpText(QObject::tr("MythTV can upconvert stereo tracks to 5.1 audio. " 76 "Set this option to enable it by default. " 77 "You can enable or disable the upconversion during playback at anytime.")); 78 return gc; 79 }; 80 70 81 static HostLineEdit *CDDevice() 71 82 { 72 83 HostLineEdit *gc = new HostLineEdit("CDDevice"); … … 545 556 general->setLabel(QObject::tr("General Settings (1)")); 546 557 general->addChild(SetMusicDirectory()); 547 558 general->addChild(MusicAudioDevice()); 559 general->addChild(MusicUpmixer()); 548 560 general->addChild(CDDevice()); 549 561 general->addChild(AutoLookupCD()); 550 562 general->addChild(AutoPlayCD()); -
mythplugins/mythmusic/mythmusic/avfdecoder.cpp
256 256 if (output()) 257 257 { 258 258 const AudioSettings settings( 259 16 /*bits*/, m_audioDec->channels, m_audioDec-> sample_rate,260 false /* AC3/DTS pass through */);259 16 /*bits*/, m_audioDec->channels, m_audioDec->codec_id, 260 m_audioDec->sample_rate, false /* AC3/DTS pass through */); 261 261 output()->Reconfigure(settings); 262 262 output()->SetSourceBitrate(m_audioDec->bit_rate); 263 263 } -
mythplugins/mythmusic/mythmusic/main.cpp
389 389 REG_KEY("Music", "VOLUMEDOWN", "Volume down", "[,{,F10,Volume Down"); 390 390 REG_KEY("Music", "VOLUMEUP", "Volume up", "],},F11,Volume Up"); 391 391 REG_KEY("Music", "MUTE", "Mute", "|,\\,F9,Volume Mute"); 392 REG_KEY("Music", "TOGGLEUPMIX","Toggle upmixer", "Ctrl+U"); 392 393 REG_KEY("Music", "CYCLEVIS", "Cycle visualizer mode", "6"); 393 394 REG_KEY("Music", "BLANKSCR", "Blank screen", "5"); 394 395 REG_KEY("Music", "THMBUP", "Increase rating", "9"); -
mythplugins/mythmusic/mythmusic/musicplayer.cpp
348 348 349 349 void MusicPlayer::openOutputDevice(void) 350 350 { 351 QString adevice ;351 QString adevice, pdevice; 352 352 353 353 if (gContext->GetSetting("MusicAudioDevice") == "default") 354 354 adevice = gContext->GetSetting("AudioOutputDevice"); 355 355 else 356 356 adevice = gContext->GetSetting("MusicAudioDevice"); 357 357 358 pdevice = gContext->GetSetting("PassThruOutputDevice"); 359 358 360 // TODO: Error checking that device is opened correctly! 359 m_output = AudioOutput::OpenAudio(adevice, "default", 16, 2, 44100, 360 AUDIOOUTPUT_MUSIC, true, false); 361 m_output = AudioOutput::OpenAudio(adevice, pdevice, 16, 2, 0, 44100, 362 AUDIOOUTPUT_MUSIC, true, false, 363 gContext->GetNumSetting("MusicDefaultUpmix", 0) + 1); 361 364 m_output->setBufferSize(256 * 1024); 362 365 m_output->SetBlocking(false); 363 366 -
mythplugins/mythmusic/mythmusic/playbackbox.h
69 69 void changeVolume(bool up_or_down); 70 70 void changeSpeed(bool up_or_down); 71 71 void toggleMute(); 72 void toggleUpmix(); 72 73 void resetTimer(); 73 74 void hideVolume(){showVolume(false);} 74 75 void showVolume(bool on_or_off); -
mythplugins/mythmusic/mythmusic/cddecoder.cpp
14 14 15 15 #include <mythtv/mythcontext.h> 16 16 #include <mythtv/mythmediamonitor.h> 17 #include <mythtv/libavcodec/avcodec.h> 17 18 18 19 CdDecoder::CdDecoder(const QString &file, DecoderFactory *d, QIODevice *i, 19 20 AudioOutput *o) : … … 149 150 if (output()) 150 151 { 151 152 const AudioSettings settings( 152 16 /*bits*/, chan, freq, false /* AC3/DTS passthru */); 153 16 /*bits*/, chan, CODEC_ID_PCM_S16LE, freq, 154 false /* AC3/DTS passthru */); 153 155 output()->Reconfigure(settings); 154 156 output()->SetSourceBitrate(44100 * 2 * 16); 155 157 } -
mythtv/libs/libmythtv/nuppeldecoder.cpp
495 495 #endif 496 496 GetNVP()->SetAudioParams(extradata.audio_bits_per_sample, 497 497 extradata.audio_channels, 498 CODEC_ID_NONE, 498 499 extradata.audio_sample_rate, 499 500 false /* AC3/DTS pass through */); 500 501 GetNVP()->ReinitAudio(); -
mythtv/libs/libmythtv/NuppelVideoPlayer.cpp
219 219 audioOutput(NULL), 220 220 audio_main_device(QString::null), 221 221 audio_passthru_device(QString::null), 222 audio_channels(2), audio_ bits(-1),223 audio_ samplerate(44100), audio_stretchfactor(1.0f),224 audio_ codec(NULL),audio_lock(QMutex::Recursive),222 audio_channels(2), audio_codec(0), 223 audio_bits(-1), audio_samplerate(44100), 224 audio_stretchfactor(1.0f), audio_lock(QMutex::Recursive), 225 225 // Picture-in-Picture stuff 226 226 pip_active(false), pip_visible(true), 227 227 // Preview window support … … 922 922 audioOutput = AudioOutput::OpenAudio(audio_main_device, 923 923 audio_passthru_device, 924 924 audio_bits, audio_channels, 925 audio_ samplerate,925 audio_codec, audio_samplerate, 926 926 AUDIOOUTPUT_VIDEO, 927 927 setVolume, audio_passthru); 928 928 if (!audioOutput) … … 950 950 951 951 if (audioOutput) 952 952 { 953 const AudioSettings settings( 954 audio_bits, audio_channels, audio_samplerate, 955 audio_passthru, audio_codec); 953 const AudioSettings settings(audio_bits, audio_channels, audio_codec, 954 audio_samplerate, audio_passthru); 956 955 audioOutput->Reconfigure(settings); 956 if (audio_passthru) 957 audio_channels = 2; 957 958 errMsg = audioOutput->GetError(); 958 959 if (!errMsg.isEmpty()) 959 960 audioOutput->SetStretchFactor(audio_stretchfactor); … … 3898 3899 return !IsErrored(); 3899 3900 } 3900 3901 3901 void NuppelVideoPlayer::SetAudioParams(int bps, int channels, 3902 void NuppelVideoPlayer::SetAudioParams(int bps, int channels, int codec, 3902 3903 int samplerate, bool passthru) 3903 3904 { 3904 3905 audio_bits = bps; 3905 3906 audio_channels = channels; 3907 audio_codec = codec; 3906 3908 audio_samplerate = samplerate; 3907 3909 audio_passthru = passthru; 3908 3910 } 3909 3911 3910 void NuppelVideoPlayer::SetAudioCodec(void *ac)3911 {3912 audio_codec = ac;3913 }3914 3915 3912 void NuppelVideoPlayer::SetEffDsp(int dsprate) 3916 3913 { 3917 3914 if (audioOutput) … … 5335 5332 } 5336 5333 } 5337 5334 5335 bool NuppelVideoPlayer::ToggleUpmix() 5336 { 5337 if (audioOutput) 5338 return audioOutput->ToggleUpmix(); 5339 return false; 5340 } 5341 5338 5342 void NuppelVideoPlayer::Zoom(ZoomDirection direction) 5339 5343 { 5340 5344 if (videoOutput) -
mythtv/libs/libmythtv/avformatdecoder.cpp
461 461 // Audio 462 462 audioSamples(NULL), 463 463 allow_ac3_passthru(false), allow_dts_passthru(false), 464 internal_vol(false), 464 465 disable_passthru(false), max_channels(2), 465 dummy_frame(NULL),466 last_ac3_channels(0), dummy_frame(NULL), 466 467 // DVD 467 468 lastdvdtitle(-1), 468 469 decodeStillFrame(false), … … 480 481 av_log_set_level((debug) ? AV_LOG_DEBUG : AV_LOG_ERROR); 481 482 av_log_set_callback(myth_av_log); 482 483 483 allow_ac3_passthru = gContext->GetNumSetting("AC3PassThru", false);484 allow_dts_passthru = gContext->GetNumSetting("DTSPassThru", false);485 484 max_channels = (uint) gContext->GetNumSetting("MaxChannels", 2); 485 allow_ac3_passthru = (max_channels > 2) ? gContext->GetNumSetting("AC3PassThru", false) : false; 486 allow_dts_passthru = (max_channels > 2) ? gContext->GetNumSetting("DTSPassThru", false) : false; 487 internal_vol = gContext->GetNumSetting("MythControlsVolume", 0); 486 488 487 489 audioIn.sample_size = -32; // force SetupAudioStream to run once 488 490 itv = GetNVP()->GetInteractiveTV(); … … 2024 2026 // waiting on audio. 2025 2027 if (GetNVP()->HasAudioIn() && tracks[kTrackTypeAudio].empty()) 2026 2028 { 2027 GetNVP()->SetAudioParams(-1, -1, -1, false /* AC3/DTS pass-through */);2029 GetNVP()->SetAudioParams(-1, -1, CODEC_ID_NONE, -1, false /* AC3/DTS pass-through */); 2028 2030 GetNVP()->ReinitAudio(); 2029 2031 if (ringBuffer && ringBuffer->isDVD()) 2030 2032 audioIn = AudioInfo(); … … 3059 3061 { 3060 3062 int idx = atracks[i].av_stream_index; 3061 3063 AVCodecContext *codec_ctx = ic->streams[idx]->codec; 3062 bool do_ac3_passthru = (allow_ac3_passthru && !transcoding &&3063 !disable_passthru &&3064 (codec_ctx->codec_id == CODEC_ID_AC3));3065 bool do_dts_passthru = (allow_dts_passthru && !transcoding &&3066 !disable_passthru &&3067 (codec_ctx->codec_id == CODEC_ID_DTS));3068 3064 AudioInfo item(codec_ctx->codec_id, 3069 3065 codec_ctx->sample_rate, codec_ctx->channels, 3070 do_ac3_passthru || do_dts_passthru);3066 DoPassThrough(codec_ctx)); 3071 3067 VERBOSE(VB_AUDIO, LOC + " * " + item.toString()); 3072 3068 } 3073 3069 #endif … … 3201 3197 bool AvFormatDecoder::GetFrame(int onlyvideo) 3202 3198 { 3203 3199 AVPacket *pkt = NULL; 3200 AC3HeaderInfo hdr; 3204 3201 int len; 3205 3202 unsigned char *ptr; 3206 3203 int data_size = 0; … … 3631 3628 reselectAudioTrack = true; 3632 3629 } 3633 3630 3634 bool do_ac3_passthru =3635 (allow_ac3_passthru && !transcoding &&3636 (curstream->codec->codec_id == CODEC_ID_AC3));3637 bool do_dts_passthru =3638 (allow_dts_passthru && !transcoding &&3639 (curstream->codec->codec_id == CODEC_ID_DTS));3640 bool using_passthru = do_ac3_passthru || do_dts_passthru;3641 3642 3631 // detect channels on streams that need 3643 3632 // to be decoded before we can know this 3644 3633 bool already_decoded = false; … … 3649 3638 QString("Setting channels to %1") 3650 3639 .arg(audioOut.channels)); 3651 3640 3652 if ( using_passthru)3641 if (DoPassThrough(curstream->codec)) 3653 3642 { 3654 3643 // for passthru let it select the max number 3655 3644 // of channels … … 3671 3660 reselectAudioTrack |= curstream->codec->channels; 3672 3661 } 3673 3662 3663 if (curstream->codec->codec_id == CODEC_ID_AC3) 3664 { 3665 GetBitContext gbc; 3666 init_get_bits(&gbc, ptr, len * 8); 3667 if (!ff_ac3_parse_header(&gbc, &hdr)) 3668 { 3669 if (hdr.channels != last_ac3_channels) 3670 { 3671 last_ac3_channels = curstream->codec->channels = hdr.channels; 3672 SetupAudioStream(); 3673 } 3674 } 3675 } 3676 3674 3677 if (reselectAudioTrack) 3675 3678 { 3676 3679 QMutexLocker locker(&avcodeclock); … … 4196 4199 } 4197 4200 } 4198 4201 4202 bool AvFormatDecoder::DoPassThrough(const AVCodecContext *ctx) 4203 { 4204 bool passthru = false; 4205 4206 if (ctx->codec_id == CODEC_ID_AC3) 4207 passthru = allow_ac3_passthru && 4208 ctx->channels >= (int)max_channels && 4209 !internal_vol; 4210 else if (ctx->codec_id == CODEC_ID_DTS) 4211 passthru = allow_dts_passthru && !internal_vol; 4212 4213 passthru &= !transcoding && !disable_passthru; 4214 // Don't know any cards that support spdif clocked at < 44100 4215 // Some US cable transmissions have 2ch 32k AC-3 streams 4216 passthru &= ctx->sample_rate >= 44100; 4217 4218 return passthru; 4219 } 4220 4199 4221 /** \fn AvFormatDecoder::SetupAudioStream(void) 4200 4222 * \brief Reinitializes audio if it needs to be reinitialized. 4201 4223 * … … 4209 4231 AVStream *curstream = NULL; 4210 4232 AVCodecContext *codec_ctx = NULL; 4211 4233 AudioInfo old_in = audioIn; 4212 AudioInfo old_out = audioOut;4213 4234 bool using_passthru = false; 4214 4235 4215 4236 if ((currentTrack[kTrackTypeAudio] >= 0) && … … 4223 4244 codec_ctx = curstream->codec; 4224 4245 if (codec_ctx) 4225 4246 { 4226 bool do_ac3_passthru = (allow_ac3_passthru && !transcoding && 4227 (codec_ctx->codec_id == CODEC_ID_AC3)); 4228 bool do_dts_passthru = (allow_dts_passthru && !transcoding && 4229 (codec_ctx->codec_id == CODEC_ID_DTS)); 4230 using_passthru = do_ac3_passthru || do_dts_passthru; 4231 info = AudioInfo(codec_ctx->codec_id, 4232 codec_ctx->sample_rate, codec_ctx->channels, 4233 using_passthru && !disable_passthru); 4247 using_passthru = DoPassThrough(codec_ctx); 4248 info = AudioInfo(codec_ctx->codec_id, codec_ctx->sample_rate, 4249 codec_ctx->channels, using_passthru); 4234 4250 } 4235 4251 } 4236 4252 … … 4247 4263 QString("audio track #%1").arg(currentTrack[kTrackTypeAudio]+1)); 4248 4264 4249 4265 audioOut = audioIn = info; 4250 AudioInfo tmpAudioOut = audioOut;4251 4266 4252 // A passthru stream looks like a 48KHz 2ch (@ 16bit) to the sound card 4253 if (using_passthru && !disable_passthru) 4267 if (!using_passthru && audioOut.channels > (int)max_channels) 4254 4268 { 4255 tmpAudioOut.channels = 2; 4256 tmpAudioOut.sample_rate = 48000; 4257 tmpAudioOut.sample_size = 4; 4258 } 4259 4260 if (audioOut.channels > (int) max_channels) 4261 { 4262 audioOut.channels = (int) max_channels; 4269 audioOut.channels = (int)max_channels; 4263 4270 audioOut.sample_size = audioOut.channels * 2; 4264 codec_ctx->channels 4271 codec_ctx->channels = audioOut.channels; 4265 4272 } 4266 4273 4267 if (!using_passthru)4268 tmpAudioOut = audioOut;4269 4270 4274 VERBOSE(VB_AUDIO, LOC + "Audio format changed " + 4271 QString("%1%2\n\t\t\tfrom %3 ; %4\n\t\t\tto %5 ; %6") 4272 .arg((using_passthru) ? "digital passthrough " : "") 4273 .arg((using_passthru) ? tmpAudioOut.toString() : QString("")) 4274 .arg(old_in.toString()).arg(old_out.toString()) 4275 .arg(audioIn.toString()).arg(audioOut.toString())); 4275 QString("\n\t\t\tfrom %1 to %2") 4276 .arg(old_in.toString()).arg(audioOut.toString())); 4276 4277 4277 if ( tmpAudioOut.sample_rate > 0)4278 GetNVP()->SetEffDsp( tmpAudioOut.sample_rate * 100);4278 if (audioOut.sample_rate > 0) 4279 GetNVP()->SetEffDsp(audioOut.sample_rate * 100); 4279 4280 4280 GetNVP()->SetAudioParams(tmpAudioOut.bps(), tmpAudioOut.channels, 4281 tmpAudioOut.sample_rate, audioIn.do_passthru); 4281 GetNVP()->SetAudioParams(audioOut.bps(), audioOut.channels, 4282 audioOut.codec_id, audioOut.sample_rate, 4283 audioOut.do_passthru); 4282 4284 4283 // allow the audio stuff to reencode4284 GetNVP()->SetAudioCodec((using_passthru) ? codec_ctx : NULL);4285 4285 GetNVP()->ReinitAudio(); 4286 4286 4287 4287 return true; -
mythtv/libs/libmythtv/tv_play.h
429 429 bool TimeStretchHandleAction(PlayerContext*, 430 430 const QStringList &actions); 431 431 432 void ToggleUpmix(PlayerContext*); 432 433 void ChangeAudioSync(PlayerContext*, int dir, bool allowEdit = true); 433 434 bool AudioSyncHandleAction(PlayerContext*, const QStringList &actions); 434 435 -
mythtv/libs/libmythtv/NuppelVideoPlayer.h
125 125 void SetAudioStretchFactor(float factor) { audio_stretchfactor = factor; } 126 126 void SetAudioOutput(AudioOutput *ao) { audioOutput = ao; } 127 127 void SetAudioInfo(const QString &main, const QString &passthru, uint rate); 128 void SetAudioParams(int bits, int channels, int samplerate, bool passthru);128 void SetAudioParams(int bits, int channels, int codec, int samplerate, bool passthru); 129 129 void SetEffDsp(int dsprate); 130 130 uint AdjustVolume(int change); 131 131 bool SetMuted(bool mute); … … 179 179 // Toggle Sets 180 180 void ToggleAspectOverride(AspectOverrideMode aspectMode = kAspect_Toggle); 181 181 void ToggleAdjustFill(AdjustFillMode adjustfillMode = kAdjustFill_Toggle); 182 bool ToggleUpmix(void); 182 183 183 184 // Gets 184 185 QSize GetVideoBufferSize(void) const { return video_dim; } … … 714 715 QString audio_main_device; 715 716 QString audio_passthru_device; 716 717 int audio_channels; 718 int audio_codec; 717 719 int audio_bits; 718 720 int audio_samplerate; 719 721 float audio_stretchfactor; 720 void *audio_codec;721 722 bool audio_passthru; 722 723 QMutex audio_lock; 723 724 -
mythtv/libs/libmythtv/tv_play.cpp
489 489 REG_KEY("TV Playback", "VOLUMEDOWN", "Volume down", "[,{,F10,Volume Down"); 490 490 REG_KEY("TV Playback", "VOLUMEUP", "Volume up", "],},F11,Volume Up"); 491 491 REG_KEY("TV Playback", "MUTE", "Mute", "|,\\,F9,Volume Mute"); 492 REG_KEY("TV Playback", "TOGGLEUPMIX", "Toggle audio upmixer", "Ctrl+U"); 492 493 REG_KEY("TV Playback", "TOGGLEPIPMODE", "Toggle Picture-in-Picture view", 493 494 "V"); 494 495 REG_KEY("TV Playback", "TOGGLEPBPMODE", "Toggle Picture-by-Picture view", … … 626 627 Teletext F2,F3,F4,F5,F6,F7,F8 627 628 ITV F2,F3,F4,F5,F6,F7,F12 628 629 629 Playback: Ctrl-B,Ctrl-G,Ctrl-Y 630 Playback: Ctrl-B,Ctrl-G,Ctrl-Y,Ctrl-U 630 631 */ 631 632 } 632 633 … … 4340 4341 DoTogglePictureAttribute(ctx, kAdjustingPicture_Playback); 4341 4342 else if (has_action("TOGGLESTRETCH", actions)) 4342 4343 ToggleTimeStretch(ctx); 4344 else if (has_action("TOGGLEUPMIX", actions)) 4345 ToggleUpmix(ctx); 4343 4346 else if (has_action("TOGGLESLEEP", actions)) 4344 4347 ToggleSleepTimer(ctx); 4345 4348 else if (has_action("TOGGLERECORD", actions) && islivetv) … … 8023 8026 SetSpeedChangeTimer(0, __LINE__); 8024 8027 } 8025 8028 8029 void TV::ToggleUpmix(PlayerContext *ctx) 8030 { 8031 if (!ctx->nvp || !ctx->nvp->HasAudioOut()) 8032 return; 8033 QString text; 8034 if (ctx->nvp->ToggleUpmix()) 8035 text = tr("Upmixer On"); 8036 else 8037 text = tr("Upmixer Off"); 8038 8039 if (ctx->nvp->GetOSD() && !browsemode) 8040 ctx->nvp->GetOSD()->SetSettingsText(text, 5); 8041 } 8042 8026 8043 // dir in 10ms jumps 8027 8044 void TV::ChangeAudioSync(PlayerContext *ctx, int dir, bool allowEdit) 8028 8045 { … … 9652 9669 SetManualZoom(actx, true, tr("Zoom Mode ON")); 9653 9670 else if (action == "TOGGLESTRETCH") 9654 9671 ToggleTimeStretch(actx); 9672 else if (action == "TOGGLEUPMIX") 9673 ToggleUpmix(actx); 9655 9674 else if (action.left(13) == "ADJUSTSTRETCH") 9656 9675 { 9657 9676 bool floatRead; … … 10017 10036 10018 10037 if (category == "AUDIOSYNC") 10019 10038 new OSDGenericTree(treeMenu, tr("Adjust Audio Sync"), "TOGGLEAUDIOSYNC"); 10039 else if (category == "TOGGLEUPMIX") 10040 new OSDGenericTree(treeMenu, tr("Toggle Audio Upmixer"), "TOGGLEUPMIX"); 10020 10041 else if (category == "TIMESTRETCH") 10021 10042 FillMenuTimeStretch(ctx, treeMenu); 10022 10043 else if (category == "VIDEOSCAN") -
mythtv/libs/libmythtv/tvosdmenuentry.cpp
232 232 curMenuEntries.append( 233 233 new TVOSDMenuEntry("AUDIOSYNC", 1, 1, 1, 1 , "Audio Sync")); 234 234 curMenuEntries.append( 235 new TVOSDMenuEntry("TOGGLEUPMIX", 1, 1, 1, 1, "Toggle Upmixer")); 236 curMenuEntries.append( 235 237 new TVOSDMenuEntry("TIMESTRETCH", 1, 1, 1, 1, "Time Stretch")); 236 238 curMenuEntries.append( 237 239 new TVOSDMenuEntry("VIDEOSCAN", 1, 1, 1, 1, "Video Scan")); -
mythtv/libs/libmythtv/avformatdecoder.h
188 188 189 189 void SeekReset(long long, uint skipFrames, bool doFlush, bool discardFrames); 190 190 191 bool DoPassThrough(const AVCodecContext *ctx); 191 192 bool SetupAudioStream(void); 192 193 void SetupAudioStreamSubIndexes(int streamIndex); 193 194 void RemoveAudioStreams(); … … 258 259 short int *audioSamples; 259 260 bool allow_ac3_passthru; 260 261 bool allow_dts_passthru; 262 bool internal_vol; 261 263 bool disable_passthru; 262 264 uint max_channels; 265 uint last_ac3_channels; 263 266 264 267 VideoFrame *dummy_frame; 265 268 -
mythtv/libs/libavcodec/aac.c
98 98 static VLC vlc_scalefactors; 99 99 static VLC vlc_spectral[11]; 100 100 101 #define CHAN_MAP_MAX 6 101 102 103 static int chan_map[CHAN_MAP_MAX] = { 2, 0, 6, 4, 3, 2 }; 104 105 102 106 static ChannelElement* get_che(AACContext *ac, int type, int elem_id) { 103 107 static const int8_t tags_per_config[16] = { 0, 1, 1, 2, 3, 3, 4, 5, 0, 0, 0, 0, 0, 0, 0, 0 }; 104 108 if (ac->tag_che_map[type][elem_id]) { … … 167 171 /* Allocate or free elements depending on if they are in the 168 172 * current program configuration. 169 173 * 170 * Set up default 1:1output mapping.174 * Set up default SMPTE output mapping. 171 175 * 172 * For a 5.1 stream the output order will be:173 * [ Center ] [ Front Left ] [ Front Right ] [ LFE ] [ Surround Left ] [ Surround Right ]174 176 */ 175 177 176 178 for(i = 0; i < MAX_ELEM_ID; i++) { … … 179 181 if(!ac->che[type][i] && !(ac->che[type][i] = av_mallocz(sizeof(ChannelElement)))) 180 182 return AVERROR(ENOMEM); 181 183 if(type != TYPE_CCE) { 182 ac->output_data[channels++] = ac->che[type][i]->ch[0].ret; 183 if(type == TYPE_CPE) { 184 ac->output_data[channels++] = ac->che[type][i]->ch[1].ret; 184 /* Convert to SMPTE channel order */ 185 int ch = 0; 186 if (che_pos[type][i] < CHAN_MAP_MAX) { 187 if (che_pos[type][i] == AAC_CHANNEL_FRONT) 188 ch == TYPE_SCE ? /* center */ 2 : /* FL */ 0; 189 else 190 ch = chan_map[che_pos[type][i]]; 191 ac->output_data[ch] = ac->che[type][i]->ch[0].ret; 192 channels++; 193 if(type == TYPE_CPE) { 194 ac->output_data[ch + 1] = ac->che[type][i]->ch[1].ret; 195 channels++; 196 } 185 197 } 198 else { 199 ac->output_data[channels++] = ac->che[type][i]->ch[0].ret; 200 if(type == TYPE_CPE) { 201 ac->output_data[channels++] = ac->che[type][i]->ch[1].ret; 202 } 203 } 186 204 } 187 205 } else 188 206 av_freep(&ac->che[type][i]); -
mythtv/libs/libmyth/audiooutputjack.h
23 23 virtual void WriteAudio(unsigned char *aubuf, int size); 24 24 virtual int GetSpaceOnSoundcard(void) const; 25 25 virtual int GetBufferedOnSoundcard(void) const; 26 vector<int> GetSupportedRates(void); 26 27 27 28 private: 28 29 -
mythtv/libs/libmyth/audiosettings.cpp
7 7 8 8 #include "audiosettings.h" 9 9 10 // startup_upmixer 10 11 AudioSettings::AudioSettings() : 11 12 main_device(QString::null), 12 13 passthru_device(QString::null), 13 14 bits(-1), 14 15 channels(-1), 16 codec(0), 15 17 samplerate(-1), 16 18 set_initial_vol(false), 17 19 use_passthru(false), 18 codec(NULL),19 source(AUDIOOUTPUT_UNKNOWN)20 source(AUDIOOUTPUT_UNKNOWN), 21 upmixer(0) 20 22 { 21 23 } 22 24 … … 25 27 passthru_device(other.passthru_device), 26 28 bits(other.bits), 27 29 channels(other.channels), 30 codec(other.codec), 28 31 samplerate(other.samplerate), 29 32 set_initial_vol(other.set_initial_vol), 30 33 use_passthru(other.use_passthru), 31 codec(other.codec),32 source(other.source)34 source(other.source), 35 upmixer(other.upmixer) 33 36 { 34 37 } 35 38 … … 38 41 const QString &audio_passthru_device, 39 42 int audio_bits, 40 43 int audio_channels, 44 int audio_codec, 41 45 int audio_samplerate, 42 46 AudioOutputSource audio_source, 43 47 bool audio_set_initial_vol, 44 48 bool audio_use_passthru, 45 void *audio_codec) :49 int upmixer_startup) : 46 50 main_device(audio_main_device), 47 51 passthru_device(audio_passthru_device), 48 52 bits(audio_bits), 49 53 channels(audio_channels), 54 codec(audio_codec), 50 55 samplerate(audio_samplerate), 51 56 set_initial_vol(audio_set_initial_vol), 52 57 use_passthru(audio_use_passthru), 53 codec(audio_codec),54 source(audio_source)58 source(audio_source), 59 upmixer(upmixer_startup) 55 60 { 56 61 } 57 62 58 63 AudioSettings::AudioSettings( 59 64 int audio_bits, 60 65 int audio_channels, 66 int audio_codec, 61 67 int audio_samplerate, 62 68 bool audio_use_passthru, 63 void *audio_codec) :69 int upmixer_startup) : 64 70 main_device(QString::null), 65 71 passthru_device(QString::null), 66 72 bits(audio_bits), 67 73 channels(audio_channels), 74 codec(audio_codec), 68 75 samplerate(audio_samplerate), 69 76 set_initial_vol(false), 70 77 use_passthru(audio_use_passthru), 71 codec(audio_codec),72 source(AUDIOOUTPUT_UNKNOWN)78 source(AUDIOOUTPUT_UNKNOWN), 79 upmixer(upmixer_startup) 73 80 { 74 81 } 75 82 -
mythtv/libs/libmyth/audiooutputbase.h
43 43 44 44 virtual void SetStretchFactor(float factor); 45 45 virtual float GetStretchFactor(void) const; 46 virtual bool ToggleUpmix(void); 46 47 47 48 virtual void Reset(void); 48 49 50 void SetSWVolume(int new_volume, bool save); 51 int GetSWVolume(void); 52 49 53 // timecode is in milliseconds. 50 54 virtual bool AddSamples(char *buffer, int samples, long long timecode); 51 55 virtual bool AddSamples(char *buffers[], int samples, long long timecode); … … 85 89 virtual void WriteAudio(unsigned char *aubuf, int size) = 0; 86 90 virtual int GetSpaceOnSoundcard(void) const = 0; 87 91 virtual int GetBufferedOnSoundcard(void) const = 0; 92 virtual vector<int> GetSupportedRates(void) 93 { vector<int> rates; return rates; } 88 94 /// You need to call this from any implementation in the dtor. 89 95 void KillAudio(void); 90 96 … … 122 128 123 129 // Basic details about the audio stream 124 130 int audio_channels; 131 int audio_codec; 125 132 int audio_bytes_per_sample; 126 133 int audio_bits; 127 134 int audio_samplerate; … … 132 139 QString audio_passthru_device; 133 140 134 141 bool audio_passthru; 142 bool audio_enc; 143 bool audio_reenc; 135 144 136 145 float audio_stretchfactor; 137 AVCodecContext *audio_codec;138 146 AudioOutputSource source; 139 147 140 148 bool killaudio; … … 144 152 bool buffer_output_data_for_use; // used by AudioOutputNULL 145 153 146 154 int configured_audio_channels; 155 int orig_config_channels; 156 int src_quality; 147 157 148 158 private: 159 // software volume 160 template <class AudioDataType> 161 void _AdjustVolume(AudioDataType *buffer, int len, bool music); 162 void AdjustVolume(void *buffer, int len, bool music); 163 149 164 // resampler 150 165 bool need_resampler; 151 166 SRC_STATE *src_ctx; … … 156 171 FreeSurround *upmixer; 157 172 158 173 int source_audio_channels; 174 int source_audio_samplerate; 159 175 int source_audio_bytes_per_sample; 160 176 bool needs_upmix; 161 177 int surround_mode; 178 bool allow_ac3_passthru; 179 float old_audio_stretchfactor; 180 int volume; 162 181 163 182 bool blocking; // do AddSamples calls block? 164 183 -
mythtv/libs/libmyth/audiooutputalsa.cpp
32 32 AudioOutputALSA::~AudioOutputALSA() 33 33 { 34 34 KillAudio(); 35 SetIECStatus(true); 35 36 } 36 37 38 void AudioOutputALSA::SetIECStatus(bool audio) 39 { 40 snd_ctl_t *ctl; 41 const char *spdif_str = SND_CTL_NAME_IEC958("", PLAYBACK, DEFAULT); 42 int spdif_index = -1; 43 snd_ctl_elem_list_t *clist; 44 snd_ctl_elem_id_t *cid; 45 snd_ctl_elem_value_t *cval; 46 snd_aes_iec958_t iec958; 47 int cidx, controls; 48 49 VERBOSE(VB_AUDIO, QString("Setting IEC958 status: %1") 50 .arg(audio ? "audio" : "non-audio")); 51 52 int err; 53 if ((err = snd_ctl_open(&ctl, "default", 0)) < 0) 54 { 55 Error(QString("AudioOutputALSA::SetIECStatus: snd_ctl_open(default): %1") 56 .arg(snd_strerror(err))); 57 return; 58 } 59 snd_ctl_elem_list_alloca(&clist); 60 snd_ctl_elem_list(ctl, clist); 61 snd_ctl_elem_list_alloc_space(clist, snd_ctl_elem_list_get_count(clist)); 62 snd_ctl_elem_list(ctl, clist); 63 controls = snd_ctl_elem_list_get_used(clist); 64 for (cidx = 0; cidx < controls; cidx++) 65 { 66 if (!strcmp(snd_ctl_elem_list_get_name(clist, cidx), spdif_str)) 67 if (spdif_index < 0 || 68 snd_ctl_elem_list_get_index(clist, cidx) == (uint)spdif_index) 69 break; 70 } 71 72 if (cidx >= controls) 73 return; 74 75 snd_ctl_elem_id_alloca(&cid); 76 snd_ctl_elem_list_get_id(clist, cidx, cid); 77 snd_ctl_elem_value_alloca(&cval); 78 snd_ctl_elem_value_set_id(cval, cid); 79 snd_ctl_elem_read(ctl,cval); 80 snd_ctl_elem_value_get_iec958(cval, &iec958); 81 82 if (!audio) 83 iec958.status[0] |= IEC958_AES0_NONAUDIO; 84 else 85 iec958.status[0] &= ~IEC958_AES0_NONAUDIO; 86 87 snd_ctl_elem_value_set_iec958(cval, &iec958); 88 snd_ctl_elem_write(ctl, cval); 89 } 90 91 vector<int> AudioOutputALSA::GetSupportedRates() 92 { 93 snd_pcm_hw_params_t *params; 94 int err; 95 const int srates[] = { 8000, 11025, 16000, 22050, 32000, 44100, 48000 }; 96 vector<int> rates(srates, srates + sizeof(srates) / sizeof(int) ); 97 QString real_device; 98 99 if (audio_passthru || audio_enc) 100 real_device = audio_passthru_device; 101 else 102 real_device = audio_main_device; 103 104 if((err = snd_pcm_open(&pcm_handle, real_device.toAscii(), 105 SND_PCM_STREAM_PLAYBACK, 106 SND_PCM_NONBLOCK|SND_PCM_NO_AUTO_RESAMPLE)) < 0) 107 { 108 Error(QString("snd_pcm_open(%1): %2") 109 .arg(real_device).arg(snd_strerror(err))); 110 111 if (pcm_handle) 112 { 113 snd_pcm_close(pcm_handle); 114 pcm_handle = NULL; 115 } 116 rates.clear(); 117 return rates; 118 } 119 120 snd_pcm_hw_params_alloca(¶ms); 121 122 if ((err = snd_pcm_hw_params_any(pcm_handle, params)) < 0) 123 { 124 Error(QString("Broken configuration for playback; no configurations" 125 " available: %1").arg(snd_strerror(err))); 126 snd_pcm_close(pcm_handle); 127 pcm_handle = NULL; 128 rates.clear(); 129 return rates; 130 } 131 132 vector<int>::iterator it = rates.begin(); 133 134 while (it != rates.end()) 135 { 136 if(snd_pcm_hw_params_test_rate(pcm_handle, params, *it, 0) < 0) 137 it = rates.erase(it); 138 else 139 it++; 140 } 141 142 snd_pcm_close(pcm_handle); 143 pcm_handle = NULL; 144 145 return rates; 146 } 147 37 148 bool AudioOutputALSA::OpenDevice() 38 149 { 39 150 snd_pcm_format_t format; 40 151 unsigned int buffer_time, period_time; 41 152 int err; 153 QString real_device; 42 154 43 155 if (pcm_handle != NULL) 44 156 CloseDevice(); … … 46 158 pcm_handle = NULL; 47 159 numbadioctls = 0; 48 160 49 QString real_device = (audio_passthru) ? 50 audio_passthru_device : audio_main_device; 161 if (audio_passthru || audio_enc) 162 { 163 real_device = audio_passthru_device; 164 SetIECStatus(false); 165 } 166 else 167 { 168 real_device = audio_main_device; 169 SetIECStatus(true); 170 } 51 171 52 172 VERBOSE(VB_GENERAL, QString("Opening ALSA audio device '%1'.") 53 173 .arg(real_device)); … … 146 266 } 147 267 } 148 268 269 void AudioOutputALSA::ReorderSmpteToAlsa6ch(unsigned char *buf, int size) 270 { 271 if (audio_bits == 8) 272 _ReorderSmpteToAlsa6ch(buf, size); 273 else if (audio_bits == 16) 274 _ReorderSmpteToAlsa6ch((short *)buf, size / sizeof(short)); 275 } 149 276 277 template <class AudioDataType> 278 void AudioOutputALSA::_ReorderSmpteToAlsa6ch(AudioDataType *buf, int size) 279 { 280 AudioDataType tmpC, tmpLFE; 281 282 for (int i = 0; i < size; i+= 6) { 283 tmpC = buf[i+2]; 284 tmpLFE = buf[i+3]; 285 buf[i+2] = buf[i+4]; 286 buf[i+3] = buf[i+5]; 287 buf[i+4] = tmpC; 288 buf[i+5] = tmpLFE; 289 } 290 291 } 150 292 void AudioOutputALSA::WriteAudio(unsigned char *aubuf, int size) 151 293 { 152 294 unsigned char *tmpbuf; … … 158 300 VERBOSE(VB_IMPORTANT, QString("WriteAudio() called with pcm_handle == NULL!")); 159 301 return; 160 302 } 303 304 if (!(audio_passthru || audio_enc) && audio_channels == 6) 305 ReorderSmpteToAlsa6ch(aubuf, size); 161 306 162 307 tmpbuf = aubuf; 163 308 … … 634 779 if (mixer_handle != NULL) 635 780 CloseMixer(); 636 781 782 if (alsadevice.toLower() == "software") 783 return; 784 637 785 VERBOSE(VB_AUDIO, QString("Opening mixer %1").arg(device)); 638 786 639 787 // TODO: This is opening card 0. Fix for case of multiple soundcards -
mythtv/libs/libmyth/volumebase.cpp
10 10 internal_vol(false), volume(80), 11 11 current_mute_state(kMuteOff) 12 12 { 13 swvol = swvol_setting = 14 (gContext->GetSetting("MixerDevice", "default").toLower() == "software"); 13 15 } 14 16 17 bool VolumeBase::SWVolume(void) 18 { 19 return swvol; 20 } 21 22 void VolumeBase::SWVolume(bool set) 23 { 24 if (swvol_setting) 25 return; 26 swvol = set; 27 } 28 15 29 uint VolumeBase::GetCurrentVolume(void) const 16 30 { 17 31 return volume; … … 76 90 void VolumeBase::UpdateVolume(void) 77 91 { 78 92 int new_volume = volume; 93 bool save = true; 79 94 if (current_mute_state == kMuteAll) 80 95 { 81 96 new_volume = 0; 97 save = false; 82 98 } 99 100 if (swvol) 101 { 102 SetSWVolume(new_volume, save); 103 return; 104 } 83 105 84 106 // TODO: Avoid assumption that there are 2 channels! 85 107 for (int i = 0; i < 2; i++) … … 102 124 void VolumeBase::SyncVolume(void) 103 125 { 104 126 // Read the volume from the audio driver and setup our internal state to match 105 volume = GetVolumeChannel(0); 127 if (swvol) 128 volume = GetSWVolume(); 129 else 130 volume = GetVolumeChannel(0); 106 131 } 107 132 -
mythtv/libs/libmyth/audiooutputjack.cpp
30 30 Reconfigure(settings); 31 31 } 32 32 33 vector<int> AudioOutputJACK::GetSupportedRates() 34 { 35 const int srates[] = { 8000, 11025, 16000, 22050, 32000, 44100, 48000 }; 36 vector<int> rates(srates, srates + sizeof(srates) / sizeof(int) ); 37 unsigned long jack_port_flags = 0; 38 unsigned int jack_port_name_count = 1; 39 const char *jack_port_name = audio_main_device.toAscii(); 40 int err = -1; 41 audioid = -1; 42 vector<int>::iterator it = rates.begin(); 43 44 while (it != rates.end()) 45 { 46 unsigned long lrate = (unsigned long) *it; 47 err = JACK_OpenEx(&audioid, 16, &lrate, 48 2, 2, &jack_port_name, jack_port_name_count, 49 jack_port_flags); 50 51 if (err == ERR_OPENING_JACK) 52 { 53 Error(QString("Error connecting to jackd: %1. Is it running?") 54 .arg(audio_main_device)); 55 rates.clear(); 56 return rates; 57 } 58 else 59 if (err == ERR_RATE_MISMATCH) 60 it = rates.erase(it); 61 else 62 it++; 63 64 JACK_Close(audioid); 65 audioid = -1; 66 } 67 return rates; 68 } 69 70 33 71 AudioOutputJACK::~AudioOutputJACK() 34 72 { 35 73 // Close down all audio stuff -
mythtv/libs/libmyth/audiooutputoss.h
23 23 virtual void WriteAudio(unsigned char *aubuf, int size); 24 24 virtual int GetSpaceOnSoundcard(void) const; 25 25 virtual int GetBufferedOnSoundcard(void) const; 26 vector<int> GetSupportedRates(void); 26 27 27 28 private: 28 29 void VolumeInit(void); -
mythtv/libs/libmyth/audiooutputbase.cpp
1 1 // Std C headers 2 2 #include <cmath> 3 #include <limits> 3 4 4 5 // POSIX headers 5 6 #include <unistd.h> … … 21 22 AudioOutputBase::AudioOutputBase(const AudioSettings &settings) : 22 23 // protected 23 24 effdsp(0), effdspstretched(0), 24 audio_channels(-1), audio_ bytes_per_sample(0),25 audio_b its(-1), audio_samplerate(-1),26 audio_ buffer_unused(0),25 audio_channels(-1), audio_codec(CODEC_ID_NONE), 26 audio_bytes_per_sample(0), audio_bits(-1), 27 audio_samplerate(-1), audio_buffer_unused(0), 27 28 fragment_size(0), soundcard_buffer_size(0), 28 29 29 30 audio_main_device(settings.GetMainDevice()), 30 31 audio_passthru_device(settings.GetPassthruDevice()), 31 audio_passthru(false), audio_stretchfactor(1.0f), 32 audio_passthru(false), audio_enc(false), 33 audio_reenc(false), audio_stretchfactor(1.0f), 32 34 33 audio_codec(NULL),34 35 source(settings.source), killaudio(false), 35 36 36 37 pauseaudio(false), audio_actually_paused(false), … … 48 49 encoder(NULL), 49 50 upmixer(NULL), 50 51 source_audio_channels(-1), 52 source_audio_samplerate(0), 51 53 source_audio_bytes_per_sample(0), 52 54 needs_upmix(false), 53 55 surround_mode(FreeSurround::SurroundModePassive), 56 old_audio_stretchfactor(1.0), 57 volume(80), 54 58 55 59 blocking(false), 56 60 … … 62 66 raud(0), waud(0), 63 67 audbuf_timecode(0), 64 68 65 numlowbuffer(0),killAudioLock(QMutex::NonRecursive),69 killAudioLock(QMutex::NonRecursive), 66 70 current_seconds(-1), source_bitrate(-1), 67 71 68 72 memory_corruption_test0(0xdeadbeef), … … 78 82 memset(tmp_buff, 0, sizeof(short) * kAudioTempBufSize); 79 83 memset(&audiotime_updated, 0, sizeof(audiotime_updated)); 80 84 memset(audiobuffer, 0, sizeof(char) * kAudioRingBufferSize); 81 configured_audio_channels = gContext->GetNumSetting("MaxChannels", 2); 85 orig_config_channels = gContext->GetNumSetting("MaxChannels", 2); 86 src_quality = gContext->GetNumSetting("AudioUpmixType", 2); 87 if (!settings.upmixer) 88 configured_audio_channels = gContext->GetNumSetting("AudioDefaultUpmix", false) ? orig_config_channels : 2; 89 else 90 if (settings.upmixer == 1) 91 configured_audio_channels = 2; 92 else 93 configured_audio_channels = 6; 82 94 95 allow_ac3_passthru = (orig_config_channels > 2) ? gContext->GetNumSetting("AC3PassThru", false) : false; 96 83 97 // You need to call Reconfigure from your concrete class. 84 98 // Reconfigure(laudio_bits, laudio_channels, 85 99 // laudio_samplerate, laudio_passthru); … … 124 138 VERBOSE(VB_GENERAL, LOC + QString("Using time stretch %1") 125 139 .arg(audio_stretchfactor)); 126 140 pSoundStretch = new soundtouch::SoundTouch(); 127 if (audio_codec) 128 { 129 if (!encoder) 130 { 131 VERBOSE(VB_AUDIO, LOC + 132 QString("Creating Encoder for codec %1 origfs %2") 133 .arg(audio_codec->codec_id) 134 .arg(audio_codec->frame_size)); 141 pSoundStretch->setSampleRate(audio_samplerate); 142 pSoundStretch->setChannels(upmixer ? 143 configured_audio_channels : source_audio_channels); 135 144 136 encoder = new AudioOutputDigitalEncoder();137 if (!encoder->Init(audio_codec->codec_id,138 audio_codec->bit_rate,139 audio_codec->sample_rate,140 audio_codec->channels141 ))142 {143 // eeks144 delete encoder;145 encoder = NULL;146 VERBOSE(VB_AUDIO, LOC +147 QString("Failed to Create Encoder"));148 }149 }150 }151 if (audio_codec && encoder)152 {153 pSoundStretch->setSampleRate(audio_codec->sample_rate);154 pSoundStretch->setChannels(audio_codec->channels);155 }156 else157 {158 pSoundStretch->setSampleRate(audio_samplerate);159 pSoundStretch->setChannels(audio_channels);160 }161 162 145 pSoundStretch->setTempo(audio_stretchfactor); 163 146 pSoundStretch->setSetting(SETTING_SEQUENCE_MS, 35); 164 147 165 148 // dont need these with only tempo change 166 149 //pSoundStretch->setPitch(1.0); 167 150 //pSoundStretch->setRate(1.0); 168 169 151 //pSoundStretch->setSetting(SETTING_USE_QUICKSEEK, true); 170 152 //pSoundStretch->setSetting(SETTING_USE_AA_FILTER, false); 171 153 } … … 183 165 return audio_stretchfactor; 184 166 } 185 167 168 bool AudioOutputBase::ToggleUpmix(void) 169 { 170 if (orig_config_channels == 2 || source_audio_channels > 2 || 171 audio_passthru) 172 return false; 173 if (configured_audio_channels == 6) 174 configured_audio_channels = 2; 175 else 176 configured_audio_channels = 6; 177 178 const AudioSettings settings(audio_bits, source_audio_channels, 179 audio_codec, source_audio_samplerate, 180 audio_passthru); 181 Reconfigure(settings); 182 return (configured_audio_channels == 6); 183 } 184 185 186 186 void AudioOutputBase::Reconfigure(const AudioSettings &orig_settings) 187 187 { 188 188 AudioSettings settings = orig_settings; 189 189 190 int codec_id = CODEC_ID_NONE;191 int lcodec_id = CODEC_ID_NONE;192 int lcchannels = 0;193 int cchannels = 0;194 190 int lsource_audio_channels = settings.channels; 195 191 bool lneeds_upmix = false; 192 bool laudio_reenc = false; 196 193 197 if (settings.codec) 194 // Are we reencoding a (previously) timestretched bitstream? 195 if ((settings.codec == CODEC_ID_AC3 || settings.codec == CODEC_ID_DTS) && 196 !settings.use_passthru && allow_ac3_passthru) 198 197 { 199 lcodec_id = ((AVCodecContext*)settings.codec)->codec_id; 200 settings.bits = 16; 201 settings.channels = 2; 202 lsource_audio_channels = settings.channels; 203 settings.samplerate = 48000; 204 lcchannels = ((AVCodecContext*)settings.codec)->channels; 198 laudio_reenc = true; 199 VERBOSE(VB_AUDIO, LOC + "Reencoding decoded AC3/DTS to AC3"); 205 200 } 206 201 207 if (audio_codec) 202 // Enough channels? Upmix if not 203 if (settings.channels < configured_audio_channels && 204 !settings.use_passthru) 208 205 { 209 codec_id = audio_codec->codec_id;210 cchannels = ((AVCodecContext*)audio_codec)->channels;211 }212 213 if ((configured_audio_channels == 6) &&214 !(settings.codec || audio_codec))215 {216 206 settings.channels = configured_audio_channels; 217 207 lneeds_upmix = true; 218 208 VERBOSE(VB_AUDIO,LOC + "Needs upmix"); … … 224 214 settings.samplerate == audio_samplerate && !need_resampler && 225 215 settings.use_passthru == audio_passthru && 226 216 lneeds_upmix == needs_upmix && 227 l codec_id == codec_id && lcchannels == cchannels);217 laudio_reenc == audio_reenc); 228 218 bool upmix_deps = 229 219 (lsource_audio_channels == source_audio_channels); 230 220 if (general_deps && upmix_deps) … … 251 241 waud = raud = 0; 252 242 audio_actually_paused = false; 253 243 254 bool redo_stretch = (pSoundStretch && audio_channels != settings.channels);255 244 audio_channels = settings.channels; 256 245 source_audio_channels = lsource_audio_channels; 257 246 audio_bits = settings.bits; 258 audio_samplerate = settings.samplerate; 259 audio_codec = (AVCodecContext*)settings.codec; 247 source_audio_samplerate = audio_samplerate = settings.samplerate; 248 audio_reenc = laudio_reenc; 249 audio_codec = settings.codec; 260 250 audio_passthru = settings.use_passthru; 261 251 needs_upmix = lneeds_upmix; 262 252 … … 265 255 Error("AudioOutput only supports 8 or 16bit audio."); 266 256 return; 267 257 } 268 audio_bytes_per_sample = audio_channels * audio_bits / 8; 269 source_audio_bytes_per_sample = source_audio_channels * audio_bits / 8; 258 259 VERBOSE(VB_AUDIO, LOC + QString("Original audio codec was %1") 260 .arg(codec_id_string((CodecID)audio_codec))); 270 261 271 262 need_resampler = false; 272 263 killaudio = false; … … 274 265 was_paused = true; 275 266 internal_vol = gContext->GetNumSetting("MythControlsVolume", 0); 276 267 277 numlowbuffer = 0; 268 // Find out what sample rates we can output (if output layer supports it) 269 vector<int> rates = GetSupportedRates(); 270 vector<int>::iterator it; 271 bool resample = true; 278 272 279 VERBOSE(VB_GENERAL, QString("Opening audio device '%1'. ch %2(%3) sr %4") 273 for (it = rates.begin(); it < rates.end(); it++) 274 { 275 VERBOSE(VB_AUDIO, LOC + QString("Sample rate %1 is supported") 276 .arg(*it)); 277 if (*it == audio_samplerate) 278 resample = false; 279 } 280 281 // Assume 48k if we can't get supported rates 282 if (rates.empty()) 283 rates.push_back(48000); 284 285 if (resample) 286 { 287 int error; 288 audio_samplerate = *(rates.end()); 289 VERBOSE(VB_GENERAL, LOC + QString("Using resampler. From: %1 to %2") 290 .arg(settings.samplerate).arg(audio_samplerate)); 291 src_ctx = src_new(2-src_quality, source_audio_channels, &error); 292 if (error) 293 { 294 Error(QString("Error creating resampler, the error was: %1") 295 .arg(src_strerror(error)) ); 296 src_ctx = NULL; 297 return; 298 } 299 src_data.src_ratio = (double) audio_samplerate / settings.samplerate; 300 src_data.data_in = src_in; 301 src_data.data_out = src_out; 302 src_data.output_frames = 16384*6; 303 need_resampler = true; 304 } 305 306 // Encode to AC-3 if not passing thru , there's > 2 channels 307 // and a passthru device is defined 308 if (!audio_passthru && allow_ac3_passthru && 309 (audio_channels > 2 || audio_reenc)) 310 { 311 VERBOSE(VB_AUDIO, LOC + "Creating AC-3 Encoder"); 312 encoder = new AudioOutputDigitalEncoder(); 313 if (!encoder->Init(CODEC_ID_AC3, 448000, audio_samplerate, audio_channels)) 314 { 315 VERBOSE(VB_AUDIO, LOC + "Can't create AC-3 encoder"); 316 delete encoder; 317 encoder = NULL; 318 } 319 320 audio_enc = true; 321 } 322 323 if(audio_passthru || audio_enc) 324 // AC-3 output - soundcard expects a 2ch 48k stream 325 audio_channels = 2; 326 327 audio_bytes_per_sample = audio_channels * audio_bits / 8; 328 source_audio_bytes_per_sample = source_audio_channels * audio_bits / 8; 329 330 VERBOSE(VB_GENERAL, QString("Opening audio device '%1'. ch %2(%3) sr %4 (reenc %5)") 280 331 .arg(audio_main_device).arg(audio_channels) 281 .arg(source_audio_channels).arg(audio_samplerate) );332 .arg(source_audio_channels).arg(audio_samplerate).arg(audio_reenc)); 282 333 283 334 // Actually do the device specific open call 284 335 if (!OpenDevice()) … … 290 341 return; 291 342 } 292 343 344 // Only used for software volume 345 if (set_initial_vol && internal_vol) 346 volume = gContext->GetNumSetting("PCMMixerVolume", 80); 347 { 348 QString controlLabel = gContext->GetSetting("MixerControl", "PCM"); 349 controlLabel += "MixerVolume"; 350 volume = gContext->GetNumSetting(controlLabel, 80); 351 } 352 293 353 SyncVolume(); 294 354 295 355 VERBOSE(VB_AUDIO, LOC + QString("Audio fragment size: %1") 296 356 .arg(fragment_size)); 297 357 298 if (audio_buffer_unused < 0) 299 audio_buffer_unused = 0; 358 audio_buffer_unused = 0; 300 359 301 if (!gContext->GetNumSetting("AggressiveSoundcardBuffer", 0))302 audio_buffer_unused = 0;303 304 360 audbuf_timecode = 0; 305 361 audiotime = 0; 306 362 samples_buffered = 0; … … 309 365 current_seconds = -1; 310 366 source_bitrate = -1; 311 367 312 // NOTE: this won't do anything as above samplerate vars are set equal313 // Check if we need the resampler314 if (audio_samplerate != settings.samplerate)315 {316 int error;317 VERBOSE(VB_GENERAL, LOC + QString("Using resampler. From: %1 to %2")318 .arg(settings.samplerate).arg(audio_samplerate));319 src_ctx = src_new (SRC_SINC_BEST_QUALITY, audio_channels, &error);320 if (error)321 {322 Error(QString("Error creating resampler, the error was: %1")323 .arg(src_strerror(error)) );324 return;325 }326 src_data.src_ratio = (double) audio_samplerate / settings.samplerate;327 src_data.data_in = src_in;328 src_data.data_out = src_out;329 src_data.output_frames = 16384*6;330 need_resampler = true;331 }332 333 368 if (needs_upmix) 334 369 { 335 370 VERBOSE(VB_AUDIO, LOC + QString("create upmixer")); … … 344 379 (FreeSurround::SurroundMode)surround_mode); 345 380 346 381 VERBOSE(VB_AUDIO, LOC + 347 QString(" create upmixer done with surround mode %1")382 QString("Create upmixer done with surround mode %1") 348 383 .arg(surround_mode)); 349 384 } 350 385 351 386 VERBOSE(VB_AUDIO, LOC + QString("Audio Stretch Factor: %1") 352 387 .arg(audio_stretchfactor)); 353 VERBOSE(VB_AUDIO, QString("Audio Codec Used: %1")354 .arg((audio_codec) ?355 codec_id_string(audio_codec->codec_id) : "not set"));356 388 357 if (redo_stretch) 358 { 359 delete pSoundStretch; 360 pSoundStretch = NULL; 361 SetStretchFactorLocked(audio_stretchfactor); 362 } 363 else 364 { 365 SetStretchFactorLocked(audio_stretchfactor); 366 if (pSoundStretch) 367 { 368 // if its passthru then we need to reencode 369 if (audio_codec) 370 { 371 if (!encoder) 372 { 373 VERBOSE(VB_AUDIO, LOC + 374 QString("Creating Encoder for codec %1") 375 .arg(audio_codec->codec_id)); 376 377 encoder = new AudioOutputDigitalEncoder(); 378 if (!encoder->Init(audio_codec->codec_id, 379 audio_codec->bit_rate, 380 audio_codec->sample_rate, 381 audio_codec->channels 382 )) 383 { 384 // eeks 385 delete encoder; 386 encoder = NULL; 387 VERBOSE(VB_AUDIO, LOC + "Failed to Create Encoder"); 388 } 389 } 390 } 391 if (audio_codec && encoder) 392 { 393 pSoundStretch->setSampleRate(audio_codec->sample_rate); 394 pSoundStretch->setChannels(audio_codec->channels); 395 } 396 else 397 { 398 pSoundStretch->setSampleRate(audio_samplerate); 399 pSoundStretch->setChannels(audio_channels); 400 } 401 } 402 } 403 389 SetStretchFactorLocked(old_audio_stretchfactor); 390 404 391 // Setup visualisations, zero the visualisations buffers 405 392 prepareVisuals(); 406 393 … … 436 423 VERBOSE(VB_AUDIO, LOC + "Killing AudioOutputDSP"); 437 424 killaudio = true; 438 425 StopOutputThread(); 426 QMutexLocker lock1(&audio_buflock); 439 427 440 428 // Close resampler? 441 429 if (src_ctx) 430 { 442 431 src_delete(src_ctx); 432 src_ctx = NULL; 433 } 434 443 435 need_resampler = false; 444 436 445 437 // close sound stretcher … … 447 439 { 448 440 delete pSoundStretch; 449 441 pSoundStretch = NULL; 442 old_audio_stretchfactor = audio_stretchfactor; 443 audio_stretchfactor = 1.0; 450 444 } 451 445 452 446 if (encoder) … … 461 455 upmixer = NULL; 462 456 } 463 457 needs_upmix = false; 458 audio_enc = false; 464 459 465 460 CloseDevice(); 466 461 … … 611 606 612 607 // include algorithmic latencies 613 608 if (pSoundStretch) 614 {615 // add the effect of any unused but processed samples,616 // AC3 reencode does this617 totalbuffer += (int)(pSoundStretch->numSamples() *618 audio_bytes_per_sample);619 // add the effect of unprocessed samples in time stretch algo620 609 totalbuffer += (int)((pSoundStretch->numUnprocessedSamples() * 621 610 audio_bytes_per_sample) / audio_stretchfactor); 622 }623 611 624 612 if (upmixer && needs_upmix) 625 {626 613 totalbuffer += upmixer->sampleLatency() * audio_bytes_per_sample; 627 }628 614 615 if (encoder) 616 totalbuffer += encoder->Buffered(); 617 629 618 audiotime = audbuf_timecode - (int)(totalbuffer * 100000.0 / 630 619 (audio_bytes_per_sample * effdspstretched)); 631 620 … … 650 639 return audbuf_timecode - GetAudiotime(); 651 640 } 652 641 642 void AudioOutputBase::SetSWVolume(int new_volume, bool save) 643 { 644 volume = new_volume; 645 if (save) 646 { 647 QString controlLabel = gContext->GetSetting("MixerControl", "PCM"); 648 controlLabel += "MixerVolume"; 649 gContext->SaveSetting(controlLabel, volume); 650 } 651 } 652 653 int AudioOutputBase::GetSWVolume() 654 { 655 return volume; 656 } 657 658 template <class AudioDataType> 659 void AudioOutputBase::_AdjustVolume(AudioDataType *buffer, int len, bool music) 660 { 661 float g = volume / 100.0; 662 663 // Should probably be exponential - this'll do 664 g *= g; 665 666 // Add gain to AC-3 - try to ~ match PCM volume 667 if (audio_enc && audio_reenc) 668 g *= 1.8; 669 670 // Music is relatively loud - ditto 671 else if (music) 672 g *= 0.4; 673 674 if (g == 1.0) 675 return; 676 677 for (int i = 0; i < (int)(len / sizeof(AudioDataType)); i++) 678 { 679 float s = static_cast<float>(buffer[i]) * g / 680 static_cast<float>(numeric_limits<AudioDataType>::max()); 681 if (s >= 1.0) 682 buffer[i] = numeric_limits<AudioDataType>::max(); 683 else if (s <= -1.0) 684 buffer[i] = numeric_limits<AudioDataType>::min(); 685 else 686 buffer[i] = static_cast<AudioDataType> 687 (s * numeric_limits<AudioDataType>::max()); 688 } 689 } 690 691 void AudioOutputBase::AdjustVolume(void *buffer, int len, bool music) 692 { 693 if (audio_bits == 8) 694 _AdjustVolume<char>((char *)buffer, len, music); 695 else if (audio_bits == 16) 696 _AdjustVolume<short>((short *)buffer, len, music); 697 } 698 653 699 bool AudioOutputBase::AddSamples(char *buffers[], int samples, 654 700 long long timecode) 655 701 { … … 681 727 return false; // would overflow 682 728 } 683 729 730 QMutexLocker lock1(&audio_buflock); 731 684 732 // resample input if necessary 685 733 if (need_resampler && src_ctx) 686 734 { … … 725 773 int abps = (encoder) ? 726 774 encoder->audio_bytes_per_sample : audio_bytes_per_sample; 727 775 int len = samples * abps; 776 777 // Give original samples to mythmusic visualisation 778 dispatchVisual((unsigned char *)buffer, len, timecode, 779 source_audio_channels, audio_bits); 728 780 729 781 // Check we have enough space to write the data 730 782 if (need_resampler && src_ctx) … … 749 801 return false; // would overflow 750 802 } 751 803 804 QMutexLocker lock1(&audio_buflock); 805 752 806 // resample input if necessary 753 807 if (need_resampler && src_ctx) 754 808 { … … 809 863 { 810 864 int error = src_reset(src_ctx); 811 865 if (error) 866 { 812 867 VERBOSE(VB_IMPORTANT, LOC_ERR + QString( 813 868 "Error occured while resetting resampler: %1") 814 869 .arg(src_strerror(error))); 870 src_ctx = NULL; 871 } 815 872 } 816 873 } 817 874 } … … 821 878 void AudioOutputBase::_AddSamples(void *buffer, bool interleaved, int samples, 822 879 long long timecode) 823 880 { 824 audio_buflock.lock();825 826 881 int len; // = samples * audio_bytes_per_sample; 827 882 int audio_bytes = audio_bits / 8; 828 883 int org_waud = waud; … … 839 894 .arg(samples * abps) 840 895 .arg(kAudioRingBufferSize-afree).arg(afree).arg(timecode) 841 896 .arg(needs_upmix)); 842 897 898 len = WaitForFreeSpace(samples); 899 843 900 if (upmixer && needs_upmix) 844 901 { 845 902 int out_samples = 0; 903 org_waud = waud; 846 904 int step = (interleaved)?source_audio_channels:1; 847 len = WaitForFreeSpace(samples); // test 905 848 906 for (int itemp = 0; itemp < samples; ) 849 907 { 850 // just in case it does a processing cycle, release the lock851 // to allow the output loop to do output852 audio_buflock.unlock();853 908 if (audio_bytes == 2) 854 909 { 855 910 itemp += upmixer->putSamples( … … 866 921 source_audio_channels, 867 922 (interleaved) ? 0 : samples); 868 923 } 869 audio_buflock.lock();870 924 871 925 int copy_samples = upmixer->numSamples(); 872 926 if (copy_samples) … … 900 954 } 901 955 else 902 956 { 903 len = WaitForFreeSpace(samples);904 905 957 if (interleaved) 906 958 { 907 959 char *mybuf = (char*)buffer; … … 936 988 } 937 989 } 938 990 939 if (samples > 0) 991 if (samples <= 0) 992 return; 993 994 if (pSoundStretch) 940 995 { 941 if (pSoundStretch) 996 // does not change the timecode, only the number of samples 997 // back to orig pos 998 org_waud = waud; 999 int bdiff = kAudioRingBufferSize - org_waud; 1000 int nSamplesToEnd = bdiff/abps; 1001 if (bdiff < len) 942 1002 { 1003 pSoundStretch->putSamples((soundtouch::SAMPLETYPE*) 1004 (audiobuffer + 1005 org_waud), nSamplesToEnd); 1006 pSoundStretch->putSamples((soundtouch::SAMPLETYPE*)audiobuffer, 1007 (len - bdiff) / abps); 1008 } 1009 else 1010 { 1011 pSoundStretch->putSamples((soundtouch::SAMPLETYPE*) 1012 (audiobuffer + org_waud), 1013 len / abps); 1014 } 943 1015 944 // does not change the timecode, only the number of samples 945 // back to orig pos 946 org_waud = waud; 947 int bdiff = kAudioRingBufferSize - org_waud; 948 int nSamplesToEnd = bdiff/abps; 949 if (bdiff < len) 950 { 951 pSoundStretch->putSamples((soundtouch::SAMPLETYPE*) 952 (audiobuffer + 953 org_waud), nSamplesToEnd); 954 pSoundStretch->putSamples((soundtouch::SAMPLETYPE*)audiobuffer, 955 (len - bdiff) / abps); 1016 int nSamples = pSoundStretch->numSamples(); 1017 len = WaitForFreeSpace(nSamples); 1018 1019 while ((nSamples = pSoundStretch->numSamples())) 1020 { 1021 if (nSamples > nSamplesToEnd) 1022 nSamples = nSamplesToEnd; 1023 1024 nSamples = pSoundStretch->receiveSamples( 1025 (soundtouch::SAMPLETYPE*) 1026 (audiobuffer + org_waud), nSamples 1027 ); 1028 1029 if (nSamples == nSamplesToEnd) { 1030 org_waud = 0; 1031 nSamplesToEnd = kAudioRingBufferSize/abps; 956 1032 } 957 else 958 { 959 pSoundStretch->putSamples((soundtouch::SAMPLETYPE*) 960 (audiobuffer + org_waud), 961 len / abps); 1033 else { 1034 org_waud += nSamples * abps; 1035 nSamplesToEnd -= nSamples; 962 1036 } 1037 } 1038 } 963 1039 964 if (encoder) 965 { 966 // pull out a packet's worth and reencode it until we 967 // don't have enough for any more packets 968 soundtouch::SAMPLETYPE *temp_buff = 969 (soundtouch::SAMPLETYPE*)encoder->GetFrameBuffer(); 970 size_t frameSize = encoder->FrameSize()/abps; 1040 if (internal_vol && SWVolume()) 1041 { 1042 int bdiff = kAudioRingBufferSize - waud; 1043 bool music = (timecode < 1); 971 1044 972 VERBOSE(VB_AUDIO+VB_TIMESTAMP, 973 QString("_AddSamples Enc sfs=%1 bfs=%2 sss=%3") 974 .arg(frameSize) 975 .arg(encoder->FrameSize()) 976 .arg(pSoundStretch->numSamples())); 977 978 // process the same number of samples as it creates 979 // a full encoded buffer just like before 980 while (pSoundStretch->numSamples() >= frameSize) 981 { 982 int got = pSoundStretch->receiveSamples( 983 temp_buff, frameSize); 984 int amount = encoder->Encode(temp_buff); 985 986 VERBOSE(VB_AUDIO+VB_TIMESTAMP, 987 QString("_AddSamples Enc bytes=%1 got=%2 left=%3") 988 .arg(amount) 989 .arg(got) 990 .arg(pSoundStretch->numSamples())); 991 992 if (!amount) 993 continue; 994 995 //len = WaitForFreeSpace(amount); 996 char *ob = encoder->GetOutBuff(); 997 if (amount >= bdiff) 998 { 999 memcpy(audiobuffer + org_waud, ob, bdiff); 1000 ob += bdiff; 1001 amount -= bdiff; 1002 org_waud = 0; 1003 } 1004 if (amount > 0) 1005 memcpy(audiobuffer + org_waud, ob, amount); 1006 1007 bdiff = kAudioRingBufferSize - amount; 1008 org_waud = (org_waud + amount) % kAudioRingBufferSize; 1009 } 1010 } 1011 else 1012 { 1013 int newLen = 0; 1014 int nSamples; 1015 len = WaitForFreeSpace(pSoundStretch->numSamples() * 1016 audio_bytes_per_sample); 1017 do 1018 { 1019 int samplesToGet = len/audio_bytes_per_sample; 1020 if (samplesToGet > nSamplesToEnd) 1021 { 1022 samplesToGet = nSamplesToEnd; 1023 } 1024 1025 nSamples = pSoundStretch->receiveSamples( 1026 (soundtouch::SAMPLETYPE*) 1027 (audiobuffer + org_waud), samplesToGet); 1028 if (nSamples == nSamplesToEnd) 1029 { 1030 org_waud = 0; 1031 nSamplesToEnd = kAudioRingBufferSize/audio_bytes_per_sample; 1032 } 1033 else 1034 { 1035 int bufsz = nSamples * audio_bytes_per_sample; 1036 org_waud = (org_waud + bufsz) % kAudioRingBufferSize; 1037 nSamplesToEnd -= nSamples; 1038 } 1039 1040 newLen += nSamples * audio_bytes_per_sample; 1041 len -= nSamples * audio_bytes_per_sample; 1042 } while (nSamples > 0); 1043 } 1045 if (bdiff < len) 1046 { 1047 AdjustVolume(audiobuffer + waud, bdiff, music); 1048 AdjustVolume(audiobuffer, len - bdiff, music); 1044 1049 } 1050 else 1051 AdjustVolume(audiobuffer + waud, len, music); 1052 } 1045 1053 1046 waud = org_waud; 1047 lastaudiolen = audiolen(false); 1054 // Encode to AC-3? 1055 if (encoder) 1056 { 1057 org_waud = waud; 1058 int bdiff = kAudioRingBufferSize - org_waud; 1059 int to_get = 0; 1048 1060 1049 if ( timecode < 0)1061 if (bdiff < len) 1050 1062 { 1051 // mythmusic doesn't give timestamps..1052 t imecode = (int)((samples_buffered * 100000.0) / effdsp);1063 encoder->Encode(audiobuffer + org_waud, bdiff); 1064 to_get = encoder->Encode(audiobuffer, len - bdiff); 1053 1065 } 1054 1055 samples_buffered += samples; 1056 1057 /* we want the time at the end -- but the file format stores 1058 time at the start of the chunk. */ 1059 // even with timestretch, timecode is still calculated from original 1060 // sample count 1061 audbuf_timecode = timecode + (int)((samples * 100000.0) / effdsp); 1066 else 1067 to_get = encoder->Encode(audiobuffer + org_waud, len); 1062 1068 1063 if ( interleaved)1069 if (to_get > 0) 1064 1070 { 1065 dispatchVisual((unsigned char *)buffer, len, timecode, 1066 source_audio_channels, audio_bits); 1071 if (to_get >= bdiff) 1072 { 1073 encoder->GetFrames(audiobuffer + org_waud, bdiff); 1074 to_get -= bdiff; 1075 org_waud = 0; 1076 } 1077 if (to_get > 0) 1078 encoder->GetFrames(audiobuffer + org_waud, to_get); 1079 1080 org_waud += to_get; 1067 1081 } 1068 1082 } 1069 1083 1070 audio_buflock.unlock(); 1084 waud = org_waud; 1085 lastaudiolen = audiolen(false); 1086 1087 if (timecode < 0) 1088 // mythmusic doesn't give timestamps.. 1089 timecode = (int)((samples_buffered * 100000.0) / effdsp); 1090 1091 samples_buffered += samples; 1092 1093 /* we want the time at the end -- but the file format stores 1094 time at the start of the chunk. */ 1095 // even with timestretch, timecode is still calculated from original 1096 // sample count 1097 audbuf_timecode = timecode + (int)((samples * 100000.0) / effdsp); 1071 1098 } 1072 1099 1073 1100 void AudioOutputBase::Status() … … 1208 1235 last_space_on_soundcard = space_on_soundcard; 1209 1236 } 1210 1237 1211 numlowbuffer++;1212 if (numlowbuffer > 5 && audio_buffer_unused)1213 {1214 VERBOSE(VB_IMPORTANT, LOC + "dropping back audio_buffer_unused");1215 audio_buffer_unused /= 2;1216 }1217 1218 1238 usleep(5000); 1219 1239 continue; 1220 1240 } 1221 else1222 numlowbuffer = 0;1223 1241 1224 1242 Status(); 1225 1243 -
mythtv/libs/libmyth/audiooutput.cpp
33 33 AudioOutput *AudioOutput::OpenAudio( 34 34 const QString &main_device, 35 35 const QString &passthru_device, 36 int audio_bits, int audio_channels, int audio_samplerate, 36 int audio_bits, int audio_channels, 37 int audio_codec, int audio_samplerate, 37 38 AudioOutputSource source, 38 bool set_initial_vol, bool audio_passthru) 39 bool set_initial_vol, bool audio_passthru, 40 int upmixer_startup) 39 41 { 40 42 AudioSettings settings( 41 43 main_device, passthru_device, audio_bits, 42 audio_channels, audio_ samplerate, source,43 set_initial_vol, audio_passthru );44 audio_channels, audio_codec, audio_samplerate, source, 45 set_initial_vol, audio_passthru, upmixer_startup); 44 46 45 47 settings.FixPassThrough(); 46 48 -
mythtv/libs/libmyth/audiosettings.h
29 29 const QString &audio_passthru_device, 30 30 int audio_bits, 31 31 int audio_channels, 32 int audio_codec, 32 33 int audio_samplerate, 33 34 AudioOutputSource audio_source, 34 35 bool audio_set_initial_vol, 35 36 bool audio_use_passthru, 36 void *audio_codec = NULL);37 int upmixer_startup = 0); 37 38 38 39 AudioSettings(int audio_bits, 39 40 int audio_channels, 41 int audio_codec, 40 42 int audio_samplerate, 41 43 bool audio_use_passthru, 42 void *audio_codec = NULL);44 int upmixer_startup = 0); 43 45 44 46 void FixPassThrough(void); 45 47 void TrimDeviceType(void); … … 54 56 public: 55 57 int bits; 56 58 int channels; 59 int codec; 57 60 int samplerate; 58 61 bool set_initial_vol; 59 62 bool use_passthru; 60 void *codec;61 63 AudioOutputSource source; 64 int upmixer; 62 65 }; 63 66 64 67 #endif // _AUDIO_SETTINGS_H_ -
mythtv/libs/libmyth/audiooutputoss.cpp
42 42 KillAudio(); 43 43 } 44 44 45 vector<int> AudioOutputOSS::GetSupportedRates() 46 { 47 const int srates[] = { 8000, 11025, 16000, 22050, 32000, 44100, 48000 }; 48 vector<int> rates(srates, srates + sizeof(srates) / sizeof(int) ); 49 audiofd = open(audio_main_device.toAscii(), O_WRONLY | O_NONBLOCK); 50 51 if (audiofd < 0) 52 { 53 VERBOSE(VB_IMPORTANT, QString("Error opening audio device (%1), the" 54 " error was: %2").arg(audio_main_device).arg(strerror(errno))); 55 rates.clear(); 56 return rates; 57 } 58 59 vector<int>::iterator it = rates.begin(); 60 61 while (it != rates.end()) 62 { 63 if(ioctl(audiofd, SNDCTL_DSP_SPEED, &audio_samplerate) < 0) 64 it = rates.erase(it); 65 else 66 it++; 67 } 68 69 close(audiofd); 70 audiofd = -1; 71 72 return rates; 73 } 74 45 75 bool AudioOutputOSS::OpenDevice() 46 76 { 47 77 numbadioctls = 0; … … 287 317 int volume = 0; 288 318 289 319 QString device = gContext->GetSetting("MixerDevice", "/dev/mixer"); 320 if (device.toLower() == "software") 321 return; 322 290 323 QByteArray dev = device.toAscii(); 291 324 mixerfd = open(dev.constData(), O_RDONLY); 292 325 -
mythtv/libs/libmyth/volumebase.h
20 20 VolumeBase(); 21 21 virtual ~VolumeBase() {}; 22 22 23 void SWVolume(bool set); 24 bool SWVolume(void); 23 25 virtual uint GetCurrentVolume(void) const; 24 26 virtual void SetCurrentVolume(int value); 25 27 virtual void AdjustCurrentVolume(int change); … … 34 36 35 37 virtual int GetVolumeChannel(int channel) const = 0; // Returns 0-100 36 38 virtual void SetVolumeChannel(int channel, int volume) = 0; // range 0-100 for vol 39 virtual void SetSWVolume(int new_volume, bool save) = 0; 40 virtual int GetSWVolume(void) = 0; 37 41 38 42 void UpdateVolume(void); 39 43 void SyncVolume(void); … … 44 48 45 49 int volume; 46 50 MuteState current_mute_state; 51 bool swvol; 52 bool swvol_setting; 47 53 48 54 }; 49 55 -
mythtv/libs/libmyth/audiooutputdigitalencoder.cpp
32 32 AudioOutputDigitalEncoder::AudioOutputDigitalEncoder(void) : 33 33 audio_bytes_per_sample(0), 34 34 av_context(NULL), 35 outbuf(NULL), 36 outbuf_size(0), 37 frame_buffer(NULL), 35 outbuflen(0), 36 inbuflen(0), 38 37 one_frame_bytes(0) 39 38 { 40 39 } … … 52 51 av_free(av_context); 53 52 av_context = NULL; 54 53 } 55 56 if (outbuf)57 {58 delete [] outbuf;59 outbuf = NULL;60 outbuf_size = 0;61 }62 63 if (frame_buffer)64 {65 delete [] frame_buffer;66 frame_buffer = NULL;67 one_frame_bytes = 0;68 }69 54 } 70 55 71 56 //CODEC_ID_AC3 … … 81 66 .arg(samplerate) 82 67 .arg(channels)); 83 68 84 //codec = avcodec_find_encoder(codec_id); 69 // We need to do this when called from mythmusic 70 avcodec_init(); 71 avcodec_register_all(); 85 72 // always AC3 as there is no DTS encoder at the moment 2005/1/9 86 73 codec = avcodec_find_encoder(CODEC_ID_AC3); 87 74 if (!codec) … … 110 97 audio_bytes_per_sample = bytes_per_frame; 111 98 one_frame_bytes = bytes_per_frame * av_context->frame_size; 112 99 113 outbuf_size = 16384; // ok for AC3 but DTS?114 outbuf = new char [outbuf_size];115 100 VERBOSE(VB_AUDIO, QString("DigitalEncoder::Init fs=%1, bpf=%2 ofb=%3") 116 101 .arg(av_context->frame_size) 117 102 .arg(bytes_per_frame) … … 259 244 static int encode_frame( 260 245 bool dts, 261 246 unsigned char *data, 262 size_t &len)247 size_t enc_len) 263 248 { 264 249 unsigned char *payload = data + 8; // skip header, currently 52 or 54bits 265 size_t enc_len;266 250 int flags, sample_rate, bit_rate; 267 251 268 252 // we don't do any length/crc validation of the AC3 frame here; presumably … … 273 257 // ignore, and if so, may as well just assume that it will ignore 274 258 // anything with a bad CRC... 275 259 276 uint nr_samples = 0, block_len; 260 uint nr_samples = 0, block_len = 0; 261 277 262 if (dts) 278 263 { 279 264 enc_len = dts_syncinfo(payload, &flags, &sample_rate, &bit_rate); … … 302 287 } 303 288 } 304 289 305 if (enc_len == 0 || enc_len > len)306 {307 int l = len;308 len = 0;309 return l;310 }311 312 290 enc_len = std::min((uint)enc_len, block_len - 8); 313 291 314 292 //uint32_t x = *(uint32_t*)payload; … … 361 339 data[6] = (enc_len << 3) & 0xFF; 362 340 data[7] = (enc_len >> 5) & 0xFF; 363 341 memset(payload + enc_len, 0, block_len - 8 - enc_len); 364 len = block_len;365 342 366 343 return enc_len; 367 344 } 368 345 369 // must have exactly 1 frames worth of data 370 size_t AudioOutputDigitalEncoder::Encode(short *buff) 346 size_t AudioOutputDigitalEncoder::Encode(void *buf, int len) 371 347 { 372 int encsize = 0;373 348 size_t outsize = 0; 374 375 // put data in the correct spot for encode frame376 outsize = avcodec_encode_audio(377 av_context, ((uchar*)outbuf) + 8, outbuf_size - 8, buff);378 349 379 size_t tmpsize = outsize; 350 int fs = FrameSize(); 351 memcpy(inbuf+inbuflen, buf, len); 352 inbuflen += len; 353 int frames = inbuflen / fs; 380 354 381 outsize = MAX_AC3_FRAME_SIZE; 382 encsize = encode_frame( 383 /*av_context->codec_id==CODEC_ID_DTS*/ false, 384 (unsigned char*)outbuf, outsize); 355 while (frames--) 356 { 357 // put data in the correct spot for encode frame 358 outsize = avcodec_encode_audio( 359 av_context, ((uchar*)outbuf) + outbuflen + 8, OUTBUFSIZE - 8, (short int *)inbuf); 385 360 386 VERBOSE(VB_AUDIO+VB_TIMESTAMP, 387 QString("DigitalEncoder::Encode len1=%1 len2=%2 finallen=%3") 388 .arg(tmpsize).arg(encsize).arg(outsize)); 361 encode_frame( 362 /*av_context->codec_id==CODEC_ID_DTS*/ false, 363 (unsigned char*)outbuf + outbuflen, outsize 364 ); 389 365 390 return outsize; 366 outbuflen += MAX_AC3_FRAME_SIZE; 367 inbuflen -= fs; 368 memmove(inbuf, inbuf+fs, inbuflen); 369 } 370 371 return outbuflen; 391 372 } 373 374 void AudioOutputDigitalEncoder::GetFrames(void *ptr, int maxlen) 375 { 376 int len = (maxlen < outbuflen ? maxlen : outbuflen); 377 memcpy(ptr, outbuf, len); 378 outbuflen -= len; 379 memmove(outbuf, outbuf+len, outbuflen); 380 } -
mythtv/libs/libmyth/audiooutput.h
15 15 static AudioOutput *OpenAudio( 16 16 const QString &audiodevice, 17 17 const QString &passthrudevice, 18 int audio_bits, int audio_channels, int audio_samplerate, 18 int audio_bits, int audio_channels, 19 int audio_codec, int audio_samplerate, 19 20 AudioOutputSource source, 20 bool set_initial_vol, bool audio_passthru); 21 bool set_initial_vol, bool audio_passthru, 22 int upmixer_startup = 0); 21 23 22 24 AudioOutput() : 23 25 VolumeBase(), OutputListeners(), … … 68 70 69 71 virtual void bufferOutputData(bool y) = 0; 70 72 virtual int readOutputData(unsigned char *read_buffer, int max_length) = 0; 73 virtual bool ToggleUpmix(void) = 0; 71 74 72 75 protected: 73 76 void Error(const QString &msg); -
mythtv/libs/libmyth/audiooutputdigitalencoder.h
5 5 #include "libavcodec/avcodec.h" 6 6 }; 7 7 8 #define INBUFSIZE 131072 9 #define OUTBUFSIZE 98304 10 8 11 class AudioOutputDigitalEncoder 9 12 { 10 13 public: … … 13 16 14 17 bool Init(CodecID codec_id, int bitrate, int samplerate, int channels); 15 18 void Dispose(void); 16 size_t Encode(short * buff); 17 18 inline char *GetFrameBuffer(void); 19 size_t Encode(void *buf, int len); 20 void GetFrames(void *ptr, int maxlen); 19 21 size_t FrameSize(void) const { return one_frame_bytes; } 20 char *GetOutBuff(void) const { return outbuf;}22 int Buffered(void) const { return inbuflen; } 21 23 22 24 public: 23 25 size_t audio_bytes_per_sample; 24 26 25 27 private: 26 28 AVCodecContext *av_context; 27 char *outbuf; 28 int outbuf_size; 29 char *frame_buffer; 29 char outbuf[OUTBUFSIZE]; 30 char inbuf[INBUFSIZE]; 31 int outbuflen; 32 int inbuflen; 30 33 size_t one_frame_bytes; 31 34 }; 32 35 33 inline char *AudioOutputDigitalEncoder::GetFrameBuffer(void)34 {35 if (!frame_buffer && av_context)36 frame_buffer = new char [one_frame_bytes];37 38 return frame_buffer;39 }40 41 36 #endif -
mythtv/libs/libmyth/audiooutputalsa.h
65 65 virtual void WriteAudio(unsigned char *aubuf, int size); 66 66 virtual int GetSpaceOnSoundcard(void) const; 67 67 virtual int GetBufferedOnSoundcard(void) const; 68 vector<int> GetSupportedRates(void); 68 69 69 70 private: 71 void SetIECStatus(bool audio); 70 72 inline int SetParameters(snd_pcm_t *handle, 71 73 snd_pcm_format_t format, unsigned int channels, 72 74 unsigned int rate, unsigned int buffer_time, 73 75 unsigned int period_time); 74 76 75 77 void ReorderSmpteToAlsa6ch(unsigned char *buf, int size); 78 template <class AudioDataType> 79 void _ReorderSmpteToAlsa6ch(AudioDataType *buf, int size); 76 80 // Volume related 77 81 void SetCurrentVolume(QString control, int channel, int volume); 78 82 void OpenMixer(bool setstartingvolume); -
mythtv/libs/libmythfreesurround/el_processor.cpp
26 26 #include "fftw3.h" 27 27 #else 28 28 extern "C" { 29 #include "libavutil/declare_aligned.h"30 29 #include "dsputil.h" 31 30 }; 32 31 typedef FFTSample FFTComplexArray[2]; … … 41 40 42 41 const float PI = 3.141592654; 43 42 const float epsilon = 0.000001; 44 //const float center_level = 0.5*sqrt(0.5); // gain of the center channel 45 //const float center_level = sqrt(0.5); // gain of the center channel 46 const float center_level = 1.0; // gain of the center channel 47 //const float center_level = 0.5; // gain of the center channel 43 const float center_level = 0.5*sqrt(0.5); 48 44 49 // should be .6-.750 // but with centerlevel 2x what its supposed to be, we halve 0.6851 // to keep center from clipping52 //const float window_gain = 0.34;53 //const float window_gain = 0.68;54 const float window_gain = 0.95; // to prive a bit of margin55 56 45 // private implementation of the surround decoder 57 46 class decoder_impl { 58 47 public: … … 99 88 outbuf[c].resize(N); 100 89 filter[c].resize(N); 101 90 } 102 // DC component of filters is always 0103 for (unsigned c=0;c<5;c++)104 {105 filter[c][0] = 0.0;106 filter[c][1] = 0.0;107 filter[c][halfN] = 0.0;108 }109 91 sample_rate(48000); 110 92 // generate the window function (square root of hann, b/c it is applied before and after the transform) 111 93 wnd.resize(N); 112 // dft normalization included in the window for zero cost scaling 113 // also add a gain factor of *2 due to processing gain in algo (see center_level) 114 surround_gain(1.0); 94 for (unsigned k=0;k<N;k++) 95 wnd[k] = sqrt(0.5*(1-cos(2*PI*k/N))/N); 115 96 current_buf = 0; 116 97 // set the default coefficients 117 98 surround_coefficients(0.8165,0.5774); … … 193 174 // set lfe filter params 194 175 void sample_rate(unsigned int srate) { 195 176 // lfe filter is just straight through band limited 196 unsigned int cutoff = ( 250*N)/srate;177 unsigned int cutoff = (30*N)/srate; 197 178 for (unsigned f=0;f<=halfN;f++) { 198 if ( (f>=2) && (f<cutoff))199 filter[5][f] = 1.0;179 if (f<cutoff) 180 filter[5][f] = 0.5*sqrt(0.5); 200 181 else 201 182 filter[5][f] = 0.0; 202 183 } … … 215 196 E = (o+v)*n; F = (o+u)*n; G = (o-v)*n; H = (o-u)*n; 216 197 } 217 198 218 void surround_gain(float gain) {219 master_gain = gain * window_gain * 0.5 * 0.25;220 for (unsigned k=0;k<N;k++)221 wnd[k] = sqrt(master_gain*(1-cos(2*PI*k/N))/N);222 }223 224 199 // set the phase shifting mode 225 200 void phase_mode(unsigned mode) { 226 201 const float modes[4][2] = {{0,0},{0,PI},{PI,0},{-PI/2,PI/2}}; … … 291 266 292 267 // 2. compare amplitude and phase of each DFT bin and produce the X/Y coordinates in the sound field 293 268 // but dont do DC or N/2 component 294 for (unsigned f= 2;f<halfN;f++) {269 for (unsigned f=0;f<halfN;f++) { 295 270 // get left/right amplitudes/phases 296 271 float ampL = amplitude(dftL[f]), ampR = amplitude(dftR[f]); 297 272 float phaseL = phase(dftL[f]), phaseR = phase(dftR[f]); … … 306 281 phaseDiff = abs(phaseDiff); 307 282 308 283 if (linear_steering) { 309 /* cfloat w = polar(sqrt(ampL*ampL+ampR*ampR), (phaseL+phaseR)/2);310 cfloat lt = cfloat(dftL[f][0],dftL[f][1])/w, rt = cfloat(dftR[f][0],dftR[f][1])/w; */311 // xfs[f] = -(C*(rt-H) - B*E + F*A + G*(D-lt)) / (G*A - C*E).real();312 // yfs[f] = (rt - (xfs[f]*E+H))/(F+xfs[f]*G);313 314 /*315 Problem:316 This assumes that the values are interpolated linearly between the cardinal points.317 But this way we have no chance of knowing the average volume...318 - Can we solve that computing everything under the assumption of normalized volume?319 No. Seemingly not.320 - Maybe we should add w explitcitly into the equation and see if we can solve it...321 */322 323 324 //cfloat lt(0.5,0),rt(0.5,0);325 //cfloat x(0,0), y(1,0);326 /*cfloat p = (C*(rt-H) - B*E + F*A + G*(D-lt)) / (G*A - C*E);327 cfloat q = B*(rt+H) + F*(D-lt) / (G*A - C*E);328 cfloat s = sqrt(p*p/4.0f - q);329 cfloat x = -p;330 cfloat x1 = -p/2.0f + s;331 cfloat x2 = -p/2.0f - s;332 float x = 0;333 if (x1.real() >= -1 && x1.real() <= 1)334 x = x1.real();335 else if (x2.real() >= -1 && x2.real() <= 1)336 x = x2.real();*/337 338 //cfloat yp = (rt - (x*E+H))/(F+x*G);339 //cfloat xp = (lt - (y*B+D))/(A+y*C);340 341 /*xfs[f] = x;342 yfs[f] = y.real();*/343 344 284 // --- this is the fancy new linear mode --- 345 285 346 286 // get sound field x/y position … … 598 538 float surround_high,surround_low; // high and low surround mixing coefficient (e.g. 0.8165/0.5774) 599 539 float surround_balance; // the xfs balance that follows from the coeffs 600 540 float surround_level; // gain for the surround channels (follows from the coeffs 601 float master_gain; // gain for all channels602 541 float phase_offsetL, phase_offsetR;// phase shifts to be applied to the rear channels 603 542 float front_separation; // front stereo separation 604 543 float rear_separation; // rear stereo separation … … 626 565 627 566 void fsurround_decoder::surround_coefficients(float a, float b) { impl->surround_coefficients(a,b); } 628 567 629 void fsurround_decoder::gain(float gain) { impl->surround_gain(gain); }630 631 568 void fsurround_decoder::phase_mode(unsigned mode) { impl->phase_mode(mode); } 632 569 633 570 void fsurround_decoder::steering_mode(bool mode) { impl->steering_mode(mode); } -
mythtv/libs/libmythfreesurround/freesurround.cpp
63 63 const unsigned default_block_size = 8192; 64 64 // there will be a slider for this in the future 65 65 //const float master_gain = 1.0; 66 //#define MASTER_GAIN * master_gain 66 //#define MASTER_GAIN * master_gain 67 67 #define MASTER_GAIN 68 //const float master_gain = 1.0/(1<<15); 69 //const float inv_master_gain = (1<<15); 68 //const float inv_master_gain = 1.0; 70 69 //#define INV_MASTER_GAIN * inv_master_gain 71 70 #define INV_MASTER_GAIN 72 71 … … 192 191 if (moviemode) 193 192 { 194 193 params.phasemode = 1; 195 params.center_width = 0;196 params. gain = 1.0;194 params.center_width = 25; 195 params.dimension = 0.5; 197 196 } 198 197 else 199 198 { 200 params.center_width = 70; 201 // for 50, gain should be about 1.9, c/lr about 2.7 202 // for 70, gain should be about 3.1, c/lr about 1.5 203 params.gain = 3.1; 199 params.center_width = 65; 200 params.dimension = 0.3; 204 201 } 205 202 switch (surround_mode) 206 203 { … … 236 233 decoder->phase_mode(params.phasemode); 237 234 decoder->surround_coefficients(params.coeff_a, params.coeff_b); 238 235 decoder->separation(params.front_sep/100.0,params.rear_sep/100.0); 239 decoder->gain(params.gain);240 236 } 241 237 } 242 238 … … 250 246 phasemode(0), 251 247 steering(1), 252 248 front_sep(100), 253 rear_sep(100), 254 gain(1.0) 249 rear_sep(100) 255 250 { 256 251 } 257 252 … … 329 324 for (i=0;(i<numSamples) && (ic < bs);i++,ic++) 330 325 { 331 326 int16bufs->l[ic] = *samples++ >> 1; 332 int16bufs->c[ic] = *samples++ >> 1;333 327 int16bufs->r[ic] = *samples++ >> 1; 328 int16bufs->c[ic] = *samples++ >> 1; 329 int16bufs->lfe[ic] = *samples++ >> 1; 334 330 int16bufs->ls[ic] = *samples++ >> 1; 335 331 int16bufs->rs[ic] = *samples++ >> 1; 336 int16bufs->lfe[ic] = *samples++ >> 1;337 332 } 338 333 break; 339 334 } … … 391 386 for (i=0;i<numSamples;i++) 392 387 { 393 388 *l++ = *samples++ >> 1; 394 *c++ = *samples++ >> 1;395 389 *r++ = *samples++ >> 1; 390 *c++ = *samples++ >> 1; 391 *lfe++ = *samples++ >> 1; 396 392 *ls++ = *samples++ >> 1; 397 393 *rs++ = *samples++ >> 1; 398 *lfe++ = *samples++ >> 1;399 394 } 400 395 } break; 401 396 } … … 479 474 for (i=0;(i<numSamples) && (ic < bs);i++,ic++) 480 475 { 481 476 int16bufs->l[ic] = *samples++ << 7; 482 int16bufs->c[ic] = *samples++ << 7;483 477 int16bufs->r[ic] = *samples++ << 7; 478 int16bufs->c[ic] = *samples++ << 7; 479 int16bufs->lfe[ic] = *samples++ << 7; 484 480 int16bufs->ls[ic] = *samples++ << 7; 485 481 int16bufs->rs[ic] = *samples++ << 7; 486 int16bufs->lfe[ic] = *samples++ << 7;487 482 } 488 483 break; 489 484 } … … 541 536 for (i=0;i<numSamples;i++) 542 537 { 543 538 *l++ = *samples++ << 7; 544 *c++ = *samples++ << 7;545 539 *r++ = *samples++ << 7; 540 *c++ = *samples++ << 7; 541 *lfe++ = *samples++ << 7; 546 542 *ls++ = *samples++ << 7; 547 543 *rs++ = *samples++ << 7; 548 *lfe++ = *samples++ << 7;549 544 } 550 545 } break; 551 546 } … … 588 583 { 589 584 *output++ = int16bufs->l[outindex]; 590 585 *output++ = int16bufs->r[outindex]; 591 *output++ = int16bufs->ls[outindex];592 *output++ = int16bufs->rs[outindex];593 586 *output++ = int16bufs->c[outindex]; 594 587 *output++ = int16bufs->lfe[outindex]; 588 *output++ = int16bufs->ls[outindex]; 589 *output++ = int16bufs->rs[outindex]; 595 590 oc--; 596 591 outindex++; 597 592 } … … 611 606 { 612 607 *output++ = lrintf(*l++ INV_MASTER_GAIN); 613 608 *output++ = lrintf(*r++ INV_MASTER_GAIN); 614 *output++ = lrintf(*ls++ INV_MASTER_GAIN);615 *output++ = lrintf(*rs++ INV_MASTER_GAIN);616 609 *output++ = lrintf(*c++ INV_MASTER_GAIN); 617 610 *output++ = lrintf(*lfe++ INV_MASTER_GAIN); 611 *output++ = lrintf(*ls++ INV_MASTER_GAIN); 612 *output++ = lrintf(*rs++ INV_MASTER_GAIN); 618 613 } 619 614 oc -= maxSamples; 620 615 outindex += maxSamples; … … 631 626 { 632 627 *output++ = *l++; 633 628 *output++ = *r++; 634 *output++ = *ls++;635 *output++ = *rs++;636 629 *output++ = *c++; 637 630 *output++ = *lfe++; 631 *output++ = *ls++; 632 *output++ = *rs++; 638 633 } 639 634 oc -= maxSamples; 640 635 outindex += maxSamples; … … 655 650 { 656 651 if (decoder) 657 652 { 658 // actually these params need only be set when they change... but it doesn't hurt659 #if 0660 decoder->steering_mode(params.steering);661 decoder->phase_mode(params.phasemode);662 decoder->surround_coefficients(params.coeff_a, params.coeff_b);663 decoder->separation(params.front_sep/100.0,params.rear_sep/100.0);664 #endif665 // decode the bufs->block666 //decoder->decode(input,output,params.center_width/100.0,params.dimension/100.0);667 //decoder->decode(output,params.center_width/100.0,params.dimension/100.0);668 653 decoder->decode(params.center_width/100.0,params.dimension/100.0); 669 654 } 670 655 } -
mythtv/libs/libmythfreesurround/el_processor.h
47 47 // a is the coefficient of left rear in left total, b is the coefficient of left rear in right total; the same is true for right. 48 48 void surround_coefficients(float a, float b); 49 49 50 // override for master surround gain51 void gain(float gain);52 53 50 // set the phase shifting mode for decoding 54 // 0 = (+0 °,+0°) - music mode55 // 1 = (+0 °,+180°) - PowerDVD compatibility56 // 2 = (+180 °,+0°) - BeSweet compatibility57 // 3 = (-90 °,+90°) - This seems to work. I just don't know why.51 // 0 = (+0,+0) - music mode 52 // 1 = (+0,+180) - PowerDVD compatibility 53 // 2 = (+180,+0) - BeSweet compatibility 54 // 3 = (-90,+90) - This seems to work. I just don't know why. 58 55 void phase_mode(unsigned mode); 59 56 60 57 // override the steering mode -
mythtv/programs/mythfrontend/globalsettings.cpp
94 94 static HostComboBox *MaxAudioChannels() 95 95 { 96 96 HostComboBox *gc = new HostComboBox("MaxChannels",false); 97 gc->setLabel(QObject::tr(" Max Audio Channels"));97 gc->setLabel(QObject::tr("Speakers configuration")); 98 98 gc->addSelection(QObject::tr("Stereo"), "2", true); // default 99 99 gc->addSelection(QObject::tr("5.1"), "6"); 100 100 gc->setHelpText( 101 101 QObject::tr( 102 "Set the maximum number of audio channels to be decoded. " 103 "This is for multi-channel/surround audio playback.")); 102 "Set your audio configuration: Stereo or Surround.")); 104 103 return gc; 105 104 } 106 105 106 static HostCheckBox *AudioUpmix() 107 { 108 HostCheckBox *gc = new HostCheckBox("AudioDefaultUpmix"); 109 gc->setLabel(QObject::tr("Upconvert stereo to 5.1 surround")); 110 gc->setValue(true); 111 gc->setHelpText(QObject::tr("MythTV can upconvert stereo to 5.1 audio. " 112 "Set this option to enable it by default. " 113 "You can enable or disable the upconversion during playback at anytime.")); 114 return gc; 115 } 116 107 117 static HostComboBox *AudioUpmixType() 108 118 { 109 119 HostComboBox *gc = new HostComboBox("AudioUpmixType",false); 110 120 gc->setLabel(QObject::tr("Upmix")); 111 gc->addSelection(QObject::tr(" Passive"), "0", true); // default112 gc->addSelection(QObject::tr(" Active Simple"), "1");113 gc->addSelection(QObject::tr(" Active Linear"), "2");121 gc->addSelection(QObject::tr("Fastest"), "0", true); // default 122 gc->addSelection(QObject::tr("Good"), "1"); 123 gc->addSelection(QObject::tr("Best"), "2"); 114 124 gc->setHelpText( 115 125 QObject::tr( 116 "Set the audio upmix type for 2ch to 6ch conversion. " 117 "This is for multi-channel/surround audio playback. " 118 "'Passive' is the least demanding on the CPU. " 119 "'Active Simple' is more demanding and 'Active Linear' " 120 "is the most demanding (but highest quality).")); 126 "Set the audio surround upconversion quality. " 127 "'Fastest' is the least demanding on the CPU at the expense of quality.")); 121 128 return gc; 122 129 } 123 130 … … 125 132 { 126 133 HostComboBox *gc = new HostComboBox("PassThruOutputDevice", true); 127 134 128 gc->setLabel(QObject::tr(" Passthroughoutput device"));135 gc->setLabel(QObject::tr("Digital output device")); 129 136 gc->addSelection(QObject::tr("Default"), "Default"); 130 137 #ifndef USING_MINGW 131 138 gc->addSelection("ALSA:iec958:{ AES0 0x02 }", "ALSA:iec958:{ AES0 0x02 }"); … … 133 140 gc->addSelection("ALSA:plughw:0,3", "ALSA:plughw:0,3"); 134 141 #endif 135 142 136 gc->setHelpText(QObject::tr("Audio output device to use for AC3 and " 137 "DTS passthrough. Default is the same as Audio output " 143 gc->setHelpText(QObject::tr("Audio output device to use for digital audio. Default is the same as Audio output " 138 144 "device. This value is currently only used with ALSA " 139 145 "sound output.")); 140 146 return gc; … … 146 152 gc->setLabel(QObject::tr("Use internal volume controls")); 147 153 gc->setValue(true); 148 154 gc->setHelpText(QObject::tr("MythTV can control the PCM and master " 149 "mixer volume. If you prefer to use an external mixer " 150 "program, then disable this option.")); 155 "mixer volume. If you prefer to control the volume externally " 156 "(like your amplifier) or use an external mixer " 157 "program, disable this option.")); 151 158 return gc; 152 159 } 153 160 … … 175 182 #ifdef USING_WINAUDIO 176 183 gc->addSelection("Windows:", "Windows:"); 177 184 #endif 185 #if !(defined(USING_DIRECTX) || defined(USING_WINAUDIO)) 186 gc->addSelection("software", "software"); 187 gc->setHelpText(QObject::tr("Setting the mixer device to \"software\" lets MythTV control " 188 "the volume of all audio at the expense of a slight quality loss.")); 189 #endif 178 190 179 191 return gc; 180 192 } … … 235 247 static HostCheckBox *AC3PassThrough() 236 248 { 237 249 HostCheckBox *gc = new HostCheckBox("AC3PassThru"); 238 gc->setLabel(QObject::tr(" Enable AC3 to SPDIF passthrough"));250 gc->setLabel(QObject::tr("Dolby Digital")); 239 251 gc->setValue(false); 240 gc->setHelpText(QObject::tr("Enable sending AC3 audio directly to your " 241 "sound card's SPDIF output, on sources which contain " 242 "AC3 soundtracks (usually digital TV). Requires that " 243 "the audio output device be set to something suitable.")); 252 gc->setHelpText(QObject::tr("Enable if your amplifier or sound decoder supports AC3/Dolby Digital. " 253 "You must use a digital connection. Uncheck if using an analog connection.")); 244 254 return gc; 245 255 } 246 256 247 257 static HostCheckBox *DTSPassThrough() 248 258 { 249 259 HostCheckBox *gc = new HostCheckBox("DTSPassThru"); 250 gc->setLabel(QObject::tr(" Enable DTS to SPDIF passthrough"));260 gc->setLabel(QObject::tr("DTS")); 251 261 gc->setValue(false); 252 gc->setHelpText(QObject::tr("Enable sending DTS audio directly to your " 253 "sound card's SPDIF output, on sources which contain " 254 "DTS soundtracks (usually DVDs). Requires that the " 255 "audio output device be set to something suitable.")); 262 gc->setHelpText(QObject::tr("Enable if your amplifier or sound decoder supports DTS. " 263 "You must use a digital connection. Uncheck if using an analog connection")); 256 264 return gc; 257 265 } 258 266 … … 1990 1998 return gc; 1991 1999 } 1992 2000 1993 static HostCheckBox *AggressiveBuffer()1994 {1995 HostCheckBox *gc = new HostCheckBox("AggressiveSoundcardBuffer");1996 gc->setLabel(QObject::tr("Aggressive Sound card Buffering"));1997 gc->setValue(false);1998 gc->setHelpText(QObject::tr("If enabled, MythTV will pretend to have "1999 "a smaller sound card buffer than is really present. This "2000 "may speed up seeking, but can also cause playback "2001 "problems."));2002 return gc;2003 }2004 2005 2001 static HostCheckBox *ClearSavedPosition() 2006 2002 { 2007 2003 HostCheckBox *gc = new HostCheckBox("ClearSavedPosition"); … … 3510 3506 return gs; 3511 3507 } 3512 3508 3513 class AudioSystemSettingsGroup : public VerticalConfigurationGroup3509 class AudioSystemSettingsGroup : public TriggeredConfigurationGroup 3514 3510 { 3515 3511 public: 3516 3512 AudioSystemSettingsGroup() : 3517 VerticalConfigurationGroup(false, true, false, false)3513 TriggeredConfigurationGroup(false, true, false, false) 3518 3514 { 3519 3515 setLabel(QObject::tr("Audio System")); 3520 3516 setUseLabel(false); 3521 3517 3522 3518 addChild(AudioOutputDevice()); 3523 addChild(PassThroughOutputDevice());3524 3519 3525 addChild(MaxAudioChannels());3526 addChild( AudioUpmixType());3520 Setting *numchannels = MaxAudioChannels(); 3521 addChild(numchannels); 3527 3522 3528 // General boolean settings 3529 addChild(AC3PassThrough()); 3530 addChild(DTSPassThrough()); 3531 addChild(AggressiveBuffer()); 3523 ConfigurationGroup *dummy = 3524 new VerticalConfigurationGroup(false, true, false, false); 3525 3526 ConfigurationGroup *settings = 3527 new VerticalConfigurationGroup(false, true, false, false); 3528 3529 settings->addChild(AudioUpmix()); 3530 settings->addChild(AudioUpmixType()); 3531 settings->addChild(PassThroughOutputDevice()); 3532 3533 ConfigurationGroup *settings2 = 3534 new HorizontalConfigurationGroup(); 3535 settings2->setLabel(QObject::tr("Audio Processing Capabilities")); 3536 settings2->addChild(AC3PassThrough()); 3537 settings2->addChild(DTSPassThrough()); 3538 3539 settings->addChild(settings2); 3540 3541 // Show surround/upmixer config only if 5.1 Audio is selected 3542 setTrigger(numchannels); 3543 addTarget("2", dummy); 3544 addTarget("6", settings); 3545 3532 3546 } 3533 3547 }; 3534 3548 -
mythtv/programs/mythtranscode/transcode.cpp
49 49 AudioReencodeBuffer(int audio_bits, int audio_channels) 50 50 { 51 51 Reset(); 52 const AudioSettings settings(audio_bits, audio_channels, 0, false);52 const AudioSettings settings(audio_bits, audio_channels, 0, 0, false); 53 53 Reconfigure(settings); 54 54 bufsize = 512000; 55 55 audiobuffer = new unsigned char[bufsize]; … … 222 222 // Do nothing 223 223 return kMuteOff; 224 224 } 225 virtual bool ToggleUpmix(void) 226 { 227 // Do nothing 228 return false; 229 } 225 230 231 virtual void SetSWVolume(int new_volume, bool save) 232 { 233 // Do nothing 234 return; 235 } 236 virtual int GetSWVolume(void) 237 { 238 // Do nothing 239 return 100; 240 } 241 226 242 // These are pure virtual in AudioOutput, but we don't need them here 227 243 virtual void bufferOutputData(bool){ return; } 228 244 virtual int readOutputData(unsigned char*, int ){ return 0; }