| 109 | } |
| 110 | |
| 111 | static void |
| 112 | flac_encoder_setup(FLAC__StreamEncoder *fse, unsigned compression, bool oggflac, |
| 113 | const AudioFormat &audio_format) |
| 114 | { |
| 115 | unsigned bits_per_sample; |
| 116 | |
| 117 | switch (audio_format.format) { |
| 118 | case SampleFormat::S8: |
| 119 | bits_per_sample = 8; |
| 120 | break; |
| 121 | |
| 122 | case SampleFormat::S16: |
| 123 | bits_per_sample = 16; |
| 124 | break; |
| 125 | |
| 126 | default: |
| 127 | bits_per_sample = 24; |
| 128 | } |
| 129 | |
| 130 | if (!FLAC__stream_encoder_set_compression_level(fse, compression)) |
| 131 | throw FmtRuntimeError("error setting flac compression to {}", |
| 132 | compression); |
| 133 | |
| 134 | if (!FLAC__stream_encoder_set_channels(fse, audio_format.channels)) |
| 135 | throw FmtRuntimeError("error setting flac channels num to {}", |
| 136 | audio_format.channels); |
| 137 | |
| 138 | if (!FLAC__stream_encoder_set_bits_per_sample(fse, bits_per_sample)) |
| 139 | throw FmtRuntimeError("error setting flac bit format to {}", |
| 140 | bits_per_sample); |
| 141 | |
| 142 | if (!FLAC__stream_encoder_set_sample_rate(fse, |
| 143 | audio_format.sample_rate)) |
| 144 | throw FmtRuntimeError("error setting flac sample rate to {}", |
| 145 | audio_format.sample_rate); |
| 146 | |
| 147 | if (oggflac && !FLAC__stream_encoder_set_ogg_serial_number(fse, |
| 148 | GenerateSerial())) |
| 149 | throw std::runtime_error{"error setting ogg serial number"}; |
| 150 | } |
| 151 | |
| 152 | FlacEncoder::FlacEncoder(AudioFormat _audio_format, FLAC__StreamEncoder *_fse, unsigned _compression, bool _oggflac, bool _oggchaining) |
| 153 | :Encoder(_oggchaining), |
no test coverage detected