Error Handling
libopenmpt C++ uses C++ exception handling for errror reporting.
Unless otherwise noted, any libopenmpt function may throw exceptions and all exceptions thrown by libopenmpt itself are derived from openmpt::exception. In addition, any libopenmpt function may also throw any exception specified by the C++ language and C++ standard library. These are all derived from std::exception.
Strings
- All strings returned from libopenmpt are encoded in UTF-8.
- All strings passed to libopenmpt should also be encoded in UTF-8. Behaviour in case of invalid UTF-8 is unspecified.
- libopenmpt does not enforce or expect any particular unicode normalization form.
Detailed documentation
libopenmpt C++
Example
#include <fstream>
#include <vector>
#include <cstring>
#include <portaudio.h>
int main( int , char * argv [] ) {
const std::size_t buffersize = 480;
const std::int32_t samplerate = 48000;
std::vector<float> left( buffersize );
std::vector<float> right( buffersize );
std::ifstream file( argv[1], std::ios::binary );
Pa_Initialize();
PaStream * stream = 0;
PaStreamParameters streamparameters;
std::memset( &streamparameters, 0, sizeof(PaStreamParameters) );
streamparameters.device = Pa_GetDefaultOutputDevice();
streamparameters.channelCount = 2;
streamparameters.sampleFormat = paFloat32 | paNonInterleaved;
streamparameters.suggestedLatency = Pa_GetDeviceInfo( streamparameters.device )->defaultHighOutputLatency;
Pa_OpenStream( &stream, NULL, &streamparameters, samplerate, paFramesPerBufferUnspecified, 0, NULL, NULL );
Pa_StartStream( stream );
while ( true ) {
std::size_t count = mod.read( samplerate, buffersize, left.data(), right.data() );
if ( count == 0 ) {
break;
}
const float * const buffers [2] = { left.data(), right.data() };
Pa_WriteStream( stream, buffers, count );
}
Pa_StopStream( stream );
Pa_CloseStream( stream );
Pa_Terminate();
return 0;
}