Exemplo n.º 1
0
    void SetupInfo(VorbisInfo& info) const
    {
      const StreamParameters stream(Params);
      const RenderParameters::Ptr sound = RenderParameters::Create(Params);

      const uint_t samplerate = sound->SoundFreq();
      Dbg("Samplerate is %1%", samplerate);
      if (stream.IsABRMode())
      {
        const uint_t bitrate = stream.GetBitrate();
        Dbg("Setting ABR to %1%kbps", bitrate);
        info.SetABR(bitrate, samplerate);
      }
      else
      {
        const uint_t quality = stream.GetQuality();
        Dbg("Setting VBR quality to %1%", quality);
        info.SetQuality(quality, samplerate);
      }

    }
Exemplo n.º 2
0
    virtual void Startup()
    {
      Dbg("Starting playback");

      SDL_AudioSpec format;
      format.format = -1;
      const bool sampleSigned = Sample::MID == 0;
      switch (Sample::BITS)
      {
      case 8:
        format.format = sampleSigned ? AUDIO_S8 : AUDIO_U8;
        break;
      case 16:
        format.format = sampleSigned ? AUDIO_S16SYS : AUDIO_U16SYS;
        break;
      default:
        assert(!"Invalid format");
      }

      const RenderParameters::Ptr sound = RenderParameters::Create(Params);
      const BackendParameters backend(*Params);
      format.freq = sound->SoundFreq();
      format.channels = static_cast< ::Uint8>(Sample::CHANNELS);
      format.samples = sound->SamplesPerFrame();
      //fix if size is not power of 2
      if (0 != (format.samples & (format.samples - 1)))
      {
        unsigned msk = 1;
        while (format.samples > msk)
        {
          msk <<= 1;
        }
        format.samples = msk;
      }
      format.callback = OnBuffer;
      format.userdata = &Queue;
      Queue.SetSize(backend.GetBuffersCount());
      CheckCall(SdlApi->SDL_OpenAudio(&format, 0) >= 0, THIS_LINE);
      SdlApi->SDL_PauseAudio(0);
    }
Exemplo n.º 3
0
    void SetupContext(lame_global_flags& ctx) const
    {
      const StreamParameters stream(Params);
      const RenderParameters::Ptr sound = RenderParameters::Create(Params);

      const uint_t samplerate = sound->SoundFreq();
      Dbg("Setting samplerate to %1%Hz", samplerate);
      CheckLameCall(LameApi->lame_set_in_samplerate(&ctx, samplerate), THIS_LINE);
      CheckLameCall(LameApi->lame_set_out_samplerate(&ctx, samplerate), THIS_LINE);
      CheckLameCall(LameApi->lame_set_num_channels(&ctx, Sample::CHANNELS), THIS_LINE);
      CheckLameCall(LameApi->lame_set_bWriteVbrTag(&ctx, true), THIS_LINE);
      switch (stream.GetBitrateMode())
      {
      case MODE_CBR:
        {
          const uint_t bitrate = stream.GetBitrate();
          Dbg("Setting bitrate to %1%kbps", bitrate);
          CheckLameCall(LameApi->lame_set_VBR(&ctx, vbr_off), THIS_LINE);
          CheckLameCall(LameApi->lame_set_brate(&ctx, bitrate), THIS_LINE);
        }
        break;
      case MODE_ABR:
        {
          const uint_t bitrate = stream.GetBitrate();
          Dbg("Setting average bitrate to %1%kbps", bitrate);
          CheckLameCall(LameApi->lame_set_VBR(&ctx, vbr_abr), THIS_LINE);
          CheckLameCall(LameApi->lame_set_VBR_mean_bitrate_kbps(&ctx, bitrate), THIS_LINE);
        }
        break;
      case MODE_VBR:
        {
          const uint_t quality = stream.GetQuality();
          Dbg("Setting VBR quality to %1%", quality);
          CheckLameCall(LameApi->lame_set_VBR(&ctx, vbr_default), THIS_LINE);
          CheckLameCall(LameApi->lame_set_VBR_q(&ctx, quality), THIS_LINE);
        }
        break;
      default:
        assert(!"Invalid mode");
      }
      switch (stream.GetChannelsMode())
      {
      case MODE_DEFAULT:
        Dbg("Using default channels mode");
        break;
      case MODE_STEREO:
        Dbg("Using stereo mode");
        CheckLameCall(LameApi->lame_set_mode(&ctx, STEREO), THIS_LINE);
        break;
      case MODE_JOINTSTEREO:
        Dbg("Using joint stereo mode");
        CheckLameCall(LameApi->lame_set_mode(&ctx, JOINT_STEREO), THIS_LINE);
        break;
      case MODE_MONO:
        Dbg("Using mono mode");
        CheckLameCall(LameApi->lame_set_mode(&ctx, MONO), THIS_LINE);
        break;
      default:
        assert(!"Invalid mode");
      }
      CheckLameCall(LameApi->lame_init_params(&ctx), THIS_LINE);
      LameApi->id3tag_init(&ctx);
    }