libopenmpt  0.2.4259
cross-platform C++ and C library to decode tracked music files
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
C++ API

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

/*
* libopenmpt_example_cxx.cpp
* --------------------------
* Purpose: libopenmpt C++ API simple example
* Notes : (currently none)
* Authors: OpenMPT Devs
* The OpenMPT source code is released under the BSD license. Read LICENSE for more details.
*/
#include <fstream>
#include <vector>
#include <cstring>
#include <portaudio.h>
int main( int /*argc*/, 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 );
openmpt::module mod( file );
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;
}