Example #1
0
//===========================================================================
// DM_FModExtPlayBuffer
//===========================================================================
int DM_FModExtPlayBuffer(int looped)
{
	if(!ext_inited)
		return false;
	DM_FModExtReset();

	// Try playing as a module first.
	if((module =
		FMUSIC_LoadSongEx(song, 0, song_size, FSOUND_LOADMEMORY, NULL, 0)))
	{
		FMUSIC_SetLooping(module, looped);
	}
	else
	{
		// Try as a stream.
		stream =
			FSOUND_Stream_Open(song,
							   FSOUND_LOADMEMORY | (looped ? FSOUND_LOOP_NORMAL
													: 0), 0, song_size);
		if(!stream)
			return false;
	}
	DM_FModExtStartPlaying();
	//ext_looped_play = looped;
	return true;
}
Example #2
0
//===========================================================================
// DM_FModExtPlayFile
//===========================================================================
int DM_FModExtPlayFile(const char *path, int looped)
{
	if(!ext_inited)
		return false;
	DM_FModExtReset();

	// Try playing as a module first.
	if((module = FMUSIC_LoadSong(path)))
	{
		FMUSIC_SetLooping(module, looped);
	}
	else
	{
		// Try as a stream.
		stream =
			FSOUND_Stream_Open(path, looped ? FSOUND_LOOP_NORMAL : 0, 0, 0);
		if(!stream)
			return false;		// Failed...!
	}
	DM_FModExtStartPlaying();
	//ext_looped_play = looped;
	return true;
}
Example #3
0
glui32 glk_schannel_play_ext(schanid_t chan, glui32 snd, glui32 repeats, glui32 notify)
{
    FILE *file;
    long pos, len;
    glui32 type;
    char *buf;
    int offset = 0;
    int i;

    if (!chan) {
	gli_strict_warning("schannel_play_ext: invalid id.");
	return 0;
    }

    /* stop previous noise */
    glk_schannel_stop(chan);

    if (repeats == 0)
	return 1;

    /* load sound resource into memory */

    if (!giblorb_is_resource_map())
    {
	char name[1024];

	sprintf(name, "%s/SND%ld", gli_workdir, snd); 

	file = fopen(name, "rb");
	if (!file)
	    return 0;

	fseek(file, 0, SEEK_END);
	len = ftell(file);

	buf = malloc(len);
	if (!buf) {
	    fclose(file);
	    return 0;
	}

	fseek(file, 0, 0);
	fread(buf, 1, len, file);
	fclose(file);

	/* identify by file magic the two types that fmod can do... */

	type = 0;	/* unidentified */

	/* AIFF */
	if (len > 4 && !memcmp(buf, "FORM", 4))		
	    type = giblorb_ID_FORM;

	/* WAVE */
	if (len > 4 && !memcmp(buf, "WAVE", 4))
	    type = giblorb_ID_WAVE;

	/* MIDI */
	if (len > 4 && !memcmp(buf, "MThd", 4))
	    type = giblorb_ID_MIDI;

	/* Ogg Vorbis */
	if (len > 4 && !memcmp(buf, "OggS", 4))
	    type = giblorb_ID_OGG;

	/* s3m */
	if (len > 0x30 && !memcmp(buf + 0x2c, "SCRM", 4))
	    type = giblorb_ID_MOD;

	/* XM */
	if (len > 20 && !memcmp(buf, "Extended Module: ", 17))
	    type = giblorb_ID_MOD;

	/* MOD */
	if (len > 1084)
	{
	    char resname[4];
	    memcpy(resname, buf + 1080, 4);
	    if (!strcmp(resname+1, "CHN") ||	/* 4CHN, 6CHN, 8CHN */
		    !strcmp(resname+2, "CN") ||	 /* 16CN, 32CN */
		    !strcmp(resname, "M.K.") || !strcmp(resname, "M!K!") ||
		    !strcmp(resname, "FLT4") || !strcmp(resname, "CD81") ||
		    !strcmp(resname, "OKTA") || !strcmp(resname, "    "))
		type = giblorb_ID_MOD;
	}

	if (!memcmp(buf, "\377\372", 2))	/* mp3 */
	    type = giblorb_ID_MP3;

	/* look for RIFF (future boy has broken resources...?) */
	if (len > 128 && type == 0)
	    for (i = 0; i < 124; i++)
		if (!memcmp(buf+i, "RIFF", 4))
		{
		    offset = i;
		    type = giblorb_ID_WAVE;
		    break;
		}

	if (type == 0)
	    type = giblorb_ID_MP3;
    }

    else
    {
	giblorb_get_resource(giblorb_ID_Snd, snd, &file, &pos, &len, &type);
	if (!file)
	    return 0;

	buf = malloc(len);
	if (!buf)
	    return 0;

	fseek(file, pos, 0);
	fread(buf, 1, len, file);
    }

    switch (type)
    {
    case giblorb_ID_FORM:
    case giblorb_ID_WAVE:
    case giblorb_ID_MP3:
	chan->sample = FSOUND_Sample_Load(FSOUND_UNMANAGED, buf + offset,
		FSOUND_NORMAL|FSOUND_LOADMEMORY, 0, len);
	if (!chan->sample) { free(buf); return 0; }
	if (repeats != 1)
	    FSOUND_Sample_SetMode(chan->sample, FSOUND_LOOP_NORMAL);
	else
	    FSOUND_Sample_SetMode(chan->sample, FSOUND_LOOP_OFF);
	chan->channel = FSOUND_PlaySound(FSOUND_FREE, chan->sample);
	FSOUND_SetVolume(chan->channel, chan->volume / 256);
	FSOUND_SetPaused(chan->channel, 0);
	break;

    case giblorb_ID_MOD:
    case giblorb_ID_MIDI:
	chan->module = FMUSIC_LoadSongEx(buf, 0, len, FSOUND_LOADMEMORY, 0, 0);
	if (!chan->module) { free(buf); return 0; }
	if (repeats != 1)
	    FMUSIC_SetLooping(chan->module, 1);
	else
	    FMUSIC_SetLooping(chan->module, 0);
	FMUSIC_SetMasterVolume(chan->module, chan->volume / 256);
	FMUSIC_PlaySong(chan->module);
	break;

    default:
	gli_strict_warning("schannel_play_ext: unknown resource type.");
    }

    free(buf);

    return 1;
}
Example #4
0
static inline VOID M_StartFMODSong(LPVOID data, int len, int looping, HWND hDlg)
{
	const int loops = FSOUND_LOOP_NORMAL|FSOUND_LOADMEMORY;
	const int nloop = FSOUND_LOADMEMORY;
	M_FreeMusic();

	if (looping)
		mod = FMUSIC_LoadSongEx(data, 0, len, loops, NULL, 0);
	else
		mod = FMUSIC_LoadSongEx(data, 0, len, nloop, NULL, 0);

	if (mod)
	{
		FMUSIC_SetLooping(mod, (signed char)looping);
		FMUSIC_SetPanSeperation(mod, 0.0f);
	}
	else
	{
		if (looping)
			fmus = FSOUND_Stream_Open(data, loops, 0, len);
		else
			fmus = FSOUND_Stream_Open(data, nloop, 0, len);
	}

	if (!fmus && !mod)
	{
		MessageBoxA(hDlg, FMOD_ErrorString(FSOUND_GetError()), "Error", MB_OK|MB_APPLMODAL);
		return;
	}

	// Scan the OGG for the COMMENT= field for a custom loop point
	if (looping && fmus)
	{
		const BYTE *origpos, *dataum = data;
		size_t scan, size = len;

		CHAR buffer[512];
		BOOL titlefound = FALSE, artistfound = FALSE;

		unsigned int loopstart = 0;

		origpos = dataum;

		for(scan = 0; scan < size; scan++)
		{
			if (!titlefound)
			{
				if (*dataum++ == 'T')
				if (*dataum++ == 'I')
				if (*dataum++ == 'T')
				if (*dataum++ == 'L')
				if (*dataum++ == 'E')
				if (*dataum++ == '=')
				{
					size_t titlecount = 0;
					CHAR title[256];
					BYTE length = *(dataum-10) - 6;

					while(titlecount < length)
						title[titlecount++] = *dataum++;

					title[titlecount] = '\0';

					sprintf(buffer, "Title: %s", title);

					SendMessage(GetDlgItem(hDlg, IDC_TITLE), WM_SETTEXT, 0, (LPARAM)(LPCSTR)buffer);

					titlefound = TRUE;
				}
			}
		}

		dataum = origpos;

		for(scan = 0; scan < size; scan++)
		{
			if (!artistfound)
			{
				if (*dataum++ == 'A')
				if (*dataum++ == 'R')
				if (*dataum++ == 'T')
				if (*dataum++ == 'I')
				if (*dataum++ == 'S')
				if (*dataum++ == 'T')
				if (*dataum++ == '=')
				{
					size_t artistcount = 0;
					CHAR artist[256];
					BYTE length = *(dataum-11) - 7;

					while(artistcount < length)
						artist[artistcount++] = *dataum++;

					artist[artistcount] = '\0';

					sprintf(buffer, "By: %s", artist);

					SendMessage(GetDlgItem(hDlg, IDC_ARTIST), WM_SETTEXT, 0, (LPARAM)(LPCSTR)buffer);

					artistfound = TRUE;
				}
			}
		}

		dataum = origpos;

		for(scan = 0; scan < size; scan++)
		{
			if (*dataum++ == 'C'){
			if (*dataum++ == 'O'){
			if (*dataum++ == 'M'){
			if (*dataum++ == 'M'){
			if (*dataum++ == 'E'){
			if (*dataum++ == 'N'){
			if (*dataum++ == 'T'){
			if (*dataum++ == '='){
			if (*dataum++ == 'L'){
			if (*dataum++ == 'O'){
			if (*dataum++ == 'O'){
			if (*dataum++ == 'P'){
			if (*dataum++ == 'P'){
			if (*dataum++ == 'O'){
			if (*dataum++ == 'I'){
			if (*dataum++ == 'N'){
			if (*dataum++ == 'T'){
			if (*dataum++ == '=')
			{
				size_t newcount = 0;
				CHAR looplength[64];
				while (*dataum != 1 && newcount < 63)
				{
					looplength[newcount++] = *dataum++;
				}

				looplength[newcount] = '\n';

				loopstart = atoi(looplength);
			}
			else
				dataum--;}
			else
				dataum--;}
			else
				dataum--;}
			else
				dataum--;}
			else
				dataum--;}
			else
				dataum--;}
			else
				dataum--;}
			else
				dataum--;}
			else
				dataum--;}
			else
				dataum--;}
			else
				dataum--;}
			else
				dataum--;}
			else
				dataum--;}
			else
				dataum--;}
			else
				dataum--;}
			else
				dataum--;}
			else
				dataum--;}
		}

		if (loopstart > 0)
		{
			const int length = FSOUND_Stream_GetLengthMs(fmus);
			const int freq = 44100;
			const unsigned int loopend = (unsigned int)((freq/1000.0f)*length-(freq/1000.0f));
			if (!FSOUND_Stream_SetLoopPoints(fmus, loopstart, loopend))
			{
				printf("FMOD(Start,FSOUND_Stream_SetLoopPoints): %s\n",
					FMOD_ErrorString(FSOUND_GetError()));
			}
		}
	}

	if (mod)
		FMUSIC_PlaySong(mod);
	if (fmus)
		fsoundchannel = FSOUND_Stream_PlayEx(FSOUND_FREE, fmus, NULL, FALSE);

	M_SetVolume(128);
}
Example #5
0
void playMusic(FMUSIC_MODULE *handle, bool loop)
{
	FMUSIC_PlaySong(handle);
	FMUSIC_SetMasterVolume(handle, DEF_VOLUME);
	FMUSIC_SetLooping(handle, loop);
}