aboutsummaryrefslogtreecommitdiff
path: root/src/psp/audio.c
blob: 7b4242f728af9a8c88ccbc5417e82e63548b832a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#include "audio.h"
#include "../game.h"

void PHL_AudioInit()
{
	oslInitAudio();
}

void PHL_AudioClose()
{
	oslDeinitAudio();
}

//Each system can use a custom music file format
OSL_SOUND* PHL_LoadMusic(char* fname, int loop)
{
	char stream = 0;
	
	OSL_SOUND* result = NULL;

	char fullPath[40];
	strcpy(fullPath, fname);
	strcat(fullPath, ".bgm");
	
	FILE* file;
	
	if ( (file = fopen(fullPath, "r")) ) {
		fclose(file);
		result = oslLoadSoundFile(fullPath, stream);
		oslSetSoundLoop(result, loop);
	}

	return result;
}

OSL_SOUND* PHL_LoadSound(char* fname)
{	
	char stream = 0;
	
	OSL_SOUND* result = NULL;

	char fullPath[40];
	strcpy(fullPath, fname);
	
	FILE* file;
	
	if ( (file = fopen(fullPath, "r")) ) {
		fclose(file);
		result = oslLoadSoundFile(fullPath, stream);
		oslSetSoundLoop(result, 0);
	}

	return result;
}


void PHL_PlayMusic(OSL_SOUND* snd)
{
	//Music always plays on the first channel
	PHL_PlaySound(snd, 0);
}

void PHL_PlaySound(OSL_SOUND* snd, int channel)
{	
	if (snd) {
		oslPlaySound(snd, channel);
	}
}

void PHL_StopMusic()
{
	PHL_StopSound(bgmMusic, 0);
}

void PHL_StopSound(OSL_SOUND* snd, int channel)
{
	if (snd) {
		oslStopSound(snd);
	}
}

void PHL_FreeSound(OSL_SOUND* snd)
{
	if (snd) {
		oslDeleteSound(snd);
	}
}