Example #1
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;
}
Example #2
0
int get_sampling_rate(void)
{
	ModPlug_Settings settings;

	ModPlug_GetSettings(&settings);

	return settings.mFrequency;
}
/*
 * Class:     com_peculiargames_andmodplug_PlayerThread
 * Method:    ModPlug_SetLoopCount
 * Signature: (I)V
 */
JNIEXPORT void JNICALL Java_com_peculiargames_andmodplug_PlayerThread_ModPlug_1SetLoopCount
  (JNIEnv *env, jclass cls, jint loopcount)
{
  ModPlug_Settings settings;

  ModPlug_GetSettings(&settings);
  settings.mLoopCount = loopcount;
  ModPlug_SetSettings(&settings);
}
Example #4
0
static unsigned int get_sample_rate(struct sppb_plugin_description *plugin, void *context)
{
	ModPlug_Settings settings;

	ModPlug_GetSettings(&settings);

	MPSP_DPRINTF("parser: get_sample_rate(): %d\n", settings.mFrequency);

	return settings.mFrequency;
}
Example #5
0
/**
 * @brief Creates an Impulse Tracker decoder.
 */
ItDecoder::ItDecoder():
  modplug_file(NULL) {

  ModPlug_Settings settings;
  ModPlug_GetSettings(&settings);
  settings.mChannels = 2;     // stereo
  settings.mBits = 16;        // 16 bits
  settings.mLoopCount = -1;   // loop forever
  ModPlug_SetSettings(&settings);
}
Example #6
0
void ModPlay::initPlayer() // Set up libmodplug
{
	ModPlug_Settings settings;
	ModPlug_GetSettings(&settings);
	settings.mFrequency = FREQUENCY;
	settings.mBits = BITS;
	settings.mChannels = CHANNELS;
	settings.mLoopCount = -1; // endless
	ModPlug_SetSettings(&settings);
}
Example #7
0
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;
}
Example #8
0
static void setupModPlug(void)
{
	ModPlug_Settings settings;

	ModPlug_GetSettings(&settings);

	settings.mFlags = MODPLUG_ENABLE_OVERSAMPLING | MODPLUG_ENABLE_NOISE_REDUCTION;
	settings.mBits = 16;
	settings.mResamplingMode = MODPLUG_RESAMPLE_SPLINE;
	settings.mLoopCount = 0;

	ModPlug_SetSettings(&settings);
}
Example #9
0
static enum sppb_channel_format get_channel_format(struct sppb_plugin_description *plugin, void *context)
{
	ModPlug_Settings settings;

	ModPlug_GetSettings(&settings);

	MPSP_DPRINTF("parser: get_channel_format(): %d\n", settings.mChannels);

	switch (settings.mChannels) {
	case 1: return SPPB_CHANNEL_FORMAT_MONO;
	case 2: return SPPB_CHANNEL_FORMAT_STEREO;
	default: return SPPB_CHANNEL_FORMAT_INVALID;
	}
}
Example #10
0
bool MPDemux::set()
{
	bool restartPlaying = false;

	ModPlug_Settings settings;
	ModPlug_GetSettings( &settings );
	if ( settings.mResamplingMode != sets().getInt( "ModplugResamplingMethod" ) )
	{
		settings.mResamplingMode = sets().getInt( "ModplugResamplingMethod" );
		restartPlaying = true;
	}
	settings.mFlags = MODPLUG_ENABLE_OVERSAMPLING;
	settings.mChannels = 2;
	settings.mBits = 32;
	settings.mFrequency = 44100;
	ModPlug_SetSettings( &settings );

	return !restartPlaying && sets().getBool( "ModplugEnabled" );
}
Example #11
0
static void S_MODPLUG_SetSettings (snd_stream_t *stream)
{
	ModPlug_Settings settings;

	ModPlug_GetSettings(&settings);
	settings.mFlags = MODPLUG_ENABLE_OVERSAMPLING;
	settings.mChannels = shm->channels;
	settings.mBits = shm->samplebits;
	settings.mFrequency = shm->speed;
	settings.mResamplingMode = MODPLUG_RESAMPLE_SPLINE;/*MODPLUG_RESAMPLE_FIR*/
	settings.mLoopCount = 0;
	ModPlug_SetSettings(&settings);

	if (stream) {
		stream->info.rate = shm->speed;
		stream->info.bits = shm->samplebits;
		stream->info.width = stream->info.bits / 8;
		stream->info.channels = shm->channels;
	}
}
Example #12
0
	void decode_initialize( unsigned p_flags, abort_callback & p_abort )
	{
		ModPlug_Settings settings;
		ModPlug_GetSettings(&settings);
		settings.mFrequency = 44100;
		settings.mBits = 32;
		unsigned interpolation_method = cfg_interpolation_none ? 0 : cfg_interpolation_cubic ? 2 : cfg_interpolation_sinc ? 3 : cfg_interpolation_linear ? 1 : 0;
		settings.mResamplingMode = interpolation_method;
		settings.mChannels = 2;
		bool dont_loop = !cfg_loop || !! ( p_flags & input_flag_no_looping );
		if ( dont_loop) 
		{
			settings.mLoopCount = 0;
			loop = false;
		}
		else
		{
			settings.mLoopCount = -1; // endless
			loop = true;
		}
		ModPlug_SetSettings(&settings);
		first_block = true;
		is_playing = 1;
	}
Example #13
0
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;
}
Example #14
0
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,"playing %s (%%d.%%d/%d\") (%%d/%%d/%%d)    \b\b\b\b",songname,ModPlug_GetLength(f2)/1000);
    if (loop) sprintf(status,"looping %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;
}
int modplug_init(SDL_AudioSpec *spec)
{
	ModPlug_GetSettings(&settings);
	settings.mFlags=MODPLUG_ENABLE_OVERSAMPLING;
	current_output_channels=spec->channels;
	settings.mChannels=spec->channels>1?2:1;
	settings.mBits=spec->format&0xFF;

	music_swap8 = 0;
	music_swap16 = 0;

	switch(spec->format)
	{
		case AUDIO_U8:
		case AUDIO_S8: {
			if ( spec->format == AUDIO_S8 ) {
				music_swap8 = 1;
			}
			settings.mBits=8;
		}
		break;

		case AUDIO_S16LSB:
		case AUDIO_S16MSB: {
			/* See if we need to correct MikMod mixing */
#if SDL_BYTEORDER == SDL_LIL_ENDIAN
			if ( spec->format == AUDIO_S16MSB ) {
#else
			if ( spec->format == AUDIO_S16LSB ) {
#endif
				music_swap16 = 1;
			}
			settings.mBits=16;
		}
		break;

		default: {
			Mix_SetError("Unknown hardware audio format");
			return -1;
		}

	}

	settings.mFrequency=spec->freq; /*TODO: limit to 11025, 22050, or 44100 ? */
	settings.mResamplingMode=MODPLUG_RESAMPLE_FIR;
	settings.mReverbDepth=0;
	settings.mReverbDelay=100;
	settings.mBassAmount=0;
	settings.mBassRange=50;
	settings.mSurroundDepth=0;
	settings.mSurroundDelay=10;
	settings.mLoopCount=0;
	ModPlug_SetSettings(&settings);
	return 0;
}

/* Uninitialize the music players */
void modplug_exit()
{
}

/* Set the volume for a modplug stream */
void modplug_setvolume(modplug_data *music, int volume)
{
	ModPlug_SetMasterVolume(music->file, volume*4);
}
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);
}
Example #17
0
File: mod.c Project: mstorsjo/vlc
/*****************************************************************************
 * 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;
}
Example #18
0
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);
}
Example #19
0
void sfMod::InitSettings()
{
  ModPlug_GetSettings(&sfMod::defaultSettings);

  sfMod::settings = sfMod::defaultSettings;
}
Example #20
0
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(&params, 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(&params);

	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);
}