| 91 | } |
| 92 | |
| 93 | static void |
| 94 | lame_encoder_setup(lame_global_flags *gfp, float quality, int bitrate, |
| 95 | const AudioFormat &audio_format) |
| 96 | { |
| 97 | if (quality >= -1.0f) { |
| 98 | /* a quality was configured (VBR) */ |
| 99 | |
| 100 | if (0 != lame_set_VBR(gfp, vbr_rh)) |
| 101 | throw std::runtime_error("error setting lame VBR mode"); |
| 102 | |
| 103 | if (0 != lame_set_VBR_q(gfp, int(quality))) |
| 104 | throw std::runtime_error("error setting lame VBR quality"); |
| 105 | } else { |
| 106 | /* a bit rate was configured */ |
| 107 | |
| 108 | if (0 != lame_set_brate(gfp, bitrate)) |
| 109 | throw std::runtime_error("error setting lame bitrate"); |
| 110 | } |
| 111 | |
| 112 | if (0 != lame_set_num_channels(gfp, audio_format.channels)) |
| 113 | throw std::runtime_error("error setting lame num channels"); |
| 114 | |
| 115 | if (0 != lame_set_in_samplerate(gfp, audio_format.sample_rate)) |
| 116 | throw std::runtime_error("error setting lame sample rate"); |
| 117 | |
| 118 | if (0 != lame_set_out_samplerate(gfp, audio_format.sample_rate)) |
| 119 | throw std::runtime_error("error setting lame out sample rate"); |
| 120 | |
| 121 | if (0 > lame_init_params(gfp)) |
| 122 | throw std::runtime_error("error initializing lame params"); |
| 123 | } |
| 124 | |
| 125 | Encoder * |
| 126 | PreparedLameEncoder::Open(AudioFormat &audio_format) |