TIGSource Forums

Developer => Technical => Topic started by: Relix on July 08, 2009, 06:38:56 AM



Title: Using PtTunes/PxTone in C++?
Post by: Relix on July 08, 2009, 06:38:56 AM
So, I'm trying to use the header file made by Pixel, but my compiler doesn't accept it (using Code::Blocks). I get punch of errors, already asked Pixel about them - which he didn't know how to fix.

Is there other options for using them, without chancing compiler or the programming language, I'd really like to use the PtTune format in my project.


Title: Re: Using PtTunes/PxTone in C++?
Post by: J.W. Hendricks on July 08, 2009, 06:42:32 AM
Well, I don't know ANYTHING about C++, but you can, however, convert PXTone files into .WAV and then convert them into .OGG via Audacity.


Title: Re: Using PtTunes/PxTone in C++?
Post by: Relix on July 08, 2009, 06:45:57 AM
But the idea is to use PtTunes and I'm positive that PtTunes are smaller than OGGs + you can easily make them loopable without messing with the code too much.


Title: Re: Using PtTunes/PxTone in C++?
Post by: William Laub on July 08, 2009, 03:43:43 PM
PxTone requires the windows api. I messed with is some a while ago, and might have gotten it to compile by adding include "windows.h" in a bunch of places including the pxtone include file. I never got it to play anything, though.

I also started working on a cross-platform pxtone player, but I got bogged down deciphering the file formats and gave up.


Title: Re: Using PtTunes/PxTone in C++?
Post by: Relix on July 08, 2009, 09:59:43 PM
Well got it to compile with that, thanks for that.

But can't hear anything either, it loads the song just fine, but no sounds.
A step in right direction, though.

Edit:
Success!

Instead of using DirectSound, you need to use wavemapper. So when initializing, the argument before last has to be false instead of true.

And big thanks for you Gold.


Title: Re: Using PtTunes/PxTone in C++?
Post by: William Laub on July 09, 2009, 05:51:01 AM
I have never managed to make it play sound. Would you mind posting some of your code?


Title: Re: Using PtTunes/PxTone in C++?
Post by: Relix on July 09, 2009, 06:08:21 AM
Quote from:  Cave Story
#include <pxtone.h>
#include "SDL/SDL.h"

const int Screen_Width = 800;
const int Screen_Height = 1;
const int Screen_Bpp = 32;
SDL_Surface *screen = NULL;

SDL_Event event;

bool init () {
    if (SDL_Init (SDL_INIT_EVERYTHING)==-1) {
        return false;
    }

    screen = SDL_SetVideoMode(Screen_Width, Screen_Height, Screen_Bpp, SDL_SWSURFACE);

    if (screen == NULL) {
        return false;
    }

    SDL_WM_SetCaption ("PtTunes!", NULL);

    return true;
}

void play () {
    char* song = "Whatever.pttune";
    pxtone_Ready(NULL, 2, 44100, 16, 0.1, false, NULL);
    pxtone_Tune_Load(NULL, NULL, song); /* ^ - this had to be false for me, for it to make sound. */
    pxtone_Tune_SetVolume(1.0f);
    pxtone_Tune_Start(0, 0);
}

int main (int arg, char* args[]) {
    bool quit = false;

    if (!init()) {
        return 1;
    }

    play();
    SDL_WM_SetCaption (pxtone_GetLastError() , NULL); // Displays the error, if any.

    while (!quit) {
        while (SDL_PollEvent(&event)) {
            if (event.type == SDL_QUIT) {
                quit = true;
            }
        }
    } // Infite loop until eXed out.

    pxtone_Release();

    return 0;
}

I'm using SDL, so I left the Window handle to be NULL, dunno if it matters though.
That + adding #include "windows.h" into the pxtone.h fixed it. Maybe you should check you sound card settings too, if this doesn't help.


Title: Re: Using PtTunes/PxTone in C++?
Post by: William Laub on July 09, 2009, 03:39:49 PM
Thank you. I use SDL as well, so this ought to be really helpful.


Title: Re: Using PtTunes/PxTone in C++?
Post by: Relix on July 10, 2009, 12:36:02 AM
Do tell, if that helped.