Author Topic: A few questions about PCM functionality  (Read 283 times)

LackofTrack

  • Newbie
  • *
  • Posts: 6
  • Karma: +0/-0
    • View Profile
A few questions about PCM functionality
« on: September 22, 2017, 01:02:44 am »
Hello, first thing I'd like to say is that this is a great engine for people wanting to create programs on the Sega Saturn but, who don't have much knowledge about how the hardware works (like myself).

One question I'd like to ask though is is there anyway to play a PCM file depending on which button you press?

I've been using the audio demo to see if I could load 3 different PCM files depending on which button I press but, it seems like I can only do 2. I've just started to learn C so maybe I'm doing something wrong?  Also it seems I can only get 44100hz PCM files to play right. Every other frequency plays too fast. Do I have to edit  jo_sound_mode for it to correctly play lower frequencies?

My last question is is there any way to loop PCM audio?

« Last Edit: September 22, 2017, 01:06:17 am by LackofTrack »

XL2

  • Jr. Member
  • **
  • Posts: 99
  • Karma: +5/-0
    • View Profile
Re: A few questions about PCM functionality
« Reply #1 on: September 22, 2017, 02:30:52 am »
Nice to know that the different frequencies didn't play nice for you since I now know I'm not alone!
For the audio, there is no overflow check AFAIK, so if you specify a channel to play on you will probably get crashes.
I also can't play more than 2 audio files at the same time, but I know Johannes wants to fully modify the audio implementation, so maybe you can try the SGL functions for the time being.

LackofTrack

  • Newbie
  • *
  • Posts: 6
  • Karma: +0/-0
    • View Profile
Re: A few questions about PCM functionality
« Reply #2 on: September 22, 2017, 04:22:18 am »
Whew! Good to know I wasn't doing something wrong.  :D

Just to be clear I wasn't trying to play 2 PCM files once. I was trying to make it so that if I presses A "A.PCM" would play then if I pressed B "A.PCM" would be cleared from memory and then "B.PCM" would play but like I said I couldn't get it to work properly.

Also for some reason CD playback only seems to play in mono even if the Wav file itself is stereo. Is this also an issue you have been having?

mindslight

  • Administrator
  • Full Member
  • *****
  • Posts: 134
  • Karma: +2/-0
    • View Profile
    • Jo Engine
Re: A few questions about PCM functionality
« Reply #3 on: September 22, 2017, 08:34:43 am »
Hi, you can't play multiple sound on the same channel, but you can play 8 sounds on the same time using jo_audio_play_sound which plays the sound on the first available channel.

See documentation here:
http://jo-engine.org/doxygen/audio_8h.html

LackofTrack

  • Newbie
  • *
  • Posts: 6
  • Karma: +0/-0
    • View Profile
Re: A few questions about PCM functionality
« Reply #4 on: September 22, 2017, 09:21:49 am »
Hello,
Thanks, but that was not the issue I having.
The problem happens when I try to load 2 PCM files at the same time that together are over the memory limit of the saturn. I've tried using jo_audio_free_pcm but it doesn't seem to work properly. Is my code is wrong?


Code: [Select]
#include <jo/jo.h>
#include <jo/audio.h>

static jo_sound     blop;
static jo_sound     cop;

void my_draw(void)
{
    jo_printf(0, 0, jo_get_last_error());
    jo_printf(0, 1, "Press A to play PCM sound");
    jo_printf(0, 2, "Press B to play CD music");
    jo_printf(0, 3, "Press C to play PCM2 music");
    jo_printf(0, 4, "Audio channel usage: %d%% ", jo_audio_usage_percent());
}


void my_gamepad(void)
{
    static int  is_cd_playing = 0;

    if (!jo_is_pad1_available())
        return ;
    if (jo_is_pad1_key_pressed(JO_KEY_A))
        jo_audio_play_sound_on_channel(&blop, 0);
    if (jo_is_pad1_key_pressed(JO_KEY_B) && !is_cd_playing)
    {
        /* the first track is reserved for the game binary so the first track is 2 */
        jo_audio_play_cd_track(2, 2, 1);
        is_cd_playing = 1;
    }
      if    (jo_is_pad1_key_pressed(JO_KEY_C))
        jo_audio_play_sound(&cop);

}



void        load_blop_sound(void)
{
            jo_audio_load_pcm("A.PCM",JoSoundMono8Bit,& blop);

}

void        load_cop_sound(void)
{
            jo_audio_free_pcm(& blop);
            jo_audio_load_pcm("B.PCM",JoSoundMono8Bit,& cop);
}


 void jo_main(void)
{
jo_core_init(JO_COLOR_Black);
load_blop_sound();
load_cop_sound();
jo_core_add_callback(my_draw);
jo_core_add_callback(my_gamepad);
jo_core_run();
}

/*
** END OF FILE
*/

mindslight

  • Administrator
  • Full Member
  • *****
  • Posts: 134
  • Karma: +2/-0
    • View Profile
    • Jo Engine
Re: A few questions about PCM functionality
« Reply #5 on: September 22, 2017, 12:30:44 pm »
Can you attach audio files please ?

XL2

  • Jr. Member
  • **
  • Posts: 99
  • Karma: +5/-0
    • View Profile
Re: A few questions about PCM functionality
« Reply #6 on: September 22, 2017, 03:43:14 pm »
For me the  jo_audio_play_sound causes crashes when more than 2 sounds are playing (like I get 2 rings in a row in Sonic and jump at the same time).
Is there an overflow check?
I'm using the play on channel function instead, which prevents crashes, but doesn't allow me to play many files at once.

Also, one thing I noticed, the audio files are loaded in the HWRAM.

Can't they simply be loaded in the audio ram to free up some main ram, or the only way to do that would be by using a .c file for the audio instead of a PCM file?

LackofTrack

  • Newbie
  • *
  • Posts: 6
  • Karma: +0/-0
    • View Profile
Re: A few questions about PCM functionality
« Reply #7 on: September 22, 2017, 04:45:23 pm »
Here's the two audio files I'm using.

XL2

  • Jr. Member
  • **
  • Posts: 99
  • Karma: +5/-0
    • View Profile
Re: A few questions about PCM functionality
« Reply #8 on: September 23, 2017, 02:51:59 am »
Just a wild guess, but they seem way too big, they wouldn't fit the audio ram and you might also run out of ram memory.
Try playing with the malloc setting to free some ram to fit them.
You could also just send them to the low work ram (I don't know by heart the adress, but it's something like 0x20000), but I'm not sure if it will work.
I don't know if it can be stored in the audio RAM either as I've never tried it, so you can also give it a try if you want.

Try to declare it something like :

#define LOW_WORK_RAM (0x20000)  //I just typed something, don't copy it blindly as I'm not sure it's the right adress)
jo_sound * blop;

void        load_cop_sound(void)
{
            blop = (jo_sound*) (LOW_WORK_RAM);
            jo_audio_load_pcm("B.PCM",JoSoundMono8Bit, blop);
}

LackofTrack

  • Newbie
  • *
  • Posts: 6
  • Karma: +0/-0
    • View Profile
Re: A few questions about PCM functionality
« Reply #9 on: September 23, 2017, 03:19:20 am »
Both files individually seem to play just fine. It is when you load them together that you start to see problems.
I'll see if your Low Work Ram solution will work. Thanks for helping!

LackofTrack

  • Newbie
  • *
  • Posts: 6
  • Karma: +0/-0
    • View Profile
Re: A few questions about PCM functionality
« Reply #10 on: September 27, 2017, 02:39:56 am »
Sadly your idea didn't work XL2.
The actual address for low work ram is 0x00200000 but that didn't work either. It's not a big problem as it was just a test to see how well I can code. Thank all you guys for the help though!

XL2

  • Jr. Member
  • **
  • Posts: 99
  • Karma: +5/-0
    • View Profile
Re: A few questions about PCM functionality
« Reply #11 on: October 24, 2017, 06:15:03 am »
For me too it's a huge issue as 44100 hz files are just filling my RAM. I still have room in LWRAM, but I have other plans for it. The audio files (only little sounds) take around 250 kb, which is ridiculus for the length. 22050 hz audio would make it half that, and 11025 hz would me it even better.

Danny

  • Newbie
  • *
  • Posts: 32
  • Karma: +2/-0
    • View Profile
Re: A few questions about PCM functionality
« Reply #12 on: October 24, 2017, 10:03:15 am »
Has anyone used midi samples? They are quite small.
The Saturn has a great sound chip and midi should sound excellent!

XL2

  • Jr. Member
  • **
  • Posts: 99
  • Karma: +5/-0
    • View Profile
Re: A few questions about PCM functionality
« Reply #13 on: October 24, 2017, 03:52:48 pm »
Wouldn't MIDI be for music? Sadly I haven't played too much with audio yet so I don't know much about it, but I'll have to improve memory usage as RAM is limited!

 

Sitemap 1 2 3 4 5 6 7 8 9 10 
SMF spam blocked by CleanTalk