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; }
virtual bool SetOrder(ALuint order) { std::vector<char> data(16384); ALuint total = 0; while(1) { fstream->read(&data[total], data.size()-total); if(fstream->gcount() == 0) break; total += fstream->gcount(); data.resize(total*2); } data.resize(total); ModPlugFile *newMod = ModPlug_Load(&data[0], data.size()); if(!newMod) { SetError("Could not reload data"); return false; } ModPlug_Unload(modFile); modFile = newMod; // There seems to be no way to tell if the seek succeeds ModPlug_SeekOrder(modFile, order); lastOrder = order; return true; }
modStream(std::istream *_fstream) : alureStream(_fstream), modFile(NULL), lastOrder(0) { std::vector<char> data(1024); ALuint total = 0; fstream->read(&data[total], data.size()-total); total += fstream->gcount(); if(total < 32) return; if(memcmp(&data[0], "Extended Module: ", 17) == 0 || /* XM */ (data[28] == 0x1A && data[29] == 0x10) || /* S3M */ memcmp(&data[0], "IMPM", 4) == 0) /* IT */ { while(1) { data.resize(total*2); fstream->read(&data[total], data.size()-total); if(fstream->gcount() == 0) break; total += fstream->gcount(); } data.resize(total); modFile = ModPlug_Load(&data[0], data.size()); } }
static qboolean S_MODPLUG_CodecOpenStream (snd_stream_t *stream) { /* need to load the whole file into memory and pass it to libmodplug */ byte *moddata; long len; int mark; len = FS_filelength (&stream->fh); mark = Hunk_LowMark(); moddata = (byte *) Hunk_Alloc(len); FS_fread(moddata, 1, len, &stream->fh); S_MODPLUG_SetSettings(stream); stream->priv = ModPlug_Load(moddata, len); Hunk_FreeToLowMark(mark); /* free original file data */ if (!stream->priv) { Con_DPrintf("Could not load module %s\n", stream->name); return false; } ModPlug_Seek((ModPlugFile*)stream->priv, 0); #if 0 /* default volume (128) sounds rather low? */ ModPlug_SetMasterVolume((ModPlugFile*)stream->priv, 384); /* 0-512 */ #endif return true; }
ModPlugFile* load_mod_plug(struct sppb_byte_input *input) { ModPlugFile *self_; if (!input->get_length || !input->seek) return NULL; ssize_t len = input->get_length(input); if (len < 0) return NULL; void *data = malloc(len); if (!data) return NULL; if (input->read(input, data, len) != len) { MPSP_EPRINTF("failed to read from input\n"); free(data); return NULL; } self_ = ModPlug_Load(data, len); if (self_) { // The default volume of 127 is lower than the GMES // volume, so set to maximum. ModPlug_SetMasterVolume(self_, 512); } else { MPSP_EPRINTF("failed to load file\n"); } free(data); return self_; }
int main(void) { char test[512] = "X: 1\nU: "; unsigned int i; i = strlen(test); while (i < 278) test[i++] = 'Q'; test[i++] = '1' + 32; test[i++] = '3'; test[i++] = '3'; test[i++] = '4'; while (i < 286) test[i++] = 'A'; test[i++] = '\n'; test[i] = '\0'; strcat(test, "T: Here Without You (Transcribed by: Bungee)\n"); strcat(test, "Z: 3 Doors Down\n"); strcat(test, "L: 1/4\n"); strcat(test, "Q: 108\n"); strcat(test, "K: C\n\n"); strcat(test, "[A,3A3/4] [E9/8z3/8] A3/8 [c9/8z3/8] [A9/8z3/8] [E3/4z3/8]\n"); i = strlen(test); ModPlug_Load(test, i); return 0; }
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; }
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; }
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); }
int main(int argc, char** argv) { struct dirent *dp; struct dirent **dps; const char *dir_path="/assets/sounds/"; DIR *dir = opendir(dir_path); if (dir) { while ((dp=readdir(dir)) != NULL) { char *tmp; tmp = path_cat(dir_path, dp->d_name); if (strcmp(".", dp->d_name) == 0 || strcmp("..", dp->d_name) == 0) { } else { FILE *fd = fopen(tmp, "rb"); fseek(fd, 0, SEEK_END); unsigned int len = ftell(fd); rewind(fd); void *buffer = (void *)malloc(sizeof(char) * len); fseek(fd, 0, SEEK_SET); size_t r = fread(buffer, 1, len, fd); if (r > 0) { m_Sounds.push_back(ModPlug_Load(buffer, len)); } free(buffer); } free(tmp); tmp=NULL; } closedir(dir); } // Set 16-bit stereo audio at 44.1Khz SDL_AudioSpec fmt; fmt.freq = 44100; fmt.format = AUDIO_S16; fmt.channels = 2; fmt.samples = (int)((1.0 / 35.0) * ((float)fmt.freq / (float)sizeof(short))); printf("%d\n", fmt.samples); fmt.callback = mixaudio; fmt.userdata = NULL; // Open the audio device and start playing sound! if (SDL_OpenAudio(&fmt, NULL) < 0) { printf("No audio: %s\n", SDL_GetError()); } else { SDL_PauseAudio(0); } throw 0; //crashes the main loop and allows the callbacks to proceed, kinda ugly return 0; }
/** * Read the contents of the first file of the ZIP file and load * it into a ModPlugFile. **/ static ModPlugFile* loadZipFile(const char *path) { ModPlugFile *self_ = NULL; int err = 0; struct zip *zf = zip_open(path, 0, &err); if (!zf) return NULL; struct zip_stat sb; // FIXME: Assumes the first file is the mod-file if (zip_stat_index(zf, 0, 0, &sb)) { MPSP_EPRINTF("failed to stat ZIP member: %s\n", zip_strerror(zf)); goto exit1; } // FIXME: Assumes the first file is the mod-file struct zip_file *file = zip_fopen_index(zf, 0, 0); if (!file) { MPSP_EPRINTF("failed to open ZIP member: %s\n", zip_strerror(zf)); goto exit1; } void *data = malloc(sb.size); if (!data) { MPSP_EPRINTF("failed to allocate memory: %s\n", strerror(errno)); goto exit2; } if (zip_fread(file, data, sb.size) != sb.size) { MPSP_EPRINTF("failed to read ZIP member: %s\n", zip_file_strerror(file)); goto exit3; } self_ = ModPlug_Load(data, sb.size); exit3: free(data); exit2: (void) zip_fclose(file); exit1: (void) zip_close(zf); return self_; }
void open( service_ptr_t<file> m_file, const char * p_path, t_input_open_reason p_reason, abort_callback & p_abort ) { if ( p_reason == input_open_info_write ) throw exception_io_data(); input_open_file_helper( m_file, p_path, p_reason, p_abort ); m_stats = m_file->get_stats( p_abort ); t_uint8 * ptr; unsigned size; t_filesize size64 = m_file->get_size_ex( p_abort ); if ( size64 > ( 1 << 24 ) ) throw exception_io_data(); size = (unsigned) size64; file_buffer.set_size( size ); ptr = file_buffer.get_ptr(); m_file->read_object( ptr, size, p_abort ); m_player = ModPlug_Load(ptr, size); if ( !m_player ) throw exception_io_data(); }
//! \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; }
/* Load a modplug stream from an SDL_RWops object */ modplug_data *modplug_new_RW(SDL_RWops *rw, int freerw) { modplug_data *music=NULL; long offset,sz; char *buf=NULL; offset = SDL_RWtell(rw); SDL_RWseek(rw, 0, RW_SEEK_END); sz = SDL_RWtell(rw)-offset; SDL_RWseek(rw, offset, RW_SEEK_SET); buf=(char*)SDL_malloc(sz); if(buf) { if(SDL_RWread(rw, buf, sz, 1)==1) { music=(modplug_data*)SDL_malloc(sizeof(modplug_data)); if (music) { music->playing=0; music->file=ModPlug_Load(buf,sz); if(!music->file) { SDL_free(music); music=NULL; } } else { SDL_OutOfMemory(); } } SDL_free(buf); } else { SDL_OutOfMemory(); } if (freerw) { SDL_RWclose(rw); } return music; }
/* * Class: com_peculiargames_andmodplug_PlayerThread * Method: ModPlug_JLoad * Signature: ([BI)Z */ JNIEXPORT jboolean JNICALL Java_com_peculiargames_andmodplug_PlayerThread_ModPlug_1JLoad (JNIEnv *env, jobject obj, jbyteArray buffer, jint size) { int csize = (int) size; /* * Set the current sample as already beyond end of buffer (so a reload * happens immediately). */ currsample = SAMPLEBUFFERSIZE+1; /* * Convert from Java buffer into a C buffer. */ jbyte* bytes = env->GetByteArrayElements(buffer, 0); currmodFile = ModPlug_Load(bytes, csize); env->ReleaseByteArrayElements(buffer, bytes, 0); env->DeleteLocalRef(buffer); DIABpatternchanged = 0; ANDMODPLUGpatternfrom = 0; ANDMODPLUGpatternto = 0; ANDMODPLUGpendingfrom = 0; ANDMODPLUGpendingto = 0; ANDMODPLUGpatternrangeset = 0; ANDMODPLUGnextpattern = -1; ANDMODPLUGnextpatternmode = 0; ANDMODPLUGjumpeffect = -1; if (currmodFile != NULL) { return JNI_TRUE; } else { return JNI_FALSE; } }
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; }
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; }
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; }
/** * Play music from the specified file. * * @param fileName Name of a file containing music data. */ void playMusic (const char * fileName) { #ifdef USE_MODPLUG File *file; ModPlug_Settings settings; unsigned char *psmData; int size; // Stop any existing music playing stopMusic(); // Load the music file try { file = new File(fileName, false); } catch (int e) { return; } // Find the size of the file size = file->getSize(); // Read the entire file into memory file->seek(0, true); psmData = file->loadBlock(size); delete file; // Set up libmodplug settings.mFlags = MUSIC_FLAGS; settings.mChannels = audioSpec.channels; if ((audioSpec.format == AUDIO_U8) || (audioSpec.format == AUDIO_S8)) settings.mBits = 8; else settings.mBits = 16; settings.mFrequency = audioSpec.freq; settings.mResamplingMode = MUSIC_RESAMPLEMODE; settings.mReverbDepth = 25; settings.mReverbDelay = 40; settings.mBassAmount = 50; settings.mBassRange = 10; settings.mSurroundDepth = 50; settings.mSurroundDelay = 40; settings.mLoopCount = -1; ModPlug_SetSettings(&settings); // Load the file into libmodplug musicFile = ModPlug_Load(psmData, size); delete[] psmData; if (!musicFile) { logError("Could not play music file", fileName); return; } // Start the audio playing SDL_PauseAudio(0); #endif return; }
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); }
/** * @brief Loads an IT file from memory. * @param sound_data the memory area to read * @param sound_size size of the memory area in bytes */ void ItDecoder::load(void* sound_data, size_t sound_size) { // load the IT data into the IT library modplug_file = ModPlug_Load((const void*) sound_data, int(sound_size)); }
/***************************************************************************** * 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; }
int main (int argc, char *argv[]) { void *mod_data; FILE *mod_fd; size_t mod_size; mod_fd = fopen("GLOS-pope.xm","r"); fseek(mod_fd, 0, SEEK_END); mod_size = ftell(mod_fd); fseek(mod_fd, 0, SEEK_SET); mod_data = malloc(mod_size); fread(mod_data, 1, mod_size, mod_fd); fclose(mod_fd); ModPlug_Settings cfg; ModPlug_GetSettings(&cfg); cfg.mChannels = 2; cfg.mBits = 16; cfg.mFrequency = 48000; cfg.mResamplingMode = MODPLUG_RESAMPLE_SPLINE; cfg.mFlags = MODPLUG_ENABLE_OVERSAMPLING; ModPlug_SetSettings(&cfg); module = ModPlug_Load(mod_data, mod_size); srandom(0); memset(¶ms, 0, sizeof params); params.rate = 48000; params.on_speed = 2.0/100.0; params.off_speed = 2.0/30.0; params.start_wait = 8; params.start_dwell = 2; params.curve_dwell = 0; params.corner_dwell = 2; params.curve_angle = cosf(30.0*(M_PI/180.0)); // 30 deg params.end_dwell = 2; params.end_wait = 1; params.snap = 1/100000.0; params.flatness = 0.000005; params.max_framelen = params.rate / 24; params.render_flags = RENDER_GRAYSCALE; if(olInit(10, 30000) < 0) return 1; olSetRenderParams(¶ms); olSetAudioCallback(gen_audio); float time = 0; float ftime; int i,j; int frames = 0; memset(mbuf, 0, sizeof mbuf); font = olGetDefaultFont(); float xpos = 1.0; DoStars(96); DoTitle(111); DoMetaballs(143); DoFire(174); DoTunnel(175+32); DoCubes(175+32+64); DoEuskal(); #if 0 while(1) { int obj; float w; points_left = cur_draw; olPushColor(); //olMultColor(C_GREY((int)(255.0f * cur_draw / count))); olSetVertexShader(cutoff); olDrawIlda(ild); olSetVertexShader(NULL); olPopColor(); /* olSetVertexShader(sinescroller); w = olDrawString(font, xpos, 0.35, 0.4, C_WHITE, "Hello, World! This is a test message displayed using the OpenLase text functions. Sine scrollers FTW!"); if (xpos < (-w-1.5)) xpos = 1.0; olSetVertexShader(NULL);*/ /* olDrawString(font, -1, 0.35, 0.4, C_WHITE, "Hello, World!"); olDrawString(font, -1, -0, 0.4, C_WHITE, "How are you?"); olDrawString(font, -1, -0.35, 0.4, C_WHITE, " (-; :-)");*/ //render_cubes(time); //render_metaballs(time); //ender_fire(); /* olBegin(OL_BEZIERSTRIP); olVertex(0,1,C_WHITE); olVertex(1,1,C_WHITE); olVertex(1,1,C_WHITE); olVertex(1,0,C_WHITE); olVertex(1,-1,C_WHITE); olVertex(1,-1,C_WHITE); olVertex(0,-1,C_WHITE); olEnd();*/ ftime = olRenderFrame(150); frames++; gbl_time += ftime; xpos -= ftime; cur_draw += ftime * count / 5.0; if (cur_draw > count) cur_draw = count; printf("Frame time: %f, FPS:%f\n", ftime, frames/time); } #endif olShutdown(); exit (0); }
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 */
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); }
/** * Play music from the specified file. * * @param fileName Name of a file containing music data. */ void playMusic (const char * fileName) { File *file; unsigned char *psmData; int size; bool loadOk = false; #ifdef USE_MODPLUG ModPlug_Settings settings; #endif // Stop any existing music playing stopMusic(); // Load the music file try { file = new File(fileName, false); } catch (int e) { return; } // Find the size of the file size = file->getSize(); // Read the entire file into memory file->seek(0, true); psmData = file->loadBlock(size); delete file; #ifdef USE_MODPLUG // Set up libmodplug settings.mFlags = MUSIC_FLAGS; settings.mChannels = audioSpec.channels; if ((audioSpec.format == AUDIO_U8) || (audioSpec.format == AUDIO_S8)) settings.mBits = 8; else settings.mBits = 16; settings.mFrequency = audioSpec.freq; settings.mResamplingMode = MUSIC_RESAMPLEMODE; settings.mReverbDepth = 25; settings.mReverbDelay = 40; settings.mBassAmount = 50; settings.mBassRange = 10; settings.mSurroundDepth = 50; settings.mSurroundDelay = 40; settings.mLoopCount = -1; ModPlug_SetSettings(&settings); // Load the file into libmodplug musicFile = ModPlug_Load(psmData, size); loadOk = (musicFile != NULL); #elif defined(USE_XMP) // Load the file into libxmp loadOk = (xmp_load_module_from_memory(xmpC, psmData, size) == 0); #endif delete[] psmData; if (!loadOk) { logError("Could not play music file", fileName); return; } #ifdef USE_XMP int playerFlags = 0; if ((audioSpec.format == AUDIO_U8) || (audioSpec.format == AUDIO_S8)) playerFlags = playerFlags & XMP_FORMAT_8BIT; if ((audioSpec.format == AUDIO_U8) || (audioSpec.format == AUDIO_U16) || (audioSpec.format == AUDIO_U16MSB) || (audioSpec.format == AUDIO_U16LSB)) playerFlags = playerFlags & XMP_FORMAT_UNSIGNED; if (audioSpec.channels == 1) playerFlags = playerFlags & XMP_FORMAT_MONO; xmp_start_player(xmpC, audioSpec.freq, playerFlags); xmp_set_player(xmpC, XMP_PLAYER_INTERP, MUSIC_INTERPOLATION); # ifdef MUSIC_EFFECTS xmp_set_player(xmpC, XMP_PLAYER_DSP, MUSIC_EFFECTS); # endif #endif // Start the audio playing SDL_PauseAudio(0); return; }
bool ModPlay::loadData(const void* data, size_t size) { modFile = ModPlug_Load(data, size); return (modFile != 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; }