MCPcopy Create free account
hub / github.com/SFML/SFML / open

Method open

src/SFML/Audio/SoundFileReaderMp3.cpp:134–166  ·  view source on GitHub ↗

///////////////////////////////////////////////////////

Source from the content-addressed store, hash-verified

132
133////////////////////////////////////////////////////////////
134std::optional<SoundFileReader::Info> SoundFileReaderMp3::open(InputStream& stream)
135{
136 // Init mp3 decoder
137 if (drmp3_init(&m_decoder, readCallback, seekCallback, tellCallback, nullptr, &stream, nullptr) != 1)
138 return std::nullopt;
139
140 // Retrieve the music attributes
141 Info info;
142 info.channelCount = static_cast<unsigned int>(m_decoder.channels);
143 info.sampleRate = static_cast<unsigned int>(m_decoder.sampleRate);
144 info.sampleCount = drmp3_get_pcm_frame_count(&m_decoder) * m_decoder.channels;
145
146 // MP3 only supports mono/stereo channels
147 switch (info.channelCount)
148 {
149 case 0:
150 err() << "No channels in MP3 file" << std::endl;
151 break;
152 case 1:
153 info.channelMap = {SoundChannel::Mono};
154 break;
155 case 2:
156 info.channelMap = {SoundChannel::SideLeft, SoundChannel::SideRight};
157 break;
158 default:
159 err() << "MP3 files with more than 2 channels not supported" << std::endl;
160 assert(false);
161 break;
162 }
163
164 m_numSamples = info.sampleCount;
165 return info;
166}
167
168
169////////////////////////////////////////////////////////////

Callers 5

openFromFileMethod · 0.45
openFromFileMethod · 0.45
openFromMemoryMethod · 0.45
openFromStreamMethod · 0.45

Calls

no outgoing calls

Tested by

no test coverage detected