static struct tag * modplug_stream_tag(struct input_stream *is) { ModPlugFile *f; struct tag *ret = NULL; GByteArray *bdatas; char *title; bdatas = mod_loadfile(NULL, is); if (!bdatas) return NULL; f = ModPlug_Load(bdatas->data, bdatas->len); g_byte_array_free(bdatas, TRUE); if (f == NULL) return NULL; ret = tag_new(); ret->time = ModPlug_GetLength(f) / 1000; title = g_strdup(ModPlug_GetName(f)); if (title) tag_add_item(ret, TAG_TITLE, title); g_free(title); ModPlug_Unload(f); return ret; }
static bool modplug_scan_stream(struct input_stream *is, const struct tag_handler *handler, void *handler_ctx) { ModPlugFile *f; GByteArray *bdatas; bdatas = mod_loadfile(NULL, is); if (!bdatas) return false; f = ModPlug_Load(bdatas->data, bdatas->len); g_byte_array_free(bdatas, TRUE); if (f == NULL) return false; tag_handler_invoke_duration(handler, handler_ctx, ModPlug_GetLength(f) / 1000); const char *title = ModPlug_GetName(f); if (title != NULL) tag_handler_invoke_tag(handler, handler_ctx, TAG_TITLE, title); ModPlug_Unload(f); return true; }
bool sfMod::Mod::LoadFromMemory(const void* data, unsigned int size) { if (getStatus() != sf::SoundStream::Stopped) stop(); if (file_ != NULL) { ModPlug_Unload(file_); file_ = NULL; } name_ = ""; length_ = 0; file_ = ModPlug_Load(data, size); if (file_ == NULL) return false; name_ = ModPlug_GetName(file_); length_ = ModPlug_GetLength(file_); ModPlug_Settings settings; ModPlug_GetSettings(&settings); initialize(settings.mChannels, settings.mFrequency); return true; }
bool sfMod::Mod::LoadFromFile(const std::string& filename) { #if SFML_VERSION_MAJOR < 2 if (GetStatus() != sf::SoundStream::Stopped) Stop(); #else if (getStatus() != sf::SoundStream::Stopped) stop(); #endif if (file_ != NULL) { ModPlug_Unload(file_); file_ = NULL; } name_ = ""; length_ = 0; std::string data; std::ifstream file; file.open(filename.c_str(), std::ios::binary); if (!file.is_open()) return false; file.seekg(0, std::ios::end); unsigned int size = static_cast<unsigned int>(file.tellg()); file.seekg(0, std::ios::beg); data.reserve(size); for (unsigned int i = 0; i < size; ++i) data += file.get(); file.close(); file_ = ModPlug_Load(data.c_str(), size); if (file_ == NULL) return false; name_ = ModPlug_GetName(file_); length_ = ModPlug_GetLength(file_); ModPlug_Settings settings; ModPlug_GetSettings(&settings); #if SFML_VERSION_MAJOR < 2 Initialize(settings.mChannels, settings.mFrequency); #else initialize(settings.mChannels, settings.mFrequency); #endif return true; }
void get_info( file_info & p_info, abort_callback & p_abort ) { ModPlugFile* m_info = ModPlug_Load(file_buffer.get_ptr(), file_buffer.get_size()); p_info.info_set( "encoding", "synthesized" ); int type_module = ModPlug_GetModuleType(m_info); p_info.info_set( "codec", "Module file" ); p_info.info_set_int( "channels", 2 ); p_info.meta_set( "title", pfc::stringcvt::string_utf8_from_ansi( ModPlug_GetName(m_info) )); int len = ModPlug_GetLength(m_info); len /= 1000; p_info.set_length( len ); if(m_info)ModPlug_Unload(m_info); }
//! \brief Initialize an audio decoder for a given file void* Init(const char* strFile, unsigned int filecache, int* channels, int* samplerate, int* bitspersample, int64_t* totaltime, int* bitrate, AEDataFormat* format, const AEChannel** channelinfo) { if (!strFile) return NULL; void* file = XBMC->OpenFile(strFile,0); if (!file) return NULL; int len = XBMC->GetFileLength(file); char *data = new char[len]; if (!data) { XBMC->CloseFile(file); return NULL; } XBMC->ReadFile(file, data, len); XBMC->CloseFile(file); // Now load the module ModPlugFile* module = ModPlug_Load(data, len); delete[] data; if (!module) return NULL; SET_IF(channels, 2) SET_IF(samplerate, 44100) SET_IF(bitspersample, 16) SET_IF(totaltime,(int64_t)(ModPlug_GetLength(module))); SET_IF(format, AE_FMT_S16NE) static enum AEChannel map[3] = { AE_CH_FL, AE_CH_FR, AE_CH_NULL }; SET_IF(channelinfo, map) SET_IF(bitrate, ModPlug_NumChannels(module)); return module; }
gboolean get_mod_info(gchar *file, struct tags *tags) { gchar *data; gsize length; ModPlugFile *mf; if(!g_file_get_contents(file, &data, &length, NULL)) { g_critical("Unable to open file : %s", file); return FALSE; } mf = ModPlug_Load((const void*)data, (int)length); if(!mf) { g_critical("ModPlug_Load failed for %s", file); g_free(data); return FALSE; } ; tags->artist = g_strdup(""); tags->album = g_strdup(""); tags->genre = g_strdup(""); tags->comment = g_strdup(""); tags->title = g_strdup(ModPlug_GetName(mf)); tags->channels = 2; tags->samplerate = 44100; tags->length = ModPlug_GetLength(mf)/1000; ModPlug_Unload(mf); g_free(data); return TRUE; }
bool sfMod::Mod::LoadFromMemory(const std::string& data) { #if SFML_VERSION_MAJOR < 2 if (GetStatus() != sf::SoundStream::Stopped) Stop(); #else if (getStatus() != sf::SoundStream::Stopped) stop(); #endif if (file_ != NULL) { ModPlug_Unload(file_); file_ = NULL; } name_ = ""; length_ = 0; file_ = ModPlug_Load(data.c_str(), data.size()); if (file_ == NULL) return false; name_ = ModPlug_GetName(file_); length_ = ModPlug_GetLength(file_); ModPlug_Settings settings; ModPlug_GetSettings(&settings); #if SFML_VERSION_MAJOR < 2 Initialize(settings.mChannels, settings.mFrequency); #else initialize(settings.mChannels, settings.mFrequency); #endif return true; }
int main(int argc, char* argv[]) { long size; char *filedata; term_size terminal; ModPlugFile *f2; int mlen; struct timeval tvstart; struct timeval tv; struct timeval tvpause, tvunpause; struct timeval tvptotal; char status[161]; char songname[41]; char notpaus[4]; int loop=0; // kontest int songsplayed = 0; int nFiles = 0, fnOffset[100]; int i; ModPlug_Settings settings; ModPlug_GetSettings(&settings); ao_device *device; ao_sample_format format = {0}; int default_driver; ao_initialize(); default_driver = ao_default_driver_id(); for (i=1; i<argc; i++) { /* check if arguments need to be parsed */ if (argv[i][0] == '-') { if (strstr(argv[i],"-h")) { printf("\n"); help(argv[0],0); } else if (strstr(argv[i],"-v")) { versioninfo(); exit(0); } else if (strstr(argv[i],"-l")) { loop=1; continue; } else if (strstr(argv[i],"-ao")) { default_driver = ao_driver_id(argv[++i]); continue; } if (argv[i][1] == '-') { // not a song if (strstr(argv[i],"--help")) { help(argv[0],0); } else if (strstr(argv[i],"--version")) { versioninfo(); exit(0); } continue; } } /* "valid" filename - store it */ fnOffset[nFiles++] = i; } format.bits = 16; format.channels = 2; format.rate = 44100; format.byte_format = AO_FMT_LITTLE; // printf("Default driver = %i\n", default_driver); char buffer[128]; int result, nread; struct pollfd pollfds; int timeout = 1; /* Timeout in msec. */ int pause=0; int mono=0; int bits=0; int song; // [rev--dly--] [sur--dly--] [bas--rng--] int rev=0; // a int revdly=0; // s int sur=0; // d int surdly=0; // y int bas=0; // x int basrng=0; // c /* Initialize pollfds; we're looking at input, stdin */ pollfds.fd = 0; /* stdin */ pollfds.events = POLLIN; /* Wait for input */ if (argc==1) { help(argv[0],1); } if (!get_term_size(STDIN_FILENO,&terminal)) { fprintf(stderr,"warning: failed to get terminal size\n"); } srand(time(NULL)); for (song=0; song<nFiles; song++) { char *filename = argv[fnOffset[song]]; /* -- Open driver -- */ if (default_driver == ao_driver_id("wav")) { device = ao_open_file(default_driver, "output.wav", 1, &format, NULL /*no options*/); } else { device = ao_open_live(default_driver, &format, NULL /* no options */); } if (device == NULL) { fprintf(stderr, "Error opening device. (%s)\n", filename); fprintf(stderr, "ERROR: %i\n", errno); return 1; } printf("%s ",filename); printf("[%d/%d]",song+1,nFiles); filedata = getFileData(filename, &size); if (filedata == NULL) continue; printf(" [%ld]\n",size); // Note: All "Basic Settings" must be set before ModPlug_Load. settings.mResamplingMode = MODPLUG_RESAMPLE_FIR; /* RESAMP */ settings.mChannels = 2; settings.mBits = 16; settings.mFrequency = 44100; settings.mStereoSeparation = 128; settings.mMaxMixChannels = 256; /* insert more setting changes here */ ModPlug_SetSettings(&settings); f2 = ModPlug_Load(filedata, size); if (!f2) { printf("could not load %s\n", filename); close(audio_fd); free(filedata); /* ? */ } else { songsplayed++; /* settings.mFlags=MODPLUG_ENABLE_OVERSAMPLING | \ MODPLUG_ENABLE_NOISE_REDUCTION | \ MODPLUG_ENABLE_REVERB | \ MODPLUG_ENABLE_MEGABASS | \ MODPLUG_ENABLE_SURROUND;*/ // settings.mReverbDepth = 100; /* 0 - 100 */ * [REV--DLY--] // settings.mReverbDelay = 200; /* 40 - 200 ms 00-FF */ // settings.mSurroundDepth = 100; /* 0 - 100 */ [SUR--DLY--] // settings.mSurroundDelay = 40; /* 5 - 40 ms */ // settings.mBassAmount = 100; /* 0 - 100 */ [BAS--RNG--] // settings.mBassRange = 100; /* 10 - 100 hz */ // [REV--DLY--] [SUR--DLY--] [BAS--RNG--] // [rev--dly--] [sur--dly--] [bas--rng--] set_keypress(); strcpy(songname, ModPlug_GetName(f2)); /* if no modplug "name" - use last 41 characters of filename */ if (strlen(songname)==0) { int l = strlen(filename); char *st = filename; if (l >= 41) st = filename + l - 41; strncpy(songname,st,41); songname[40] = 0; } sprintf(status,"[1Gplaying %s (%%d.%%d/%d\") (%%d/%%d/%%d) \b\b\b\b",songname,ModPlug_GetLength(f2)/1000); if (loop) sprintf(status,"[1Glooping %s (%%d.%%d/%d\") (%%d/%%d/%%d) \b\b\b\b",songname,ModPlug_GetLength(f2)/1000); gettimeofday(&tvstart,NULL); tvptotal.tv_sec=tvptotal.tv_usec=0; mlen=1; while(mlen!=0) { if (mlen==0) { break; } if (!pause) { gettimeofday(&tv,NULL); mlen = ModPlug_Read(f2,audio_buffer,BUF_SIZE); if (mlen > 0 && ao_play(device, audio_buffer, mlen) == 0) { perror("audio write"); exit(1); } } printf(status,tv.tv_sec-tvstart.tv_sec-tvptotal.tv_sec,tv.tv_usec/100000,format.rate,format.channels,settings.mBits/*,rev,revdly,sur,surdly,bas,basrng*/); fflush(stdout); if ((mlen==0) && (loop==1)) { /*printf("LOOPING NOW\n");*/ ModPlug_Seek(f2,0); gettimeofday(&tvstart,NULL); mlen=ModPlug_Read(f2,audio_buffer,BUF_SIZE); tvptotal.tv_sec=tvptotal.tv_usec=0; } result = poll(&pollfds, 1, timeout); switch (result) { case 0: /*printf(".");*/ break; case -1: perror("select"); exit(1); default: if (pollfds.revents && POLLIN) { nread = read(0, buffer, 1); /* s/nread/1/2 */ if (nread == 0) { printf("keyboard done\n"); exit(0); } else { buffer[nread] = 0; /* printf("%s", buffer); */ if (buffer[0]=='q') { mlen=0; song=nFiles; } /* quit */ if (buffer[0]=='f') { if ((tv.tv_sec-tvstart.tv_sec-tvptotal.tv_sec+10) < (ModPlug_GetLength(f2)/1000)) { ModPlug_Seek(f2,(tv.tv_sec-tvstart.tv_sec-tvptotal.tv_sec)*1000+10000); tvstart.tv_sec-=10; } } /* forward 10" */ if (buffer[0]=='b') { if ((tv.tv_sec-tvstart.tv_sec-tvptotal.tv_sec-10) > 0) { ModPlug_Seek(f2,(tv.tv_sec-tvstart.tv_sec-tvptotal.tv_sec)*1000-10000); tvstart.tv_sec+=10; } } /* backward 10" */ /* if (buffer[0]=='i') { printf("\n"); } */ /* if (buffer[0]=='a') { rev++; settings.mReverbDepth=rev; ModPlug_SetSettings(&settings); } if (buffer[0]=='A') { rev--; settings.mReverbDepth=rev; ModPlug_SetSettings(&settings); } if (buffer[0]=='s') { revdly++; settings.mReverbDelay=revdly; ModPlug_SetSettings(&settings); } if (buffer[0]=='S') { revdly--; settings.mReverbDelay=revdly; ModPlug_SetSettings(&settings); } if (buffer[0]=='d') { sur++; settings.mSurroundDepth=sur; ModPlug_SetSettings(&settings); } if (buffer[0]=='D') { sur--; settings.mSurroundDepth=sur; ModPlug_SetSettings(&settings); } if (buffer[0]=='y') { surdly++; settings.mSurroundDelay=surdly; ModPlug_SetSettings(&settings); } if (buffer[0]=='Y') { surdly--; settings.mSurroundDelay=surdly; ModPlug_SetSettings(&settings); } if (buffer[0]=='x') { bas++; settings.mBassAmount=bas; ModPlug_SetSettings(&settings); } if (buffer[0]=='X') { bas--; settings.mBassAmount=bas; ModPlug_SetSettings(&settings); } if (buffer[0]=='c') { basrng++; settings.mBassRange=basrng; ModPlug_SetSettings(&settings); } if (buffer[0]=='C') { basrng--; settings.mBassRange=basrng; ModPlug_SetSettings(&settings); } */ if (buffer[0]=='n') { if (song<argc) { mlen=0; pause=0; } } if (buffer[0]=='N') { if (song>1) { song-=2; mlen=0; pause=0; } } if (buffer[0]=='r') { song=(int) ((float)(argc-1)*rand()/(RAND_MAX+1.0)); mlen=0; pause=0; // ioctl(audio_fd,SNDCTL_DSP_RESET,0); /* printf("\n[%d?]\n",song+1); */ } /*if (buffer[0]=='R') { song=(int) ((float)(argc-1)*rand()/(RAND_MAX+1.0)); mlen=0; pause=0; }*/ /* if (buffer[0]=='m') { // mono/stereo mono^=1; if (mono) format.channels=1; else format.channels=2; ioctl(audio_fd,SNDCTL_DSP_RESET,0); if (ioctl(audio_fd, SNDCTL_DSP_CHANNELS, &channels) == -1) { perror("SNDCTL_DSP_CHANNELS"); exit(1); } if (mono) settings.mChannels=1; else settings.mChannels=2; ModPlug_SetSettings(&settings); f2=ModPlug_Load(d,size); ModPlug_Seek(f2,(tv.tv_sec-tvstart.tv_sec-tvptotal.tv_sec)*1000+10000); } */ if (buffer[0]=='l') { loop^=1; if (loop) { memcpy(status+4,"loop",4); } else { memcpy(status+4,"play",4); } } /* loop */ if (buffer[0]=='p') { pause^=1; if (pause) { gettimeofday(&tvpause,NULL); memcpy(notpaus,status+4,4); memcpy(status+4,"paus",4); } else { gettimeofday(&tvunpause,NULL); memcpy(status+4,notpaus,4); tvptotal.tv_sec+=tvunpause.tv_sec-tvpause.tv_sec; tvptotal.tv_usec+=tvunpause.tv_usec-tvpause.tv_usec; /* printf(status,tv.tv_sec-tvstart.tv_sec,tv.tv_usec/100000); */ } } /* pause */ } } } } printf("\n"); reset_keypress(); ModPlug_Unload(f2); ao_close(device); fprintf(stderr, "Closing audio device.\n"); free(filedata); } /* valid module */ } /* for */ ao_shutdown(); return 0; }
static void mod_decode(struct decoder *decoder, struct input_stream *is) { ModPlugFile *f; ModPlug_Settings settings; GByteArray *bdatas; struct audio_format audio_format; int ret; char audio_buffer[MODPLUG_FRAME_SIZE]; enum decoder_command cmd = DECODE_COMMAND_NONE; bdatas = mod_loadfile(decoder, is); if (!bdatas) { g_warning("could not load stream\n"); return; } ModPlug_GetSettings(&settings); /* alter setting */ settings.mResamplingMode = MODPLUG_RESAMPLE_FIR; /* RESAMP */ settings.mChannels = 2; settings.mBits = 16; settings.mFrequency = 44100; /* insert more setting changes here */ ModPlug_SetSettings(&settings); f = ModPlug_Load(bdatas->data, bdatas->len); g_byte_array_free(bdatas, TRUE); if (!f) { g_warning("could not decode stream\n"); return; } audio_format_init(&audio_format, 44100, SAMPLE_FORMAT_S16, 2); assert(audio_format_valid(&audio_format)); decoder_initialized(decoder, &audio_format, is->seekable, ModPlug_GetLength(f) / 1000.0); do { ret = ModPlug_Read(f, audio_buffer, MODPLUG_FRAME_SIZE); if (ret <= 0) break; cmd = decoder_data(decoder, NULL, audio_buffer, ret, 0); if (cmd == DECODE_COMMAND_SEEK) { float where = decoder_seek_where(decoder); ModPlug_Seek(f, (int)(where * 1000.0)); decoder_command_finished(decoder); } } while (cmd != DECODE_COMMAND_STOP); ModPlug_Unload(f); }
static unsigned int get_length_in_samples(struct sppb_plugin_description *plugin, void *context) { MPSP_DPRINTF("parser: get_length_in_samples(): %u\n", (ModPlug_GetLength(self) + 500) / 1000 * getSamplingRate()); return (ModPlug_GetLength(self) + 500) / 1000 * get_sampling_rate(); }
/***************************************************************************** * Open *****************************************************************************/ static int Open( vlc_object_t *p_this ) { demux_t *p_demux = (demux_t*)p_this; demux_sys_t *p_sys; ModPlug_Settings settings; /* We accept file based on extension match */ if( !p_demux->obj.force ) { const char *psz_ext = p_demux->psz_filepath ? strrchr( p_demux->psz_filepath, '.' ) : NULL; if( psz_ext ) psz_ext++; if( Validate( p_demux, psz_ext ) ) { msg_Dbg( p_demux, "MOD validation failed (ext=%s)", psz_ext ? psz_ext : ""); return VLC_EGENERIC; } } const int64_t i_size = stream_Size( p_demux->s ); if( i_size <= 0 || i_size >= MOD_MAX_FILE_SIZE ) return VLC_EGENERIC; p_sys = vlc_obj_malloc( p_this, sizeof (*p_sys) ); if( !p_sys ) return VLC_ENOMEM; msg_Dbg( p_demux, "loading complete file (could be long)" ); p_sys->i_data = i_size; p_sys->p_data = vlc_obj_malloc( p_this, p_sys->i_data ); if( unlikely(p_sys->p_data == NULL) ) return VLC_ENOMEM; p_sys->i_data = vlc_stream_Read( p_demux->s, p_sys->p_data, p_sys->i_data ); if( p_sys->i_data <= 0 ) { msg_Err( p_demux, "failed to read the complete file" ); return VLC_EGENERIC; } /* Configure modplug before loading the file */ vlc_mutex_lock( &libmodplug_lock ); ModPlug_GetSettings( &settings ); settings.mFlags = MODPLUG_ENABLE_OVERSAMPLING; settings.mChannels = 2; settings.mBits = 16; settings.mFrequency = 44100; settings.mResamplingMode = MODPLUG_RESAMPLE_FIR; if( var_InheritBool( p_demux, "mod-noisereduction" ) ) settings.mFlags |= MODPLUG_ENABLE_NOISE_REDUCTION; if( var_InheritBool( p_demux, "mod-reverb" ) ) settings.mFlags |= MODPLUG_ENABLE_REVERB; settings.mReverbDepth = var_InheritInteger( p_demux, "mod-reverb-level" ); settings.mReverbDelay = var_InheritInteger( p_demux, "mod-reverb-delay" ); if( var_InheritBool( p_demux, "mod-megabass" ) ) settings.mFlags |= MODPLUG_ENABLE_MEGABASS; settings.mBassAmount = var_InheritInteger( p_demux, "mod-megabass-level" ); settings.mBassRange = var_InheritInteger( p_demux, "mod-megabass-range" ); if( var_InheritBool( p_demux, "mod-surround" ) ) settings.mFlags |= MODPLUG_ENABLE_SURROUND; settings.mSurroundDepth = var_InheritInteger( p_demux, "mod-surround-level" ); settings.mSurroundDelay = var_InheritInteger( p_demux, "mod-surround-delay" ); ModPlug_SetSettings( &settings ); p_sys->f = ModPlug_Load( p_sys->p_data, p_sys->i_data ); vlc_mutex_unlock( &libmodplug_lock ); if( !p_sys->f ) { msg_Err( p_demux, "failed to understand the file" ); return VLC_EGENERIC; } /* init time */ date_Init( &p_sys->pts, settings.mFrequency, 1 ); date_Set( &p_sys->pts, VLC_TICK_0 ); p_sys->i_length = VLC_TICK_FROM_MS( ModPlug_GetLength( p_sys->f ) ); msg_Dbg( p_demux, "MOD loaded name=%s length=%"PRId64"ms", ModPlug_GetName( p_sys->f ), MS_FROM_VLC_TICK( p_sys->i_length ) ); #ifdef WORDS_BIGENDIAN es_format_Init( &p_sys->fmt, AUDIO_ES, VLC_FOURCC( 't', 'w', 'o', 's' ) ); #else es_format_Init( &p_sys->fmt, AUDIO_ES, VLC_FOURCC( 'a', 'r', 'a', 'w' ) ); #endif p_sys->fmt.audio.i_rate = settings.mFrequency; p_sys->fmt.audio.i_channels = settings.mChannels; p_sys->fmt.audio.i_bitspersample = settings.mBits; p_sys->es = es_out_Add( p_demux->out, &p_sys->fmt ); if( unlikely(p_sys->es == NULL) ) return VLC_ENOMEM; /* Fill p_demux field */ p_demux->pf_demux = Demux; p_demux->pf_control = Control; p_demux->p_sys = p_sys; return VLC_SUCCESS; }
static int modplug_read_header(AVFormatContext *s) { AVStream *st; AVIOContext *pb = s->pb; ModPlug_Settings settings; ModPlugContext *modplug = s->priv_data; int sz = avio_size(pb); if (sz < 0) { av_log(s, AV_LOG_WARNING, "Could not determine file size\n"); sz = modplug->max_size; } else if (modplug->max_size && sz > modplug->max_size) { sz = modplug->max_size; av_log(s, AV_LOG_WARNING, "Max file size reach%s, allocating %dB " "but demuxing is likely to fail due to incomplete buffer\n", sz == FF_MODPLUG_DEF_FILE_SIZE ? " (see -max_size)" : "", sz); } if (modplug->color_eval) { int r = av_expr_parse(&modplug->expr, modplug->color_eval, var_names, NULL, NULL, NULL, NULL, 0, s); if (r < 0) return r; } modplug->buf = av_malloc(modplug->max_size); if (!modplug->buf) return AVERROR(ENOMEM); sz = avio_read(pb, modplug->buf, sz); ModPlug_GetSettings(&settings); settings.mChannels = 2; settings.mBits = 16; settings.mFrequency = 44100; settings.mResamplingMode = MODPLUG_RESAMPLE_FIR; // best quality settings.mLoopCount = 0; // prevents looping forever if (modplug->noise_reduction) settings.mFlags |= MODPLUG_ENABLE_NOISE_REDUCTION; SET_OPT_IF_REQUESTED(mReverbDepth, reverb_depth, MODPLUG_ENABLE_REVERB); SET_OPT_IF_REQUESTED(mReverbDelay, reverb_delay, MODPLUG_ENABLE_REVERB); SET_OPT_IF_REQUESTED(mBassAmount, bass_amount, MODPLUG_ENABLE_MEGABASS); SET_OPT_IF_REQUESTED(mBassRange, bass_range, MODPLUG_ENABLE_MEGABASS); SET_OPT_IF_REQUESTED(mSurroundDepth, surround_depth, MODPLUG_ENABLE_SURROUND); SET_OPT_IF_REQUESTED(mSurroundDelay, surround_delay, MODPLUG_ENABLE_SURROUND); if (modplug->reverb_depth) settings.mReverbDepth = modplug->reverb_depth; if (modplug->reverb_delay) settings.mReverbDelay = modplug->reverb_delay; if (modplug->bass_amount) settings.mBassAmount = modplug->bass_amount; if (modplug->bass_range) settings.mBassRange = modplug->bass_range; if (modplug->surround_depth) settings.mSurroundDepth = modplug->surround_depth; if (modplug->surround_delay) settings.mSurroundDelay = modplug->surround_delay; ModPlug_SetSettings(&settings); modplug->f = ModPlug_Load(modplug->buf, sz); if (!modplug->f) return AVERROR_INVALIDDATA; st = avformat_new_stream(s, NULL); if (!st) return AVERROR(ENOMEM); avpriv_set_pts_info(st, 64, 1, 1000); st->duration = ModPlug_GetLength(modplug->f); st->codec->codec_type = AVMEDIA_TYPE_AUDIO; st->codec->codec_id = AV_CODEC_ID_PCM_S16LE; st->codec->channels = settings.mChannels; st->codec->sample_rate = settings.mFrequency; // timebase = 1/1000, 2ch 16bits 44.1kHz-> 2*2*44100 modplug->ts_per_packet = 1000*AUDIO_PKT_SIZE / (4*44100.); if (modplug->video_stream) { AVStream *vst = avformat_new_stream(s, NULL); if (!vst) return AVERROR(ENOMEM); avpriv_set_pts_info(vst, 64, 1, 1000); vst->duration = st->duration; vst->codec->codec_type = AVMEDIA_TYPE_VIDEO; vst->codec->codec_id = AV_CODEC_ID_XBIN; vst->codec->width = modplug->w << 3; vst->codec->height = modplug->h << 3; modplug->linesize = modplug->w * 3; modplug->fsize = modplug->linesize * modplug->h; } return modplug_load_metadata(s); }
double MPDemux::length() const { return ModPlug_GetLength( mpfile ) / 1000.0; }
static gboolean xmms_modplug_init (xmms_xform_t *xform) { xmms_modplug_data_t *data; const gchar *metakey; gint filesize; xmms_config_property_t *cfgv; gint i; g_return_val_if_fail (xform, FALSE); data = g_new0 (xmms_modplug_data_t, 1); xmms_xform_private_data_set (xform, data); for (i = 0; i < G_N_ELEMENTS (config_params); i++) { cfgv = xmms_xform_config_lookup (xform, config_params[i].key); xmms_config_property_callback_set (cfgv, xmms_modplug_config_changed, data); xmms_modplug_config_changed (XMMS_OBJECT (cfgv), NULL, data); } /* mFrequency and mResamplingMode are set in config_changed */ data->settings.mChannels = 2; data->settings.mBits = 16; ModPlug_SetSettings (&data->settings); xmms_xform_outdata_type_add (xform, XMMS_STREAM_TYPE_MIMETYPE, "audio/pcm", XMMS_STREAM_TYPE_FMT_FORMAT, XMMS_SAMPLE_FORMAT_S16, XMMS_STREAM_TYPE_FMT_CHANNELS, 2, XMMS_STREAM_TYPE_FMT_SAMPLERATE, data->settings.mFrequency, XMMS_STREAM_TYPE_END); data->buffer = g_string_new (""); for (;;) { xmms_error_t error; gchar buf[4096]; gint ret; ret = xmms_xform_read (xform, buf, sizeof (buf), &error); if (ret == -1) { XMMS_DBG ("Error reading mod"); return FALSE; } if (ret == 0) { break; } g_string_append_len (data->buffer, buf, ret); } data->mod = ModPlug_Load (data->buffer->str, data->buffer->len); if (!data->mod) { XMMS_DBG ("Error loading mod"); return FALSE; } metakey = XMMS_MEDIALIB_ENTRY_PROPERTY_SIZE; if (xmms_xform_metadata_get_int (xform, metakey, &filesize)) { metakey = XMMS_MEDIALIB_ENTRY_PROPERTY_DURATION; xmms_xform_metadata_set_int (xform, metakey, ModPlug_GetLength (data->mod)); } metakey = XMMS_MEDIALIB_ENTRY_PROPERTY_TITLE; xmms_xform_metadata_set_str (xform, metakey, ModPlug_GetName (data->mod)); return TRUE; }
static int MODPLUG_open(Sound_Sample *sample, const char *ext) { Sound_SampleInternal *internal = (Sound_SampleInternal *) sample->opaque; ModPlugFile *module; Uint8 *data; size_t size; Uint32 retval; int has_extension = 0; int i; /* * Apparently ModPlug's loaders are too forgiving. They gladly accept * streams that they shouldn't. For now, rely on file extension instead. */ for (i = 0; extensions_modplug[i] != NULL; i++) { if (__Sound_strcasecmp(ext, extensions_modplug[i]) == 0) { has_extension = 1; break; } /* if */ } /* for */ if (!has_extension) { SNDDBG(("MODPLUG: Unrecognized file type: %s\n", ext)); BAIL_MACRO("MODPLUG: Not a module file.", 0); } /* if */ /* * ModPlug needs the entire stream in one big chunk. I don't like it, * but I don't think there's any way around it. */ data = (Uint8 *) malloc(CHUNK_SIZE); BAIL_IF_MACRO(data == NULL, ERR_OUT_OF_MEMORY, 0); size = 0; do { retval = SDL_RWread(internal->rw, &data[size], 1, CHUNK_SIZE); size += retval; if (retval == CHUNK_SIZE) { data = (Uint8 *) realloc(data, size + CHUNK_SIZE); BAIL_IF_MACRO(data == NULL, ERR_OUT_OF_MEMORY, 0); } /* if */ } while (retval > 0); /* * It's only safe to change these settings when there're * no other mods being decoded... */ if (modplug_mutex != NULL) SDL_LockMutex(modplug_mutex); if (total_mods_decoding > 0) { /* other mods decoding: use the same settings they are. */ memcpy(&sample->actual, ¤t_audioinfo, sizeof (Sound_AudioInfo)); } /* if */ else { /* no other mods decoding: define the new ModPlug output settings. */ memcpy(&sample->actual, &sample->desired, sizeof (Sound_AudioInfo)); if (sample->actual.rate == 0) sample->actual.rate = 44100; if (sample->actual.channels == 0) sample->actual.channels = 2; if (sample->actual.format == 0) sample->actual.format = AUDIO_S16SYS; memcpy(¤t_audioinfo, &sample->actual, sizeof (Sound_AudioInfo)); settings.mChannels=sample->actual.channels; settings.mFrequency=sample->actual.rate; settings.mBits = sample->actual.format & 0xFF; ModPlug_SetSettings(&settings); } /* else */ /* * The buffer may be a bit too large, but that doesn't matter. I think * it's safe to free it as soon as ModPlug_Load() is finished anyway. */ module = ModPlug_Load((void *) data, size); free(data); if (module == NULL) { if (modplug_mutex != NULL) SDL_UnlockMutex(modplug_mutex); BAIL_MACRO("MODPLUG: Not a module file.", 0); } /* if */ total_mods_decoding++; if (modplug_mutex != NULL) SDL_UnlockMutex(modplug_mutex); SNDDBG(("MODPLUG: [%d ms] %s\n", ModPlug_GetLength(module), ModPlug_GetName(module))); internal->decoder_private = (void *) module; sample->flags = SOUND_SAMPLEFLAG_CANSEEK; SNDDBG(("MODPLUG: Accepting data stream\n")); return(1); /* we'll handle this data. */ } /* MODPLUG_open */