sdk-world
v2026.11.05
PS2 SDK - world tier (copyleft-allowed, non-essential packages)
Toggle main menu visibility
Loading...
Searching...
No Matches
main.c
1
#include <kernel.h>
2
#include <loadfile.h>
3
#include <sbv_patches.h>
4
#include <sifrpc.h>
5
#include <stdio.h>
6
#include <stdlib.h>
7
#include <unistd.h>
8
9
#include "
audio.h
"
10
#include "libsd_irx.h"
11
#include "audio_irx.h"
12
13
static
void
*read_file(
const
char
*path,
int
*size_out)
14
{
15
FILE *file = fopen(path,
"rb"
);
16
long
length;
17
void
*data;
18
19
if
(!file)
20
return
NULL;
21
fseek(file, 0, SEEK_END);
22
length = ftell(file);
23
fseek(file, 0, SEEK_SET);
24
data = malloc((
size_t
)length);
25
if
(data && fread(data, 1, (
size_t
)length, file) != (
size_t
)length) {
26
free(data);
27
data = NULL;
28
}
29
fclose(file);
30
*size_out = (int)length;
31
return
data;
32
}
33
34
int
main(
int
argc,
char
**argv)
35
{
36
const
char
*path = argc > 1 ? argv[1] :
"host:sound.adp"
;
37
audio_sound_t
sound;
38
void
*file_data;
39
int
file_size = 0;
40
int
channel;
41
int
rc;
42
43
SifInitRpc(0);
44
sbv_patch_enable_lmb();
45
SifExecModuleBuffer(libsd_irx, size_libsd_irx, 0, NULL, NULL);
46
SifExecModuleBuffer(audio_irx, size_audio_irx, 0, NULL, NULL);
47
48
rc =
audio_init
();
49
if
(rc !=
AUDIO_OK
) {
50
printf(
"audio_init: %s\n"
,
audio_get_error_message
(rc));
51
SleepThread();
52
}
53
54
file_data = read_file(path, &file_size);
55
if
(!file_data) {
56
printf(
"cannot read %s\n"
, path);
57
SleepThread();
58
}
59
60
rc =
audio_sound_load_apcm
(file_data, file_size, &sound);
61
free(file_data);
62
if
(rc !=
AUDIO_OK
) {
63
printf(
"load: %s\n"
,
audio_get_error_message
(rc));
64
SleepThread();
65
}
66
67
channel =
audio_play_sound
(sound);
68
if
(channel < 0) {
69
printf(
"play: %s\n"
,
audio_get_error_message
(-channel));
70
SleepThread();
71
}
72
printf(
"playing on channel %d\n"
, channel);
73
74
audio_channel_set_volume_and_pan
(channel, 80, -50);
75
while
(
audio_channel_is_playing
(channel) == 1)
76
usleep(10000);
77
78
audio_sound_free
(sound);
79
audio_shutdown
();
80
printf(
"done\n"
);
81
SleepThread();
82
return
0;
83
}
audio.h
audio_sound_t
int32_t audio_sound_t
Definition
audio.h:72
audio_channel_is_playing
int audio_channel_is_playing(int channel)
audio_play_sound
int audio_play_sound(audio_sound_t sound)
audio_channel_set_volume_and_pan
int audio_channel_set_volume_and_pan(int channel, int volume_percent, int pan)
AUDIO_OK
#define AUDIO_OK
Definition
audio.h:33
audio_get_error_message
const char * audio_get_error_message(int error_code)
audio_shutdown
int audio_shutdown(void)
audio_init
int audio_init(void)
audio_sound_free
int audio_sound_free(audio_sound_t sound)
audio_sound_load_apcm
int audio_sound_load_apcm(const void *file_data, int32_t file_size_bytes, audio_sound_t *sound_out)
audio
examples
sound
main.c
Generated by
1.18.0