slPCMOn() Format Specification

slinga

Established Member
Sorry to keep spamming about slPCMOn(). I'm struggling with the documentation in the "SGL Developer's Manual." I'm trying to port code that currently uses Alsa with the following parameters: SND_PCM_FORMAT_S16_LE, SND_PCM_ACCESS_RW_INTERLEAVED, 1 channel, and I can modify the rate to 8000 or 44100.

1) I don't understand what format slPCMOn() takes in. Passing in my PCM stream in doesn't sound correct at all and the length feels shorter. I have tried swapping the endianness of the PCM stream and it sounds worse. I'm guessing the SND_PCM_ACCESS_INTERLEAVED is the problem but if I'm only outputting on one channel that shouldn't be the issue correct?
2) Jo Engine doesn't seem to set the PCM frequency anywhere:

Code:
typedef struct
{
    Uint8    mode ;        /* Mode */
    Uint8    channel ;    /* PCM Channel Number */
    Uint8    level ;        /* 0 ~ 127 */
    Sint8    pan ;        /* -128 ~ +127 */
    Uint16    pitch ;
    Uint8    eflevelR ;    /* Effect level for Right(mono) 0 ~ 7 */
    Uint8    efselectR ;    /* Effect select for Right(mono) 0 ~ 15 */
    Uint8    eflevelL ;    /* Effect level for Left 0 ~ 7 */
    Uint8    efselectL ;    /* Effect select for Left 0 ~ 15 */
} PCM ;

static PCM             __jo_internal_pcm[JO_SOUND_MAX_CHANNEL] =
{
    {(_Stereo | _PCM16Bit), 0, 127, 0, 0x0, 0, 0, 0, 0},
    {(_Stereo | _PCM16Bit), 2, 127, 0, 0x0, 0, 0, 0, 0},
    {(_Stereo | _PCM16Bit), 4, 127, 0, 0x0, 0, 0, 0, 0},
    {(_Stereo | _PCM16Bit), 6, 127, 0, 0x0, 0, 0, 0, 0},
    {(_Stereo | _PCM16Bit), 8, 127, 0, 0x0, 0, 0, 0, 0},
    {(_Stereo | _PCM16Bit), 10, 127, 0, 0x0, 0, 0, 0, 0},
};

Clearly the pitch is set to 0 and I don't see it get changed anywhere. What frequency does that correspond to? I've looked at Ponut's lib and I think I understand how to set the pitch value now.

Thanks in advance.
 
So stealing Ponut's frequency macros seemed to do the trick:

Code:
     octr = PCM_CALC_OCT(sa->rate);
    shiftr = PCM_CALC_SHIFT_FREQ(octr);
    fnsr = PCM_CALC_FNS(sa->rate, shiftr);

    pcmChannel.pitch = PCM_SET_PITCH_WORD(octr, fnsr);
 
Back
Top