Jo Engine Forum

Sega Saturn Development => General Jo Engine Help => Topic started by: ponut64 on June 22, 2018, 06:45:20 pm

Title: Doomsday Phrase: undefined reference to "ADP_DecMono" (and stereo)
Post by: ponut64 on June 22, 2018, 06:45:20 pm
/e: Nevermind, I seem to have fixed it!

Regardless for anyone who wants to use ADPCM, here is an updated LIBPCM.A and an updated jo engine makefile.

For anyone curious as to what the problem was, there's no SBL source code for ADPCM system. There is however LIBADP, which contains the object code for said functions, and they are in fact linked in the code its just there's no source.

So I downloaded SaturnOrbit and simply included the .o files in LIBPCM.A -- you shouldn't need LIBADP.A anymore, but it is there in any case.

You put LIBPCM.A in
\joengine-master\Compiler\SGL_302j\LIB_COFF
Keep your old LIBPCM! Who knows what I have broken!
You also should put the following line in your Jo engine makefile
JO_COMPILE_USING_SGL = 1
**IT SHOULD BE NOTED THIS IS THE SBL PCM LIBRARY, NOT SGL
Title: Re: Doomsday Phrase: undefined reference to "ADP_DecMono" (and stereo)
Post by: LackofTrack on June 23, 2018, 12:00:56 am
Awesome work ponut64! Hopefully this will be able to make more people use the SBL ADPCM library now.
Title: Re: Doomsday Phrase: undefined reference to "ADP_DecMono" (and stereo)
Post by: ponut64 on June 23, 2018, 02:02:46 am
Thanks, I should be working with 22 KHz ADPCM in the following days.
It's really impressive since 22 KHz ADPCM is the same file-size as 44.1 KHz mp3 files.
Sure, half as compressed as mp3 files, but the Saturn can handle it.
Title: Re: Doomsday Phrase: undefined reference to "ADP_DecMono" (and stereo)
Post by: LackofTrack on June 23, 2018, 02:31:31 am
22 khz ADPCM is pretty impressive. You save quite a lot of space with it compared to Redbook audio and it doesn't sound that bad either.
Only problem with it is the amount of CPU overhead it takes.
Title: Re: Doomsday Phrase: undefined reference to "ADP_DecMono" (and stereo)
Post by: ponut64 on June 23, 2018, 04:24:46 am
I'm not sure if we should be at all concerned with the CPU overhead, since I am pretty sure they are referring to the M68K which is dedicated to sound. You also probably don't need stereo for music, and using mono will cut the CPU usage in half.
If that isn't the case, then certainly, 20% of your work area CPU grunt being eaten up by music would be alarming.
You wouldn't have to worry about that overhead unless you were using a lot of special effects on many different PCM channels.
Which I suppose you could!
Title: Re: Doomsday Phrase: undefined reference to "ADP_DecMono" (and stereo)
Post by: LackofTrack on June 23, 2018, 04:48:54 am
I thought the CPU overhead they were referring to was one of the SH2 processors.
It would be a relief if they were talking about the M68k processor, but if that's the case then what's stopping you from doing 44khz ADPCM? It is only has about 30% CPU overhead.(What else would the M68k processor be doing besides this?)
Title: Re: Doomsday Phrase: undefined reference to "ADP_DecMono" (and stereo)
Post by: ponut64 on June 23, 2018, 11:27:55 am
I'm not planning on 44 KHz ADPCM since that's too much data for the CD system (mostly the A bus) to handle simultaneously with the other tasks I have planned for it.
Assuming my ideas even work. They should though.
If you wonder what else might the M68K be doing, well there are 8 PCM sound channels and one could in theory be playing 44 KHz sound bytes on all of them.
Not just that, but let's say you processed some sort of reverb or echo in the program, that would involve some SH2 work but also the M68K too.

I guess once I get an ADPCM program implemented, someone might be able to probe the performance impact.

/e: Well, it would seem that the ADPCM decompression program is indeed using the SH2s to a significant extent (by looking over the source code). However, keep in mind the ADP library has no source code to be found and I imagine that's the case because its written in Assembly for the M68K. I don't know why I wonder so deeply when I can test it very soon.
Though it looks like it does a few back-and-forth transfers to sound RAM and if that's the case you're far more concerned about B-bus usage than anything else.
Title: Re: Doomsday Phrase: undefined reference to "ADP_DecMono" (and stereo)
Post by: XL2 on June 23, 2018, 02:49:01 pm
The impact is mainly on SH2 as, as you said, we don't care about sound cpu usage since it doesn't do much.
The decompression is done in software.
Have you checked the SBL library to make sure it doesn't have the source code?
They also have the code for the sound cpus and drivers if I'm not mistaken.
AFAIK the compression ratio should be 1:4, which is quite nice.
Title: Re: Doomsday Phrase: undefined reference to "ADP_DecMono" (and stereo)
Post by: ponut64 on June 23, 2018, 07:47:33 pm
Now I have a different problem.

Sega's documentation has stuff like this:
Code: [Select]
PCM_PARA_WORK(&para) = &pcm_work;
PCM_PARA_RING_ADDR(&para) = ring_buf;
PCM_PARA_RING_SIZE(&para) = RING_BUF_SIZE;
PCM_PARA_PCM_ADDR(&para) = PCM_ADDR;
PCM_PARA_PCM_SIZE(&para) = PCM_SIZE;
pcm = PCM_CreateStmHandle(&para, stm);

The issue is, PCM_PARA_WORK references a member of the PCM_PARA struct (&para) called "work".
.. No such member exists.

This is a basic fact of SBL PCM playback and I am not sure of a way around it.

There's also a plethora of other issues, such as the SBL STM documentation stating some functions have have void inputs, but in fact don't. (Stream functions aren't entirely necessary, they just decided to make a usage example with the stream functions..)
I guess this is going to take longer than "a few days" to get working.

And to get any of this to compile, it's best you just include the entire SBL library in jo engine makefile.

It's really not clear how to use SBL PCM. Not clear at all!

/e: So, they did not specify what type "para" in the example. It turns out it is the type "PcmCreatePara", not "PcmPara".
I better do a little more research before I post this stuff on the forums eh?
Title: Re: Doomsday Phrase: undefined reference to "ADP_DecMono" (and stereo)
Post by: ponut64 on June 24, 2018, 02:44:17 pm
It looks like this is another one of my "play-by-play" update threads.

So here is some code. It's errorless, but the sound does not play. I am not sure where to put the data in memory to get it to play.

Of course one must earlier plan out your GFS and also call the commands PCM_Init(); and     PCM_DeclareUseAdpcm();

Code: [Select]
#ifndef __AUDIO_H__
#define __AUDIO_H__

#define RING_BUF_SIZE  (2048L*10)
#define PCM_ADDR  ((void*)0x25a20000)
// The above seems to point somewhere in LWRAM.
#define PCM_SIZE  (4096L*2)
#define SND_RAM (94371840)
#define LW_RAM (2097152)

//Functions go here
void adpcm_load(void);



#endif

//audio.c
//this file is compiled separately
#include <jo/jo.h>
#include "audio.h"

//goals:
//load an ADPCM file from CD (GFS_Load)
//Set up a PCM memory handle using the loaded CD data
//--> Understand PCM_VblIn or otherwise SBL interrupt system
//Playback the PCM file from PCM memory handle

void adpcm_load(void){
/* Work  */
PcmWork pcm_work;
PcmCreatePara para;
/* Ring Buffer  */
Uint32  ring_buf[RING_BUF_SIZE / sizeof(Uint32)];
PcmHn       adpcm;
/* Create Handle */
PCM_PARA_WORK(&para) = &pcm_work;
PCM_PARA_RING_ADDR(&para) = ring_buf;
PCM_PARA_RING_SIZE(&para) = RING_BUF_SIZE;
PCM_PARA_PCM_ADDR(&para) = PCM_ADDR;
PCM_PARA_PCM_SIZE(&para) = PCM_SIZE;
adpcm = PCM_CreateMemHandle(&para);
//Load
    void * soundAddress;
soundAddress = PCM_ADDR;
Sint8* name = "SHELL.ADP";
//Data of read structure
    Sint32 fid = GFS_NameToId(name);
GfsHn gfs;
Sint32 nsct;
Sint32 fsize;
//Data of read-in-process
Sint32 stat;
Sint32 rdsize;
//Destination address?
void * ptr2 = adpcm;
//Loading follows
gfs = GFS_Open(fid);
//Get sectors
//HEY! SBL DOCUMENTATION IS WRONG! THIRD ITEM nzect IS GFS SECTOR COUNT. SECOND ITEM IS CD SECTOR SIZE.
GFS_GetFileSize(gfs, NULL, &nsct, NULL);
GFS_GetFileInfo(gfs, NULL, NULL, &fsize, NULL);
//TIP: GFS_NwCdRead cannot be checked for completion. Sorry!
GFS_NwCdRead(gfs, fsize);
GFS_NwFread(gfs, nsct, (Uint32*)(soundAddress), fsize);
do{
GFS_NwExecOne(gfs);
GFS_NwGetStat(gfs, &stat, &rdsize);
jo_printf(0, 11, "(%i)", rdsize);
jo_printf(10, 11, "(fetched filesize)");
}while(stat != GFS_SVR_COMPLETED && rdsize < fsize);
// slDMACopy(soundAddress, ptr2, sizeof(PcmHn));
// slDMAWait();
/* Start Playback */
PCM_Start(adpcm);
while(TRUE) {
/* Playback task processing */
PCM_Task(adpcm);
/* End condition */
if (PCM_GetPlayStatus(adpcm) == PCM_STAT_PLAY_END) break;
}
/* Destroy Handle */
PCM_DestroyStmHandle(adpcm);
/* End Processing */
PCM_Finish();

}


i've also included some sample files
Title: Re: Doomsday Phrase: undefined reference to "ADP_DecMono" (and stereo)
Post by: ponut64 on June 24, 2018, 08:51:04 pm
I really don't have a clue.

I can use the ADP_DecMono (decompress mono) function with the Jo engine PCM load function, which should work since it just outputs a decompressed PCM.
It compiles, it doesn't crash, but the sound doesn't play.
I am not sure what to do...
Title: Re: Doomsday Phrase: undefined reference to "ADP_DecMono" (and stereo)
Post by: LackofTrack on June 24, 2018, 09:58:43 pm
Are you using the XA ADPCM audio encoder by Sega for Mac? If So then you need to use the function 'PCM_SetInfo'. The files the XA encoder outputs doesn't have a header
so you need to specify the audio information. Also I'm pretty sure you can only use Stream playback mode when using XA audio.
Title: Re: Doomsday Phrase: undefined reference to "ADP_DecMono" (and stereo)
Post by: ponut64 on June 24, 2018, 10:50:42 pm
That is a thought, but this is converted AIFF files to ADPCM using a different tool (still a Mac tool though). The documentation refers to this as "User-specified ADPCM" (not the optimage thing, but referred at the bottom of this page as "ADPCM Encoder" https://antime.kapsi.fi/sega/docs.html). In that case, since the AIFF file has a header, so should the ADPCM file (it isn't discarded when compressed). It should be noted that if you try to playback the ADPCM file as a PCM file with Jo engine functions, you get sound, it's just garbage. T
Maybe CD-XA would work. The issue is I imagine that won't work over an .ISO file. The reason I've skipped over CD-DA is because Bizhawk, Yabause, and SSF won't accept files like that. Maybe it will work for CD-XA though I am no more certain on how to actually playback CD-XA than AIFF-ADPCM files seeing as the documentation tells you jack shit about how to do that. (I exaggerate, I just vehemently dislike their code example because it leaves so much up to imagination)
Title: Re: Doomsday Phrase: undefined reference to "ADP_DecMono" (and stereo)
Post by: LackofTrack on June 24, 2018, 11:09:41 pm
 :) That is the Sega XA ADPCM encoder I'm taking about. It outputs a XA audio file with no header. So you are using XA audio. Also CD-XA has nothing to do with the fact that you are using an iso.
CD-XA will work perfectly fine in a iso.(CD-XA is within the iso itself. CD-DA is not actually in the iso. You have to use a cue file in order to tell the iso to use your CD-DA files.)
Title: Re: Doomsday Phrase: undefined reference to "ADP_DecMono" (and stereo)
Post by: ponut64 on June 24, 2018, 11:28:02 pm
https://youtu.be/GD6qtc2_AQA

I am learned.

I didn't know that was the XA Audio encoder. It makes sense that it would be, it's the only one there, and they say the other one is from a 3rd party.
I'll have to move forward with SBL Stream system then!
I DID try that at one point, but it didn't work, but there's probably quite a few more reasons why it wouldn't that are explained since I need to figure out the stream library too.
And the header stuff. They say it should be filled in by the subheader?
Also, 22KHz ADPCM should not be possible with CD-XA. I'll have to re-do at 18.9 KHz right? (that only takes about 30 seconds)

Also, where's that other ADPCM encoder they mentioned?

More /e: There is a sample program for Stream playback, that's very good.
smppcm5.c in SBL
Title: Re: Doomsday Phrase: undefined reference to "ADP_DecMono" (and stereo)
Post by: ponut64 on June 25, 2018, 08:38:40 pm
More posts

I'm not sure why the Stream library is working in Yabause and not working on real hardware or in SSF.
Clearly some of the commands are "getting through"
Still not getting any sound, by the way, but understanding the stream system would be first.
/e: It has something to do with the CD-ROM XA keys. So commenting out the one line with 0x04 ant at least the Stream works in SSF.
The documentation does say CD-ROM XA needs the CD to be formatted as Mode 2 Form 2... how would I format like that, or is it even relevant?

Code: [Select]
#ifndef __AUDIO_H__
#define __AUDIO_H__

#define RING_BUF_SIZE  (2048L*10)
#define PCM_ADDR  ((void*)0x25a20000)
#define PCM_SIZE  (4096L*2)

#define SMP_1TASK_SAMPLE (1024)
#define SMP_TR_MODE_CD (PCM_TRMODE_SCU)
#define SMP_LOAD_NUM (10)

#define SND_RAM (94371840)
#define LW_RAM (2097152)

//Functions go here
void adpcm_load(void);



#endif

//audio.c
//this file is compiled separately
#include <jo/jo.h>
#include "audio.h"

//goals:
//Apparently, this file is CD-ROM XA.
void adpcm_load(void){
/* Work  */
PcmWork  pcm_work;
PcmCreatePara para;
/* Ring Buffer  */
Uint32  ring_buf[RING_BUF_SIZE / sizeof(Uint32)];
// Handles
StmHn       stm;
PcmHn       pcm;
StmGrpHn stmfpcm;
StmKey key;
PcmInfo info;
Sint8* name = "SHELL.ADP";
Sint32 fid = GFS_NameToId(name);

//Data of read in process
Sint32 rdsize;

/* Set Interrupt Process */
// Use
 // INT_???
// and set V-Blank IN interrupt.
// Call
 // PCM_VblIn();
// within V-Blank IN interrupt.

/* File initialization */
stmfpcm = STM_OpenGrp();
STM_SetExecGrp(stmfpcm);
STM_KEY_FN(&key) = STM_KEY_CN(&key) = STM_KEY_SMMSK(&key) =
STM_KEY_SMVAL(&key) = STM_KEY_CIMSK(&key) = STM_KEY_CIVAL(&key) =
STM_KEY_NONE;
//FOR CDROM XA
STM_KEY_SMMSK(&key) = STM_KEY_SMVAL(&key) = 0x04;/* Audio Sector */
STM_KEY_CN(&key) = 0; /* channel No. */

/* Open Stream */
stm = STM_OpenFid(stmfpcm, fid, &key, STM_LOOP_NOREAD);

/* Create Handle */
PCM_PARA_WORK(&para) = &pcm_work;
PCM_PARA_RING_ADDR(&para) = ring_buf;
PCM_PARA_RING_SIZE(&para) = RING_BUF_SIZE;
PCM_PARA_PCM_ADDR(&para) = PCM_ADDR;
PCM_PARA_PCM_SIZE(&para) = PCM_SIZE;
pcm = PCM_CreateStmHandle(&para, stm);
//SET PCM INFO FOR ADPCM
PCM_INFO_FILE_TYPE(&info) = PCM_FILE_TYPE_NO_HEADER;
PCM_INFO_DATA_TYPE(&info) = PCM_DATA_TYPE_ADPCM_SCT;
PCM_SetVolume(pcm, 7);
PCM_SetInfo(pcm, &info);
PCM_SetLoadNum(pcm, SMP_LOAD_NUM);
PCM_SetTrModeCd(pcm, SMP_TR_MODE_CD);
PCM_Set1TaskSample(pcm, SMP_1TASK_SAMPLE);
PCM_ChangePcmPara(pcm);
/* Start Playback */
PCM_Start(pcm);
while(TRUE) {
STM_ExecServer();
rdsize = STM_GetNumCdbuf(stm);
jo_printf(0, 0, "(%i)", rdsize);
/* Playback task processing */
PCM_Task(pcm);
/* End condition */
if (PCM_GetPlayStatus(pcm) == PCM_STAT_PLAY_END) break;
if(jo_is_pad1_key_pressed(JO_KEY_A)){
break;
}
}
/* Destroy Handle */
PCM_DestroyStmHandle(pcm);
/* Close stream */
STM_Close(stm);
/* End Processing */
PCM_Finish();

}


/e: You can add these, it doesn't seem to care. I might get somewhere in a few years.

Code: [Select]
info.sampling_rate = 18900;
info.sampling_bit = 16;
info.channel = 1;
info.sample_file = 1;

More /e:

Frankly I don't even know where the data from the stream is going.
STM_SetTrBuf(stm, ring_buf, 2048, RING_BUF_SIZE);
doesn't seem to change anything.

Also, thank you again for clarifying that encoder is for XA audio. It IS headerless...
Title: Re: Doomsday Phrase: undefined reference to "ADP_DecMono" (and stereo)
Post by: LackofTrack on June 26, 2018, 12:15:33 am
I don't think the CD needs to be formatted as Mode 2 Form 2. I'm pretty sure this is only for Photo/Video CDs.
When you say commenting out one of the XA key lines makes the program work in SSF, does that mean it plays sound?
Title: Re: Doomsday Phrase: undefined reference to "ADP_DecMono" (and stereo)
Post by: ponut64 on June 26, 2018, 12:45:15 am
It doesn't play sound, but the Stream program does work. I am assuming if SSF would do that, then real hardware would. (Because when SSF didn't, real hardware didn't even if other emulators did)

I really think since it isn't playing ANY sound right now, I am either setting up the PCM play info completely wrong (which is weird, since Sega samples set it up like that, but also they don't work when I compile them either! when sent at PCM or ADPCM files!) OR I am sending the stream to the wrong address. I really do not know where I am supposed to put the data to play it back as a PCM file.

I tell ya what, if SGL had ADPCM, that would be really sweet because SGL is a helluva lot simpler to work with than SBL so far. Better documentation, less verbose code.
Unfortunately I am stuck with SBL since even if I could grab an ADPCM decompression program (in C) off the 'net, the point is to be able to stream it from the CD in some fashion.
I did find a M68K decompression program but listen, I barely understand what a "while" loop is, let alone live program addresses between two different CPUs through the SCU and SCSP.

Also, for a fun way to annihilate your ears, use the jo engine audio demo to try and playback ADPCM files.
... It's not fun. Heh.
Title: Re: Doomsday Phrase: undefined reference to "ADP_DecMono" (and stereo)
Post by: LackofTrack on June 26, 2018, 01:38:22 am
After looking at your code I noticed a few things off about it. So I made some adjustments to it. Please review it.
Code: [Select]
#ifndef __AUDIO_H__
#define __AUDIO_H__

#define SECTOR_SIZE     (2324L)
#define RING_BUF_SIZE  (2324L*10)
#define PCM_ADDR  ((void*)0x25a20000)
#define PCM_SIZE  (4096L*4)

#define SMP_1TASK_SAMPLE (1024)
#define SMP_TR_MODE_CD (PCM_TRMODE_SCU)
#define SMP_LOAD_NUM (10)

#define SND_RAM (94371840)
#define LW_RAM (2097152)

//Functions go here
void adpcm_load(void);



#endif

//audio.c
//this file is compiled separately
#include <jo/jo.h>
#include "audio.h"

//goals:
//Apparently, this file is CD-ROM XA.
void adpcm_load(void){
/* Work  */
PcmWork  pcm_work;
PcmCreatePara para;
/* Ring Buffer  */
Uint32  ring_buf[RING_BUF_SIZE / sizeof(Uint32)];
// Handles
StmHn       stm;
PcmHn       pcm;
StmGrpHn stmfpcm;
StmKey key;
PcmInfo info;
Sint8* name = "SHELL.ADP";
Sint32 fid = GFS_NameToId(name);

//Data of read in process
Sint32 rdsize;

/* Set Interrupt Process */
// Use
 // INT_???
// and set V-Blank IN interrupt.
// Call
 // PCM_VblIn();
// within V-Blank IN interrupt.

/* File initialization */
stmfpcm = STM_OpenGrp();
STM_SetExecGrp(stmfpcm);
STM_KEY_FN(&key) = STM_KEY_CN(&key) = STM_KEY_SMMSK(&key) =
STM_KEY_SMVAL(&key) = STM_KEY_CIMSK(&key) = STM_KEY_CIVAL(&key) =
STM_KEY_NONE;
//FOR CDROM XA
STM_KEY_SMMSK(&key) = STM_KEY_SMVAL(&key) = 0x04;/* Audio Sector */
STM_KEY_CN(&key) = 0; /* channel No. */

/* Open Stream */
stm = STM_OpenFid(stmfpcm, fid, &key, STM_LOOP_NOREAD);

/* Create Handle */
PCM_PARA_WORK(&para) = &pcm_work;
PCM_PARA_RING_ADDR(&para) = ring_buf;
PCM_PARA_RING_SIZE(&para) = RING_BUF_SIZE;
PCM_PARA_PCM_ADDR(&para) = PCM_ADDR;
PCM_PARA_PCM_SIZE(&para) = PCM_SIZE;
pcm = PCM_CreateStmHandle(&para, stm);
//SET PCM INFO FOR ADPCM
typedef struct  {
    PCM_INFO_FILE_TYPE;
    PCM_INFO_DATA_TYPE;
    //  Sint32 file_size;           how big is your file in bytes?
    //  Sint32 channel;             how many channels does your file have? '1' if mono '2' if stereo.
    //  Sint32 sampling_bit;        based on your comment I think this is 16.
    //  Sint32 sampling_rate;       in your case this is 18900.
    //  Sint32 sample_file;         I think this is asking for how many samples are in your file. In order to check this
    //                                         use a program like audacity.
    //  Sint32 compression_type;    I don't actually know what this is asking for and have no idea what to put here. 
}   PcmInfo;
PCM_INFO_FILE_TYPE(&info) = PCM_FILE_TYPE_NO_HEADER;
PCM_INFO_DATA_TYPE(&info) = PCM_DATA_TYPE_ADPCM_SCT;
PCM_SetVolume(pcm, 7);
PCM_SetInfo(pcm, &info);
PCM_SetLoadNum(pcm, SMP_LOAD_NUM);
PCM_SetTrModeCd(pcm, SMP_TR_MODE_CD);
PCM_Set1TaskSample(pcm, SMP_1TASK_SAMPLE);
PCM_ChangePcmPara(pcm);
/* Start Playback */
PCM_Start(pcm);
while(TRUE) {
STM_ExecServer();
rdsize = STM_GetNumCdbuf(stm);
jo_printf(0, 0, "(%i)", rdsize);
/* Playback task processing */
PCM_Task(pcm);
/* End condition */
if (PCM_GetPlayStatus(pcm) == PCM_STAT_PLAY_END) break;
if(jo_is_pad1_key_pressed(JO_KEY_A)){
break;
}
}
/* Destroy Handle */
PCM_DestroyStmHandle(pcm);
/* Close stream */
STM_Close(stm);
/* End Processing */
PCM_Finish();

}

Also if ADPCM doesn't work out for you in the end I'd probably just try to play AIFF files(Seems a lot easier to play compared to ADPCM) or even CD-DA files if your project allows it.
Title: Re: Doomsday Phrase: undefined reference to "ADP_DecMono" (and stereo)
Post by: ponut64 on June 26, 2018, 02:21:13 am
That is a good catch that they are asking for number of samples. I know so little about audio files. What we need the number of samples for is to determine how long to play the file.

Changing
PCM_INFO_FILE_TYPE(&info) = PCM_FILE_TYPE_NO_HEADER;
to
PCM_INFO_FILE_TYPE(&info) = PCM_FILE_TYPE_AIFF;
makes the stream read more of the file specified, if that means anything.

I just haven't got it to make any sound so far.
AIFF or CDDA really is not an option ATM (unless I can 'accept' 6 KHz music..) because I need time free on the CD system.
Of course it's entirely possible I have the bandwidth capabilities of the CD system grossly underestimated, but I'm pretty sure we are working with somewhere in the realm of 768 bytes per frame (at 30 FPS). Program-controlled by GFS inside each program's frame of course. The idea is to get music files that can be read 256 bytes or less to get the sound in time each frame.

The reason that could be heavily understated is because the Saturn can obviously play 44.1KHz redbook audio.
I'm more concerned about A-bus/SH1 saturation, because of course the Saturn's CD-ROM is X2 speed and thus should be able to spit out around 5 KB per frame (300 KB/s).
Maybe I should just do more testing on the fetch speed.
Still it would be nice to get ADPCM to free up more time on the CD system to do other things.

/e: Okay, So. 2048 bytes per frame works. I do not know what was happening that made that slow-down at one point. Maybe a bad burn? Man, that makes things a lot faster.
I might be able to use 16 KHz mono PCM then.
I only estimate need of the CD for the following things:
- Area data (Level - paths - visibility - item data - etc)
- SFX (PCM at leisure, and needed much less often)
- ZTP (Binary model files and textures)
- Music

My plan has always been to segment these into different buffers that can have reads to them activated or deactivated at any time, with overlapping requests being simultaneous fetch, interleaved CD reads. I guess that is unncessarily complicated; it should all be interleaved reads & fetch, allowing every read data type to be using full bandwidth.

... I'm not giving up on pursuing SBL PCM though. I want it to make SOUND ! Sure, Jo engine can already do that...
Title: Re: Doomsday Phrase: undefined reference to "ADP_DecMono" (and stereo)
Post by: XL2 on June 26, 2018, 04:55:05 am
For sounds I already got the tone data fully working, so it's all on sound ram now.
For CDDA, I'm not sure if you know, but it bypasses the system fully (DAC), so it doesn't use the A bus and uses no system ressources (well, maybe the SH1, but you can't do anything with it) .
Good job so far with your tests!
Title: Re: Doomsday Phrase: undefined reference to "ADP_DecMono" (and stereo)
Post by: ponut64 on June 26, 2018, 06:08:13 am
That's what I thought but I didn't know for sure.
I always assumed the A bus was slower than the system could process from, maybe it is maybe it isn't.

I will probably give up on SBL in a day or two but I will keep poking at it tomorrow
Title: Re: Doomsday Phrase: undefined reference to "ADP_DecMono" (and stereo)
Post by: ponut64 on June 26, 2018, 11:27:39 pm
My guess at this point is in order to use the SBL PCM-ADPCM library, you have to set up an SBL program (rather than an SGL program).
And that is much more complicated than SGL, since you must manage the system interrupts (like a DOS program, but worse).
That's something that will make a lot of other things break, so I am abandoning this quest.

I will post back here when I get PCM streaming under SGL working, though.
I am happy I could at least get some code to compile.

Title: Re: Doomsday Phrase: undefined reference to "ADP_DecMono" (and stereo)
Post by: ponut64 on June 27, 2018, 05:33:24 pm
Nevermind.

SGL seems completely unable to properly playback anything different from 44.1 KHz PCM. Nowhere can you set the bitrate...
That makes things extra difficult. It looks like I have to figure out the PCM-ADPCM SBL library, one way or another...
Why is sound such a pain in the ass?

thankfully, the Rockin' B might come to the rescue with Saturn Sound Player. It mixes SBL and SGL PCM libraries so he proves it's possible.
Title: Re: Doomsday Phrase: undefined reference to "ADP_DecMono" (and stereo)
Post by: LackofTrack on June 27, 2018, 09:06:57 pm
Yeah. Rockin'B's sound player definitely proves that mixing the two libraries is possible, but when I looked through the source code I found the player only plays AIF and Adpcm that already have a header. I think for now you should see if you can get AIFs to play as that seems a lot easier to playback compared to XA audio, but that's for you to decide.  :)
Title: Re: Doomsday Phrase: undefined reference to "ADP_DecMono" (and stereo)
Post by: ponut64 on June 27, 2018, 09:47:38 pm
AIFFs do play (not with 'my SBL' yet... may it be damned), they are formatted identically to Saturn PCM as far as I can tell. (They just have a header)
Using AIFFs is the simplest of any variety as far as converting the files.
But I have put in the SBL init functions and SGL still plays sound, so that should at least indicate that SBL would play sound whenever I actually got the stupid stuff to work.
SGL still doesn't play them back at the correct rate.

It's funny how the documentation says
Quote
The PCM-ADPCM Playback Library enables simplified playback of PCM audio on the
SEGA SATURN
Yes, "simplified"
I am humoring myself don't worry
Title: Re: Doomsday Phrase: undefined reference to "ADP_DecMono" (and stereo)
Post by: ponut64 on June 29, 2018, 05:59:45 pm
Well I had a day where I couldn't work on it, so now I don't remember what did and what didn't produce 'results' with SBL.

But I would like to let nobody know that the code is still freezing at "PCM_Task".
Trying to use GFS handles with AIFF files.
I do know it is the handle because if I use a bad file-name, it doesn't get stuck (but obviously, it doesn't play sound).
So if I figure out what's crashing or freezing it, maybe I will get it to make sound.
--> And I am no longer using jo engine callback (though it doesn't behave differently with or without it so far)
Title: Re: Doomsday Phrase: undefined reference to "ADP_DecMono" (and stereo)
Post by: ponut64 on June 30, 2018, 08:44:07 am
I'd like to share something that might be important.

Here is a structure to get some error codes:

Code: [Select]
PcmErrCode pcmsysErr = PCM_GetErr();
jo_printf(0, 19, "(%x)", pcmsysErr);
PCM_Task(pcm);

What could these codes be?

Code: [Select]
/* エラーコード	*/
typedef enum {
PCM_ERR_OK = 0x00000000,/* エラーは発生していない */

/* PCM_Create のエラー */
PCM_ERR_OUT_OF_HANDLE = 0x00000101,/* ハンドル売り切れ */
PCM_ERR_NO_INIT = 0x00000103,/* 初期化関数がコールされてない */

/* PCM_Destroy のエラー */
PCM_ERR_INVALID_HN = 0x00000201,/* 不正なハンドルで消去 */
PCM_ERR_ILL_CREATE_MODE = 0x00000202,/* Create 時のモードと違う */

/* pcm_HeaderProcess のエラー */
PCM_ERR_TOO_LARGE_HEADER = 0x00000302,/* ヘッダがき大すぎる */
/* (バッファサイズが小さすぎる) */
PCM_ERR_HEADER_DATA = 0x00000303,/* ヘッダデータエラー */
PCM_ERR_TOO_SMALL_PCMBUF = 0x00000304,/* PCMバッファサイズが小さすぎる */
PCM_ERR_ILL_SIZE_PCMBUF = 0x00000305,/* PCMバッファサイズ不正 4096*2~16 */
PCM_ERR_AFI_NO_COMMON = 0x00000306,/* CommonChunk が無い */
PCM_ERR_AFI_COMMPRESS = 0x00000307,/* 未対応圧縮タイプ */
PCM_ERR_NOT_DECLARE_ADPCM = 0x00000308,/* ADPCM使用宣言がない */

/*  */
PCM_ERR_ILLEGAL_PARA = 0x00000503,/* 引き数の指定が間違っている */
PCM_ERR_ILLEGAL_HANDLE = 0x00000504,/* ハンドルが異常 */

/* 連続再生に関するエラー */
PCM_ERR_NEXT_HN_STATUS = 0x00000601,/* 連続再生ハンドルの状態異常 */
PCM_ERR_NEXT_HN_AUDIO = 0x00000602,/* オーディオの条件が一致しない */
PCM_ERR_CHANGE_NO_ENTRY = 0x00000605,/* エントリがない状態でチェンジ */

/* ポーズに関するエラー */
PCM_ERR_PAUSE_STATUS = 0x00000701,/* PCM_STAT_PLAY_TIME, または、
* PCM_STAT_PLAY_PAUSE 以外の
* 状態でポーズ関数をコールした。
*/
PCM_ERR_PAUSE_WORK_NULL = 0x00000702,/* ポーズ処理用ワーク異常 */
PCM_ERR_PAUSE_WORK_SIZE = 0x00000703,/* ポーズ処理用ワーク異常 */
PCM_ERR_PAUSE_WORK_SET = 0x00000704,/* ポーズ処理用ワーク指定が不正*/

/* DMA転送に関するエラー */
PCM_ERR_DMA_MODE = 0x00000801,/* 未対応の転送方式 */
PCM_ERR_DMA_CPU_PCM = 0x00000802,/* DMAが異常終了 */

/* ファイル読み込みエラー */
PCM_ERR_GFS_READ = 0x00000901,/* GFSの読み込みで失敗 */

/* リングバッファへのデータ供給に関するエラー */
PCM_ERR_RING_SUPPLY = 0x00000a01,/* 再生完了後に供給があった    */
/* (供給が間に合わす中断した)*/

PCM_ERR_END
} PcmErrCode;

I am currently facing Error 303. Header data error. Hmm...
I wonder if... it's not reading the header correctly?
I wonder if... my files simply do not have the correct header data for the Saturn to read? Any period-correct (like Apple / Basilisk II compatible) WAV / MP3 to AIFF converters you guys know of?
Title: Re: Doomsday Phrase: undefined reference to "ADP_DecMono" (and stereo)
Post by: XL2 on June 30, 2018, 04:53:25 pm
Did you manage to load your aiff files in the Sega sound tools?
Check this out first.
Also, modern aiff don't have the same endianness as older versions, so that's also an issue.
Title: Re: Doomsday Phrase: undefined reference to "ADP_DecMono" (and stereo)
Post by: ponut64 on June 30, 2018, 07:17:32 pm
No, actually... I don't know what sound tool is relevant to this, and how to even open them.
The PCM to ADPCM (XA?) converter converts them and correctly reports their bitrate and such correctly, though that doesn't mean anything about what Saturn hardware would read.
Every program of "Sound tools" in the Macintosh section of the documentation site opens with errors.

From the documentation, it looks like they expect you to have a Saturn dev kit for any of it to work. Obviously I don't have one of those.
Title: Re: Doomsday Phrase: undefined reference to "ADP_DecMono" (and stereo)
Post by: XL2 on June 30, 2018, 08:35:57 pm
The tone editor works for me and the simulator allows me to write my maps, so you could start with those.
Title: Re: Doomsday Phrase: undefined reference to "ADP_DecMono" (and stereo)
Post by: ponut64 on June 30, 2018, 09:08:05 pm
I'm trying a different Mac emulator. Basilisk II maybe just doesn't work I DON'T KNOW
Title: Re: Doomsday Phrase: undefined reference to "ADP_DecMono" (and stereo)
Post by: ponut64 on June 30, 2018, 09:41:50 pm
Interesting.

Tone editor can play the files as expected.
There is this error, though.

https://i.imgur.com/jqELbKK.png?1

https://i.imgur.com/GKgDmPb.png?1

I really don't think there is anything wrong the files. The issue is most likely my code.
It crashes when I use PCM-GFS handle but gives Error 303 when I use PCM-Memory handle after GFS_Load.

I did find out the Sega tools expect the file to have the extension AIFF, I wonder if SBL is the same? No big deal, I can just not-shorten it to AIF, doesn't change anything.
Title: Re: Doomsday Phrase: undefined reference to "ADP_DecMono" (and stereo)
Post by: XL2 on June 30, 2018, 10:19:05 pm
It depends, if you just want to play sound effects and it fits in the sound ram, I could just share with you my implementation.
For streaming, I never tried it besides work ram stream.
Title: Re: Doomsday Phrase: undefined reference to "ADP_DecMono" (and stereo)
Post by: ponut64 on June 30, 2018, 10:31:57 pm
Well, I need* both. Looking at what you have done (assuming it uses SBL PCM!) couldn't hurt, because I can't fathom why this code is not working when compared against Rockin'Bs sound player.
I would hope that I don't need to straight-up copy something, so I say, hold the thought for now.
In time, I expect to get something working. Got to be simple.

/e:
Interesting.
STM handle does not return an error, yet it plays no sound. Very odd.
This time, I have registered the interrupt.
Code: [Select]
void	my_vlank(void){
PCM_VblIn();
//Put gouraud shade table in place
    slGouraudTblCopy();
}
//and in main
slIntFunction(my_vlank);
Title: Re: Doomsday Phrase: undefined reference to "ADP_DecMono" (and stereo)
Post by: ponut64 on July 02, 2018, 03:00:59 am
An update:

There's actually a "Pitch" value in SGL sound effects that you can manipulate to play the sound back at different rates.
I did see this before I looked at the Rockin'Bs code, but I hadn't figured out how to manipulate it. I don't think I ever would have, it's really complex.
This unfortunately does not comply directly with a sample rate.

Fortunately Rockin'B has some code that can take an input sample rate, and convert that to an output pitch for SGL sound.
This is pretty dang useful, but it uses double-precision values so the Saturn cannot compute it itself (plus, where would you even know the sample rate?)

To get around that, I just used an online C compiler. With that, I can generate a table of common sample rates and convert those to pitch rates.

Code: [Select]
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#define PCM_toPitch(OCT, FNS)   ((FNS & 0x03FF) | ((OCT & 0xF) << 11))
#define PCM_toOCT(pitch)        ((pitch & 0x7800) >> 11)
#define PCM_TIMES   1.000577789
// SOURCE: The Rockin' B, Rockin' B Saturn Libraries, RB_PCM.C, line 766
unsigned short PCM_computePitch(double sampleRate)
{
    double c, s;
    int OCT, FNS;
   
    // Fn = Fo * 2^(n/1200)

    // compute necessary slowdown / speedup
    // assuming a base frequency of 44100 Hz
    // Fn / Fo = 2^(n/1200)
    // with Fo = 44100 Hz, the saturn base sample frequency
    s = sampleRate / 44100.0;
//    printf("s = %f\n", s);
   
    // compute the pitch to this(cents)
//    n = log(s) / log(PCM_TIMES);
    // log2(Fn / Fo) * 1200 = n
    c = (log(s) / log(2)); // * 1200.0;
//    printf("c1 = %f\n", c);
    if(c >= 0) {
        // compute OCT
        OCT = (int)c;
        // compute FNS
        c -= (double)OCT;
       
    } else {
        // compute OCT
        OCT = (int)c;
        if(c < OCT)
            OCT -= 1;
        // compute FNS
        c = c - ((double)OCT);
            // respect to new base frequency
//        s = sampleRate / (44100.0 / (1 - OCT));
            // n is now >= 0
//        c = (log(s) / log(2));
    }
   
    OCT &= 0xF;
//    printf("OCT = %x\n", OCT);
    // compute FNS
    c *= 1200.0;
//    printf("c2 = %f\n", c);
        // remove OCT from cents,
        // it's a seperate value
        // the argument needs to be in range 0 <= a < 1200
//    printf("(c / 1200.0) = %f\n", (c / 1200.0));
//    printf("(double)((int)(c / 1200.0)) = %f\n", (double)((int)(c / 1200.0)));
//    printf("pow arg = %f\n", (c / 1200.0) - (double)((int)(c / 1200.0)));
//    printf("pow() = %f\n", pow(2, (c / 1200.0) - (double)((int)(c / 1200.0))));
    FNS = ((int)(1024.0 * (pow(2, (c / 1200.0) ) - 1.0))) & 0x3FF;
//    printf("FNS = %i\n", FNS);
// interpret
//    return ((int)(1024.0 * (pow(2, c/1200.0) - 1.0))) & (0x3FF + (0xF << 11));
   
    return PCM_toPitch(OCT, FNS);
}


void main(void){
int Rate = 18900;
int Pitch;
Pitch = PCM_computePitch(Rate);
printf("(%i)", Pitch);
}

On this website: https://www.onlinegdb.com/online_c_compiler

You can modify the sound data like this:
   __jo_internal_pcm[(int)channel].pitch = [pitch number];

Table of simple rates:
Code: [Select]
44.10 KHz     0 Pitch
37.80 KHz     (31451) Pitch
30.72 KHz     (31122) Pitch
22.05 KHz     (30720) Pitch
18.90 KHz     (29403) Pitch
16.00 KHz     (29134) Pitch
11.00 KHz     (27643) Pitch
08.00 KHz     (27086) Pitch

With this, you can play sound at any sample rate using SGL.
And I should be able to continue my efforts and forge some sort of sound-streaming system using it.
Well, since I got the SBL STM library to cooperate, maybe? Probably not...

On another note: Why did I finally give up on SBL PCM-ADPCM library?
Well, I got it to run playback code errorless, meaning it did not report an error playing back the sound.
But it did not play any sound, even on real hardware, with the interrupt registered. So I had nowhere left to go. Code was Errorless, crashless code that doesn't work is the worst. And you know that's what most game bugs are...
Title: Re: Doomsday Phrase: undefined reference to "ADP_DecMono" (and stereo)
Post by: XL2 on July 02, 2018, 04:23:40 pm
Something stupid but worth a try : did you set the volume?
Check in Yabause to see if it's playing any sounds in one of the 32 channels.

For the pitch the tone editor fixes it for you more or less.
For all audio I'm only using SBL and it works fine.
In fact SBL documentation is better than SGL's documentation.

As for ADPCM, I haven't tried it as I'm super busy with other things, so I can't really help you ATM.
Title: Re: Doomsday Phrase: undefined reference to "ADP_DecMono" (and stereo)
Post by: ponut64 on July 02, 2018, 04:25:45 pm
Don't worry, I'm going to move forward with SGL. I did set the volume. Did a "rollback" and checked Yabause sound channels, nothing was playing. This isn't for ADPCM either, I've concluded I don't need that (though I do wonder how the ADP_DecMono / ADP_DecStereo functions work).
I've found a solution so now I just have to organize it. If I come back to needing SBL, well, I'll have to try and use a more isolated program to use it.
Thanks for reading.