Add CDDA playback example
This commit is contained in:
parent
efa03ac844
commit
2920c94841
6
hello_cdda/Makefile
Normal file
6
hello_cdda/Makefile
Normal file
@ -0,0 +1,6 @@
|
||||
TARGET = hello_cdda
|
||||
|
||||
SRCS = hello_cdda.c \
|
||||
|
||||
include ../common.mk
|
||||
include ../thirdparty/nugget/common.mk \
|
35
hello_cdda/README.md
Normal file
35
hello_cdda/README.md
Normal file
@ -0,0 +1,35 @@
|
||||
## Creating the disk image
|
||||
|
||||
You need [mkpsxiso](https://github.com/Lameguy64/mkpsxiso) in your $PATH and type in a command line :
|
||||
|
||||
```bash
|
||||
mkpsxiso -y isoconfig.xml
|
||||
```
|
||||
|
||||
## Using ffmpeg to generate a CDDA compliant Wav file
|
||||
|
||||
Needed Specification : `RIFF (little-endian) data, WAVE audio, Microsoft PCM, 16 bit, stereo 44100 Hz`
|
||||
|
||||
### Conversion
|
||||
|
||||
```bash
|
||||
ffmpeg -i input.mp3 -acodec pcm_s16le -ac 2 -ar 44100 output.wav
|
||||
```
|
||||
|
||||
### Merging two mono audio channels into one stereo channel
|
||||
|
||||
```bash
|
||||
ffmpeg -i herb.wav.new -filter_complex "[0:a][0:a]amerge=inputs=2[a]" -map "[a]" herbi.wav
|
||||
```
|
||||
|
||||
## Music credits
|
||||
|
||||
Track 1 :
|
||||
Beach Party by Kevin MacLeod
|
||||
Link: https://incompetech.filmmusic.io/song/3429-beach-party
|
||||
License: https://filmmusic.io/standard-license
|
||||
|
||||
Track 2:
|
||||
Funk Game Loop by Kevin MacLeod
|
||||
Link: https://incompetech.filmmusic.io/song/3787-funk-game-loop
|
||||
License: https://filmmusic.io/standard-license
|
BIN
hello_cdda/audio/beach.wav
Normal file
BIN
hello_cdda/audio/beach.wav
Normal file
Binary file not shown.
BIN
hello_cdda/audio/funk.wav
Normal file
BIN
hello_cdda/audio/funk.wav
Normal file
Binary file not shown.
110
hello_cdda/hello_cdda.c
Normal file
110
hello_cdda/hello_cdda.c
Normal file
@ -0,0 +1,110 @@
|
||||
// CDDA track playing example
|
||||
// based on Lameguy64's tutorial : http://lameguy64.net/svn/pstutorials/chapter1/1-display.html
|
||||
#include <sys/types.h>
|
||||
#include <stdio.h>
|
||||
#include <libgte.h>
|
||||
#include <libetc.h>
|
||||
#include <libgpu.h>
|
||||
// CD library
|
||||
#include <libds.h>
|
||||
// SPU library
|
||||
#include <libspu.h>
|
||||
|
||||
#define VMODE 0 // Video Mode : 0 : NTSC, 1: PAL
|
||||
#define SCREENXRES 320 // Screen width
|
||||
#define SCREENYRES 240 + (VMODE << 4) // Screen height : If VMODE is 0 = 240, if VMODE is 1 = 256
|
||||
#define CENTERX SCREENXRES/2 // Center of screen on x
|
||||
#define CENTERY SCREENYRES/2 // Center of screen on y
|
||||
#define MARGINX 0 // margins for text display
|
||||
#define MARGINY 32
|
||||
#define FONTSIZE 8 * 7 // Text Field Height
|
||||
DISPENV disp[2]; // Double buffered DISPENV and DRAWENV
|
||||
DRAWENV draw[2];
|
||||
short db = 0; // index of which buffer is used, values 0, 1
|
||||
// SPU attributes
|
||||
SpuCommonAttr spuSettings;
|
||||
// CD tracks
|
||||
int playing = -1;
|
||||
int tracks[] = {2, 0}; // Track to play , 1 is data, 2 is beach.wav, 3 is funk.wav. See isoconfig.xml
|
||||
|
||||
void init(void)
|
||||
{
|
||||
ResetGraph(0); // Initialize drawing engine with a complete reset (0)
|
||||
SetDefDispEnv(&disp[0], 0, 0 , SCREENXRES, SCREENYRES); // Set display area for both &disp[0] and &disp[1]
|
||||
SetDefDispEnv(&disp[1], 0, SCREENYRES, SCREENXRES, SCREENYRES); // &disp[0] is on top of &disp[1]
|
||||
SetDefDrawEnv(&draw[0], 0, SCREENYRES, SCREENXRES, SCREENYRES); // Set draw for both &draw[0] and &draw[1]
|
||||
SetDefDrawEnv(&draw[1], 0, 0 , SCREENXRES, SCREENYRES); // &draw[0] is below &draw[1]
|
||||
// Set video mode
|
||||
if (VMODE){ SetVideoMode(MODE_PAL);}
|
||||
SetDispMask(1); // Display on screen
|
||||
setRGB0(&draw[0], 50, 50, 50); // set color for first draw area
|
||||
setRGB0(&draw[1], 50, 50, 50); // set color for second draw area
|
||||
draw[0].isbg = 1; // set mask for draw areas. 1 means repainting the area with the RGB color each frame
|
||||
draw[1].isbg = 1;
|
||||
PutDispEnv(&disp[db]); // set the disp and draw environnments
|
||||
PutDrawEnv(&draw[db]);
|
||||
FntLoad(960, 0); // Load font to vram at 960,0(+128)
|
||||
FntOpen(MARGINX, SCREENYRES - MARGINY - FONTSIZE, SCREENXRES - MARGINX * 2, FONTSIZE, 0, 280 ); // FntOpen(x, y, width, height, black_bg, max. nbr. chars
|
||||
}
|
||||
void display(void)
|
||||
{
|
||||
DrawSync(0); // Wait for all drawing to terminate
|
||||
VSync(0); // Wait for the next vertical blank
|
||||
PutDispEnv(&disp[db]); // set alternate disp and draw environnments
|
||||
PutDrawEnv(&draw[db]);
|
||||
db = !db; // flip db value (0 or 1)
|
||||
}
|
||||
int main(void)
|
||||
{
|
||||
init(); // init() display
|
||||
// Init extended CD system
|
||||
DsInit();
|
||||
// Init Spu
|
||||
SpuInit();
|
||||
// Set master & CD volume to max
|
||||
spuSettings.mask = (SPU_COMMON_MVOLL | SPU_COMMON_MVOLR | SPU_COMMON_CDVOLL | SPU_COMMON_CDVOLR | SPU_COMMON_CDMIX);
|
||||
spuSettings.mvol.left = 0x7FFF;
|
||||
spuSettings.mvol.right = 0x7FFF;
|
||||
spuSettings.cd.volume.left = 0x7FFF;
|
||||
spuSettings.cd.volume.right = 0x7FFF;
|
||||
// Enable CD input ON
|
||||
spuSettings.cd.mix = SPU_ON;
|
||||
// Apply settings
|
||||
SpuSetCommonAttr(&spuSettings);
|
||||
// Set transfer mode
|
||||
SpuSetTransferMode(SPU_TRANSFER_BY_DMA);
|
||||
|
||||
int count = 0;
|
||||
int flip = 0;
|
||||
|
||||
while (1) // infinite loop
|
||||
{
|
||||
if ( count == 0){
|
||||
DsPlay(2, tracks, 0);
|
||||
}
|
||||
|
||||
count ++;
|
||||
|
||||
// Afer 5 seconds
|
||||
if ( count == 300 ){
|
||||
// Stop playback
|
||||
DsPlay(0, tracks, 0);
|
||||
}
|
||||
// Wait one second
|
||||
if ( count == 360 ){
|
||||
// Flip value
|
||||
flip = !flip;
|
||||
// Switch track (can be 2 or 3)
|
||||
tracks[0] = 2 + flip;
|
||||
// Reset counter
|
||||
count = 0;
|
||||
}
|
||||
|
||||
FntPrint("Hello CDDA !\n"); // Send string to print stream
|
||||
FntPrint("Playback status: %d", DsPlay(3, tracks, 0)); // Send string to print stream
|
||||
|
||||
FntFlush(-1); // Draw printe stream
|
||||
display(); // Execute display()
|
||||
}
|
||||
return 0;
|
||||
}
|
111
hello_cdda/isoconfig.xml
Normal file
111
hello_cdda/isoconfig.xml
Normal file
@ -0,0 +1,111 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<!-- MKPSXISO example XML script -->
|
||||
|
||||
<!-- <iso_project>
|
||||
Starts an ISO image project to build. Multiple <iso_project> elements may be
|
||||
specified within the same xml script which useful for multi-disc projects.
|
||||
|
||||
<iso_project> elements must contain at least one <track> element.
|
||||
|
||||
Attributes:
|
||||
image_name - File name of the ISO image file to generate.
|
||||
cue_sheet - Optional, file name of the cue sheet for the image file
|
||||
(required if more than one track is specified).
|
||||
-->
|
||||
<iso_project image_name="disk.bin" cue_sheet="disk.cue">
|
||||
|
||||
<!-- <track>
|
||||
Specifies a track to the ISO project. This example element creates a data
|
||||
track for storing data files and CD-XA/STR streams.
|
||||
|
||||
Only one data track is allowed and data tracks must only be specified as the
|
||||
first track in the ISO image and cannot be specified after an audio track.
|
||||
|
||||
Attributes:
|
||||
type - Track type (either data or audio).
|
||||
source - For audio tracks only, specifies the file name of a wav audio
|
||||
file to use for the audio track.
|
||||
|
||||
-->
|
||||
<track type="data">
|
||||
|
||||
<!-- <identifiers>
|
||||
Optional, Specifies the identifier strings to use for the data track.
|
||||
|
||||
Attributes:
|
||||
system - Optional, specifies the system identifier (PLAYSTATION if unspecified).
|
||||
application - Optional, specifies the application identifier (PLAYSTATION if unspecified).
|
||||
volume - Optional, specifies the volume identifier.
|
||||
volume_set - Optional, specifies the volume set identifier.
|
||||
publisher - Optional, specifies the publisher identifier.
|
||||
data_preparer - Optional, specifies the data preparer identifier. If unspecified, MKPSXISO
|
||||
will fill it with lengthy text telling that the image file was generated
|
||||
using MKPSXISO.
|
||||
-->
|
||||
<identifiers
|
||||
system ="PLAYSTATION"
|
||||
application ="PLAYSTATION"
|
||||
volume ="HELOCD"
|
||||
volume_set ="HELOCD"
|
||||
publisher ="SCHNAPPY"
|
||||
data_preparer ="MKPSXISO"
|
||||
/>
|
||||
|
||||
<!-- <license>
|
||||
Optional, specifies the license file to use, the format of the license file must be in
|
||||
raw 2336 byte sector format, like the ones included with the PsyQ SDK in psyq\cdgen\LCNSFILE.
|
||||
|
||||
License data is not included within the MKPSXISO program to avoid possible legal problems
|
||||
in the open source environment... Better be safe than sorry.
|
||||
|
||||
Attributes:
|
||||
file - Specifies the license file to inject into the ISO image.
|
||||
-->
|
||||
<!--
|
||||
<license file="LICENSEA.DAT"/>
|
||||
-->
|
||||
|
||||
<!-- <directory_tree>
|
||||
Specifies and contains the directory structure for the data track.
|
||||
|
||||
Attributes:
|
||||
None.
|
||||
-->
|
||||
<directory_tree>
|
||||
|
||||
<!-- <file>
|
||||
Specifies a file in the directory tree.
|
||||
|
||||
Attributes:
|
||||
name - File name to use in the directory tree (can be used for renaming).
|
||||
type - Optional, type of file (data for regular files and is the default, xa for
|
||||
XA audio and str for MDEC video).
|
||||
source - File name of the source file.
|
||||
-->
|
||||
<!-- Stores system.txt as system.cnf -->
|
||||
<file name="system.cnf" type="data" source="system.cnf"/>
|
||||
<file name="SCES_313.37" type="data" source="hello_cdda.ps-exe"/>
|
||||
<dummy sectors="1024"/>
|
||||
|
||||
<!-- <dir>
|
||||
Specifies a directory in the directory tree. <file> and <dir> elements inside the element
|
||||
will be inside the specified directory.
|
||||
-->
|
||||
</directory_tree>
|
||||
|
||||
</track>
|
||||
<!--
|
||||
Track 1 :
|
||||
Beach Party by Kevin MacLeod
|
||||
Link: https://incompetech.filmmusic.io/song/3429-beach-party
|
||||
License: https://filmmusic.io/standard-license
|
||||
Track 2:
|
||||
Funk Game Loop by Kevin MacLeod
|
||||
Link: https://incompetech.filmmusic.io/song/3787-funk-game-loop
|
||||
License: https://filmmusic.io/standard-license
|
||||
-->
|
||||
<track type="audio" source="audio/beach.wav"/>
|
||||
<track type="audio" source="audio/funk.wav"/>
|
||||
|
||||
</iso_project>
|
4
hello_cdda/system.cnf
Normal file
4
hello_cdda/system.cnf
Normal file
@ -0,0 +1,4 @@
|
||||
BOOT=cdrom:\SCES_313.37;1
|
||||
TCB=4
|
||||
EVENT=10
|
||||
STACK=801FFFF0
|
Loading…
x
Reference in New Issue
Block a user