| 126 | } |
| 127 | |
| 128 | bool AudioDecoderMp3::open(std::string_view fullPath) |
| 129 | { |
| 130 | #if !AX_USE_MPG123 |
| 131 | do |
| 132 | { |
| 133 | _fileStream = FileUtils::getInstance()->openFileStream(fullPath, IFileStream::Mode::READ); |
| 134 | if (!_fileStream) |
| 135 | { |
| 136 | AXLOGE("Trouble with minimp3(1): {}\n", strerror(errno)); |
| 137 | break; |
| 138 | } |
| 139 | |
| 140 | auto handle = new mp3dec_impl(); |
| 141 | |
| 142 | handle->_decIO.read = minimp3_read_r; |
| 143 | handle->_decIO.seek = minimp3_seek_r; |
| 144 | handle->_decIO.read_data = handle->_decIO.seek_data = _fileStream.get(); |
| 145 | |
| 146 | if (mp3dec_ex_open_cb(&handle->_dec, &handle->_decIO, MP3D_SEEK_TO_SAMPLE) != 0) |
| 147 | { |
| 148 | delete handle; |
| 149 | break; |
| 150 | } |
| 151 | |
| 152 | auto& info = handle->_dec.info; |
| 153 | _channelCount = info.channels; // the _channelCount is samplesPerFrame |
| 154 | _sampleRate = info.hz; |
| 155 | # ifndef MINIMP3_FLOAT_OUTPUT |
| 156 | _sourceFormat = AUDIO_SOURCE_FORMAT::PCM_16; |
| 157 | _bytesPerBlock = sizeof(uint16_t) * _channelCount; |
| 158 | # else |
| 159 | _sourceFormat = AUDIO_SOURCE_FORMAT::PCM_FLT32; |
| 160 | _bytesPerBlock = sizeof(float) * _channelCount; |
| 161 | # endif |
| 162 | // samples |
| 163 | _totalFrames = handle->_dec.samples / _channelCount; |
| 164 | |
| 165 | // store the handle |
| 166 | _handle = handle; |
| 167 | |
| 168 | _isOpened = true; |
| 169 | return true; |
| 170 | } while (false); |
| 171 | |
| 172 | return false; |
| 173 | #else |
| 174 | int32_t rate = 0; |
| 175 | int error = MPG123_OK; |
| 176 | int mp3Encoding = 0; |
| 177 | int channel = 0; |
| 178 | do |
| 179 | { |
| 180 | _handle = mpg123_new(nullptr, &error); |
| 181 | if (nullptr == _handle) |
| 182 | { |
| 183 | AXLOGE("Basic setup goes wrong: {}", mpg123_plain_strerror(error)); |
| 184 | break; |
| 185 | } |
no test coverage detected