| 93 | } |
| 94 | |
| 95 | bool AudioPlayer::LoadFromFile(const std::string& filename) |
| 96 | { |
| 97 | if (m_loaded) |
| 98 | m_clean(); |
| 99 | |
| 100 | m_loaded = false; |
| 101 | |
| 102 | ma_pcm_rb_init(ma_format_s16, 2, PLAYER_PCM_FRAME_CHUNK_SIZE, NULL, NULL, &m_rb); |
| 103 | m_decoderConfig = ma_decoder_config_init(ma_format_s16, 2, 48000); |
| 104 | |
| 105 | ma_result result = ma_decoder_init_file(filename.c_str(), &m_decoderConfig, &m_decoder); |
| 106 | if (result != MA_SUCCESS) |
| 107 | return false; |
| 108 | |
| 109 | m_deviceConfig = ma_device_config_init(ma_device_type_playback); |
| 110 | m_deviceConfig.playback.format = m_decoder.outputFormat; |
| 111 | m_deviceConfig.playback.channels = m_decoder.outputChannels; |
| 112 | m_deviceConfig.sampleRate = m_decoder.outputSampleRate; |
| 113 | m_deviceConfig.dataCallback = audioPlayerCallback; |
| 114 | m_deviceConfig.pUserData = this; |
| 115 | |
| 116 | if (ma_device_init(NULL, &m_deviceConfig, &m_device) != MA_SUCCESS) { |
| 117 | ma_decoder_uninit(&m_decoder); |
| 118 | ma_pcm_rb_uninit(&m_rb); |
| 119 | return false; |
| 120 | } |
| 121 | |
| 122 | m_loaded = true; |
| 123 | |
| 124 | return true; |
| 125 | } |
| 126 | |
| 127 | void AudioPlayer::Start() |
| 128 | { |
nothing calls this directly
no outgoing calls
no test coverage detected