Error on the tutorial code... SGDK

SGDK only sub forum

Moderator: Stef

POLYGAMe
Very interested
Posts: 151
Joined: Sun Apr 14, 2013 1:19 am
Location: Auckland, New Zealand
Contact:

Error on the tutorial code... SGDK

Post by POLYGAMe » Fri May 03, 2013 7:01 am

Here's the code, as copied and pasted from the SGDK tutorial:

Code: Select all

#include <genesis.h>
#include "moon.h"

int main( )
{
        // get the image width (in pixel) ==> should be 8pix aligned
        u16 w = moon[0];
        // get the image height (in pixel)  ==> should be 8px aligned
        u16 h = moon[1];

        // get the palette at moon[2 to 17]
        VDP_setPalette(PAL1, &moon[2]);


        // load bitmap data at moon[18....] in VRAM
        // w/8 = width in tiles we want to load
        // h/8 = height in tile we want to load
        // w/8 = width in tiles of the bitamp
        // the 3rd arg is needed because you could load only a part of the bitmap if you want but SGDK needs the width as reference
        VDP_loadBMPTileData((u32*) &moon[18], 1, w / 8, h / 8, w/8 );


        while(1)
        {
                VDP_waitVSync();
        }
        return 0;
}
And I get the following errors:

main.c||In function `main':|
main.c|7|error: subscripted value is neither array nor pointer|
main.c|9|error: subscripted value is neither array nor pointer|
main.c|12|error: subscripted value is neither array nor pointer|
main.c|20|error: subscripted value is neither array nor pointer|
||=== Build finished: 4 errors, 0 warnings (0 minutes, 1 seconds) ===|

To be honest, I'm not even sure what the array moon[] is even pointing to... data in the moon.o file?!?!

Any help appreciated ;-)

Stef
Very interested
Posts: 3131
Joined: Thu Nov 30, 2006 9:46 pm
Location: France - Sevres
Contact:

Post by Stef » Fri May 03, 2013 8:13 am

Unfortunately the tutorial are outdated and some methods were replaced as some structures too.

moon has now be replaced by a Bitmap structure for easier manipulation so code become :

Code: Select all

        // get the image width (in pixel) ==> should be 8pix aligned
        u16 w = moon.w;
        // get the image height (in pixel)  ==> should be 8px aligned
        u16 h = moon.h;

        // get the palette
        VDP_setPalette(PAL1, moon.palette);


        // load bitmap data in VRAM
        // w/8 = width in tiles we want to load
        // h/8 = height in tile we want to load
        // w/8 = width in tiles of the bitamp
        // the 3rd arg is needed because you could load only a part of the bitmap if you want but SGDK needs the width as reference
        VDP_loadBMPTileData((u32*) moon.image, 1, w / 8, h / 8, w/8 ); 
I really need to update that tutorials :p

POLYGAMe
Very interested
Posts: 151
Joined: Sun Apr 14, 2013 1:19 am
Location: Auckland, New Zealand
Contact:

Post by POLYGAMe » Fri May 03, 2013 8:42 am

Stef wrote:Unfortunately the tutorial are outdated and some methods were replaced as some structures too.

moon has now be replaced by a Bitmap structure for easier manipulation so code become :

Code: Select all

        // get the image width (in pixel) ==> should be 8pix aligned
        u16 w = moon.w;
        // get the image height (in pixel)  ==> should be 8px aligned
        u16 h = moon.h;

        // get the palette
        VDP_setPalette(PAL1, moon.palette);


        // load bitmap data in VRAM
        // w/8 = width in tiles we want to load
        // h/8 = height in tile we want to load
        // w/8 = width in tiles of the bitamp
        // the 3rd arg is needed because you could load only a part of the bitmap if you want but SGDK needs the width as reference
        VDP_loadBMPTileData((u32*) moon.image, 1, w / 8, h / 8, w/8 ); 
I really need to update that tutorials :p
Great, thanks! I'll give it a go :)

POLYGAMe
Very interested
Posts: 151
Joined: Sun Apr 14, 2013 1:19 am
Location: Auckland, New Zealand
Contact:

Post by POLYGAMe » Fri May 03, 2013 9:12 am

Hmmm... I'm not getting any errors now, but it's displaying a blank screen when run :(

POLYGAMe
Very interested
Posts: 151
Joined: Sun Apr 14, 2013 1:19 am
Location: Auckland, New Zealand
Contact:

Post by POLYGAMe » Fri May 03, 2013 9:42 am

Okay, by commenting out the set palette line, I get my image in red. How do I get the palette from the actual image file? It seems to be ignoring the colour data in it...

POLYGAMe
Very interested
Posts: 151
Joined: Sun Apr 14, 2013 1:19 am
Location: Auckland, New Zealand
Contact:

Post by POLYGAMe » Fri May 03, 2013 12:17 pm

Nevermind, got it working :D

It was my image export settings in GIMP.

I sent this .bin to my old videogame dev tutor... LOL. Lucky we're friends :P

Image

Stef
Very interested
Posts: 3131
Joined: Thu Nov 30, 2006 9:46 pm
Location: France - Sevres
Contact:

Post by Stef » Fri May 03, 2013 12:52 pm

Hehe, excellent :D Glad you got it working correctly :)

POLYGAMe
Very interested
Posts: 151
Joined: Sun Apr 14, 2013 1:19 am
Location: Auckland, New Zealand
Contact:

Post by POLYGAMe » Fri May 03, 2013 1:15 pm

Stef wrote:Hehe, excellent :D Glad you got it working correctly :)
Got sound now too but my wav file is being played at different speeds, depending on the playback rate... I assumed the rate is just the quality... any ideas?

Stef
Very interested
Posts: 3131
Joined: Thu Nov 30, 2006 9:46 pm
Location: France - Sevres
Contact:

Post by Stef » Fri May 03, 2013 1:28 pm

POLYGAMe wrote:
Stef wrote:Hehe, excellent :D Glad you got it working correctly :)
Got sound now too but my wav file is being played at different speeds, depending on the playback rate... I assumed the rate is just the quality... any ideas?
The rate is indeed the quality but right now SGDK automatically convert any wav file to 16Khz sample as this is the sample rate used by 4 PCM sound driver. The first idea was to make it easier so people does not need to convert it to 16 Khz but then you cannot use the other available sample rate for the single PCM driver, or you have to use .raw file directly which is not practical. I have to thing about way of improving that...

POLYGAMe
Very interested
Posts: 151
Joined: Sun Apr 14, 2013 1:19 am
Location: Auckland, New Zealand
Contact:

Post by POLYGAMe » Fri May 03, 2013 10:03 pm

Stef wrote:
POLYGAMe wrote:
Stef wrote:Hehe, excellent :D Glad you got it working correctly :)
Got sound now too but my wav file is being played at different speeds, depending on the playback rate... I assumed the rate is just the quality... any ideas?
The rate is indeed the quality but right now SGDK automatically convert any wav file to 16Khz sample as this is the sample rate used by 4 PCM sound driver. The first idea was to make it easier so people does not need to convert it to 16 Khz but then you cannot use the other available sample rate for the single PCM driver, or you have to use .raw file directly which is not practical. I have to thing about way of improving that...
Okay, so what do I need to do to stop it adjusting the speed?!?

Stef
Very interested
Posts: 3131
Joined: Thu Nov 30, 2006 9:46 pm
Location: France - Sevres
Contact:

Post by Stef » Fri May 03, 2013 10:23 pm

If you play it at 16 Khz it should be at correct speed.
If you rename your file to .wavpcm then SGDK will convert your wav file to adpcm sound file, then you can use the 2ADPCM driver to play it (22 Khz but smaller rom usage as sample is compressed).

POLYGAMe
Very interested
Posts: 151
Joined: Sun Apr 14, 2013 1:19 am
Location: Auckland, New Zealand
Contact:

Post by POLYGAMe » Fri May 03, 2013 11:08 pm

Stef wrote:If you play it at 16 Khz it should be at correct speed.
If you rename your file to .wavpcm then SGDK will convert your wav file to adpcm sound file, then you can use the 2ADPCM driver to play it (22 Khz but smaller rom usage as sample is compressed).
So currently there's no way to play the sounds at higher quality, without adjusting speed?

kubilus1
Very interested
Posts: 237
Joined: Thu Aug 16, 2012 2:25 am
Contact:

Post by kubilus1 » Sat May 04, 2013 7:19 pm

Awesome, I see what I was doing wrong with BMP loading with the new method. Thanks!

Stef
Very interested
Posts: 3131
Joined: Thu Nov 30, 2006 9:46 pm
Location: France - Sevres
Contact:

Post by Stef » Sat May 04, 2013 9:42 pm

POLYGAMe wrote:
Stef wrote:If you play it at 16 Khz it should be at correct speed.
If you rename your file to .wavpcm then SGDK will convert your wav file to adpcm sound file, then you can use the 2ADPCM driver to play it (22 Khz but smaller rom usage as sample is compressed).
So currently there's no way to play the sounds at higher quality, without adjusting speed?
If you keep your file as .wav --> only 16 Khz play with the method

Code: Select all

SND_startPlay_PCM(...)
If you rename it to .wavpcm --> only 22 Khz play with the method

Code: Select all

SND_startPlay_2ADPCM(...)
If you convert it to binary file (8 bits signed) with tools as audacity or wavosaur and name your file with .raw extension then you can use whatever quality you want (always with

Code: Select all

SND_startPlay_PCM(...)
method).

Honestly 22Khz ADPCM is already quite good quality for the MD, you are quite limited on rom size.

POLYGAMe
Very interested
Posts: 151
Joined: Sun Apr 14, 2013 1:19 am
Location: Auckland, New Zealand
Contact:

Post by POLYGAMe » Sat May 04, 2013 10:37 pm

Stef wrote:
POLYGAMe wrote:
Stef wrote:If you play it at 16 Khz it should be at correct speed.
If you rename your file to .wavpcm then SGDK will convert your wav file to adpcm sound file, then you can use the 2ADPCM driver to play it (22 Khz but smaller rom usage as sample is compressed).
So currently there's no way to play the sounds at higher quality, without adjusting speed?
If you keep your file as .wav --> only 16 Khz play with the method

Code: Select all

SND_startPlay_PCM(...)
If you rename it to .wavpcm --> only 22 Khz play with the method

Code: Select all

SND_startPlay_2ADPCM(...)
If you convert it to binary file (8 bits signed) with tools as audacity or wavosaur and name your file with .raw extension then you can use whatever quality you want (always with

Code: Select all

SND_startPlay_PCM(...)
method).

Honestly 22Khz ADPCM is already quite good quality for the MD, you are quite limited on rom size.
Thanks! That helps heaps :)

Post Reply