MCPcopy Create free account
hub / github.com/ObEngine/ObEngine / drmp3_init_internal

Function drmp3_init_internal

extlibs/soloud/src/audiosource/wav/dr_mp3.h:2585–2639  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2583}
2584
2585drmp3_bool32 drmp3_init_internal(drmp3* pMP3, drmp3_read_proc onRead, drmp3_seek_proc onSeek, void* pUserData, const drmp3_config* pConfig)
2586{
2587 drmp3_assert(pMP3 != NULL);
2588 drmp3_assert(onRead != NULL);
2589
2590 // This function assumes the output object has already been reset to 0. Do not do that here, otherwise things will break.
2591 drmp3dec_init(&pMP3->decoder);
2592
2593 // The config can be null in which case we use defaults.
2594 drmp3_config config;
2595 if (pConfig != NULL) {
2596 config = *pConfig;
2597 } else {
2598 drmp3_zero_object(&config);
2599 }
2600
2601 pMP3->channels = config.outputChannels;
2602 if (pMP3->channels == 0) {
2603 pMP3->channels = DR_MP3_DEFAULT_CHANNELS;
2604 }
2605
2606 // Cannot have more than 2 channels.
2607 if (pMP3->channels > 2) {
2608 pMP3->channels = 2;
2609 }
2610
2611 pMP3->sampleRate = config.outputSampleRate;
2612 if (pMP3->sampleRate == 0) {
2613 pMP3->sampleRate = DR_MP3_DEFAULT_SAMPLE_RATE;
2614 }
2615
2616 pMP3->onRead = onRead;
2617 pMP3->onSeek = onSeek;
2618 pMP3->pUserData = pUserData;
2619
2620 // We need a sample rate converter for converting the sample rate from the MP3 frames to the requested output sample rate.
2621 drmp3_src_config srcConfig;
2622 drmp3_zero_object(&srcConfig);
2623 srcConfig.sampleRateIn = DR_MP3_DEFAULT_SAMPLE_RATE;
2624 srcConfig.sampleRateOut = pMP3->sampleRate;
2625 srcConfig.channels = pMP3->channels;
2626 srcConfig.algorithm = drmp3_src_algorithm_linear;
2627 if (!drmp3_src_init(&srcConfig, drmp3_read_src, pMP3, &pMP3->src)) {
2628 drmp3_uninit(pMP3);
2629 return DRMP3_FALSE;
2630 }
2631
2632 // Decode the first frame to confirm that it is indeed a valid MP3 stream.
2633 if (!drmp3_decode_next_frame(pMP3)) {
2634 drmp3_uninit(pMP3);
2635 return DRMP3_FALSE; // Not a valid MP3 stream.
2636 }
2637
2638 return DRMP3_TRUE;
2639}
2640
2641drmp3_bool32 drmp3_init(drmp3* pMP3, drmp3_read_proc onRead, drmp3_seek_proc onSeek, void* pUserData, const drmp3_config* pConfig)
2642{

Callers 2

drmp3_initFunction · 0.85
drmp3_init_memoryFunction · 0.85

Calls 4

drmp3dec_initFunction · 0.85
drmp3_src_initFunction · 0.85
drmp3_uninitFunction · 0.85
drmp3_decode_next_frameFunction · 0.85

Tested by

no test coverage detected