int wmain( int argc, wchar_t * argv[] ) { #else int main( int argc, char * argv[] ) { #endif FILE * file = 0; openmpt_module * mod = 0; size_t count = 0; PaStream * stream = 0; (void)argc; #if ( defined( _WIN32 ) || defined( WIN32 ) ) && ( defined( _UNICODE ) || defined( UNICODE ) ) file = _wfopen( argv[1], L"rb" ); #else file = fopen( argv[1], "rb" ); #endif mod = openmpt_module_create2( openmpt_stream_get_file_callbacks(), file, NULL, NULL, NULL, NULL, NULL, NULL, NULL ); fclose( file ); Pa_Initialize(); Pa_OpenDefaultStream( &stream, 0, 2, paInt16 | paNonInterleaved, SAMPLERATE, paFramesPerBufferUnspecified, NULL, NULL ); Pa_StartStream( stream ); while ( 1 ) { count = openmpt_module_read_stereo( mod, SAMPLERATE, BUFFERSIZE, left, right ); if ( count == 0 ) { break; } Pa_WriteStream( stream, buffers, (unsigned long)count ); } Pa_StopStream( stream ); Pa_CloseStream( stream ); Pa_Terminate(); openmpt_module_destroy( mod ); return 0; }
static int read_close_openmpt(AVFormatContext *s) { OpenMPTContext *openmpt = s->priv_data; openmpt_module_destroy(openmpt->module); openmpt->module = NULL; return 0; }
LIBOPENMPT_MODPLUG_API void ModPlug_Unload(ModPlugFile* file) { int p; if(!file) return; if(file->patterns){ for(p=0;p<openmpt_module_get_num_patterns(file->mod);p++){ if(file->patterns[p]){ free(file->patterns[p]); file->patterns[p] = NULL; } } free(file->patterns); file->patterns = NULL; } if(file->mixerbuf){ free(file->mixerbuf); file->mixerbuf = NULL; } openmpt_module_destroy(file->mod); file->mod = NULL; openmpt_free_string(file->name); file->name = NULL; openmpt_free_string(file->message); file->message = NULL; free(file->buf); file->buf = NULL; free(file); }
LIBOPENMPT_MODPLUG_API ModPlugFile* ModPlug_Load(const void* data, int size) { ModPlugFile* file = malloc(sizeof(ModPlugFile)); if(!file) return NULL; memset(file,0,sizeof(ModPlugFile)); memcpy(&file->settings,&globalsettings,sizeof(ModPlug_Settings)); file->mod = openmpt_module_create_from_memory(data,size,NULL,NULL,NULL); if(!file->mod){ free(file); return NULL; } file->buf = malloc(BUFFER_COUNT*sizeof(signed short)*4); if(!file->buf){ openmpt_module_destroy(file->mod); free(file); return NULL; } openmpt_module_set_repeat_count(file->mod,file->settings.mLoopCount); file->name = openmpt_module_get_metadata(file->mod,"title"); file->message = openmpt_module_get_metadata(file->mod,"message"); #ifndef LIBOPENMPT_MODPLUG_0_8_7 openmpt_module_set_render_param(file->mod,OPENMPT_MODULE_RENDER_STEREOSEPARATION_PERCENT,file->settings.mStereoSeparation*100/128); #endif openmpt_module_set_render_param(file->mod,OPENMPT_MODULE_RENDER_INTERPOLATIONFILTER_LENGTH,modplugresamplingmode_to_filterlength(file->settings.mResamplingMode)); return file; }
int main( int argc, char * argv[] ) { FILE * file = 0; size_t size = 0; void * data = 0; openmpt_module * mod = 0; size_t count = 0; PaStream * stream = 0; PaStreamParameters streamparameters; memset( &streamparameters, 0, sizeof( PaStreamParameters ) ); (void)argc; file = fopen( argv[1], "rb" ); fseek( file, 0, SEEK_END ); size = ftell( file ); fseek( file, 0, SEEK_SET ); data = malloc( size ); size = fread( data, 1, size, file ); fclose( file ); mod = openmpt_module_create_from_memory( data, size, NULL, NULL, NULL ); free( data ); Pa_Initialize(); streamparameters.device = Pa_GetDefaultOutputDevice(); streamparameters.channelCount = 2; streamparameters.sampleFormat = paInt16 | paNonInterleaved; streamparameters.suggestedLatency = Pa_GetDeviceInfo( streamparameters.device )->defaultHighOutputLatency; Pa_OpenStream( &stream, NULL, &streamparameters, SAMPLERATE, paFramesPerBufferUnspecified, 0, NULL, NULL ); Pa_StartStream( stream ); while ( 1 ) { count = openmpt_module_read_stereo( mod, SAMPLERATE, BUFFERSIZE, left, right ); if ( count == 0 ) { break; } Pa_WriteStream( stream, buffers, count ); } Pa_StopStream( stream ); Pa_CloseStream( stream ); Pa_Terminate(); openmpt_module_destroy( mod ); return 0; }
static int read_header_openmpt(AVFormatContext *s) { AVStream *st; OpenMPTContext *openmpt = s->priv_data; int64_t size; char *buf; #if OPENMPT_API_VERSION_AT_LEAST(0,3,0) int error; #endif int ret; size = avio_size(s->pb); if (size <= 0) return AVERROR_INVALIDDATA; buf = av_malloc(size); if (!buf) return AVERROR(ENOMEM); size = avio_read(s->pb, buf, size); if (size < 0) { av_log(s, AV_LOG_ERROR, "Reading input buffer failed.\n"); av_freep(&buf); return size; } #if OPENMPT_API_VERSION_AT_LEAST(0,3,0) error = OPENMPT_ERROR_OK; openmpt->module = openmpt_module_create_from_memory2(buf, size, openmpt_logfunc, s, NULL, NULL, &error, NULL, NULL); av_freep(&buf); if (!openmpt->module) { if (error == OPENMPT_ERROR_OUT_OF_MEMORY) return AVERROR(ENOMEM); else if (error >= OPENMPT_ERROR_GENERAL) return AVERROR_INVALIDDATA; else return AVERROR_UNKNOWN; } #else openmpt->module = openmpt_module_create_from_memory(buf, size, openmpt_logfunc, s, NULL); av_freep(&buf); if (!openmpt->module) return AVERROR_INVALIDDATA; #endif openmpt->channels = av_get_channel_layout_nb_channels(openmpt->layout); if (openmpt->subsong >= openmpt_module_get_num_subsongs(openmpt->module)) { openmpt_module_destroy(openmpt->module); av_log(s, AV_LOG_ERROR, "Invalid subsong index: %d\n", openmpt->subsong); return AVERROR(EINVAL); } if (openmpt->subsong != -2) { if (openmpt->subsong >= 0) { av_dict_set_int(&s->metadata, "track", openmpt->subsong + 1, 0); } ret = openmpt_module_select_subsong(openmpt->module, openmpt->subsong); if (!ret){ openmpt_module_destroy(openmpt->module); av_log(s, AV_LOG_ERROR, "Could not select requested subsong: %d", openmpt->subsong); return AVERROR(EINVAL); } } openmpt->duration = openmpt_module_get_duration_seconds(openmpt->module); add_meta(s, "artist", openmpt_module_get_metadata(openmpt->module, "artist")); add_meta(s, "title", openmpt_module_get_metadata(openmpt->module, "title")); add_meta(s, "encoder", openmpt_module_get_metadata(openmpt->module, "tracker")); add_meta(s, "comment", openmpt_module_get_metadata(openmpt->module, "message")); add_meta(s, "date", openmpt_module_get_metadata(openmpt->module, "date")); st = avformat_new_stream(s, NULL); if (!st) { openmpt_module_destroy(openmpt->module); openmpt->module = NULL; return AVERROR(ENOMEM); } avpriv_set_pts_info(st, 64, 1, AV_TIME_BASE); st->duration = llrint(openmpt->duration*AV_TIME_BASE); st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; st->codecpar->codec_id = AV_NE(AV_CODEC_ID_PCM_F32BE, AV_CODEC_ID_PCM_F32LE); st->codecpar->channels = openmpt->channels; st->codecpar->sample_rate = openmpt->sample_rate; return 0; }
JNIEXPORT void JNICALL Java_com_ssb_droidsound_plugins_OpenMPTPlugin_N_1unload(JNIEnv *env, jobject obj, jlong song) { openmpt_module* mod = (openmpt_module*)song; openmpt_module_destroy(mod); return; }
MPTWrap::~MPTWrap() { openmpt_module_destroy(mod); }